﻿//tab插件 关闭
Ext.ux.TabCloseMenu = function() {
    var tabs, menu, ctxItem;
    this.init = function(tp) {
        tabs = tp;
        tabs.on('contextmenu', onContextMenu);
    }
    function onContextMenu(ts, item, e) {
        if (!menu) { // create context menu on first right click
            menu = new Ext.menu.Menu([{
                id: tabs.id + '-close',
                text: '关闭标签',
                handler: function() {
                    tabs.remove(ctxItem);
                }
            }, {
                id: tabs.id + '-close-others',
                text: '关闭其他标签',
                handler: function() {
                    tabs.items.each(function(item) {
                        if (item.closable && item != ctxItem) {
                            tabs.remove(item);
                        }
                    });
                }
            }
]);
        }
        ctxItem = item;
        var items = menu.items;
        items.get(tabs.id + '-close').setDisabled(!item.closable);
        var disableOthers = true;
        tabs.items.each(function() {
            if (this != item && this.closable) {
                disableOthers = false;
                return false;
            }
        });
        items.get(tabs.id + '-close-others').setDisabled(disableOthers);
        menu.showAt(e.getPoint());
    }
}

function JsLoader() {
    this.load = function(url) {
        var ss = document.getElementsByTagName("script"); //获取所有的<script>标记
        for (i = 0; i < ss.length; i++) {//判断指定的文件是否已经包含，如果已包含则触发onsuccess事件并返回
            if (ss[i].src && ss[i].src.indexOf(url) != -1) {
                this.onsuccess();
                return;
            }
        }
        s = document.createElement("script"); //创建script结点,并将其属性设为外联JavaScript文件
        s.type = "text/javascript";
        s.src = url;
        var head = document.getElementsByTagName("head")[0]; //获取head结点，并将<script>插入到其中
        head.appendChild(s);
        var self = this; //获取自身的引用
        //对于IE浏览器，使用readystatechange事件判断是否载入成功
        //对于其他浏览器，使用onload事件判断载入是否成功
        //s.onload=s.onreadystatechange=function(){
        s.onload = s.onreadystatechange = function() {
            //在此函数中this指针指的是s结点对象，而不是JsLoader实例,
            //所以必须用self来调用onsuccess事件，下同。
            if (this.readyState && this.readyState == "loading") return;
            self.onsuccess();
        }
        s.onerror = function() {
            head.removeChild(s);
            self.onfailure();
        }
    };
    this.onsuccess = function() { }; //定义载入成功事件
    this.onfailure = function() { }; //定义失败事件
}

function IndexLoad(type) {
    var jsLoader = new JsLoader(); //创建对象
    jsLoader.onfailure = function() {//定义载入失败处理程序
        alert("文件载入失败！");
    }
    var kjnode = new Object();
    var n = 0;
    switch (type) {
        case "1":
            jsLoader.onsuccess = function() {
                WebManageFn(); //系统参数设置
            }
            jsLoader.load("include/js/sys/WebManage.js");
            break;
        case "2":
            jsLoader.onsuccess = function() {
                SetLogFn(); //操作日志设置
            }
            jsLoader.load("include/js/cj/Managelog.js");
            break;
        case "4":
            jsLoader.onsuccess = function() {
                ManageCodeInfo(); //管理认证码管理
            }
            jsLoader.load("include/js/sys/ManageCode.js");
            break;
        case "5":
            jsLoader.onsuccess = function() {
                NewsGradeManageFn(); //资讯等级设置
            }
            jsLoader.load("include/js/cj/NewsGrade.js");
            break;
        case "6":
            jsLoader.onsuccess = function() {
                BackupManageFn(); //数据备份
            }
            jsLoader.load("include/js/cj/Backup.js");
            break;
        case "8":
            jsLoader.onsuccess = function() {
                UserpassFn(); //修改密码
            }
            jsLoader.load("include/js/user/UserModiPass.js");
            break;
    }
}

