dialog-import-config.html 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 id="div-option-system" style="display:none;">
  5. <input id="chk-option-system" type="checkbox" />
  6. <label for="chk-option-system" system-lang="dialog['export-config']['option-system']"></label>
  7. </div>
  8. <div id="div-option-dictionary-folders" style="display:none;">
  9. <input id="chk-option-dictionary-folders" type="checkbox" />
  10. <label for="chk-option-dictionary-folders" system-lang="dialog['export-config']['option-dictionary']"></label>
  11. </div>
  12. <div id="div-option-server" style="display:none;">
  13. <input id="chk-option-server" type="checkbox" />
  14. <label for="chk-option-server" system-lang="dialog['export-config']['option-server']"></label>
  15. </div>
  16. </div>
  17. </div>
  18. <div data-options="region:'south',border:false" style="text-align:right;padding:6px;">
  19. <span id="text-nochange" style="display:none;"></span>
  20. <span id="text-count"></span>
  21. <a id="button-ok" class="easyui-linkbutton" data-options="iconCls:'icon-ok',plain:true" href="javascript:void(0);"
  22. system-lang="dialog['public']['button-ok']">Ok</a>
  23. <a id="button-cancel" class="easyui-linkbutton" data-options="iconCls:'icon-cancel',plain:true" href="javascript:void(0);"
  24. system-lang="dialog['public']['button-cancel']">Cancel</a>
  25. </div>
  26. </div>
  27. <script type="text/javascript">
  28. (function (thisDialog) {
  29. var page = {
  30. config: thisDialog.data("config"),
  31. init: function () {
  32. system.resetLangText(thisDialog);
  33. this.initEvents();
  34. this.initValues();
  35. },
  36. // 初始化事件
  37. initEvents: function () {
  38. // Cancel
  39. $("#button-cancel", thisDialog).click(function () {
  40. page.close();
  41. });
  42. $("#button-ok", thisDialog).click(function () {
  43. if (page.done()) {
  44. page.close();
  45. }
  46. });
  47. },
  48. initValues: function () {
  49. for (const key in this.config) {
  50. if (this.config.hasOwnProperty(key)) {
  51. $("#div-option-" + key, thisDialog).show();
  52. $("#chk-option-" + key, thisDialog).prop("checked", true);
  53. }
  54. }
  55. },
  56. done: function () {
  57. var data = {};
  58. // 系统
  59. if ($("#chk-option-system", thisDialog).prop("checked")) {
  60. data["system"] = this.config.system;
  61. data["user"] = this.config.user;
  62. }
  63. // 目录字典
  64. if ($("#chk-option-dictionary-folders", thisDialog).prop("checked")) {
  65. data["dictionary-folders"] = (this.config["dictionary-folders"]).join("\n");
  66. }
  67. // 服务器
  68. if ($("#chk-option-server", thisDialog).prop("checked")) {
  69. data["server"] = this.config.server;
  70. }
  71. if ($.isEmptyObject(data)) {
  72. thisDialog.find("#text-nochange").html(system.lang.dialog["import-config"].title).fadeInAndOut();
  73. return false;
  74. }
  75. if (confirm(system.lang.dialog["system-config"]["import-config-confirm"])) {
  76. system.config = data["system"] || system.config;
  77. system.userConfig = data["user"] || system.userConfig;
  78. system.dictionary.folders = data["dictionary-folders"] || system.dictionary.folders;
  79. system.saveConfig();
  80. system.saveUserConfig();
  81. if (data["server"]) {
  82. this.updateServerConfig(data["server"]);
  83. } else {
  84. location.href = location.href;
  85. }
  86. }
  87. return true;
  88. },
  89. updateServerConfig: function(config) {
  90. // Start setting parameters
  91. transmission.exec({
  92. method: "session-set",
  93. arguments: config
  94. }, function (data) {
  95. if (data.result == "success") {
  96. location.href = location.href;
  97. }
  98. });
  99. },
  100. close: function () {
  101. var source = thisDialog.data("popoverSource");
  102. if (source) {
  103. $(source).webuiPopover("hide");
  104. } else {
  105. thisDialog.dialog("close");
  106. }
  107. }
  108. };
  109. page.init();
  110. })($("#dialog-import-config"));
  111. </script>