// Current system global object var system = { version: "1.6.0 beta", rootPath: "tr-web-control/", codeupdate: "20180906", configHead: "transmission-web-control", // default config, can be customized in config.js config: { autoReload: true, reloadStep: 5000, pageSize: 30, pagination: true, pageList: [10, 20, 30, 40, 50, 100, 150, 200, 250, 300], defaultSelectNode: null, autoExpandAttribute: false, defaultLang: "", foldersShow: false, // theme theme: "default", // 是否显示BT服务器 showBTServers: false, ui: { status: { tree: {}, layout: { main: {}, body: {}, left: {} }, panel: {}, size: { nav: {}, attribute: {} } } }, hideSubfolders: false, simpleCheckMode: false, nav: { servers: true, folders: true, statistics: true, labels: false }, labels: [], labelMaps: {}, ignoreVersion: [] }, storageKeys: { dictionary: { folders: "dictionary.folders" } }, // Local data storage dictionary: { folders: null }, checkUpdateScript: "https://api.github.com/repos/ronggang/transmission-web-control/releases/latest", contextMenus: {}, panel: null, lang: null, reloading: false, autoReloadTimer: null, downloadDir: "", islocal: false, B64: new Base64(), // The currently selected torrent number currentTorrentId: 0, control: { tree: null, torrentlist: null }, userConfig: { torrentList: { fields: [], sortName: null, sortOrder: "asc" } }, serverConfig: null, serverSessionStats: null, // Dialog Templates Temporary list templates: {}, // 当前已选中的行 checkedRows: [], uiIsInitialized: false, popoverCount: 0, /** * 设置语言 */ setlang: function (lang, callback) { // If no language is specified, acquires the current browser default language if (!lang) { if (this.config.defaultLang) lang = this.config.defaultLang; else lang = navigator.language || navigator.browserLanguage; //this.debug("lang",lang); } if (!lang) lang = "zh-CN"; // If - contains the language code, you need to turn the second half to uppercase if (lang.indexOf("-") != -1) { // Because Linux file size restrictions lang = lang.split("-")[0].toLocaleLowerCase() + "-" + lang.split("-")[1].toLocaleUpperCase(); } // If the language pack is not defined, English is used if (!this.languages[lang]) { lang = "en"; } // 统一使用 _ 替代 - lang = lang.replace("-", "_"); $.getJSON(system.rootPath + "i18n/" + lang + ".json", function (result) { if (result) { system.lang = $.extend(true, system.defaultLang, result); } system.resetLangText(); // Set the easyui language $.getScript(system.rootPath + "script/easyui/locale/easyui-lang-" + lang + ".js") .done(function (script, textStatus) { if (callback) callback(); // If the loading fails, the English language is loaded }) .fail(function (jqxhr, settings, exception) { $.getScript(system.rootPath + "script/easyui/locale/easyui-lang-en.js", function () { if (callback) callback(); }); }); }); }, /** * 程序初始化 */ init: function (lang, islocal, devicetype) { this.readConfig(); this.lastUIStatus = JSON.parse(JSON.stringify(this.config.ui.status)); this.islocal = (islocal == 1 ? true : false); this.panel = { main: $("#main"), top: $("#m_top"), toolbar: $("#m_toolbar"), left_layout: $("#m_left_layout"), left: $("#m_left"), body: $("#m_body"), layout_body: $("#layout_body"), layout_left: $("#layout_left"), list: $("#m_list"), attribute: $("#m_attribute"), bottom: $("#m_bottom"), title: $("#m_title"), status: $("#m_status"), statusbar: $("#m_statusbar"), status_text: $("#status_text"), droparea: $("#dropArea") }; if (this.lang == null) { this.setlang(lang, function () { system.initdata() }); } else { this.initdata(); } this.initThemes(); // 剪切板组件 this.clipboard = new ClipboardJS('#toolbar_copyPath'); }, // Set the language information resetLangText: function (parent) { if (!parent) parent = $; var items = parent.find("*[system-lang]"); $.each(items, function (key, item) { var name = $(item).attr("system-lang"); if (name.substr(0, 1) == "[") { $(item).html(eval("system.lang" + name)); } else { $(item).html(eval("system.lang." + name)); } }); items = parent.find("*[system-tip-lang]"); $.each(items, function (key, item) { var name = $(item).attr("system-tip-lang"); if (name.substr(0, 1) == "[") { $(item).attr("title", eval("system.lang" + name)); } else { $(item).attr("title", eval("system.lang." + name)); } }); }, initdata: function () { //this.panel.title.text(this.lang.system.title+" "+this.version+" ("+this.codeupdate+")"); $(document).attr("title", this.lang.system.title + " " + this.version); // 设置开关组件默认文字 $.fn.switchbutton.defaults.onText = this.lang["public"]["text-on"]; $.fn.switchbutton.defaults.offText = this.lang["public"]["text-off"]; // The initial navigation bar var buttons = new Array(); var title = "" + this.lang.title.left + ""; // 暂时取消导航栏上的额外按钮 // buttons.push(""); // for (var key in this.lang.tree.toolbar.nav) { // var value = this.lang.tree.toolbar.nav[key]; // buttons.push('' + value + ""); // } // buttons.push(""); if (buttons.length > 1) { title += buttons.join(""); this.panel.left_layout.panel("setTitle", title); for (var key in this.lang.tree.toolbar.nav) { $("#tree-toolbar-nav-" + key).linkbutton(); switch (key) { case "folders": if (system.config.foldersShow) { $("tree-toolbar-nav-" + key).linkbutton({ iconCls: "icon-enabled" }).data("status", 1); } else { $("tree-toolbar-nav-" + key).linkbutton({ iconCls: "icon-disabled" }).data("status", 0); } break; default: break; } } } else { this.panel.left_layout.panel("setTitle", title); } // Initialize the torrent list column title title = "" + this.lang.title.list + ""; buttons.length = 0; // buttons.push(""); // for (var key in this.lang["torrent-head"].buttons) { // var value = this.lang["torrent-head"].buttons[key]; // buttons.push('' + value + ""); // } // buttons.push(""); if (buttons.length > 1) { title += buttons.join(""); this.panel.body.panel("setTitle", title); for (var key in this.lang["torrent-head"].buttons) { $("#torrent-head-buttons-" + key).linkbutton(); switch (key) { case "autoExpandAttribute": if (system.config.autoExpandAttribute) { $("#torrent-head-buttons-" + key).linkbutton({ iconCls: "icon-enabled" }).data("status", 1); } else { $("#torrent-head-buttons-" + key).linkbutton({ iconCls: "icon-disabled" }).data("status", 0); } break; default: break; } } } else { this.panel.body.panel("setTitle", title); } this.panel.status.panel("setTitle", this.lang.title.status); // 设置属性栏 this.panel.attribute.panel({ title: this.lang.title.attribute, onExpand: function () { if (system.currentTorrentId != 0 && $(this).data("isload")) { system.getTorrentInfos(system.currentTorrentId); } else { system.clearTorrentAttribute(); } }, onLoad: function () { if (!$(this).data("isload")) { $(this).data("isload", true); if (system.currentTorrentId != 0) { setTimeout(function () { system.getTorrentInfos(system.currentTorrentId); }, 500); } } } }); // Set the language $.each(this.languages, function (key, value) { $("