var user = {
    name: "demo",
    chinesename: "",
    rights: {
        "load": false,
        "addFeature": false,
        "addFeaturePartition": false,
        "adminSub ": true,
        "addCourse ": true,
        "searchProblem": false,
        "calProblem": false,
    }
}
Ext.BLANK_IMAGE_URL = "images/s.gif";
Ext.QuickTips.init();
Ext.lib.Ajax.defaultPostHeader += ";charset=utf-8";
Ext.form.Field.prototype.msgTarget = "side";

//var USERCONFIG = { "userName": "s003" };
var TEMP_GRID = null;
// JScript 文件
Ext.namespace('Ext.ux.form'); //fck编辑器的命名
Ext.ns('Ext.ux.grid');//grid扩展的命名空间

Ext.namespace('Ext.ux.maximgb.treegrid');//gridTree的命名

Ext.namespace("Ext.ux.tree");//tree扩展的命名

Ext.namespace("TestGen");//智能组卷
Ext.namespace("CommonCmp");//公用组件
Ext.namespace("UserGroup");//用户组

Ext.namespace("Ext.ux.StatusBar");

Ext.namespace("NatureTest");//在线考试
var JS_NatureUserCmp = "js/NatureUserCmp_20230206.js?v2.1.2";
var JS_NaturePaperCmp = "js/NaturePaperCmp.v2152.js?v215";
var JS_NaturePaperAnalyseCmp = "js/NaturePaperAnalyseCmp_20200825.js";
var JS_NatureProblemCmp = "js/NatureProblemCmp.v2152.js?v2.1.5";
var JS_NatureTxtToDBCmp = "js/NatureTxtToDBCmp_20231114.js?v2.1.2";
var JS_NatureSubCourseCmp = "js/NatureSubCourseCmp.js?v2024";
var JS_NatureTestArrangeCmp = "js/NatureTestArrangeCmp.v2151.js";
var JS_NatureMarkPapersAdminCmp = "js/NatureMarkPapersAdminCmp_20200102.js?v2.1.5";
var JS_NatureScoreAdminCmp = "js/NatureScoreAdminCmp_20230508.js";
var JS_NatureResourcesCmp = "js/NatureResourcesCmp_20240521.js";
var JS_SXYKDXScoreAdminCmp = "js/SXYKDXScoreAdminCmp.js";
var JS_NaturePracticeArrangeCmp = "js/NaturePracticeArrangeCmp_20230116.js";
var JS_NatureTestMonitorCmp = "js/NatureTestMonitorCmp_20230905.js?v202407"
var JS_NatureSystemSettingCmp = "js/NatureSystemSettingCmp.js?v2023";
//LoadRights();
function LoadRights() {
    //var CONFIG=localStorage.getItem("natureexam_settings", _data);

    var _rights = CONFIG["Rights"];
    var words = CryptoJS.enc.Base64.parse(_rights);
    var strRights = CryptoJS.enc.Utf8.stringify(words);
    var RIGHTS = JSON.parse("[" + strRights + "]");
    //console.log("权限项目:" + strRights);
    user.rights["addUser"] = (RIGHTS.indexOf(2) < 0);
    user.rights["adminUser"] = (RIGHTS.indexOf(1) < 0);
    user.rights["addPaper"] = (RIGHTS.indexOf(61) < 0);
    user.rights["addFeature"] = (RIGHTS.indexOf(11) < 0);
    user.rights["addFeaturePartition"] = (RIGHTS.indexOf(12) < 0);
    //user.rights["adminSub"] = (RIGHTS.indexOf(51) < 0);
    user.rights["addCourse"] = (RIGHTS.indexOf(31) < 0);
    user.rights["addProblem"] = (RIGHTS.indexOf(51) < 0);
    user.rights["searchProblem"] = (RIGHTS.indexOf(53) < 0);
    user.rights["calProblem"] = (RIGHTS.indexOf(54) < 0);
    user.rights["load"] = true;
}

