WebServers.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. MWF.xDesktop.requireApp("Setting", "servers.DataServers", null, false);
  2. MWF.xApplication.Setting.servers = MWF.xApplication.Setting.servers || {};
  3. MWF.xApplication.Setting.servers.WebServers = 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.webServerContent;
  13. this.page = this.app.serverPage;
  14. this.load();
  15. },
  16. load: function(){
  17. this.actions.listWebServer(function(json){
  18. json.data.each(function(serverJson){
  19. this.servers.push(new MWF.xApplication.Setting.servers.WebServer(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.setWebServerAreaWidth();}.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.WebServer(this.list, this.json));
  39. }
  40. }
  41. var doc = new MWF.xApplication.Setting.servers.WebServer.Document(server);
  42. }
  43. });
  44. MWF.xApplication.Setting.servers.WebServer = 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.WebServer.Document(this);
  64. },
  65. reload: function(){
  66. this.app.actions.getWebServer(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.WebServer.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>host</td><td><input value='"+(this.json.host || "")+"'/></td></tr>" +
  86. "<tr><td>port</td><td><input value='"+(this.json.port || "")+"'/></td></tr>" +
  87. "<tr><td>username</td><td><input value='"+(this.json.username || "")+"'/></td></tr>" +
  88. "<tr><td>password</td><td><input type='password' value='"+(this.json.password || "")+"'/></td></tr>" +
  89. "<tr><td>proxyHost</td><td><input type='text' value='"+(this.json.proxyHost || "")+"'/></td></tr>" +
  90. "<tr><td>proxyPort</td><td><input type='text' value='"+(this.json.proxyPort || "")+"'/></td></tr>" +
  91. "</table>";
  92. this.inforNode.set("html", html);
  93. var tds = this.inforNode.getElements("td");
  94. var inputs = this.inforNode.getElements("input");
  95. tds.setStyles(this.css.applicationServerDocumentTdNode);
  96. inputs.setStyles(this.css.applicationServerDocumentInputNode);
  97. },
  98. saveDocument: function(){
  99. var inputs = this.inforNode.getElements("input");
  100. this.json.name = inputs[0].get("value");
  101. this.json.order = inputs[1].get("value");
  102. this.json.host = inputs[2].get("value");
  103. this.json.port = inputs[3].get("value");
  104. this.json.username = inputs[4].get("value");
  105. this.json.password = inputs[5].get("value");
  106. this.json.proxyHost = inputs[6].get("value");
  107. this.json.proxyPort = inputs[7].get("value");
  108. if (this.server.name){
  109. this.app.actions.updateWebServer(this.server.name, this.json, function(){
  110. this.closeDocument();
  111. this.server.reload();
  112. }.bind(this));
  113. }else{
  114. this.app.actions.addWebServer(this.json, function(){
  115. this.closeDocument();
  116. this.server.reload();
  117. }.bind(this));
  118. }
  119. },
  120. deleteDocument: function(e){
  121. var _self = this;
  122. this.app.confirm("warn", e, this.app.lp.deleteWebServer_title, this.app.lp.deleteWebServer, "350", "120", function(){
  123. _self.app.actions.removeWebServer(_self.server.name, function(){
  124. this.closeDocument();
  125. this.server.destroy();
  126. }.bind(_self));
  127. this.close();
  128. }, function(){
  129. this.close();
  130. });
  131. }
  132. });