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

    /* *************************** 模块初始化 ***************************** */
    var processor = {
        grid: null,
        dialog: null,
        init: function () {
            var me = this;
            $('.m-retrieve-area').show();
            $("#txtName").ligerSearch({
                onClick:function(value){
                    me.reloadGrid();
                }});
            me.grid = $("#div_grid").ligerGrid({
                url: '${contextRoot}/processor/getProcessorList',
                parms: {
                    name: $('#txtName').val()
                },
                columns: [
                    {display: '转换器名称', id: 'id', name: 'name', width: '20%'},
                    {display: '类名', name: 'className', width: '10%'},
                    {display: '包名', name: 'packageName', width: '40%'},
                    {
                        display: '操作', name: 'operator', width: '30%', render: function (row) {

                        var html = '<div class="m-inline-buttons" style="width:350px;">';
                        html += "<a class=\"m-btn\" style=\"padding-right:10px\" onclick=\"processor.dialogDetail('"+row.id+"')\">查看详情</a>";
                        html += "<a class=\"m-btn-edit\" onclick=\"processor.editorDialog('"+row.id+"')\"></a>";
                        html += "<a class=\"m-btn-delete\" onclick=\"processor.delete('"+row.id+"')\"></a>";
                        html += '</div>';
                        return html;
                    }
                    }
                ],
                onDblClickRow: function (row) {
                    me.editorDialog(row.id,row.appId);
                }
            });
            me.bindEvents();

        },
        bindEvents: function () {
            var me = this;

            $('#div_new_record').click(function () {
                var appId= "${appId}";
                me.editorDialog(null,appId);
            });

            $(".l-text").css("display","inline-block");
            $(".l-text-wrapper").css("display","inline-block");

        },
        delete:function(id){
            var message = "服务删除后无法恢复，是否确认删除？";

            jQuery.ligerDialog.confirm(message, function (confirm) {
                if (confirm)
                {
                    $.ajax({ //ajax处理
                        type: "POST",
                        url : "${contextRoot}/processor/deleteProcessor",
                        dataType : "json",
                        data:{id:id},
                        cache:false,
                        success :function(data){
                            if(data.successFlg) {
                                $.ligerDialog.success(data.message);
                                processor.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,appId) {
            var me = this;
            var title = "新增转换器";
            var params = null;
            if (id != undefined && id != null) {
                title = "编辑转换器";
                params = {"id": id};
            }

            me.dialog = $.ligerDialog.open({
                height: 400,
                width: 600,
                title: title,
                url: '${contextRoot}/processor/editorProcessor',
                //load: true,
                urlParms: params
            });
        },
        dialogDetail: function (id) {
            var me = this;
            var title = "转换器详情";
            var params = null;
            if (id != undefined && id != null) {
                params = {"id": id};
            }

            me.dialog = $.ligerDialog.open({
                height: 400,
                width: 600,
                title: title,
                url: '${contextRoot}/processor/processorDetail',
                //load: true,
                urlParms: params
            });
        },
        //弹窗返回
        dialogSuccess: function (message) {
            $.ligerDialog.success(message);
            this.reloadGrid();
            this.dialog.close();
        }


    };

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