<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="utf-8" %>
<%@include file="/WEB-INF/ehr/commons/jsp/commonInclude.jsp" %>

<script type="text/javascript">
    var rsCategoryInfo = {
        init: function () {
            this.initForm();
            this.bindEvents();
        },
        initForm: function () {

            var mode = '${mode}';
            /*
             if(mode == 'view'){
             $("input,select", this.$form).prop('disabled', false);
             }
             */
            //初始化下拉框

            $("#inp_dialog_parent_category").ligerComboBox({
                url: "${contextRoot}/resource/rsCategory/getCategoryWithOutId",
                dataParmName: 'detailModelList',
                urlParms: {id: '${model.id}'},
                valueField: 'id',
                textField: 'name'
            });
            $("#inp_dialog_status").ligerComboBox({dict: true, dictName: "SYSTEM_STATUS"});

            var data = {
                name: '${model.name}',
                pid: '${model.pid}',
                status: '${model.status}'
            };

            if(data.pid!=""){
                $("#inp_dialog_parent_category").ligerComboBox().setDisabled("true");
            }
            $("#rsCategoryInfoForm").ligerAutoForm({
                data:data,
                validate:{
                    status:"required",
                    name: {
                        required:true
                    }
                }
            });

        },
        bindEvents: function () {
            $("#btn_save").click(function () {
                if(!$("#rsCategoryInfoForm").ligerAutoForm("validate"))
                {
                    return;
                }
                var data = $("#rsCategoryInfoForm").ligerAutoForm("getData");
                data.id='${model.id}';
                debugger
                if ('${mode}' == 'new') {
                    $.ajax({ //ajax处理
                        type: "POST",
                        url: "${contextRoot}/resource/rsCategory/createCategory",
                        dataType: "json",
                        data:data,
                        cache: false,
                        success: function (data) {
                            if (data.successFlg) {
                                //调用主页面接口，重新刷新Grid
                                parent.window.rsCategoryManage.dialogCallBack(data.message);
                            } else {
                                $.ligerMethos.AutoForm.showError($("#name"),"资源名称重复");
                            }
                        },
                        error: function (data) {
                            $.ligerDialog.error(data.message);
                        }
                    });
                } else {
                    $.ajax({ //ajax处理
                        type: "POST",
                        url: "${contextRoot}/resource/rsCategory/updateCategory",
                        dataType: "json",
                        data: data,
                        cache: false,
                        success: function (data) {
                            if (data.successFlg) {
                                //调用主页面接口，重新刷新Grid
                                parent.window.rsCategoryManage.dialogCallBack(data.message);
                            } else {
                                $.ligerDialog.error(data.message);
                            }
                        },
                        error: function (data) {
                            $.ligerDialog.error(data.message);
                        }
                    });
                }
            });

            $("#btn_cancel").click(function () {
                parent.rsCategoryManage.appInfoDialog.close();
            });
        }
    };
    $(function () {
        rsCategoryInfo.init();
    });
</script>