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

    /* *************************** 模块初始化 ***************************** */
    var resourceRest = {
        $layout: $("#div_wrapper"),//layout对象
        $dictname: $("#dictname"),//字典输入框
        $dictItemName: $("#dictItemName"),//字典项输入框
        $btnADDDict: $("#btn_dict"),//新增字典
        $btnADDdictItem: $("#btn_dict_item"),//新增字典项
        $dictGrid: $("#dict_grid"),//字典datagrid
        $dictItemGrid: $("#dictItem_grid"),//字典datagrid
        $dialog:null,
        init: function () {
            this.initLayout();
            this.initButton();
            this.initGrid();
        },
        initLayout: function () {
            this.$layout.ligerLayout({
                height:"98%",
                leftWidth: 370,
                isLeftCollapse: false,//左边区域初始化不可以隐藏
                allowLeftCollapse: false//左边区域不可以隐藏
            });
            $("#div_wrapper .l-layout-left").css({"border": "0px"});
            $("#div_wrapper .l-layout-right").css({"border": "0px"});
            $("#div_wrapper .l-layout-center").css({"border": "0px"});
            $("#div_wrapper .l-layout-top").css({"border": "0px"});
            $("#div_wrapper .l-layout-bottom").css({"border": "0px"});
            $("#div_wrapper .l-layout-left .l-layout-header").hide();

        },
        initButton: function () {
            resourceRest.$dictname.ligerSearch({

                width: 200,onClick: function (value) {
                    resourceRest.$dictGrid.set({
                        parms: {categoryId: $("#dictname").val()}
                    });
                    resourceRest.$dictGrid.reload();
                    resourceRest.$dictGrid.changePage("first");
                }
            });
            resourceRest.$dictItemName.ligerSearch({
                width: 200,onClick: function (value) {
                    var selectRow=resourceRest.$dictGrid.getSelectedRow();
                    var param={resourceRestName: $("#dictItemName").val()};
                    if(selectRow){
                        param.resourceRestId=selectRow.id;
                    }
                    resourceRest.$dictItemGrid.set({
                        parms: param
                    });
                    resourceRest.$dictItemGrid.reload();
                    resourceRest.$dictItemGrid.changePage("first");
                }
            });
            this.$btnADDDict.click(function(){
                resourceRest.editorResourceRestDialog();
            });
            this.$btnADDdictItem.click(function(){
                resourceRest.editorResourceRestDetailDialog();
            });
        },
        editorResourceRestDialog: function (resourceRestId) {
            var title = "新增业务资源信息";
            var params = null;
            if (resourceRestId != undefined && resourceRestId != null) {
                title = "编辑业务资源信息";
                params = {id: resourceRestId,mode:"modify"};
            }

            this.$dialog = $.ligerDialog.open({
                height: 330,
                width: 600,
                title: title,
                url: '${contextRoot}/resourceRest/resourceRestDialog',
                //load: true,
                urlParms: params
            });
        },
        deleteResourceRest: function (resourceRestId) {

            var message = "确定要删除业务资源吗？";

            jQuery.ligerDialog.confirm(message, function (confirm) {
                if (confirm)
                {
                    $.ajax({ //ajax处理
                        type: "POST",
                        url : "${contextRoot}/resourceRest/deleteResourceRest",
                        dataType : "json",
                        data:{id:resourceRestId},
                        cache:false,
                        success :function(data){
                            if(data.successFlg) {
                                $.ligerDialog.success(data.message);
                                resourceRest.$dictGrid.reload();
                                resourceRest.$dictGrid.changePage("first");
                            }
                            else{
                                $.ligerDialog.error(data.message);
                            }
                        },
                        error :function(data){
                            $.ligerDialog.error("Status:"+data.status +"(" +data.statusText+")");
                        }
                    });
                }
            });
        },
        editorResourceRestDetailDialog: function (resourceRestDetailId) {
            var title = "新增业务资源项信息";
            var params = null;
            if (resourceRestDetailId != undefined && resourceRestDetailId != null) {
                title = "编辑业务资源项信息";
                params = {id: resourceRestDetailId,mode:"modify"};
            }

            this.$dialog = $.ligerDialog.open({
                height: 520,
                width: 600,
                title: title,
                url: '${contextRoot}/resourceRest/resourceRestDetailDialog',
                //load: true,
                urlParms: params
            });
        },
        deleteResourceRestDetail: function (resourceRestDetailId) {

            var message = "确定要删除该业务资源项吗？";

            jQuery.ligerDialog.confirm(message, function (confirm) {
                if (confirm)
                {
                    $.ajax({ //ajax处理
                        type: "POST",
                        url : "${contextRoot}/resourceRest/deleteResourceRestDetail",
                        dataType : "json",
                        data:{id:resourceRestDetailId},
                        cache:false,
                        success :function(data){
                            if(data.successFlg) {
                                $.ligerDialog.success(data.message);
                                resourceRest.$dictItemGrid.reload();
                                resourceRest.$dictItemGrid.changePage("first");
                            }
                            else{
                                $.ligerDialog.error(data.message);
                            }
                        },
                        error :function(data){
                            $.ligerDialog.error("Status:"+data.status +"(" +data.statusText+")");
                        }
                    });
                }
            });
        },
        //弹窗返回
        dialogSuccess: function (message,reloadType) {
            $.ligerDialog.success(message);
            if("1"==reloadType){
                resourceRest.$dictGrid.reload();
                resourceRest.$dictGrid.changePage("first");
            }else{
                resourceRest.$dictItemGrid.reload();
                resourceRest.$dictItemGrid.changePage("first");
            }
            this.$dialog.close();
        },
        initGrid: function () {
            this.$dictGrid=this.$dictGrid.ligerGrid({
                url: '${contextRoot}/resourceRest/getResourceRestList',
                columns: [
                    {display: '业务资源名称', name: 'name', width: '25%'},
                    {display: 'url', name: 'url', width: '47%'},
                    {
                        display: '操作', name: 'operator', width: '25%', render: function (row) {
                        var html = '<div class="m-inline-buttons" style="width:80px;">';
                        html += "<a class=\"m-btn-edit\" onclick=\"resourceRest.editorResourceRestDialog('"+row.id+"')\"></a>";
                        html += "<a class=\"m-btn-delete\" onclick=\"resourceRest.deleteResourceRest('"+row.id+"')\"></a>";
                        html += '</div>';
                        return html;
                    }
                    }
                ],
                alternatingRow: false,
                checkbox: false,
                heightDiff: -10,
                headerRowHeight: 40,
                height:"96%",
                rowHeight: 40,
                onDblClickRow:function(data,rowid,rowdata) {
                    resourceRest.editorResourceRestDialog(data.id);
                },
                onSelectRow:function(rowdata, rowid, rowobj) {
                    //resourceRest.$dictItemGrid.loadServerData({resourceRestId:rowdata.id});
                   // resourceRest.$dictItemGrid.changePage("first");
                    resourceRest.$dictItemGrid.set({
                        parms: {resourceRestId:rowdata.id}
                    });
                    resourceRest.$dictItemGrid.reload();
                    resourceRest.$dictItemGrid.changePage("first");
                }
            });
            this.$dictItemGrid= this.$dictItemGrid.ligerGrid({
                url: '${contextRoot}/resourceRest/getResourceRestDetilList',
                columns: [
                    {display: '业务资源项名称', name: 'name', width: '20%', align: "center"},
                    {display: '业务资源项代码', name: 'code', width: '20%', align: "center"},
                    {display: '命名空间', name: 'namespace', width: '40%', align: "center"},
                    {
                        display: '操作', name: 'operator', width: '17%', render: function (row) {
                        var html = '<div class="m-inline-buttons" style="width:80px;">';
                        html += "<a class=\"m-btn-edit\" onclick=\"resourceRest.editorResourceRestDetailDialog('"+row.id+"')\"></a>";
                        html += "<a class=\"m-btn-delete\" onclick=\"resourceRest.deleteResourceRestDetail('"+row.id+"')\"></a>";
                        html += '</div>';
                        return html;
                    }
                    }
                ],
                alternatingRow: false,
                checkbox: false,
                height:"96%",
                heightDiff: -10,
                onDblClickRow:function(data,rowid,rowdata) {
                    resourceRest.editorResourceRestDetailDialog(data.id);
                },
                headerRowHeight: 40,
                rowHeight: 40,
            });
        },
    };

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