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

    /* *************************** 模块初始化 ***************************** */
    var dimension = {
        $leftSearch: $("#div_wrapper_left_inp_search"),
        $leftTree: $("#dimension_tree"),
        $rightGrid: $("#div_grid"),
        $rightSearch: $("#txtName"),
        $layout: $("#div_wrapper"),
        $newDimension: $("#div_new_dimension"),
        $dialog: null,
        init: function () {
            this.initLayout();
            this.initLeft();
            this.initRight();
        },
        initLayout: function () {
            this.$layout = this.$layout.ligerLayout({
                leftWidth: 200,
                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-left .l-layout-header").hide();

        },
        initLeft: function () {
            this.$leftSearch = this.$leftSearch.ligerTextBox({
                width: 200, isSearch: true, onChangeValue: function (value) {
                    if (value != "" && value != null && value != undefined && value.length > 0) {

                    }
                }
            });
            $.ajax({
                type: "POST",
                url: "${contextRoot}/dimension/getDimensionCategoryList",
                success: function (msg) {
                    dimension.$leftTree = dimension.$leftTree.ligerTree({
                        data: msg.data,
                        checkbox: false,
                        nodeWidth: 200,
                        idFieldName: 'id',
                        textFieldName: 'name',
                        parentIDFieldName: 'pid',
                        isExpand: false,
                        onClick: function (obj) {
                            dimension.$rightGrid.loadServerData({dimensionCategoryId: obj.data.id});
                        },
                        onSuccess: function (data) {

                        }
                    });
                    //修改样式
                    $("#menu_tree span").css({"line-height": "2", "font-weight": "normal"});
                }
            });
        },
        initRight: function () {
            this.$newDimension.click(function () {
                dimension.editorDialog();
            });
            this.$rightSearch = this.$rightSearch.ligerTextBox({
                width: 200, isSearch: true, onChangeValue: function (value) {
                    if (value != "" && value != null && value != undefined && value.length > 0) {

                    }
                }
            });
            this.$rightGrid = this.$rightGrid.ligerGrid({
                url: '${contextRoot}/dimension/getDimensionList',
                columns: [
                    {display: '维度名称', id: 'name', name: 'name', width: '30%'},
                    {
                        display: '维度类型', name: 'type', width: '30%', render: function (row) {
                        if (row.type == "1") {
                            return "字符串";
                        } else if (row.type == "2") {
                            return "字典";
                        } else if (row.type == "3") {
                            return "日期";
                        }
                    }
                    },
                    {display: '维度字典', name: 'dictCode', width: '20%'},
                    {
                        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=\"dimension.editorDialog('"+row.id+"', 'modify')\"></a>";
                        html += "<a class=\"m-btn-delete\" onclick=\"dimension.delete('"+row.id+"')\"></a>";
                        html += '</div>';
                        return html;
                    }
                    }
                ],
                onDblClickRow: function (row) {
                    dimension.editorDialog(row.id);
                },
                parms: {
                    rows: 10000
                }
            });
        },
        delete: function (id) {
            jQuery.ligerDialog.confirm("否是删除?", function (confirm) {
                if (confirm) {
                    $.ajax({ //ajax处理
                        type: "POST",
                        url: "${contextRoot}/dimension/deleteDimension",
                        dataType: "json",
                        data: {id: id},
                        cache: false,
                        success: function (data) {
                            if (data.successFlg) {
                                parent.dimension.dialogSuccess(data.message);
                            }
                            else {
                                $.ligerDialog.error(data.message);
                            }
                        },
                        error: function (data) {
                            $.ligerDialog.error("Status:" + data.status + "(" + data.statusText + ")");
                        }
                    });
                }
            })
        }, dialogSuccess: function (message) {
            $.ligerDialog.success(message);
            this.$rightGrid.reload();
            this.$dialog.close();
        },
        editorDialog: function (id) {
            var me = this;
            var title = "新增维度信息";
            var params = null;
            if (id != undefined && id != null) {
                title = "编辑维度信息";
                params = {id: id};
            }

            this.$dialog = $.ligerDialog.open({
                height: 300,
                width: 600,
                title: title,
                url: '${contextRoot}/dimension/editorDimension',
                //load: true,
                urlParms: params
            });
        }
    };

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