StorageServers.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. MWF.xDesktop.requireApp("Setting", "servers.DataServers", null, false);
  2. MWF.xApplication.Setting.servers = MWF.xApplication.Setting.servers || {};
  3. MWF.xApplication.Setting.servers.StorageServers = new Class({
  4. Extends: MWF.xApplication.Setting.servers.DataServers,
  5. Implements: [Options, Events],
  6. initialize: function(explorer){
  7. this.explorer = explorer;
  8. this.app = this.explorer.app;
  9. this.actions = this.app.actions;
  10. this.css = this.app.css;
  11. this.servers = [];
  12. this.content = this.explorer.storageServerContent;
  13. this.page = this.app.serverPage;
  14. this.load();
  15. },
  16. load: function(){
  17. this.actions.listStorageServer(function(json){
  18. json.data.each(function(serverJson){
  19. this.servers.push(new MWF.xApplication.Setting.servers.StorageServer(this, serverJson));
  20. }.bind(this));
  21. this.createAddAction();
  22. this.setServerAreaWidthFun = this.setServerAreaWidth.bind(this);
  23. this.addEvent("resize", this.setServerAreaWidthFun);
  24. this.addEvent("resize", function(){this.setStorageServerAreaWidth();}.bind(this));
  25. }.bind(this));
  26. },
  27. createServer: function(){
  28. var server = {
  29. "list": this,
  30. "app": this.app,
  31. "json": {
  32. "contextList": [],
  33. "planList": []
  34. },
  35. "node": this.createServerAction,
  36. "name": "",
  37. "reload": function(){
  38. this.list.servers.push(new MWF.xApplication.Setting.servers.StorageServer(this.list, this.json));
  39. }
  40. }
  41. var doc = new MWF.xApplication.Setting.servers.StorageServer.Document(server);
  42. }
  43. });
  44. MWF.xApplication.Setting.servers.StorageServer = new Class({
  45. Extends: MWF.xApplication.Setting.servers.DataServer,
  46. Implements: [Events],
  47. initialize: function(list, json){
  48. this.list = list
  49. this.app = this.list.app;
  50. this.json = json;
  51. this.container = this.list.content;
  52. this.css = this.app.css;
  53. this.name = this.json.name;
  54. this.load();
  55. },
  56. setServerText: function(){
  57. this.nameNode.set("text", (this.json.name || ""));
  58. this.hostNode.set("text", (this.json.host || "")+" : "+(this.json.port || ""));
  59. this.adminNode.set("text", (this.json.username || ""));
  60. this.messageNode.set("text", (this.json.message || ""));
  61. },
  62. open: function(){
  63. new MWF.xApplication.Setting.servers.StorageServer.Document(this);
  64. },
  65. reload: function(){
  66. this.app.actions.getStorageServer(this.json.name, function(json){
  67. this.name = this.json.name;
  68. this.json = json.data;
  69. this.nameNode.set("text", this.json.name);
  70. this.hostNode.set("text", this.json.host+" : "+this.json.port);
  71. this.adminNode.set("text", this.json.username);
  72. this.messageNode.set("text", this.json.message);
  73. }.bind(this));
  74. }
  75. });
  76. MWF.xApplication.Setting.servers.StorageServer.Document = new Class({
  77. Extends: MWF.xApplication.Setting.servers.DataServer.Document,
  78. Implements: [Events],
  79. createBaseInfo: function(){
  80. this.inforAreaNode = new Element("div", {"styles": this.css.applicationServerDocumentInforAreaNode}).inject(this.node);
  81. this.inforNode = new Element("div", {"styles": this.css.dataServerDocumentInforNode}).inject(this.inforAreaNode);
  82. var html = "<table cellSpacing='8px' width='90%' align='center'>" +
  83. "<tr><td width='160px'>name</td><td><input value='"+(this.json.name || "")+"'/></td></tr>" +
  84. "<tr><td>order</td><td><input value='"+(this.json.order || "0")+"'/></td></tr>" +
  85. "<tr><td>storageServiceType</td><td><select>" +
  86. "<option value='ftp' "+((this.json.storageServiceType=="ftp") ? "selected" : "")+">ftp</option>" +
  87. "</select></td></tr>" +
  88. "<tr><td>host</td><td><input value='"+(this.json.host || "")+"'/></td></tr>" +
  89. "<tr><td>port</td><td><input value='"+(this.json.port || "")+"'/></td></tr>" +
  90. "<tr><td>path</td><td><input value='"+(this.json.path || "")+"'/></td></tr>" +
  91. "<tr><td>username</td><td><input value='"+(this.json.username || "")+"'/></td></tr>" +
  92. "<tr><td>password</td><td><input type='password' value='"+(this.json.password || "")+"'/></td></tr>" +
  93. "</table>";
  94. this.inforNode.set("html", html);
  95. var tds = this.inforNode.getElements("td");
  96. var inputs = this.inforNode.getElements("input");
  97. tds.setStyles(this.css.applicationServerDocumentTdNode);
  98. inputs.setStyles(this.css.applicationServerDocumentInputNode);
  99. },
  100. saveDocument: function(){
  101. var inputs = this.inforNode.getElements("input");
  102. this.json.name = inputs[0].get("value");
  103. this.json.order = inputs[1].get("value");
  104. this.json.host = inputs[2].get("value");
  105. this.json.port = inputs[3].get("value");
  106. this.json.path = inputs[4].get("value");
  107. this.json.username = inputs[5].get("value");
  108. this.json.password = inputs[6].get("value");
  109. var select = this.inforNode.getElement("select");
  110. this.json.storageServiceType = select.options[select.selectedIndex].value;
  111. if (this.server.name){
  112. this.app.actions.updateStorageServer(this.server.name, this.json, function(){
  113. this.closeDocument();
  114. this.server.reload();
  115. }.bind(this));
  116. }else{
  117. this.app.actions.addStorageServer(this.json, function(){
  118. this.closeDocument();
  119. this.server.reload();
  120. }.bind(this));
  121. }
  122. },
  123. deleteDocument: function(e){
  124. var _self = this;
  125. this.app.confirm("warn", e, this.app.lp.deleteStorageServer_title, this.app.lp.deleteStorageServer, "350", "120", function(){
  126. _self.app.actions.removeStorageServer(_self.server.name, function(){
  127. this.closeDocument();
  128. this.server.destroy();
  129. }.bind(_self));
  130. this.close();
  131. }, function(){
  132. this.close();
  133. });
  134. }
  135. });