<%@ 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 rsResourceAuthorizeDialogJs={
         resourceId : "${resourceId}",
         dialog : frameElement.dialog,
         $form: $("#div_look_form"),//表单对象
         $id: $("#inp_resource_id"),//资源数据源
         $btnSave: $("#btn_save"),//保存按钮对象
         $btnCancel: $("#btn_cancel"),//关闭按钮对象
         $rightDG: $("#div_look_right_datgrid"),//右边的datagrid
         $leftDG: $("#div_look_left_datgrid"),//左边的datagrid
         $div_look_form: $("#div_look_form"),//layout对象
         $searchBtn: $("#div_look_form_inp_search"),//查找对象
         $btnToRight: $("#btn_toright"),//向右的按钮
         $btnToLeft: $("#btn_toleft"),//向左的按钮
         init: function () {
             this.bindEvents();
             this.initlayout();
             this.getGridData();
         },
         getGridData: function () {
             $.ajax({
                 type: "POST",
                 url: "${contextRoot}/resource/resource/getResourceApp",
                 data: {"id": rsResourceAuthorizeDialogJs.resourceId},
                 success: function (msg) {
                     rsResourceAuthorizeDialogJs.initDatagrid(msg.data);
                 }
             });
         },
         initlayout: function () {
             //初始化layout
             this.$div_look_form.ligerLayout({
                 leftWidth: 260,
                 rightWidth: 250,
                 centerWidth: 60,
                 bottomHeight: 40,
                 height:"98%",
                 topHeight: 40,
                 isLeftCollapse: false,//左边区域初始化不可以隐藏
                 isRightCollapse: false,//左边区域初始化不可以隐藏
                 allowLeftCollapse: false,//左边区域不可以隐藏
                 allowRightCollapse: false,//左边区域不可以隐藏
                 allowRightResize: false,
                 allowLeftResize: false,
                 allowBottomResize: false,
                 allowTopResize: false
             });
             //隐藏layout左右两边的标题
             $("#div_look_form .l-layout-left .l-layout-header").hide();
             $("#div_look_form .l-layout-right .l-layout-header").hide();
             //l-layout-left
             $("#div_look_form .l-layout-left").css({"border": "0px"});
             $("#div_look_form .l-layout-right").css({"border": "0px"});
             $("#div_look_form .l-layout-center").css({"border": "0px"});
             $("#div_look_form .l-layout-top").css({"border": "0px"});
             $("#div_look_form .l-layout-bottom").css({"border": "0px"});
         },
         bindEvents: function () {
             var self = this;
             this.$btnSave.click(function () {
                 var rows = rsResourceAuthorizeDialogJs.$rightDG.rows;
                 var ids = "";
                 //拼凑ids
                 for (var i = 0; i < rows.length; i++) {
                     ids += rows[i].id;
                     if (i != rows.length - 1) {
                         ids += ",";
                     }
                 }
                 $.ajax({
                     type: "POST",
                     url: "${contextRoot}/resource/resource/updateResourceApp",
                     data: {"resourceId": rsResourceAuthorizeDialogJs.resourceId, "ids": ids},
                     success: function (data) {
                         if (data.successFlg) {
                             window.parent.reResourceAuthorize.dialogSuccess(data.message, "1");
                         }
                         else {
                             $.ligerDialog.error(data.message);
                         }
                     }
                 });
             });

             this.$btnCancel.click(function () {
                 rsResourceAuthorizeDialogJs.dialog.close();
             });
             this.$searchBtn.ligerTextBox({
                 width: 180
             });

             this.$btnToRight.click(function () {
                 var row = rsResourceAuthorizeDialogJs.$leftDG.getSelected();
                 rsResourceAuthorizeDialogJs.$leftDG.deleteRow(row);
                 rsResourceAuthorizeDialogJs.$rightDG.addRow( {"name": row.name, "id": row.id});
             });
             this.$btnToLeft.click(function () {
                 var row = rsResourceAuthorizeDialogJs.$rightDG.getSelected();
                 rsResourceAuthorizeDialogJs.$rightDG.deleteRow( row);
                 rsResourceAuthorizeDialogJs.$leftDG. addRow( {"name": row.name, "id": row.id});
             });

         },
         initDatagrid: function (data) {
             var this$rightDG = this.$rightDG;
             var this$leftDG = this.$leftDG;
             this.$rightDG = this.$rightDG.ligerGrid({
                 columns: [
                     {display: '全流程(已授权)', name: 'name', width: '90%', isAllowHide: false}
                 ],
                 rownumbers: false,//不显示行号
                 allowAdjustColWidth: false,//不可以调整列宽
                 validate: true,
                 width: 200,
                 height: 360,
                 fitColumn: false,
                 data: {detailModelList: data.select},
                 usePager: false,//不显示分页
                 onDblClickRow: function (data, rowid, rowdata) {
                     this$rightDG.ligerGrid("deleteRow", rowdata);//
                     this$leftDG.ligerGrid("addRow", {"name": data.name, "id": data.id});
                 }
             });

             this.$leftDG = this.$leftDG.ligerGrid({
                 columns: [
                     {display: '全流程(未授权)', name: 'name', width: '90%', isAllowHide: false}
                 ],
                 validate: true,
                 rownumbers: false,
                 allowAdjustColWidth: false,
                 width: 200,
                 data: {detailModelList: data.noSelect},
                 fitColumn: false,
                 height: 360,
                 usePager: false,//不显示分页
                 onDblClickRow: function (data, rowid, rowdata) {
                     this$leftDG.ligerGrid("deleteRow", rowdata);
                     this$rightDG.ligerGrid("addRow", {"name": data.name, "id": data.id});
                 }
             });
         }
     }

     $(function () {
         rsResourceAuthorizeDialogJs.init();
     });
</script>