@@ -77,6 +91,64 @@
thisDialog.find("#chkautostart").prop("checked", system.serverConfig["start-added-torrents"]);
thisDialog.find("#download-dir").combobox();
+
+ // label
+ var labelPage = {
+ divSelectedList: $("#divSelectedList", thisDialog),
+ init: function() {
+ if(system.config.nav.labels){
+ system.resetLangText(thisDialog);
+ this.initLabels();
+ }
+ else{
+ $("#label_page").css("display", "none");
+ }
+ },
+ // 初始化标签列表
+ initLabels: function() {
+ var box = $("#divAvailableList", thisDialog);
+ for (var index = 0; index < system.config.labels.length; index++) {
+ var item = system.config.labels[index];
+ if (item) {
+ item.index = index;
+ var label = this.createLabel(item);
+ label.on("click", function(){
+ labelPage.setLabel("#divAvailableList", "#divSelectedList", $(this).data("label"));
+ $(this).remove();
+ }).appendTo(box);
+ }
+ }
+ },
+ createLabel: function(label) {
+ return $("
").data("label", label).html(label.name).css({
+ "background-color": label.color,
+ "color": (getGrayLevel(label.color) > 0.5 ? "#000" : "#fff")
+ });
+ },
+ setLabel: function(from, to, item) {
+ var box = $(to, thisDialog);
+ var label = this.createLabel(item);
+ label.on("click", function(){
+ labelPage.setLabel(to, from, $(this).data("label"));
+ $(this).remove();
+ }).appendTo(box);
+ },
+ getLabels: function() {
+ if(!system.config.nav.labels)
+ return null;
+ var items = $(".user-label-big", this.divSelectedList);
+ var labels = [];
+
+ for (var index = 0; index < items.length; index++) {
+ var item = $(items[index]);
+ var label = item.data("label");
+ labels.push(label.index);
+ }
+ return labels;
+ }
+ };
+ labelPage.init();
+
// Confirm
thisDialog.find("#torrent-button-ok").click(function()
{
@@ -133,7 +205,10 @@
thisDialog.find("#dialog-torrent-add-queue").html("").hide();
thisDialog.dialog("close");
}
-
+ if(system.config.nav.labels && data.hashString != null){
+ system.saveLabelsConfig(data.hashString, labelPage.getLabels());
+ system.saveConfig();
+ }
system.reloadData();
});
return;
@@ -161,7 +236,7 @@
else if (url!="")
{
var urls = url.split("\n");
- system.addTorrentsToServer(urls,urls.length,autostart,dir);
+ system.addTorrentsToServer(urls,urls.length,autostart,dir,labelPage.getLabels());
urls = null;
thisDialog.dialog("close");
}
@@ -213,6 +288,10 @@
//alert(data);
if (callback)
callback();
+ if(system.config.nav.labels && data.hashString != null){
+ system.saveLabelsConfig(data.hashString, labelPage.getLabels());
+ system.saveConfig();
+ }
thisDialog.dialog("close");
system.reloadData();
}
diff --git a/src/tr-web-control/template/dialog-torrent-addfile.html b/src/tr-web-control/template/dialog-torrent-addfile.html
index 2232fa9..be22210 100644
--- a/src/tr-web-control/template/dialog-torrent-addfile.html
+++ b/src/tr-web-control/template/dialog-torrent-addfile.html
@@ -28,6 +28,20 @@
+
+
+
@@ -71,6 +85,61 @@
thisDialog.find("#chkautostart").prop("checked", system.serverConfig["start-added-torrents"]);
+ // label
+ var labelPage = {
+ divSelectedList: $("#divSelectedList", thisDialog),
+ init: function() {
+ if(system.config.nav.labels){
+ system.resetLangText(thisDialog);
+ this.initLabels();
+ }
+ else{
+ $("#label_page").css("display", "none");
+ }
+ },
+ // 初始化标签列表
+ initLabels: function() {
+ var box = $("#divAvailableList", thisDialog);
+ for (var index = 0; index < system.config.labels.length; index++) {
+ var item = system.config.labels[index];
+ if (item) {
+ item.index = index;
+ var label = this.createLabel(item);
+ label.on("click", function(){
+ labelPage.setLabel("#divAvailableList", "#divSelectedList", $(this).data("label"));
+ $(this).remove();
+ }).appendTo(box);
+ }
+ }
+ },
+ createLabel: function(label) {
+ return $("
").data("label", label).html(label.name).css({
+ "background-color": label.color,
+ "color": (getGrayLevel(label.color) > 0.5 ? "#000" : "#fff")
+ });
+ },
+ setLabel: function(from, to, item) {
+ var box = $(to, thisDialog);
+ var label = this.createLabel(item);
+ label.on("click", function(){
+ labelPage.setLabel(to, from, $(this).data("label"));
+ $(this).remove();
+ }).appendTo(box);
+ },
+ getLabels: function() {
+ var items = $(".user-label-big", this.divSelectedList);
+ var labels = [];
+
+ for (var index = 0; index < items.length; index++) {
+ var item = $(items[index]);
+ var label = item.data("label");
+ labels.push(label.index);
+ }
+ return labels;
+ }
+ };
+ labelPage.init();
+
// Confirm
thisDialog.find("#torrent-button-ok").click(function()
{
@@ -108,15 +177,25 @@
var files = thisDialog.data("files");
var uploaded = 0;
+ var islabelChange = false;
$.each(files,function(i,item){
- transmission.addTorrentFromFile(item,dir,!autostart,function(){
+ transmission.addTorrentFromFile(item,dir,!autostart,function(data, count){
uploaded++;
thisDialog.find("#dialog-torrent-add-queue").html(uploaded+"/"+files.length).show();
+
+ // save label for torrent
+ if(system.config.nav.labels && data.hashString != null){
+ islabelChange = true;
+ system.saveLabelsConfig(data.hashString, labelPage.getLabels());
+ }
+
if (uploaded==files.length)
{
thisDialog.find("#dialog-torrent-add-queue").html("").hide();
button.linkbutton({disabled:false});
thisDialog.dialog("close");
+ if(islabelChange)
+ system.saveConfig();
}
system.reloadData();
});