<%@ 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">
    (function ($, win) {
        /* ************************** 变量定义 ******************************** */
        var Util = $.Util;
        var stdInfoForm = null;

        var dialog = frameElement.dialog;

        /* *************************** 函数定义 ******************************* */
        function pageInit() {
            stdInfoForm.init();
        }

        /* *************************** 模块初始化 ***************************** */
        stdInfoForm = {
            $form: $("#div_std_info_form"),
            $code: $("#inp_std_code"),
            $name: $("#inp_std_name"),
            $type: $("#inp_std_type"),
            $id: $("#id"),
            $description: $("#inp_std_description"),

            $btnSave: $("#btn_save"),
            $btnCancel: $("#btn_cancel"),

            init: function () {
                this.initForm();
                this.bindEvents();
            },
            initForm: function () {
                this.initDDL(1, this.$type);
                this.$name.ligerTextBox({width:240,validate:{required:true }});
                this.$code.ligerTextBox({width:240,validate:{required:true }});
                this.$type.ligerTextBox({width:240 });
                this.$description.ligerTextBox({width:240,height:180 });

                this.$form.attrScan();
                this.$form.Fields.fillValues({
                    name:'${std.name}',
                    code: '${std.code}',
                    type:'${std.sourceType}',
                    id:'${std.id}',
                    description:'${std.description}'
                });

                this.$form.show();
            },
            initDDL: function (dictId, target) {
                target.ligerComboBox({
                    data : [{code:'11111',value:'类型1'},{code:'22222',value:'类型2'},{code:'33333',value:'类型3'}],
                    <%--url: "${contextRoot}/dict/searchDictEntryList",--%>
                    dataParmName: 'detailModelList',
                    urlParms: {dictId: dictId},
                    valueField: 'code',
                    textField: 'value'
                });
            },

            bindEvents: function () {
                var self = this;
                this.$btnSave.click(function () {
                    self.$btnSave.attr('disabled','disabled');
                    var values = self.$form.Fields.getValues();
                    if($.trim(values.code)==''|| $.trim(values.name)==''){
                        $.Notice.warn('*号为必填项');
                        self.$btnSave.removeAttr('disabled');
                        return;
                    }
                    var dataModel = $.DataModel.init();
                    dataModel.updateRemote("${contextRoot}/standardsource/updateStdSource",{data: $.extend({}, values),
                        success: function(data) {
                            if(data.successFlg){
                                var app = data.obj;
                                //调用主页面接口，重新刷新Grid
                                parent.reloadMasterGrid();
                                parent.closeDialog('保存成功');
//                                dialog.close();
                            }else{
                                if(data.errorMsg)
                                    $.ligerDialog.error( data.errorMsg);
                                else
                                    $.ligerDialog.error( '出错了！');
                            }
                            self.$btnSave.removeAttr('disabled');
                        },
                        error: function () {
                            $.ligerDialog.error( '出错了！');
                            self.$btnSave.removeAttr('disabled');
                        }
                    });
                });

                this.$btnCancel.click(function () {
                    dialog.close();
                });
            }
        };

        /* *************************** 页面初始化 **************************** */
        pageInit();

    })(jQuery, window);
</script>