mirror of
https://github.com/ronggang/transmission-web-control.git
synced 2026-07-15 10:31:52 +02:00
feat: 增加参数配置导入导出功能
Add configuration import and export function
This commit is contained in:
@@ -8,13 +8,13 @@
|
||||
<link rel='shortcut icon' href='favicon.ico' type='image/x-icon'/ >
|
||||
<title>Transmission Web Control</title>
|
||||
<!-- Style sheet -->
|
||||
<link rel="stylesheet" type="text/css" href="tr-web-control/style/before-easyui.css?v=20180422" />
|
||||
<link id="styleEasyui" rel="stylesheet" type="text/css" href="tr-web-control/script/easyui/themes/default/easyui.css?v=20180422"/>
|
||||
<link rel="stylesheet" type="text/css" href="tr-web-control/style/before-easyui.css?v=20180906" />
|
||||
<link id="styleEasyui" rel="stylesheet" type="text/css" href="tr-web-control/script/easyui/themes/default/easyui.css?v=20180906"/>
|
||||
<link rel="stylesheet" type="text/css" href="tr-web-control/script/plugins/jquery.webui-popover.css" />
|
||||
<link rel="stylesheet" type="text/css" href="tr-web-control/style/base.css?v=20180422" />
|
||||
<link rel="stylesheet" type="text/css" href="tr-web-control/script/easyui/themes/icon.css?v=20180422"/>
|
||||
<link rel="stylesheet" type="text/css" href="tr-web-control/style/icon.custom.css?v=20180422"/>
|
||||
<link rel="stylesheet" type="text/css" href="tr-web-control/style/iconfont/iconfont.css?v=20180422"/>
|
||||
<link rel="stylesheet" type="text/css" href="tr-web-control/style/base.css?v=20180906" />
|
||||
<link rel="stylesheet" type="text/css" href="tr-web-control/script/easyui/themes/icon.css?v=20180906"/>
|
||||
<link rel="stylesheet" type="text/css" href="tr-web-control/style/icon.custom.css?v=20180906"/>
|
||||
<link rel="stylesheet" type="text/css" href="tr-web-control/style/iconfont/iconfont.css?v=20180906"/>
|
||||
<!-- <link rel="stylesheet" type="text/css" href="//at.alicdn.com/t/font_584244_g4d8d6qr58nnrk9.css"/> -->
|
||||
|
||||
<!-- Base class library -->
|
||||
@@ -22,20 +22,20 @@
|
||||
<script type="text/javascript" src="tr-web-control/script/jquery/jquery.form.js"></script>
|
||||
<script type="text/javascript" src="tr-web-control/script/jquery/json2.min.js"></script>
|
||||
<script type="text/javascript" src="tr-web-control/script/jquery/Base64.js"></script>
|
||||
<script type="text/javascript" src="tr-web-control/script/easyui/jquery.easyui.min.js?v=20180422"></script>
|
||||
<script type="text/javascript" src="tr-web-control/script/easyui/jquery.easyui.min.js?v=20180906"></script>
|
||||
<script type="text/javascript" src="tr-web-control/script/easyui/plugins/jquery.datagrid.drophead.js"></script>
|
||||
<script type="text/javascript" src="tr-web-control/script/plugins/jquery.webui-popover.min.js"></script>
|
||||
<!-- -->
|
||||
<!-- System class library -->
|
||||
<script type="text/javascript" src="tr-web-control/script/min/FileSaver.min.js?v=20180422"></script>
|
||||
<script type="text/javascript" src="tr-web-control/script/min/FileSaver.min.js?v=20180906"></script>
|
||||
<script type="text/javascript" src="tr-web-control/script/min/clipboard.min.js"></script>
|
||||
<script type="text/javascript" src="tr-web-control/script/min/public.min.js?v=20180422"></script>
|
||||
<script type="text/javascript" src="tr-web-control/script/min/ua-parser.min.js?v=20180422"></script>
|
||||
<script type="text/javascript" src="tr-web-control/script/min/transmission.min.js?v=20180422"></script>
|
||||
<script type="text/javascript" src="tr-web-control/script/min/public.min.js?v=20180906"></script>
|
||||
<script type="text/javascript" src="tr-web-control/script/min/ua-parser.min.js?v=20180906"></script>
|
||||
<script type="text/javascript" src="tr-web-control/script/min/transmission.min.js?v=20180906"></script>
|
||||
<script type="text/javascript" src="tr-web-control/script/min/transmission.torrents.min.js?v=20171027"></script>
|
||||
<script type="text/javascript" src="tr-web-control/script/min/system.min.js?v=20180422"></script>
|
||||
<script type="text/javascript" src="tr-web-control/config.js?v=20180422"></script>
|
||||
<script type="text/javascript" src="tr-web-control/plugin.js?v=20180422"></script>
|
||||
<script type="text/javascript" src="tr-web-control/script/min/system.min.js?v=20180906"></script>
|
||||
<script type="text/javascript" src="tr-web-control/config.js?v=20180906"></script>
|
||||
<script type="text/javascript" src="tr-web-control/plugin.js?v=20180906"></script>
|
||||
<script type="text/javascript">
|
||||
var nonpc = [ "console", "mobile", "tablet", "smarttv", "wearable", "embedded" ]
|
||||
if ((nonpc.indexOf($.ua.device.type) != -1 )&&location.search.getQueryString("devicetype")!="computer")
|
||||
|
||||
@@ -219,7 +219,10 @@
|
||||
"color": "Color",
|
||||
"actions": "Actions",
|
||||
"import-confirm": "Do you want to import labels? This overrides the current configuration."
|
||||
}
|
||||
},
|
||||
"import-config": "Import configuration from file",
|
||||
"export-config": "Export current configuration",
|
||||
"import-config-confirm": "Do you want to import these configurations? This overrides the current configuration."
|
||||
},
|
||||
"public": {
|
||||
"button-ok": "OK",
|
||||
@@ -294,6 +297,17 @@
|
||||
"title": "Set User Labels",
|
||||
"available": "Available:",
|
||||
"selected": "Selected:"
|
||||
},
|
||||
"export-config": {
|
||||
"title": "Please select the details need to be exported",
|
||||
"option-all": "All configuration",
|
||||
"option-system": "Web Control configuration",
|
||||
"option-dictionary": "Defined Folders Dictionary",
|
||||
"option-server": "Transmission configuration (Download directory, cache, speed limit, etc.)"
|
||||
},
|
||||
"import-config": {
|
||||
"title": "Please select the details need to be import",
|
||||
"invalid-file": "Invalid profile"
|
||||
}
|
||||
},
|
||||
"torrent": {
|
||||
@@ -429,6 +443,7 @@
|
||||
"text-on": "ON",
|
||||
"text-off": "OFF",
|
||||
"text-how-to-update": "How to update?",
|
||||
"text-ignore-this-version": "Ignore this version"
|
||||
"text-ignore-this-version": "Ignore this version",
|
||||
"text-json-file-parsing-failed": "JSON file parsing failed!"
|
||||
}
|
||||
}
|
||||
@@ -218,7 +218,10 @@
|
||||
"color": "颜色",
|
||||
"actions": "操作",
|
||||
"import-confirm": "是否确认导入标签信息?这将覆盖当前配置。"
|
||||
}
|
||||
},
|
||||
"import-config": "从备份文件中导入配置",
|
||||
"export-config": "导出当前配置到配置文件(内容包括:Transmission 参数、WebUI 配置)",
|
||||
"import-config-confirm": "是否确认导入这些配置信息?这将覆盖当前配置。"
|
||||
},
|
||||
"public": {
|
||||
"button-ok": "确定",
|
||||
@@ -293,6 +296,17 @@
|
||||
"title": "设置用户标签",
|
||||
"available": "可用标签:",
|
||||
"selected": "已选择:"
|
||||
},
|
||||
"export-config": {
|
||||
"title": "请选择需要导出的配置",
|
||||
"option-all": "所有配置",
|
||||
"option-system": "Web Control 参数配置(包含用户标签)",
|
||||
"option-dictionary": "用户定义的目录字典",
|
||||
"option-server": "Transmission 服务端配置(如下载目录、缓存、限速等所有可配置参数)"
|
||||
},
|
||||
"import-config": {
|
||||
"title": "请选择需要导入的配置",
|
||||
"invalid-file": "无效的配置文件"
|
||||
}
|
||||
},
|
||||
"torrent": {
|
||||
@@ -428,6 +442,7 @@
|
||||
"text-on": "开",
|
||||
"text-off": "关",
|
||||
"text-how-to-update": "如何更新?",
|
||||
"text-ignore-this-version": "忽略这个版本"
|
||||
"text-ignore-this-version": "忽略这个版本",
|
||||
"text-json-file-parsing-failed": "JSON文件解析失败!"
|
||||
}
|
||||
}
|
||||
8
src/tr-web-control/script/min/public.min.js
vendored
8
src/tr-web-control/script/min/public.min.js
vendored
@@ -3,9 +3,11 @@ Number.prototype.formatNumber=function(a){this.fStr=function(c,d,g){if(c==""||c=
|
||||
d.charAt(f)!="0")r=r.substr(0,f+1)+c.substr(j)+r.substr(f+1);r=(g?r:r.split("").reverse().join("")).replace(/(^,)|(,$)|(,,+)/g,"");if(r.substr(0,1)==",")r=r.substr(1);if(r.substr(0,2)=="-,")r="-"+r.substr(2);return r};var b=this.toString();if(b.length==0)return"";if(a==undefined)return this;a=a.split(".");b=b.split(".");return a.length>1?this.fStr(b[0],a[0])+"."+this.fStr(b[1],a[1],1):this.fStr(b[0],a[0])};
|
||||
String.prototype.getRGB=function(){var a=/^#([0-9a-f]{3}|[0-9a-f]{6})$/,b=this.toLowerCase();if(b&&a.test(b)){if(b.length===4){var c="#";for(a=1;a<4;a+=1)c+=b.slice(a,a+1).concat(b.slice(a,a+1));b=c}c=[];for(a=1;a<7;a+=2)c.push(parseInt("0x"+b.slice(a,a+2)));return{R:c[0],G:c[1],B:c[2]}}else return this};function getGrayLevel(a){a||(a={R:0,G:0,B:0});if(typeof a==="string")a=a.getRGB();return(0.299*a.R+0.587*a.G+0.114*a.B)/255}
|
||||
function getLocalTime(a){return(new Date(parseInt(a)*1E3)).toLocaleString().replace(/年|月/g,"-").replace(/日/g," ")}function formatLongTime(a){a=new Date(parseInt(a)*1E3);return formatDate(a)}
|
||||
function formatDate(a,b){b||(b="yyyy-mm-dd hh:nn:ss");if(a instanceof Date){var c=a.getFullYear(),d=c.toString().substring(2),g=a.getMonth()+1,e=g<10?"0"+g:g,f=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"][g],h=a.getDate(),m=h<10?"0"+h:h,i=a.getHours(),n=i<10?"0"+i:i,k=a.getMinutes(),o=k<10?"0"+k:k,l=a.getSeconds(),p=l<10?"0"+l:l;b=b.replace(/yyyy/i,c);b=b.replace(/yy/i,d);b=b.replace(/mmm/i,f);b=b.replace(/mm/i,e);b=b.replace(/m/i,g);b=b.replace(/dd/i,m);b=b.replace(/d/i,
|
||||
h);b=b.replace(/hh/i,n);b=b.replace(/h/i,i);b=b.replace(/nn/i,o);b=b.replace(/n/i,k);b=b.replace(/ss/i,p);return b=b.replace(/s/i,l)}else return""}
|
||||
function formatDate(a,b){b||(b="yyyy-mm-dd hh:nn:ss");if(a instanceof Date){var c=a.getFullYear(),d=c.toString().substring(2),g=a.getMonth()+1,e=g<10?"0"+g:g,f=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"][g],h=a.getDate(),i=h<10?"0"+h:h,k=a.getHours(),n=k<10?"0"+k:k,l=a.getMinutes(),o=l<10?"0"+l:l,m=a.getSeconds(),p=m<10?"0"+m:m;b=b.replace(/yyyy/i,c);b=b.replace(/yy/i,d);b=b.replace(/mmm/i,f);b=b.replace(/mm/i,e);b=b.replace(/m/i,g);b=b.replace(/dd/i,i);b=b.replace(/d/i,
|
||||
h);b=b.replace(/hh/i,n);b=b.replace(/h/i,k);b=b.replace(/nn/i,o);b=b.replace(/n/i,l);b=b.replace(/ss/i,p);return b=b.replace(/s/i,m)}else return""}
|
||||
function formatSize(a,b,c){if(a==0)return b==true?"":c=="speed"?"0.00 KB/s":"0.00";b="";var d="KB";if(a<1024E3){b=a/1024;d="KB"}else if(a<1048576E3){b=a/1048576;d="MB"}else if(a<1073741824E3){b=a/1073741824;d="GB"}else if(a<1099511627776E3){b=a/1099511627776;d="TB"}else{b=a/1125899906842624;d="PB"}if(c=="speed")d+="/s";return b.formatNumber("###,###,###,###.00 ")+d}function getHoursFromMinutes(a){return("00"+parseInt(a/60,10)).right(2)+":"+("00"+a%60).right(2)}
|
||||
function getMinutesFromHours(a){return parseInt(a.split(":")[0],10)*60+parseInt(a.split(":")[1],10)}function getTotalTime(a,b){b||(b="%dd %hh %mm %ss ");var c=Math.floor(a/864E5),d=a%864E5,g=Math.floor(d/36E5),e=d%36E5;d=Math.floor(e/6E4);e=Math.round(e%6E4/1E3);var f=b;f=c==0?f.replace(/(%d+\s)/,""):f.replace("%d",c);f=g==0?f.replace(/(%h+\s)/,""):f.replace("%h",g);f=d==0?f.replace(/(%m+\s)/,""):f.replace("%m",d);return f=e==0?f.replace(/(%s+\s)/,""):f.replace("%s",e)}
|
||||
function arrayObjectSort(a,b){return function(c,d){var g=c[a],e=d[a];return g<e?b=="desc"?1:-1:g>e?b=="desc"?-1:1:0}}function timedChunk(a,b,c,d,g){var e=a.concat();if(d==undefined)d=25;setTimeout(function(){var f=+new Date;do b.call(c,e.shift());while(e.length>0&&+new Date-f<100);if(e.length>0)setTimeout(arguments.callee,d);else g&&g(a)},d)}
|
||||
(function(a){a.fn.fadeInAndOut=function(b,c,d){b={speed:b,easing:c,fn:d};a.extend(b,a.fn.fadeInAndOut.defaults);this.fadeIn(b.speed).delay(b.speed).fadeOut(b.speed,b.easing,b.fn)};a.fn.fadeInAndOut.defaults={speed:1E3,easing:"swing",fn:null}})(jQuery);function uniq(a){var b={};return a.filter(function(c){return b.hasOwnProperty(c)?false:b[c]=true})};
|
||||
(function(a){a.fn.fadeInAndOut=function(b,c,d){b={speed:b,easing:c,fn:d};a.extend(b,a.fn.fadeInAndOut.defaults);this.fadeIn(b.speed).delay(b.speed).fadeOut(b.speed,b.easing,b.fn)};a.fn.fadeInAndOut.defaults={speed:1E3,easing:"swing",fn:null}})(jQuery);function uniq(a){var b={};return a.filter(function(c){return b.hasOwnProperty(c)?false:b[c]=true})}
|
||||
function loadFileContent(a,b){$("<input id='file-loadContent' type='file' style='display:none;' multiple='true'/>").on("change",function(){var c=this;if(c.files.length>0&&c.files[0].name.length>0){var d=c.files,g=d.length,e=0,f=new FileReader;f.onload=function(i){b&&b.call(system,i.target.result);h()};f.onerror=function(){alert("文件加载失败");console.log("文件加载失败");h()};var h=function(i){if(e==g){$(c).remove();c.value=""}else{i=d[e];var k=i.name.lastIndexOf(".");k=i.name.substr(k+1);e++;if(a)if(k!=a){alert("文件类型错误");
|
||||
return}f.readAsText(i)}};h()}}).click()}function saveFileAs(a,b){try{var c=window.Blob||window.WebKitBlob,d=false;if(c)try{new c([],{type:"text/plain"});d=true}catch(g){}var e=null;if(d)e=new c([b],{type:"text/plain"});else{var f=new (window.BlobBuilder||window.WebKitBlobBuilder);f.append(b);e=f.getBlob("text/plain")}saveAs(e,a)}catch(h){console.log(h.toString())}};
|
||||
|
||||
8
src/tr-web-control/script/min/system.min.js
vendored
8
src/tr-web-control/script/min/system.min.js
vendored
@@ -1,4 +1,4 @@
|
||||
var system={version:"1.6.0 alpha",rootPath:"tr-web-control/",codeupdate:"20180905",configHead:"transmission-web-control",config:{autoReload:true,reloadStep:5E3,pageSize:30,pagination:true,pageList:[10,20,30,40,50,100,150,200,250,300],defaultSelectNode:null,autoExpandAttribute:false,defaultLang:"",foldersShow:false,theme:"default",showBTServers:false,ui:{status:{tree:{},layout:{main:{},body:{},left:{}},panel:{},size:{nav:{},attribute:{}}}},hideSubfolders:false,simpleCheckMode:false,nav:{servers:true,
|
||||
var system={version:"1.6.0 beta",rootPath:"tr-web-control/",codeupdate:"20180906",configHead:"transmission-web-control",config:{autoReload:true,reloadStep:5E3,pageSize:30,pagination:true,pageList:[10,20,30,40,50,100,150,200,250,300],defaultSelectNode:null,autoExpandAttribute:false,defaultLang:"",foldersShow:false,theme:"default",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"}},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,currentTorrentId:0,control:{tree:null,torrentlist:null},userConfig:{torrentList:{fields:[],sortName:null,sortOrder:"asc"}},
|
||||
serverConfig:null,serverSessionStats:null,templates:{},checkedRows:[],uiIsInitialized:false,popoverCount:0,setlang:function(a,b){a||(a=this.config.defaultLang?this.config.defaultLang:navigator.language||navigator.browserLanguage);a||(a="zh-CN");if(a.indexOf("-")!=-1)a=a.split("-")[0].toLocaleLowerCase()+"-"+a.split("-")[1].toLocaleUpperCase();this.languages[a]||(a="en");a=a.replace("-","_");$.getJSON(system.rootPath+"i18n/"+a+".json",function(c){if(c)system.lang=$.extend(true,system.defaultLang,c);
|
||||
system.resetLangText();$.getScript(system.rootPath+"script/easyui/locale/easyui-lang-"+a+".js").done(function(){b&&b()}).fail(function(){$.getScript(system.rootPath+"script/easyui/locale/easyui-lang-en.js",function(){b&&b()})})})},init:function(a,b){this.readConfig();this.lastUIStatus=JSON.parse(JSON.stringify(this.config.ui.status));this.islocal=b==1?true:false;this.panel={main:$("#main"),top:$("#m_top"),toolbar:$("#m_toolbar"),left_layout:$("#m_left_layout"),left:$("#m_left"),body:$("#m_body"),
|
||||
@@ -103,9 +103,9 @@ checkUpdate:function(){$.ajax({url:this.checkUpdateScript,dataType:"json",succes
|
||||
" ("+b+")").appendTo(e).linkbutton();$("<span/>").html(" ").appendTo(e);$('<a href="https://github.com/ronggang/transmission-web-control/wiki" target="_blank" class="easyui-linkbutton" data-options="iconCls:\'iconfont tr-icon-help\'"/>').html(system.lang["public"]["text-how-to-update"]).appendTo(e).linkbutton();$("<span/>").html(" ").appendTo(e);$("<button onclick=\"javascript:system.addIgnoreVersion('"+c+'\');" class="easyui-linkbutton" data-options="iconCls:\'iconfont tr-icon-cancel-checked\'"/>').html(system.lang["public"]["text-ignore-this-version"]).appendTo(e).linkbutton();
|
||||
$("<hr/>").appendTo(d);$("<div/>").html(f).appendTo(d);$("#button-download-update").webuiPopover({content:d.html(),backdrop:true})}else $("#area-update-infos").hide()}}})},addIgnoreVersion:function(a){if($.inArray(a,system.config.ignoreVersion)==-1){this.config.ignoreVersion.push(a);this.saveConfig()}$("#button-download-update").webuiPopover("hide");$("#area-update-infos").hide()},changeLanguages:function(a){if(!(a==this.lang.name||!a)){this.config.defaultLang=a;this.saveConfig();location.href="?lang="+
|
||||
a}},getStorageData:function(a,b){return window.localStorage[a]==null?b:window.localStorage[a]},setStorageData:function(a,b){window.localStorage[a]=b},openDialogFromTemplate:function(a){a=$.extend(true,{id:null,options:null,datas:null,type:0},a);if(a.id!=null){var b=a.id,c=a.options,d=a.datas,f=$("#"+b);if(f.length){d&&$.each(d,function(e,g){f.data(e,g)});if(a.type==0&&f.attr("type")==a.type){f.dialog("open");f.dialog({content:system.templates[b]});return}else{if(system.popoverCount!=0){setTimeout(function(){system.openDialogFromTemplate(a)},
|
||||
350);return}f.remove()}}c=$.extend(true,{title:"",width:100,height:100,resizable:false,cache:true,content:system.lang.dialog["system-config"].loading,modal:true},c);f=$("<div/>").attr({id:b,type:a.type}).appendTo(document.body);if(a.type==0)f.dialog(c);else{f.css({width:c.width,height:c.height}).data("popoverSource",a.source);$(a.source).webuiPopover({url:"#"+b,width:c.width,height:c.height-18,padding:false,onHide:function(e){$(a.source).webuiPopover("destroy");$("#"+b).remove();$(e).remove();system.popoverCount--},
|
||||
onShow:function(){system.popoverCount++}})}$.get(system.rootPath+"template/"+b+".html?time="+new Date,function(e){system.templates[b]=e;d&&$.each(d,function(g,h){$("#"+b).data(g,h)});if(a.type==0)$("#"+b).dialog({content:e});else{f.html(e);$.parser.parse("#"+b);$(a.source).webuiPopover("show")}})}},debug:function(a,b){window.console&&window.console.log&&window.console.log(a,b)},initThemes:function(){this.themes&&$("#select-themes").combobox({groupField:"group",data:this.themes,editable:false,panelHeight:"auto",
|
||||
onChange:function(a){var b=(a+";").split(";"),c=b[0];b=b[1]||"logo.png";$("#styleEasyui").attr("href","tr-web-control/script/easyui/themes/"+c+"/easyui.css");$("#logo").attr("src","tr-web-control/"+b);system.config.theme=a;system.saveConfig()},onLoadSuccess:function(){$(this).combobox("setValue",system.config.theme||"default")}})},getValidTreeKey:function(a){if(!a)return"";return this.B64.encode(a).replace(/[+|\/|=]/g,"0")}};
|
||||
350);return}f.remove()}}c=$.extend(true,{title:"",width:100,height:100,resizable:false,cache:true,content:system.lang.dialog["system-config"].loading,modal:true},c);f=$("<div/>").attr({id:b,type:a.type}).appendTo(document.body);if(a.type==0)f.dialog(c);else{f.css({width:c.width,height:c.height}).data("popoverSource",a.source);$(a.source).webuiPopover({url:"#"+b,title:c.title,width:c.width,height:c.height-18,padding:false,onHide:function(e){$(a.source).webuiPopover("destroy");$("#"+b).remove();$(e).remove();
|
||||
system.popoverCount--;a.onClose&&a.onClose(a.source)},onShow:function(){system.popoverCount++}})}$.get(system.rootPath+"template/"+b+".html?time="+new Date,function(e){system.templates[b]=e;d&&$.each(d,function(g,h){$("#"+b).data(g,h)});if(a.type==0)$("#"+b).dialog({content:e});else{f.html(e);$.parser.parse("#"+b);$(a.source).webuiPopover("show")}})}},debug:function(a,b){window.console&&window.console.log&&window.console.log(a,b)},initThemes:function(){this.themes&&$("#select-themes").combobox({groupField:"group",
|
||||
data:this.themes,editable:false,panelHeight:"auto",onChange:function(a){var b=(a+";").split(";"),c=b[0];b=b[1]||"logo.png";$("#styleEasyui").attr("href","tr-web-control/script/easyui/themes/"+c+"/easyui.css");$("#logo").attr("src","tr-web-control/"+b);system.config.theme=a;system.saveConfig()},onLoadSuccess:function(){$(this).combobox("setValue",system.config.theme||"default")}})},getValidTreeKey:function(a){if(!a)return"";return this.B64.encode(a).replace(/[+|\/|=]/g,"0")}};
|
||||
$(document).ready(function(){$.getJSON(system.rootPath+"i18n/en.json").done(function(a){system.defaultLang=a});$.getJSON(system.rootPath+"i18n.json").done(function(a){system.languages=a;system.init(location.search.getQueryString("lang"),location.search.getQueryString("local"))})});
|
||||
function pagerFilter(a){if(typeof a.length=="number"&&typeof a.splice=="function")a={total:a.length,rows:a};var b=$(this),c=b.datagrid("options"),d=b.datagrid("getPager"),f=b.data("buttons");d.pagination({onSelectPage:function(h,i){c.pageNumber=h;c.pageSize=i;d.pagination("refresh",{pageNumber:h,pageSize:i});b.datagrid("loadData",a)},buttons:f});if(!a.originalRows)a.originalRows=a.rows;var e=(c.pageNumber-1)*parseInt(c.pageSize),g=e+parseInt(c.pageSize);a.rows=a.originalRows.slice(e,g);if(f&&f.length)for(e=
|
||||
0;e<f.length;e++){g=f[e];g.id&&g.title&&$("#"+g.id,d).attr("title",g.title)}return a};
|
||||
|
||||
@@ -405,4 +405,90 @@ function uniq(a) {
|
||||
return a.filter(function(item) {
|
||||
return seen.hasOwnProperty(item) ? false : (seen[item] = true);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载指定的文件内容
|
||||
*/
|
||||
function loadFileContent(fileType, callback) {
|
||||
$("<input id='file-loadContent' type='file' style='display:none;' multiple='true'/>").on("change", function () {
|
||||
var fileSelector = this;
|
||||
if (fileSelector.files.length > 0 && fileSelector.files[0].name.length > 0) {
|
||||
var files = fileSelector.files;
|
||||
var count = files.length;
|
||||
var index = 0;
|
||||
var r = new FileReader();
|
||||
r.onload = function (e) {
|
||||
callback && callback.call(system, e.target.result);
|
||||
readFile();
|
||||
};
|
||||
r.onerror = function () {
|
||||
alert("文件加载失败");
|
||||
console.log("文件加载失败");
|
||||
readFile();
|
||||
};
|
||||
|
||||
function readFile(file) {
|
||||
|
||||
if (index == count) {
|
||||
$(fileSelector).remove();
|
||||
fileSelector.value = "";
|
||||
return;
|
||||
}
|
||||
var file = files[index];
|
||||
var lastIndex = file.name.lastIndexOf(".");
|
||||
var fix = file.name.substr(lastIndex + 1);
|
||||
|
||||
index++;
|
||||
|
||||
if (fileType) {
|
||||
if (fix != fileType) {
|
||||
alert("文件类型错误");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
r.readAsText(file);
|
||||
}
|
||||
readFile();
|
||||
}
|
||||
}).click();
|
||||
}
|
||||
/**
|
||||
* 将指定的内容保存为文件
|
||||
* @param fileName 文件名
|
||||
* @param fileData 文件内容
|
||||
*/
|
||||
function saveFileAs(fileName, fileData) {
|
||||
try {
|
||||
var Blob = window.Blob || window.WebKitBlob;
|
||||
|
||||
// Detect availability of the Blob constructor.
|
||||
var constructor_supported = false;
|
||||
if (Blob) {
|
||||
try {
|
||||
new Blob([], {
|
||||
"type": "text/plain"
|
||||
});
|
||||
constructor_supported = true;
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
var b = null;
|
||||
if (constructor_supported) {
|
||||
b = new Blob([fileData], {
|
||||
"type": "text/plain"
|
||||
});
|
||||
} else {
|
||||
// Deprecated BlobBuilder API
|
||||
var BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder;
|
||||
var bb = new BlobBuilder();
|
||||
bb.append(fileData);
|
||||
b = bb.getBlob("text/plain");
|
||||
}
|
||||
|
||||
saveAs(b, fileName);
|
||||
} catch (e) {
|
||||
console.log(e.toString());
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
// Current system global object
|
||||
var system = {
|
||||
version: "1.6.0 alpha",
|
||||
version: "1.6.0 beta",
|
||||
rootPath: "tr-web-control/",
|
||||
codeupdate: "20180905",
|
||||
codeupdate: "20180906",
|
||||
configHead: "transmission-web-control",
|
||||
// default config, can be customized in config.js
|
||||
config: {
|
||||
@@ -3111,7 +3111,8 @@ var system = {
|
||||
}).data("popoverSource", config.source);
|
||||
|
||||
$(config.source).webuiPopover({
|
||||
url: '#' + dialogId,
|
||||
url: '#' + dialogId,
|
||||
title: options.title,
|
||||
width: options.width,
|
||||
height: options.height -18,
|
||||
padding: false,
|
||||
@@ -3120,6 +3121,9 @@ var system = {
|
||||
$("#" + dialogId).remove();
|
||||
$(e).remove();
|
||||
system.popoverCount--;
|
||||
if (config.onClose) {
|
||||
config.onClose(config.source);
|
||||
}
|
||||
},
|
||||
onShow: function() {
|
||||
system.popoverCount++;
|
||||
|
||||
102
src/tr-web-control/template/dialog-export-config.html
Normal file
102
src/tr-web-control/template/dialog-export-config.html
Normal file
@@ -0,0 +1,102 @@
|
||||
<div class="easyui-layout" data-options="fit:true" style="width:100%;height:100%;">
|
||||
<div data-options="region:'center'" style="padding:3px;border:0px;overflow: hidden;">
|
||||
<div id="" class="dialog" style="width:100%;padding:0px;height:100%;border-bottom: 1px dotted #ccc;">
|
||||
<div>
|
||||
<input id="chk-export-system" type="checkbox" checked="checked" />
|
||||
<label for="chk-export-system" system-lang="dialog['export-config']['option-system']"></label>
|
||||
</div>
|
||||
<div>
|
||||
<input id="chk-export-dictionary" type="checkbox" checked="checked"/>
|
||||
<label for="chk-export-dictionary" system-lang="dialog['export-config']['option-dictionary']"></label>
|
||||
</div>
|
||||
<div>
|
||||
<input id="chk-export-server" type="checkbox" checked="checked"/>
|
||||
<label for="chk-export-server" system-lang="dialog['export-config']['option-server']"></label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div data-options="region:'south',border:false" style="text-align:right;padding:6px;">
|
||||
<span id="text-nochange" style="display:none;"></span>
|
||||
<span id="text-count"></span>
|
||||
<a id="button-ok" class="easyui-linkbutton" data-options="iconCls:'icon-ok',plain:true" href="javascript:void(0);"
|
||||
system-lang="dialog['public']['button-ok']">Ok</a>
|
||||
<a id="button-cancel" class="easyui-linkbutton" data-options="iconCls:'icon-cancel',plain:true" href="javascript:void(0);"
|
||||
system-lang="dialog['public']['button-cancel']">Cancel</a>
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
(function (thisDialog) {
|
||||
var page = {
|
||||
init: function () {
|
||||
system.resetLangText(thisDialog);
|
||||
this.initEvents();
|
||||
},
|
||||
// 初始化事件
|
||||
initEvents: function () {
|
||||
// Cancel
|
||||
$("#button-cancel", thisDialog).click(function () {
|
||||
page.close();
|
||||
});
|
||||
|
||||
$("#button-ok", thisDialog).click(function () {
|
||||
if (page.done()) {
|
||||
page.close();
|
||||
}
|
||||
});
|
||||
},
|
||||
done: function () {
|
||||
var data = {};
|
||||
|
||||
// 系统
|
||||
if ($("#chk-export-system", thisDialog).prop("checked")) {
|
||||
data["system"] = system.config;
|
||||
data["user"] = system.userConfig;
|
||||
}
|
||||
|
||||
// 目录字典
|
||||
if ($("#chk-export-dictionary", thisDialog).prop("checked")) {
|
||||
data["dictionary-folders"] = system.dictionary.folders.split("\n");
|
||||
}
|
||||
|
||||
// 服务器
|
||||
if ($("#chk-export-server", thisDialog).prop("checked")) {
|
||||
data["server"] = $.extend({}, system.serverConfig);
|
||||
|
||||
// 排除一些不需要的参数
|
||||
var except = ["blocklist-size", "config-dir", "rpc-version",
|
||||
"rpc-version-minimum", "version", "session-id", "units",
|
||||
"download-dir-free-space"];
|
||||
|
||||
for (const key in except) {
|
||||
if (except.hasOwnProperty(key)) {
|
||||
const item = except[key];
|
||||
data.server.hasOwnProperty(item) && delete data.server[item];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($.isEmptyObject(data)) {
|
||||
thisDialog.find("#text-nochange").html(system.lang.dialog["export-config"].title).fadeInAndOut();
|
||||
return false;
|
||||
}
|
||||
|
||||
data["configVersion"] = 1;
|
||||
|
||||
var exportData = JSON.parse(JSON.stringify(data));
|
||||
|
||||
saveFileAs("tr-web-contorl-config.json", JSON.stringify(exportData));
|
||||
return true;
|
||||
},
|
||||
close: function () {
|
||||
var source = thisDialog.data("popoverSource");
|
||||
|
||||
if (source) {
|
||||
$(source).webuiPopover("hide");
|
||||
} else {
|
||||
thisDialog.dialog("close");
|
||||
}
|
||||
}
|
||||
};
|
||||
page.init();
|
||||
})($("#dialog-export-config"));
|
||||
</script>
|
||||
119
src/tr-web-control/template/dialog-import-config.html
Normal file
119
src/tr-web-control/template/dialog-import-config.html
Normal file
@@ -0,0 +1,119 @@
|
||||
<div class="easyui-layout" data-options="fit:true" style="width:100%;height:100%;">
|
||||
<div data-options="region:'center'" style="padding:3px;border:0px;overflow: hidden;">
|
||||
<div id="" class="dialog" style="width:100%;padding:0px;height:100%;border-bottom: 1px dotted #ccc;">
|
||||
<div id="div-option-system" style="display:none;">
|
||||
<input id="chk-option-system" type="checkbox" />
|
||||
<label for="chk-option-system" system-lang="dialog['export-config']['option-system']"></label>
|
||||
</div>
|
||||
<div id="div-option-dictionary-folders" style="display:none;">
|
||||
<input id="chk-option-dictionary-folders" type="checkbox" />
|
||||
<label for="chk-option-dictionary-folders" system-lang="dialog['export-config']['option-dictionary']"></label>
|
||||
</div>
|
||||
<div id="div-option-server" style="display:none;">
|
||||
<input id="chk-option-server" type="checkbox" />
|
||||
<label for="chk-option-server" system-lang="dialog['export-config']['option-server']"></label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div data-options="region:'south',border:false" style="text-align:right;padding:6px;">
|
||||
<span id="text-nochange" style="display:none;"></span>
|
||||
<span id="text-count"></span>
|
||||
<a id="button-ok" class="easyui-linkbutton" data-options="iconCls:'icon-ok',plain:true" href="javascript:void(0);"
|
||||
system-lang="dialog['public']['button-ok']">Ok</a>
|
||||
<a id="button-cancel" class="easyui-linkbutton" data-options="iconCls:'icon-cancel',plain:true" href="javascript:void(0);"
|
||||
system-lang="dialog['public']['button-cancel']">Cancel</a>
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
(function (thisDialog) {
|
||||
var page = {
|
||||
config: thisDialog.data("config"),
|
||||
init: function () {
|
||||
system.resetLangText(thisDialog);
|
||||
this.initEvents();
|
||||
this.initValues();
|
||||
},
|
||||
// 初始化事件
|
||||
initEvents: function () {
|
||||
// Cancel
|
||||
$("#button-cancel", thisDialog).click(function () {
|
||||
page.close();
|
||||
});
|
||||
|
||||
$("#button-ok", thisDialog).click(function () {
|
||||
if (page.done()) {
|
||||
page.close();
|
||||
}
|
||||
});
|
||||
},
|
||||
initValues: function () {
|
||||
for (const key in this.config) {
|
||||
if (this.config.hasOwnProperty(key)) {
|
||||
$("#div-option-" + key, thisDialog).show();
|
||||
$("#chk-option-" + key, thisDialog).prop("checked", true);
|
||||
}
|
||||
}
|
||||
},
|
||||
done: function () {
|
||||
var data = {};
|
||||
|
||||
// 系统
|
||||
if ($("#chk-option-system", thisDialog).prop("checked")) {
|
||||
data["system"] = this.config.system;
|
||||
data["user"] = this.config.user;
|
||||
}
|
||||
|
||||
// 目录字典
|
||||
if ($("#chk-option-dictionary-folders", thisDialog).prop("checked")) {
|
||||
data["dictionary-folders"] = (this.config["dictionary-folders"]).join("\n");
|
||||
}
|
||||
|
||||
// 服务器
|
||||
if ($("#chk-option-server", thisDialog).prop("checked")) {
|
||||
data["server"] = this.config.server;
|
||||
}
|
||||
|
||||
if ($.isEmptyObject(data)) {
|
||||
thisDialog.find("#text-nochange").html(system.lang.dialog["import-config"].title).fadeInAndOut();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (confirm(system.lang.dialog["system-config"]["import-config-confirm"])) {
|
||||
system.config = data["system"] || system.config;
|
||||
system.userConfig = data["user"] || system.userConfig;
|
||||
system.dictionary.folders = data["dictionary-folders"] || system.dictionary.folders;
|
||||
system.saveConfig();
|
||||
system.saveUserConfig();
|
||||
|
||||
if (data["server"]) {
|
||||
this.updateServerConfig(data["server"]);
|
||||
} else {
|
||||
location.href = location.href;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
},
|
||||
updateServerConfig: function(config) {
|
||||
// Start setting parameters
|
||||
transmission.exec({
|
||||
method: "session-set",
|
||||
arguments: config
|
||||
}, function (data) {
|
||||
if (data.result == "success") {
|
||||
location.href = location.href;
|
||||
}
|
||||
});
|
||||
},
|
||||
close: function () {
|
||||
var source = thisDialog.data("popoverSource");
|
||||
|
||||
if (source) {
|
||||
$(source).webuiPopover("hide");
|
||||
} else {
|
||||
thisDialog.dialog("close");
|
||||
}
|
||||
}
|
||||
};
|
||||
page.init();
|
||||
})($("#dialog-import-config"));
|
||||
</script>
|
||||
@@ -326,7 +326,10 @@
|
||||
</div>
|
||||
<div data-options="region:'south',border:false" style="text-align:right;padding:6px;">
|
||||
<a id="system-config-button-reload" href="javascript:void(0)" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-reload'" style="float:left;display:none;"></a>
|
||||
<button id="restore-default-settings" style="float:left;" system-lang="dialog['system-config']['restore-default-settings']" data-options="iconCls:'iconfont tr-icon-restore'" class="easyui-linkbutton"></button>
|
||||
<button id="restore-default-settings" style="float:left;" system-lang="dialog['system-config']['restore-default-settings']" data-options="iconCls:'iconfont tr-icon-restore',plain:true" class="easyui-linkbutton"></button>
|
||||
<span style="float:left;margin-top: 4px;height: auto;" class="button-split">|</span>
|
||||
<button id="btn-import-config" style="float:left;" system-lang="dialog['public']['button-import']" system-tip-lang="dialog['system-config']['import-config']" data-options="iconCls:'iconfont tr-icon-download',plain:true" class="easyui-linkbutton"></button>
|
||||
<button id="btn-export-config" style="float:left;" system-lang="dialog['public']['button-export']" system-tip-lang="dialog['system-config']['export-config']" data-options="iconCls:'iconfont tr-icon-upload',plain:true" class="easyui-linkbutton"></button>
|
||||
<span id="system-config-nochange" style="display:none;"></span>
|
||||
<span id="system-config-saved" style="display:none;"></span>
|
||||
<a id="system-config-button-save" class="easyui-linkbutton" data-options="iconCls:'icon-save',plain:true" href="javascript:void(0);">Ok</a>
|
||||
@@ -843,18 +846,18 @@
|
||||
}
|
||||
var exportData = JSON.parse(JSON.stringify(data));
|
||||
|
||||
page.saveFileAs("tr-web-contorl-labels.json", JSON.stringify(exportData));
|
||||
saveFileAs("tr-web-contorl-labels.json", JSON.stringify(exportData));
|
||||
});
|
||||
|
||||
// 导入
|
||||
$("#btn-UserLabel-import").on("click", function () {
|
||||
page.loadFileContent("json", function (content) {
|
||||
$("#btn-UserLabel-import", thisDialog).on("click", function () {
|
||||
loadFileContent("json", function (content) {
|
||||
var item = content;
|
||||
if (typeof (content) === "string") {
|
||||
try {
|
||||
item = JSON.parse(content);
|
||||
} catch (error) {
|
||||
alert("JSON文件解析失败!");
|
||||
alert(system.lang["public"]["text-json-file-parsing-failed"]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -946,6 +949,14 @@
|
||||
};
|
||||
|
||||
reloadData();
|
||||
|
||||
$("#btn-export-config", thisDialog).on("click.cus", function() {
|
||||
page.exportConfig(this);
|
||||
});
|
||||
|
||||
$("#btn-import-config", thisDialog).on("click", function() {
|
||||
page.importConfig(this);
|
||||
})
|
||||
},
|
||||
endEditing: function(){
|
||||
if (page.editIndex == undefined){return true}
|
||||
@@ -957,91 +968,63 @@
|
||||
return false;
|
||||
}
|
||||
},
|
||||
/**
|
||||
* 加载指定的文件内容
|
||||
*/
|
||||
loadFileContent: function (fileType, callback) {
|
||||
$("<input id='file-loadContent' type='file' style='display:none;' multiple='true'/>").on("change", function () {
|
||||
var fileSelector = this;
|
||||
if (fileSelector.files.length > 0 && fileSelector.files[0].name.length > 0) {
|
||||
var files = fileSelector.files;
|
||||
var count = files.length;
|
||||
var index = 0;
|
||||
var r = new FileReader();
|
||||
r.onload = function (e) {
|
||||
callback && callback.call(system, e.target.result);
|
||||
readFile();
|
||||
};
|
||||
r.onerror = function () {
|
||||
alert("文件加载失败");
|
||||
console.log("文件加载失败");
|
||||
readFile();
|
||||
};
|
||||
|
||||
function readFile(file) {
|
||||
|
||||
if (index == count) {
|
||||
$(fileSelector).remove();
|
||||
fileSelector.value = "";
|
||||
return;
|
||||
}
|
||||
var file = files[index];
|
||||
var lastIndex = file.name.lastIndexOf(".");
|
||||
var fix = file.name.substr(lastIndex + 1);
|
||||
|
||||
index++;
|
||||
|
||||
if (fileType) {
|
||||
if (fix != fileType) {
|
||||
alert("文件类型错误");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
r.readAsText(file);
|
||||
}
|
||||
readFile();
|
||||
}
|
||||
}).click();
|
||||
},
|
||||
/**
|
||||
* 将指定的内容保存为文件
|
||||
* @param fileName 文件名
|
||||
* @param fileData 文件内容
|
||||
*/
|
||||
saveFileAs: function (fileName, fileData) {
|
||||
try {
|
||||
var Blob = window.Blob || window.WebKitBlob;
|
||||
|
||||
// Detect availability of the Blob constructor.
|
||||
var constructor_supported = false;
|
||||
if (Blob) {
|
||||
importConfig: function(button) {
|
||||
loadFileContent("json", function (content) {
|
||||
var item = content;
|
||||
if (typeof (content) === "string") {
|
||||
try {
|
||||
new Blob([], {
|
||||
"type": "text/plain"
|
||||
});
|
||||
constructor_supported = true;
|
||||
} catch (_) {}
|
||||
item = JSON.parse(content);
|
||||
} catch (error) {
|
||||
alert(system.lang["public"]["text-json-file-parsing-failed"]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
var b = null;
|
||||
if (constructor_supported) {
|
||||
b = new Blob([fileData], {
|
||||
"type": "text/plain"
|
||||
if (item.system || item.user || item.server || item.dictionary) {
|
||||
system.openDialogFromTemplate({
|
||||
id: "dialog-import-config",
|
||||
options: {
|
||||
title: system.lang.dialog["import-config"].title,
|
||||
width: 500,
|
||||
height: 120
|
||||
},
|
||||
datas: {
|
||||
config: item
|
||||
},
|
||||
type: 1,
|
||||
source: $(button),
|
||||
onClose: function() {
|
||||
$(button).on("click", function(){
|
||||
page.importConfig(this);
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// Deprecated BlobBuilder API
|
||||
var BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder;
|
||||
var bb = new BlobBuilder();
|
||||
bb.append(fileData);
|
||||
b = bb.getBlob("text/plain");
|
||||
alert(system.lang.dialog["import-config"]["invalid-file"]);
|
||||
// thisDialog.find("#system-config-nochange").html(system.lang.dialog["import-config"]["invalid-file"]).fadeInAndOut();
|
||||
}
|
||||
|
||||
saveAs(b, fileName);
|
||||
} catch (e) {
|
||||
console.log(e.toString());
|
||||
}
|
||||
});
|
||||
},
|
||||
/**
|
||||
* 导出当前配置到文件
|
||||
*/
|
||||
exportConfig: function(button) {
|
||||
system.openDialogFromTemplate({
|
||||
id: "dialog-export-config",
|
||||
options: {
|
||||
title: system.lang.dialog["export-config"].title,
|
||||
width: 500,
|
||||
height: 120
|
||||
},
|
||||
type: 1,
|
||||
source: $(button),
|
||||
onClose: function() {
|
||||
$(button).on("click", function(){
|
||||
page.exportConfig(this);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
page.init();
|
||||
})($("#dialog-system-config"));
|
||||
|
||||
Reference in New Issue
Block a user