var nature = {

    event_handle: function (_node) {
        //id:menu_nature_showgrid_12，title:课程设置urls:#nature.showgrid:12
        //#nature.showgrid:12
        //#nature.showgrid:53,arrangeid:3423 '考试监控
        //#nature.showgrid?action=showmonitor53&arrangeid=232
        if (!user.rights.load) {
            LoadRights();
        }

        //先占坑，然后后面填充进来。

        var menu_id = 0;
        var querystring = "";
        //console.log(_node.id.substring(0, 9));
        //console.log(_node.id.substring(9));
        //{ title:"" urls:""}
        if (_node.urls.substring(8, 15) == "showtab") {
            if (_node.urls.substring(15, 16) == "?") {
                //#nature.showgrid?action=showtestsetting&paperID=232
                querystring = _node.urls.substring(16);
            } else {
                menu_id = parseInt(_node.urls.substring(16));
            }
            return;
        }
        if (_node.urls.substring(8, 16) == "showgrid") {
            if (_node.urls.substring(16, 17) == "?") {
                //#nature.showgrid?action=showmonitor53&arrangeid=232
                querystring = _node.urls.substring(17);
            } else {
                menu_id = parseInt(_node.urls.substring(17));
            }
        } else if (_node.urls.substring(8, 15) == "showwin") {
            if (_node.urls.substring(15, 16) == "?") {
                //#nature.showgrid?action=showtestsetting&paperID=232
                querystring = _node.urls.substring(16);
            } else {
                menu_id = parseInt(_node.urls.substring(16));
            }
            //menu_id = parseInt(_node.urls.substring(16));
        }
        //showc
        console.log("menu_id:" + menu_id)
        //menu_nav_
        //try {
        //    //写入新消息数，用户名称。

        //    layui.$('#admin_username').text(USERCONFIG["userName"]);
        //    if (USERCONFIG["messageCount"] > 0) {
        //        layui.$("#admin_newmessage").css("display", "display");
        //    } else {
        //        layui.$("#admin_newmessage").css("display", "none");
        //    }
        //    //layui.jquery('#panel_newmessage', USERCONFIG["userName"]);
        //    console.log("渲染登录账号信息!");
        //} catch (e) {
        //    alert(e.message);
        //}
        if (menu_id == 0) {
            if (querystring != "") {
                //
                var para = {};
                var arr_para = querystring.split("&");
                for (var k = 0; k < arr_para.length; k++) {
                    var temp_para = arr_para[k].split("=");
                    if (temp_para.length == 2) {
                        para[temp_para[0]] = temp_para[1];
                    } else if (temp_para.length == 1) {
                        para[temp_para[0]] = "";
                    }
                }

                if (para["action"] == "showmonitor") {
                    console.log("打开监控窗口。" + querystring);
                    var arrangeID = para["arrangeID"];
                    //
                    nature.ShowMonitor(arrangeID);
                } else if (para["action"] == "showtestsetting") {
                    console.log("打开考试设置。" + querystring);
                    var paperID = para["paperID"];
                    //
                    nature.ShowTestSettingWin(paperID);
                } else if (para["action"] == "showteststudents") {
                    console.log("学生管理。" + querystring);
                    var paperID = para["paperID"];
                    //
                    nature.ShowTestStudentsWin(paperID);
                } else if (para["action"] == "showpaperedit") {
                    console.log("打开考试设置。" + querystring);
                    var paperID = para["paperID"];
                    //
                    nature.ShowPaperEdit(paperID);
                } else if (para["action"] == "showpaperprint") {
                    console.log("打开考试设置。" + querystring);
                    var paperID = para["paperID"];
                    //
                    nature.ShowPaperPrint(paperID);
                } else if (para["action"] == "showproblemimport") {
                    console.log("打开考试设置。" + querystring);
                    var paperID = para["courseID"];
                    //
                    nature.ShowProblemImport(paperID);
                } else if (para["action"] == "showcoursestat") {
                    console.log("打开考试设置。" + querystring);
                    var paperID = para["courseID"];
                    //
                    nature.ShowCourseStat(paperID);
                } else if (para[action] == "showuser")
                {
                    //TODO:建设中。
                    var userID = para["userid"];
                    layui.layer.alert("显示用户"+userID);
                }
            }
        }
        else if (menu_id == 11) {//指标设置
            Load.js(["js/NatureFeatureCmp.js"], function () {
                var grid = new FeatureListGridPanel({
                    featureButton: user.rights["addFeature"],
                    partitionButton: user.rights["addFeaturePartition"]
                });
                nature.addPanel(_node, grid, "", 0);

            });

        } else if (menu_id == 12) {//专业课程设置
            try {
                Load.js([JS_NatureSubCourseCmp], function () {
                    nature.addPanel(_node, new SubjectCoursePanel({
                        subButton: user.rights["adminSub"],//是否有专业管理的权限
                        addCourseButton: user.rights["addCourse"]//是否有课程增删改的权限
                    }), "");
                });
            } catch (e) {
                alert(e.message);
            }
        } else if (menu_id == 13) {//备份数据库
            new CommonCmp.BackUpDatabaseWin().show();
        } else if (menu_id == 14) {//审核设置
            console.log("click:" + _node.id);
            Load.js([JS_NatureSystemSettingCmp], function () {
                nature.addPanel(_node, new CheckSettingPanel(), "");
            });

        } else if (menu_id == 15) {//个人中心设置
            Load.js([JS_NatureSystemSettingCmp], function () {
                nature.addPanel(_node, new StudentCenterSettingPanel(), "");
            });

        } else if (menu_id == 16) {//考试服务器设置

            Load.js([JS_NatureSystemSettingCmp], function () {
                new TestServerSettingWin().show();
            });
        } else if (menu_id == 17) {//新版本的系统设置
            Load.js([JS_NatureSystemSettingCmp], function () {
                nature.addPanel(_node, "", "", 2);
            });
        } else if (menu_id == 19) {//分支机构授权
            Load.js([JS_NatureSystemSettingCmp], function () {
                nature.addPanel(_node, new BranchModulesControlPanel(), "");
            });

        } else if (menu_id == 21) {//角色管理
            console.log("click:" + menu_id);
            Load.js(["js/NatureRoleCmp.js"], function () {
                //"js/NatureRoleCmp.js"
                //if (!getTBarOfAddButtonByModuleID(ModuleIDs["adminRole"])) {//有角色管理权限 UpdateUserGroupWin.js中双击tree节点修改角色需要权限验证
                try {
                    var grid = new RoleListGridPanel();
                    nature.addPanel(_node, grid, "");
                } catch (e) {
                    alert("new RoleListGridPanel err" + e);
                }
                //}
            });
        } else if (menu_id == 22) {//用户组管理	
            Load.js([JS_NatureUserCmp], function () {
                //if (!getTBarOfAddButtonByModuleID(ModuleIDs["adminUser"])) {//拥有用户管理权限才可以进入用户组管理
                nature.addPanel(_node, new UserGroup.UserGroupListPanel(), "");
                //}
            });
        } else if (menu_id == 23) {//用户管理
            console.log(user.rights);
            Load.js([JS_NatureUserCmp], function () {
                nature.addPanel(_node, new UserListPanel({
                    //后面再修改为通过CONFIG获得权限项。
                    addUserButton: user.rights["addUser"], adminUserButton: user.rights["adminUser"]
                    //    addUserButton: getTBarOfAddButtonByModuleID(ModuleIDs["addUser"]),//添加用户权限
                    //    adminUserButton: getTBarOfAddButtonByModuleID(ModuleIDs["adminUser"])//有用户管理权限时才可以进行批量操作和导入/导出
                }), "");
            });
        } else if (menu_id == 24) {//用户日志
            Load.js([JS_NatureUserCmp], function () {
                nature.addPanel(_node, new UserLogListPanel(), "");
            });
        } else if (menu_id == 31) {//智能组卷	
            Load.js([JS_NaturePaperCmp], function () {
                //REMOVETESTGENWINDOW({ showWindow: true });

                //addPanel(_node,new PaperAdjustPanel(),"",0,mainPanel);	
                //menu_nav_31
                //TODO：试卷编辑窗口。
                //var obj = layui.jquery("ul>li[lay-id=menu_nav_35]");
                //alert(obj);
                console.log(user.rights["addPaper"]);
                if (!nature.getTabComponent("31")) {
                    if (!user.rights["addPaper"]) {//有增加试卷的权限
                        //Ext.getBody().mask("加载中...");
                        layui.layer.msg("加载中...");
                        localStorage.setItem("PaperDesignID", '');
                        localStorage.setItem("PaperDesignTitle", "智能组卷向导");
                        //(
                        //function () {
                        localStorage.setItem("PaperDesignID", '');
                        localStorage.setItem("PaperDesignTitle", "智能组卷向导");
                        var _win = new TestGenWin();
                        _win.on("show", function () {
                            //Ext.getBody().unmask();
                            layui.layer.closeAll();
                        });
                        _win.show();
                        //}
                        //).defer(100, this);
                    }
                } else {
                    layui.layer.msg("请关闭正在编辑中的试卷...");
                }

            });
        } else if (menu_id == 32) {//试卷管理
            Load.js([JS_NaturePaperCmp, JS_NatureTxtToDBCmp, JS_NatureTestMonitorCmp, JS_NatureTestArrangeCmp], function () {
                if (Ext.getCmp("32")) {
                    //如果此panel存在则删除
                    RemoveCurTab("32");
                }
                nature.addPanel(_node, new PaperAdminPanel({
                    addPaperButton: user.rights["addPaper"]//是否有增加试卷的权限
                }), "");
            });
        } else if (menu_id == 33) {//试卷管理
            Load.js([JS_NaturePaperCmp], function () {
                if (Ext.getCmp("33")) {
                    //如果此panel存在则删除
                    RemoveCurTab("33");
                }
                nature.addPanel(_node, new QDQTExamPlanPanel({
                    addPaperButton: user.rights["addPaper"]//是否有增加试卷的权限
                }), "");
            });
        } else if (menu_id == 55) {//试卷分析
            //addPanel(_node,"","",2,mainPanel);	   
            Load.js([JS_NaturePaperAnalyseCmp], function () {
                //var anchor_id = "nature-grid-#nature.showgrid:43";
                if (!nature.getTabComponent("55")) {
                    new PaperAnalyseCardWin().show();
                }
            });
        } else if (menu_id == 41) {//试题检索
            //如果没有ProblemPanel，渲染ProblemPanel.
            //href:"#nature.showgrid:43"
            //condition: AdvanceSearchShow.....
            if (!nature.getTabComponent("43")) {
                layui.admin.render({ id: "#nature.showgrid:43", urls: "#nature.showgrid:43", title: "试题管理", "condition": "showsearchwin" });
            } else {
                //窗口已存在，触发_problemPanel的事件。
                alert("窗口已经打开，尝试触发搜索！");
                //layui.admin.setTab("#nature.showgrid:43");
                layui.element.tabChange('swiftadmin-tabs', "#nature.showgrid:43");
                var _problemPanel = Ext.getCmp("ext_panel_#nature.showgrid:43").items.itemAt(0);
                _problemPanel._rightPanel._rightGrid.onAdvanceSearchShow.defer(1000, _problemPanel._rightPanel._rightGrid);
            }


            //Load.js([JS_NatureProblemCmp, JS_NatureTxtToDBCmp, JS_NatureSubCourseCmp], function () {
            //    var _problemPanel = new ProblemPanel({
            //        addProblemButton: user.rights["addProblem"],//添加试题的权限
            //        searchProblemButton: user.rights["searchProblem"]//搜索试题的权限
            //    });

            //    nature.addPanel({ id: "#nature.showgrid:43", urls: "#nature.showgrid:43", title: "试题管理" }, _problemPanel, "");
            //    //TODO:打开
            //    //41.admin.render({
            //    //});
            //    //_problemPanel._rightPanel._rightGrid.onAdvanceSearchShow.defer(1000, _problemPanel._rightPanel._rightGrid);

            //});

        } else if (menu_id == 42) {//试题统计
            Load.js([JS_NatureProblemCmp], function () {
                if (!user.rights["calProblem"]) {//有权限试题统计
                    new ProblemStatisticsWin().show();
                } else {
                    unPermissionsMsg(false);
                }
            });
        } else if (menu_id == 43) {//试题管理
            Load.js([JS_NatureProblemCmp, JS_NatureTxtToDBCmp, JS_NatureSubCourseCmp], function () {
                layui.layer.load(1);
                var _problemPanel = new ProblemPanel({
                    addProblemButton: user.rights["addProblem"],//添加试题的权限
                    searchProblemButton: user.rights["searchProblem"]//搜索试题的权限
                });
                nature.addPanel(_node, _problemPanel, "");
                if ("showsearchwin" == _node.condition) {
                    _problemPanel._rightPanel._rightGrid.onAdvanceSearchShow.defer(1000, _problemPanel._rightPanel._rightGrid);
                    layui.layer.closeAll();
                }
            });
        } else if (menu_id == 44) {//文本转库
            Load.js([JS_NatureTxtToDBCmp, JS_NatureSubCourseCmp], function () {
                //Ext.getBody().mask("加载中...");
                (function () {
                    var _win = new ImportDataWin();
                    _win.on("show", function () {
                        //Ext.getBody().unmask();
                    });
                    _win.show();
                }).defer(100, this);
            });
        } else if (menu_id == 49) {//新建试题
            //Ext.getBody().mask("加载中...");
            (function () {
                AddNewProblem();
            }).defer(100, this);
        } else if (menu_id == "51") {//考试安排固定试卷
            if (CONFIG["ExamAdmin"] == false) {
                //
                layui.layer.msg("尚未开通考试功能，请联系技术支持！");
                return;
            }
            Load.js([JS_NatureTestMonitorCmp, JS_NatureTestArrangeCmp], function () {
                //if (Ext.getCmp("51")) {
                //    //如果此panel存在则删除
                //    RemoveCurTab("51");
                //}
                nature.addPanel(
                _node, new NatureTest.SettingPaperPanel({ UserLoginName: user.name }), "");
                //addPanel(_node, new NatureTest.SettingPaperPanel(), "");
            });
        } else if (menu_id == 52) {//考试监控
            if (CONFIG["ExamAdmin"] == false) {
                //
                layui.layer.msg("尚未开通考试功能，请联系技术支持！");
                return;
            }
            Load.js([JS_NatureTestMonitorCmp], function () {
                new TestPaperListWin().show();
            });
        } else if (menu_id == 56) {//成绩管理(考试)
            if (CONFIG["ExamAdmin"] == false) {
                //
                layui.layer.msg("尚未开通考试功能，请联系技术支持！");
                return;
            }
            Load.js([JS_NatureSystemSettingCmp, JS_NatureScoreAdminCmp, JS_NatureTestArrangeCmp, JS_NaturePaperAnalyseCmp], function () {
                new ScoreAdminWin().show();
            });
        } else if (menu_id == 59) {//成绩管理(部门成绩查询)
            if (CONFIG["ExamAdmin"] == false) {
                //
                layui.layer.msg("尚未开通考试功能，请联系技术支持！");
                return;
            }
            Load.js([JS_NatureSystemSettingCmp, JS_NatureScoreAdminCmp, JS_NatureTestArrangeCmp, JS_NaturePaperAnalyseCmp], function () {
                new ScoreAdminWin({ mode: "GroupAdmin" }).show();
            });
        } else if (menu_id == 141) {////学期管理（山西医科大学定制）

            Load.js([JS_SXYKDXScoreAdminCmp], function () {
                nature.addPanel(_node, new SemesterPanel(), "");
            });
        }
        else if (menu_id == 142) {//课程成绩管理（山西医科大学定制）

            Load.js([JS_SXYKDXScoreAdminCmp], function () {
                nature.addPanel(_node, new CourseScoreAdminPanel(), "");
            });
        }
        else if (menu_id == 143) {//成绩查询（山西医科大学定制）
            if (CONFIG["ExamAdmin"] == false) {
                //
                layui.layer.msg("尚未开通考试功能，请联系技术支持！");
                return;
            }
            Load.js([JS_SXYKDXScoreAdminCmp,JS_NatureUserCmp], function () {
                nature.addPanel(_node, new UserScoreQueryPanel(), "");
            });
        }
        else if (menu_id == 144) {//留级预警（山西医科大学定制）

            Load.js([JS_SXYKDXScoreAdminCmp], function () {
                nature.addPanel(_node, new UserBelowMarkQueryPanel(), "");
            });
        }
        else if (menu_id == 81) {//作业安排
            Load.js(["js/NatureHomeWorkArrangeCmp_20231025.js", JS_NatureTestArrangeCmp], function () {
                nature.addPanel(_node, new NatureTest.HomeWorkingListPanel(), "");
            });
        } else if (menu_id == 82) {//批改作业
            Load.js([JS_NatureMarkPapersAdminCmp], function () {
                new NatureTest.MarkPapersListWin({ type: "markWork" }).show();
            });

        } else if (menu_id == 83) {//作业成绩管理
            Load.js([JS_NatureScoreAdminCmp], function () {
                new ScoreAdminWin({ type: "scoreWork" }).show();
            });
        } else if (menu_id == 54) {//批改试卷
            if (CONFIG["ExamAdmin"] == false) {
                //
                layui.layer.msg("尚未开通考试功能，请联系技术支持！");
                return;
            }
            Load.js([JS_NatureMarkPapersAdminCmp], function () {
                new NatureTest.MarkPapersListWin({ type: "markPaper" }).show();
            });
        } else if (menu_id == 57) {//准考证管理
            if (CONFIG["ExamAdmin"] == false) {
                //
                layui.layer.msg("尚未开通考试功能，请联系技术支持！");
                return;
            }
            Load.js(["js/jquery-migrate-1.4.1.js", "StudentCenter/Exam/js/xheditor-1.1.14-zh-cn.min.js", "js/NatureTicketAdminCmp.js"], function () {
                nature.addPanel(_node, new Ticket.TicketManageMentPanel(), "");
            });

        } else if (menu_id == 58) {//课程总评设置
            if (CONFIG["ExamAdmin"] == false) {
                //
                layui.layer.msg("尚未开通考试功能，请联系技术支持！");
                return;
            }
            Load.js([JS_NatureScoreAdminCmp], function () {
                nature.addPanel(_node, new CourseTotalScoreSettingPanel(), "");
            });
        } else if (menu_id == 61) {//学习安排，练习设置
            if (CONFIG["ExamAdmin"] == false) {
                //
                layui.layer.msg("尚未开通练习功能，请联系技术支持！");
                return;
            }
            //练习页面设置
            Load.js([JS_NaturePracticeArrangeCmp, JS_NatureTestArrangeCmp], function () {
                nature.addPanel(_node, new PracticeAdminPanel(), "");
            });
        } else if (menu_id == 62) {//练习统计
            if (CONFIG["ExamAdmin"] == false) {
                //
                layui.layer.msg("尚未开通练习功能，请联系技术支持！");
                return;
            }
            Load.js([JS_NaturePracticeArrangeCmp], function () {
                nature.addPanel(_node, new PracticeStatisticsGrid(), "");
            });
        } else if (menu_id == 63) {//练习记录
            if (CONFIG["ExamAdmin"] == false) {
                //
                layui.layer.msg("尚未开通练习功能，请联系技术支持！");
                return;
            }
            Load.js([JS_NaturePracticeArrangeCmp], function () {
                nature.addPanel(_node, new PracticeRecordsPanel(), "");
            });
        } else if (menu_id == 91) {  //充值卡管理
            if (CONFIG["ExamAdmin"] == false) {
                //
                layui.layer.msg("尚未开通练习功能，请联系技术支持！");
                return;
            }
            Load.js(["js/NatureAccountAdminCmp.js"], function () {
                nature.addPanel(_node, new PrePaidCard(), "");
            });
        } else if (menu_id == 92) {  //积分消费统计
            Load.js(["js/NatureAccountAdminCmp.js"], function () {
                nature.addPanel(_node, new ConsumptionManagementGrid(), "");
            });
        } else if (menu_id == 93) {  //充值消费统计
            Load.js(["js/NatureAccountAdminCmp.js"], function () {
                nature.addPanel(_node, new RechargeConsumptionStatisticsGrid(), "");
            });
        } else if (menu_id == 94) {  //充值消费统计
            Load.js(["js/NatureAccountAdminCmp.js"], function () {
                nature.addPanel(_node, new BalanceGrid(), "");
            });
        } else if (menu_id == 95) {  //积分金额设置
            Load.js(["js/NatureAccountAdminCmp.js"], function () {
                nature.addPanel(_node, new IntegralMoneySetting(), "");
            });
        } else if (menu_id == 101) {  //资源类别管理ResourcesManagement.js
            Load.js([JS_NatureResourcesCmp], function () {
                nature.addPanel(_node, new ResourcesCategoryManagement(), "");
            });
        } else if (menu_id == 102) {  //资源管理
            Load.js([JS_NatureResourcesCmp, JS_NatureSubCourseCmp], function () {
                nature.addPanel(_node, new ResourcesManagementPanel(), "");
            });
        } else if (menu_id == 103) {  //文库管理
            Load.js([JS_NatureResourcesCmp], function () {
                nature.addPanel(_node, new LibraryManagement(), "");
            });
        } else if (menu_id == 104) {  //课件浏览统计
            Load.js([JS_NatureResourcesCmp], function () {
                nature.addPanel(_node, new coursewareBSGridPanel(), "");
            });

        } else if (menu_id == 105) {  //文库浏览统计
            Load.js([JS_NatureResourcesCmp], function () {
                nature.addPanel(_node, new libraryBSGridPanel(), "");
            });

        } else if (menu_id == 106) {  //课程统计
            Load.js([JS_NatureResourcesCmp], function () {
                nature.addPanel(_node, new learnStatiGridPanel(), "");
            });
        } else if (menu_id == 107) {  //学习签到
            Load.js([JS_NatureResourcesCmp], function () {
                nature.addPanel(_node, new learnProjectSignPanel(), "");
            });
        } else if (menu_id == 111 || menu_id == 112 || menu_id == 113) {
            nature.addPanel(_node, "", "", 2);
        }

        else if (menu_id == 121) {  //问卷管理
            Load.js(["js/NatureQuestionnaireCmp.js", JS_NatureTxtToDBCmp, JS_NatureTestArrangeCmp, JS_NaturePaperAnalyseCmp], function () {
                if (Ext.getCmp("questionnaireStatisticsLoad")) {
                    //如果此panel存在则删除

                    RemoveCurTab("questionnaireStatisticsLoad");
                }
                nature.addPanel(_node, new QuestionnaireStatisticsPanel(), "");
                //nature.addPanel(
                //    { id: "questionnaireStatisticsLoad", text: "问卷" },
                //    new QuestionnaireStatisticsPanel(), "", 0);
            });
        }
        else if (menu_id == 122) {  //查询部门问卷结果。
            Load.js(["js/NatureQuestionnaireCmp.js", JS_NatureTxtToDBCmp, JS_NatureTestArrangeCmp, JS_NaturePaperAnalyseCmp], function () {
                if (Ext.getCmp("questionnaireStatisticsLoad")) {
                    //如果此panel存在则删除

                    RemoveCurTab("questionnaireStatisticsLoad");
                }
                nature.addPanel(_node, new QuestionnaireStatisticsPanel({ mode: "query" }), "");
                //nature.addPanel(
                //    { id: "questionnaireStatisticsLoad", text: "问卷" },
                //    new QuestionnaireStatisticsPanel({ mode: "query" }), "");
            });
        }
        else if (menu_id == 131) {  //学分统计
            Load.js(["js/NatureCreditCmp.js"], function () {
                nature.addPanel(_node, new creditStatisticsGridPanel(), "");
            });
        }
        else {
            if (_node.attributes.hrefTarget == "_self") {
                window.location.href = _node.attributes.href;
                location.replace(_node.attributes.href);
                event.returnValue = false;
            } else {
                openWin(_node.attributes.href);
            }
        }
    }
   ,
    addPanel: function (_node, _grid, iconCls, style, anchor) {
        var anchor_id = "nature-grid-" + _node.urls.substring(17);
        console.log("渲染ext.grid到:" + anchor_id);
        //TODO: if no tab, addTab
        var _content = layui.jquery(".layui-tab-content");
        var _height = layui.jquery(".layui-tab-content").height();
        console.log("height1:" + _height);
        console.log("height2:" + _height);

        _height = _height - 10;

        if (_height < 0) {
            _height = 750;
        }
        console.log("height3:" + _height);


        var SubPanel = Ext.extend(Ext.Panel, {
            id: "ext_panel_" + _node.id,
            bodyStyle: "line-height:20px;",
            style: "padding:15px;",//background-color:#dfe8f6;
            //cls: "x-border-layout-ct",
            //title: "<span style='padding-top:3px;padding-left:1px;'>" + "node_test" + "</span>",
            //iconCls: iconCls,
            //closable: true,
            autoScroll: true,
            height: _height,
            //height: "max-content",
            //border:false,
            layout: "fit"
        });

        var _panel = new SubPanel({
            items: [_grid], renderTo: anchor_id,
            listeners: {
                "activate": function () {
                    //var _height = layui.jquery(".layui-tab-content").height();
                    //var _width = layui.jquery(".layui-tab-content").width();

                    //console.log("resize：" + "_height:" + _height + ",_width:" + _width);
                    //var submain = Ext.getCmp(Atab + "_main");
                    ////alert(submain);
                    //if (submain) {
                    //    console.log("ActiveTabSize:" + Atab + "_main,w:" + w + ",h:" + h);
                    //    submain.setWidth(w);
                    //    submain.setHeight(h);
                    //}
                    //ActiveTabSize(tabPanel)

                } //这里加了个激活时的侦听动作，目的是切换Tab页时改变对应页面内容里的内容大小
                , "resize": function () {
                    //var _height = layui.jquery(".layui-tab-content").height();
                    //var _width = layui.jquery(".layui-tab-content").width();

                    //console.log("resize：" + "_height:" + _height + ",_width:" + _width);

                }
            }
        }
            );
        console.log("渲染ext.grid完毕1!");
        //SubPanel.add(grid);
        console.log("渲染ext.grid完毕2!");


    }
    ,
    ShowMonitor: function (arrangeID) {
        layui.$.ajax({
            url: "../admin/handler/arranges.ashx",
            type: "post",
            data: { "action": "GetArrangeInfo", "arrangeID": arrangeID },
            success: function (pResult) {
                var _data = eval("(" + pResult + ")")
                ///
                //加载考试监控窗口。
                //console.log("onEnterMonitor:0");
                //_selRecord.data["problemCount"] = pResult["problemCount"];
                //_selRecord.data["addTestTime"] = pResult["addTestTime"];
                //_selRecord.data["timeType"] = pResult["timeType"];
                //var _paperName = Ext.util.Format.ellipsis(_selRecord.get("paperName"), 30);
                //var _arrangeName = Ext.util.Format.ellipsis(_selRecord.get("arrangeName"), 10);
                //console.log("onEnterMonitor:" + _paperName + "," + _arrangeName);

                //if (UIMODE == "NEWUI") {
                console.log("onEnterMonitor:2,NEWUI");
                Load.js([JS_NatureTestMonitorCmp], function () {
                    addPanel2({ id: "testMonitor" + _data.arrangeID, text: _data.paperName + "--" + _data.arrangeName },
                         new MonitorStudentListPanel({ rowHeight: 30, selRecordData: _data }));
                    //var _node = {};
                    //_node.id = "#nature.showgrid?action=showmonitor&arrangeID=" + arrangeID;
                    //_node.urls = "#nature.showgrid?action=showmonitor&arrangeID=" + arrangeID;
                    //_node.title = _data.paperName + "--" + _data.arrangeName;
                    //nature.addPanel(
                    //_node, new MonitorStudentListPanel({ rowHeight: 30, selRecordData: _data }), "");
                    //console.log("onEnterMonitor:3,addPanel2 over");

                });
                console.log("onEnterMonitor:4,close over");
                //} else {

                //}
            }
        });
    }
    , ShowTestSettingWin: function (paperID) {
        //考试设置窗口显示。
        Load.js([JS_NatureTestArrangeCmp], function () {
            //考试设置窗口。
            var pid, pName;
            var pName = "试卷001";
            var activeIndex = 1;
            //if (this.selModel.getCount() == 0) {
            //    pid = paperID;
            //    pName = paperName;
            //} else {
            //    pid = this.selModel.getSelections()[0].get("paperID");
            //    pName = this.selModel.getSelections()[0].get("paperName");
            //}
            var _win = new NatureTest.SettingPaperAdminWin({
                paperID: paperID,
                title: "" + GetLangString(Examinationarrangement.Examination_arrangement) + "--[" + pName + "]"//考试安排
            });
            _win.show();
            if (activeIndex) {
                _win.tab.getLayout().setActiveItem(1);//激活tab

            }
            //_win.on("winclose", function () { this.store.reload(); }, this);

        });
    }, ShowTestStudentsWin: function (paperID) {
        //考试设置窗口显示。
        Load.js([JS_NatureTestArrangeCmp], function () {
            //考试设置窗口。
            layui.layer.msg("考生管理，功能修改中...");

            //var pid, pName;
            //var pName = "";
            //var activeIndex = 1;
            ////if (this.selModel.getCount() == 0) {
            ////    pid = paperID;
            ////    pName = paperName;
            ////} else {
            ////    pid = this.selModel.getSelections()[0].get("paperID");
            ////    pName = this.selModel.getSelections()[0].get("paperName");
            ////}
            //var _win = new NatureTest.SettingPaperAdminWin({
            //    paperID: paperID,
            //    title: "" + GetLangString(Examinationarrangement.Examination_arrangement) + "--[" + pName + "]"//考试安排
            //});
            //_win.show();
            //if (activeIndex) {
            //    _win.tab.getLayout().setActiveItem(1);//激活tab

            //}
            //_win.on("winclose", function () { this.store.reload(); }, this);

        });
    }, ShowPaperEdit: function (paperID) {
        Load.js([JS_NaturePaperCmp], function () {
            layui.$.ajax({
                url: 'Paper/PaperAdmin/Data/PaperAdminLoadPaper.aspx',
                type: "post",
                data: { action: "", paperID: paperID },
                success: function (pResult) {
                    var _editPaperPanel = new PaperAdjustPanel({
                        paperID: paperID,
                        isSavePaper: true,//edit by lxj 2012-05-21 新增审核试卷时不可以修改试卷
                        allowPrint: true,
                        allowExport: true
                    });
                    addPanel2({ id: "31", text: GetLangString(papermanagement.Edit_test_paper) }, _editPaperPanel);//编辑试卷
                }
            });

            //CommonAjaxRequest(
            //'Paper/PaperAdmin/Data/PaperAdminLoadPaper.aspx',
            //{ action: "", paperID: this._paperID },
            //this.activeRequestLoadPaper, this, function () {
            //    var _editPaperPanel = new PaperAdjustPanel({
            //        paperID: this._paperID,
            //        isSavePaper: true,//edit by lxj 2012-05-21 新增审核试卷时不可以修改试卷
            //        allowPrint: this.getRowSelectedRecords()[0].get("OptionsBehavior")["isPrint"],
            //        allowExport: this.getRowSelectedRecords()[0].get("OptionsBehavior")["isExport"]
            //    });
            //        addPanel2({ id: "31", text: GetLangString(papermanagement.Edit_test_paper) }, _editPaperPanel);//编辑试卷

            //}, pFailureFun, this.ownerCt
            //);


        });
    }, ShowPaperPrint: function (paperID) {
        //var _paperID = this.getRowSelectedRecords()[0].get("paperID");
        Load.js([JS_NaturePaperCmp], function () {
            new PrintPaperWin({
                title: GetLangString(papermanagement.examination_paper_print),//试卷打印
                type: "paperPrint",
                paperID: paperID,
                allowPrint: true,
                allowExport: true
                //action:"adminPaper"//试卷管理的页面打印时需要验证密码

            }).show();
        });
    }, ShowCourseStat: function (courseID) {
        Load.js([JS_NatureTxtToDBCmp, JS_NatureSubCourseCmp], function () {
            var _subID = -1;

            var _courseName = "【题库统计】";//导出是单课程时，写上课程名称
            //多课程

            var subjectCoursePanel = {};
            subjectCoursePanel._subject = this.subjectGridPanel;
            subjectCoursePanel._course = this;
            var _courseIDs = [];
            _courseIDs.push(courseID);
            var _doubleWin = new ProblemStatisticsDoubleWin2({ doubleWinOwner: subjectCoursePanel, manager: this._winGroup, subID: _subID, courseIDs: _courseIDs, courseName: _courseName });//进行双向统计时根据专业或课程读取指标或统计题目

            //_doubleWin.on("show", function () { this.el.unmask(); }, this);
            //_doubleWin.on("winclose", function () {
            //    //this.buttons[1].setDisabled(false);
            //    //this.buttons[1].setText(GetLangString(Itemstatistics.Twoway_statistics));//双向统计
            //}, this);
            _doubleWin.show();
        });

    }
    , ShowProblemImport: function (courseID) {
        Load.js([JS_NatureTxtToDBCmp, JS_NatureSubCourseCmp], function () {
            localStorage.setItem("txt2DBCourseID", courseID);
            //Ext.getBody().mask("加载中...");
            (function () {
                var _win = new ImportDataWin();
                _win.on("show", function () {
                    //Ext.getBody().unmask();
                });
                _win.show();
            }).defer(100, this);
        });
    }
    , getTabComponent: function (anchor) {
        //var anchor_id = "nature-grid-"+anchor;
        var obj = layui.$("#nature-grid-" + anchor);
        //alert(JSON.stringify(obj));
        console.log("#nature-grid-" + anchor);
        //
        if (obj.length > 0) {
            return true;
        } else {
            return false;
        }

    }, encrypt: function (text) {
        var encrypt1 = function (data, key, iv) { //key,iv：16位的字符串
            var key1 = CryptoJS.enc.Utf8.parse(key);
            var iv1 = CryptoJS.enc.Utf8.parse(iv);
            return CryptoJS.AES.encrypt(data, key1, {
                iv: iv1,
                mode: CryptoJS.mode.ECB,
                padding: CryptoJS.pad.Pkcs7
            }).toString();
        }
        var message = "";
        if (typeof text === 'object') {
            message = JSON.stringify(text);

        } else {
            message = text;
        }
        //var message = sUserName + ":" + sPassword;
        var srcs = CryptoJS.enc.Utf8.parse(message);
        var v = "nature" + CONFIG["CustomerNumber"];
        var encryptdata = encrypt1(srcs, "12345678123456781234567812345678", v);
        return encryptdata;
    }
};
var UIMODE = "NEWUI";
//var mainPanel = null;
//添加panel
addPanel2 = function (node, grid, iconCls, style, tabPanel) {
    //node.id
    //node.text
    //alert("addPanel2");
    console.log(JSON.stringify(node));
    //var _tabID = node.id;
    //var _subMainId = _tabID + "_main";
    //alert(tabID);
    //var _node = { id: "#nature.showgrid:43", urls: "#nature.showgrid:43", title: "试题管理", "condition": "showsearchwin" };
    var _node2 = { "id": "#nature.showtab:" + node.id, title: node.text, urls: "#nature.showtab:" + node.id };
    TEMP_GRID = grid;
    layui.admin.render(_node2);
    //nature.addPanel(_node2, grid, "");
    //grid.renderTo
}

addPanel = function (node, grid, iconCls, style, tabPanel) {
    //node.id
    //node.text
    //alert("addPanel2");
    console.log(JSON.stringify(node));
    //var _tabID = node.id;
    //var _subMainId = _tabID + "_main";
    //alert(tabID);
    //var _node = { id: "#nature.showgrid:43", urls: "#nature.showgrid:43", title: "试题管理", "condition": "showsearchwin" };
    var _node2 = { "id": "#nature.showtab:" + node.id, title: node.text, urls: "#nature.showtab:" + node.id };
    TEMP_GRID = grid;
    layui.admin.render(_node2);
    //nature.addPanel(_node2, grid, "");
    //grid.renderTo
}

