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

    /* *************************** 模块初始化 ***************************** */
    var dimensioncate = {
        grid: null,
        dialog: null,
        init: function () {
            var me = this;
            $('.m-retrieve-area').show();

            me.grid = $("#div_grid").ligerGrid({
                url: '${contextRoot}/dimension/getDimensionCatecoryList',
                parms: {
                    name: $('#txtName').val()
                },
                columns: [
                    {display: '类别名称', id: 'name', name: 'name', width: '70%'},
                    {
                        display: '操作', name: 'operator', width: '30%', render: function (row) {
                        var html = '<div class="m-inline-buttons" style="width:80px;">';
                        html += "<a class=\"m-btn-edit\" onclick=\"dimensioncate.editorDialog('"+row.id+"', 'modify')\"></a>";
                        html += "<a class=\"m-btn-delete\" onclick=\"dimensioncate.delete('"+row.id+"')\"></a>";
                        html += '</div>';

                        return html;
                    }
                    }
                ],
                onDblClickRow: function (row) {
                    me.editorDialog(row.id);
                }
            });
            me.bindEvents();

        },
        bindEvents: function () {
            var me = this;
            $('#btn_search').click(function () {
                me.reloadGrid();
            });
            $('#div_new_record').click(function () {
                me.editorDialog();
            });
        },
        delete:function(id){
            var message = "确定要删除该类别吗？";

            jQuery.ligerDialog.confirm(message, function (confirm) {
                if (confirm)
                {
                    $.ajax({ //ajax处理
                        type: "POST",
                        url : "${contextRoot}/dimension/deleteDimensionCatetory",
                        dataType : "json",
                        data:{id:id},
                        cache:false,
                        success :function(data){
                            if(data.successFlg) {
                                $.ligerDialog.success(data.message);
                                dimensioncate.grid.reload();
                            }
                            else{
                                $.ligerDialog.error(data.message);
                            }
                        },
                        error :function(data){
                            $.ligerDialog.error("Status:"+data.status +"(" +data.statusText+")");
                        }
                    });
                }
            });
        },
        //刷新列表数据
        reloadGrid: function () {
            this.grid.set({
                parms: {name: $('#txtName').val()}
            });
            this.grid.reload();
        },
        //编辑弹窗
        editorDialog: function (id) {
            var me = this;
            var title = "新增维度类别";
            var params = null;
            if (id != undefined && id != null) {
                title = "编辑维度类别";
                params = {"id": id};
            }

            me.dialog = $.ligerDialog.open({
                height: 260,
                width: 500,
                title: title,
                url: '${contextRoot}/dimension/editorDimensionCatetory',
                //load: true,
                urlParms: params
            });
        },
        anthorize: function (id) {

        },
        //弹窗返回
        dialogSuccess: function (message) {
            $.ligerDialog.success(message);
            this.reloadGrid();
            this.dialog.close();
        }
    };

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