function NewsLoad(type, pid, lid) {
    switch (type) {
        case "index":
            {
                Ext.MessageBox.show({ title: '请等待...', msg: '网站首页皮肤更新中...', progressText: '初始中...', width: 300, progress: true, closable: false });
                Ext.Ajax.request({
                    url: 'include/url/sys/homemanage.aspx?type=refreshdefault',
                    method: 'post',
                    params: { inlmids: lid },
                    callback: function(options, success, response) {
                        var responseArray = Ext.util.JSON.decode(response.responseText);
                        if (responseArray.success == "true") { for (var i = 1; i < 5; i++) { setTimeout(f(i), i * 500); } }
                        else { Ext.Msg.alert("提示信息", "<br/>网站首页皮肤数据更新失败!"); }
                    }
                });
                var f = function(v) { return function() { if (v == 4) { Ext.MessageBox.hide(); } else { var i = v / 3; Ext.MessageBox.updateProgress(i, Math.round(100 * i) + '% completed'); } }; };

                break;
            }
        case "lanmu":
            {
                Ext.MessageBox.show({ title: '请等待...', msg: '栏目页皮肤更新中...', progressText: '初始中...', width: 300, progress: true, closable: false });
                Ext.Ajax.request({
                    url: 'include/url/news/skin.aspx?type=inrefreshlm&pdid=11111' + pid,
                    method: 'post',
                    params: { inlmids: lid },
                    callback: function(options, success, response) {
                        var responseArray = Ext.util.JSON.decode(response.responseText);
                        if (responseArray.success == "true") { for (var i = 1; i < 5; i++) { setTimeout(f(i), i * 500); } }
                        else { Ext.Msg.alert("提示信息", "<br/>栏目页数据更新失败!"); }
                    }
                });
                var f = function(v) { return function() { if (v == 4) { Ext.MessageBox.hide(); } else { var i = v / 3; Ext.MessageBox.updateProgress(i, Math.round(100 * i) + '% completed'); } }; };
            }
            break;
        case "pindao":
            {
                Ext.MessageBox.show({ title: '请等待...', msg: '栏目页皮肤更新中...', progressText: '初始中...', width: 300, progress: true, closable: false });
                Ext.Ajax.request({
                    url: 'include/url/news/skin.aspx?type=refreshpd&pdid=1111' + lid,
                    method: 'post',
                    callback: function(options, success, response) {
                        var responseArray = Ext.util.JSON.decode(response.responseText);
                        if (responseArray.success == "true") { for (var i = 1; i < 5; i++) { setTimeout(f(i), i * 500); } }
                        else { Ext.Msg.alert("提示信息", "<br/>栏目页数据更新失败!"); }
                    }
                });
                var f = function(v) { return function() { if (v == 4) { Ext.MessageBox.hide(); } else { var i = v / 3; Ext.MessageBox.updateProgress(i, Math.round(100 * i) + '% completed'); } }; };
            }
            break;
    }
}

//判断权限
CheckRole = function(menuid, actionid) {
    var html = $.ajax({ url: "include/url/pub/checkrole.aspx?menuid=" + menuid + "&actionid=" + actionid, async: false, dataType: "json", cache: false }).responseText;
    var respText = Ext.util.JSON.decode(html);
    if (respText.success.toString() == "true") {
        return true;
    } else {
        ShowError();
        return false;
    }
}

CheckWebRole = function(type, pindao, opt) {
    var html = $.ajax({ url: "include/url/pub/checkrole.aspx?type=" + type + "&pindao=" + pindao + "&opt=" + opt, async: false, dataType: "json", cache: false }).responseText;
    var respText = Ext.util.JSON.decode(html);
    if (respText.success.toString() == "true") {
        return true;
    } else {
        ShowError();
        return false;
    }
}

ShowError = function() {
    Ext.Msg.alert("提示信息", "没有执行此项操作的权限！");
}

var PublicWindow;
ShowPublicWindow = function(urls, title, width, height) {
    if (!PublicWindow) {
        PublicWindow = new Ext.Window({
            title: title,
            width: width,
            height: height,
            iconCls: "addicon",
            maximizable: true, //是否可以最大化 
            //maximized: true,
            resizable: false,
            collapsible: true, //允许缩放条
            closeAction: 'close',
            closable: true,
            plain: true,
            bodyStyle: "padding:1px",
            html: urls
        })
        PublicWindow.show();
    } else {
        PublicWindow.close();
        PublicWindow = new Ext.Window({
            title: title,
            width: width,
            height: height,
            iconCls: "addicon",
            maximizable: true, //是否可以最大化 
            //maximized: true,
            resizable: false,
            collapsible: true, //允许缩放条
            closeAction: 'close',
            closable: true,
            plain: true,
            bodyStyle: "padding:1px",
            html: urls
        })
        PublicWindow.show();
    }
}

PublicWinInfo = function(url, title, width, height) {
    urls = '<iframe id="addlmif" scrolling="auto" frameborder="0" width="100%" allowTransparency="true" height="100%" src="' + url + '"></iframe>';
    ShowPublicWindow(urls, unescape(title), parseInt(width), parseInt(height));
}

ClosWinInfo = function() {
    if (PublicWindow) {
        PublicWindow.close();
    }
}

/*提示信息*/
Ext.example = function() {
    var msgCt;

    function createBox(t, s) {
        return ['<div class="msg">',
                '<div class="x-box-tl"><div class="x-box-tr"><div class="x-box-tc"></div></div></div>',
                '<div class="x-box-ml"><div class="x-box-mr"><div class="x-box-mc"><h3>', t, '</h3>', s, '</div></div></div>',
                '<div class="x-box-bl"><div class="x-box-br"><div class="x-box-bc"></div></div></div>',
                '</div>'].join('');
    }
    return {
        msg: function(title, format) {
            if (!msgCt) {
                msgCt = Ext.DomHelper.insertFirst(document.body, { id: 'msg-div' }, true);
            }
            msgCt.alignTo(document, 't-t');
            var s = String.format.apply(String, Array.prototype.slice.call(arguments, 1));
            var m = Ext.DomHelper.append(msgCt, { html: createBox(title, s) }, true);
            m.slideIn('t').pause(2).ghost("t", { remove: true });
        },

        init: function() {
            var lb = Ext.get('lib-bar');
            if (lb) {
                lb.show();
            }
        }
    };
} ();

//使用    showResult("按钮提示");
function showResult(btn) {
    Ext.example.msg('系统提示', '{0}', btn);
}




