<%@ 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 dialog = frameElement.dialog;
    var adapterInfo = null;

    //适配方案变量
    var adapterPlanModel = null;
    var adapterType = 21;
    var type;

    /* ************************** 变量定义结束 **************************** */

    /* *************************** 函数定义 ******************************* */
    /**
     * 页面初始化
     */
    function pageInit() {
      adapterInfo.init();
    }

    /* ************************** 函数定义结束 **************************** */

    /* *************************** 模块初始化 ***************************** */
    adapterInfo = {
      $form: $("#div_adapter_info_form"),
      $id:$("#id"),
      $type: $('#ipt_type'),
      $code: $("#ipt_code"),
      $name: $('#ipt_name'),
      $version: $('#ipt_version'),
      $org: $('#ipt_org'),
      $parent: $('#ipt_parent'),
      $description: $('#ipt_description'),

      $updateAdapterBtn: $("#btn_save"),
      $cancelBtn: $("#btn_cancel"),
      init: function () {
        this.initForm();
        this.bindEvents();
      },
      initForm: function () {
        var self = this;
        self.$form.removeClass("m-form-readonly");
        self.$type.ligerComboBox(
                {
                  url: '${contextRoot}/dict/searchDictEntryList',
                  valueField: 'code',
                  textField: 'value',
                  dataParmName: 'detailModelList',
                  urlParms: {
                    dictId: adapterType
                  },
                  onSelected: function(value) {
                    self.$org.ligerComboBox(
                            {
                              url: '${contextRoot}/adapter/getOrgList',
                              valueField: 'code',
                              textField: 'value',
                              dataParmName: 'detailModelList',
                              urlParms: {
                                type: value
                              }
                            });
                    self.$parent.ligerComboBox(
                            {
                              url: '${contextRoot}/adapter/getAdapterPlanList',
                              valueField: 'code',
                              textField: 'value',
                              dataParmName: 'detailModelList',
                              urlParms: {
                                type: value
                              }
                            });
                  }
                });

        self.$code.ligerTextBox({width: 240});
        self.$name.ligerTextBox({width: 240});
        self.$version.ligerComboBox(
                {
                  url: '${contextRoot}/standardsource/getVersionList',
                  valueField: 'code',
                  textField: 'value',
                  dataParmName: 'detailModelList',
                  urlParms: {
                    dictId: 4
                  }
                });
        self.$org.ligerComboBox(
                {
                  data: null
                });
        self.$parent.ligerComboBox(
                {
                  data:null
                });
        self.$description.ligerTextBox({width: 240, height: 180});
        if ('${mode}' == 'new') {
          self.$type.removeClass("u-ui-readonly");
          self.$version.removeClass("u-ui-readonly");
          self.$org.removeClass("u-ui-readonly");
          self.$parent.removeClass("u-ui-readonly");
          self.$description.removeClass("u-ui-readonly");
        }else if ('${mode}' == 'modify') {
          //设值
          self.$form.attrScan();
          self.$form.Fields.fillValues({
            id:'${adapterPlan.id}',
            type: '${adapterPlan.type}',
            code: '${adapterPlan.code}',
            name: '${adapterPlan.name}',
            version: '${adapterPlan.version}',
            org: '${adapterPlan.org}',
            parentId: '${adapterPlan.parentId}',
            description: '${adapterPlan.description}'
          });
          //不可编辑 //todo:还不行
          self.$type.addClass("u-ui-readonly");
          self.$version.addClass("u-ui-readonly");
          self.$org.addClass("u-ui-readonly");
          self.$parent.addClass("u-ui-readonly");
          self.$description.addClass("u-ui-readonly");
        }
      },
      bindEvents: function () {
        var self = this;
        //修改用户的点击事件
        this.$updateAdapterBtn.click(function () {
          self.$form.attrScan();
          adapterPlanModel = self.$form.Fields.getValues();
          var dataModel = $.DataModel.init();
          dataModel.createRemote("${contextRoot}/adapter/updateAdapterPlan", {
            data: adapterPlanModel,
            success: function (data) {
              if (data.successFlg) {
                //$.Notice.open({type: 'success', msg: '修改成功！'});
                //调用主页面接口，重新刷新Grid
                parent.reloadAdapterMasterGrid();
              } else {
                //$.Notice.open({type: 'error', msg: data.errorMsg});
              }
              dialog.close();
            }
          })
        });
        this.$cancelBtn.click(function () {
          dialog.close();
        });
      }


    };

    /* ************************* 模块初始化结束 ************************** */

    /* *************************** 页面初始化 **************************** */

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

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