dialog-torrent-setLabels.html 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <div class="easyui-layout" data-options="fit:true" style="width:100%;height:100%;">
  2. <div data-options="region:'center'" style="padding:3px;border:0px;overflow: hidden;">
  3. <div id="" class="dialog" style="width:100%;padding:0px;height:100%;border-bottom: 1px dotted #ccc;">
  4. <div style="position: absolute;width:50%;height: 100%;">
  5. <div system-lang="dialog['torrent-setLabels']['available']"></div>
  6. <div id="divAvailableList" style="padding-top: 5px;"></div>
  7. </div>
  8. <div style="position: absolute;left:50%;width:50%;height: 100%;border-left: 1px dotted #ccc;padding-left: 5px;">
  9. <div system-lang="dialog['torrent-setLabels']['selected']"></div>
  10. <div id="divSelectedList" style="padding-top: 5px;"></div>
  11. </div>
  12. </div>
  13. </div>
  14. <div data-options="region:'south',border:false" style="text-align:right;padding:6px;">
  15. <span id="text-nochange" style="display:none;"></span>
  16. <span id="text-count"></span>
  17. <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>
  18. <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>
  19. </div>
  20. </div>
  21. <script type="text/javascript">
  22. (function(thisDialog) {
  23. var page = {
  24. hashs: thisDialog.data("hashs")||[],
  25. divSelectedList: $("#divSelectedList", thisDialog),
  26. init: function() {
  27. system.resetLangText(thisDialog);
  28. this.initEvents();
  29. this.initLabels();
  30. },
  31. // 初始化事件
  32. initEvents: function() {
  33. // Cancel
  34. thisDialog.find("#button-cancel").click(function () {
  35. page.close();
  36. });
  37. $("#button-ok", thisDialog).click(function(){
  38. page.save();
  39. page.close();
  40. });
  41. },
  42. // 初始化标签列表
  43. initLabels: function() {
  44. var box = $("#divAvailableList", thisDialog);
  45. for (var index = 0; index < system.config.labels.length; index++) {
  46. var item = system.config.labels[index];
  47. if (item) {
  48. item.index = index;
  49. var label = this.createLabel(item);
  50. label.on("click", function(){
  51. page.setLabel("#divAvailableList", "#divSelectedList", $(this).data("label"));
  52. $(this).remove();
  53. }).appendTo(box);
  54. }
  55. }
  56. if (this.hashs.length==1) {
  57. var labels = system.config.labelMaps[this.hashs[0]];
  58. if (labels) {
  59. for (var i = 0; i < labels.length; i++) {
  60. var index = labels[i];
  61. var item = system.config.labels[index];
  62. if (item) {
  63. this.setLabel("#divAvailableList", "#divSelectedList", item);
  64. $(".label-index-"+index, box).remove();
  65. }
  66. }
  67. }
  68. }
  69. },
  70. createLabel: function(label) {
  71. return $("<a href='javascript:void(0);' class='user-label-big label-index-"+label.index+"'/>").data("label", label).html(label.name).css({
  72. "background-color": label.color,
  73. "color": (getGrayLevel(label.color) > 0.5 ? "#000" : "#fff")
  74. });
  75. },
  76. setLabel: function(from, to, item) {
  77. var box = $(to, thisDialog);
  78. var label = this.createLabel(item);
  79. label.on("click", function(){
  80. page.setLabel(to, from, $(this).data("label"));
  81. $(this).remove();
  82. }).appendTo(box);
  83. },
  84. save: function() {
  85. var items = $(".user-label-big", this.divSelectedList);
  86. var labels = [];
  87. for (var index = 0; index < items.length; index++) {
  88. var item = $(items[index]);
  89. var label = item.data("label");
  90. labels.push(label.index);
  91. }
  92. for (var index = 0; index < this.hashs.length; index++) {
  93. var item = this.hashs[index];
  94. if (labels.length==0) {
  95. delete system.config.labelMaps[item];
  96. } else {
  97. system.config.labelMaps[item] = labels;
  98. }
  99. }
  100. system.saveConfig();
  101. setTimeout(function(){
  102. system.control.torrentlist.refresh();
  103. }, 200);
  104. },
  105. close: function() {
  106. var source = thisDialog.data("popoverSource");
  107. if (source) {
  108. $(source).webuiPopover("hide");
  109. } else {
  110. thisDialog.dialog("close");
  111. }
  112. }
  113. };
  114. page.init();
  115. })($("#dialog-torrent-setLabels"));
  116. </script>