ServerSetting.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. MWF.xDesktop.requireApp("Setting", "servers.DataServers", null, false);
  2. MWF.xApplication.Setting.mobile = MWF.xApplication.Setting.mobile || {};
  3. MWF.xApplication.Setting.mobile.ServerSetting = new Class({
  4. Extends: MWF.xApplication.Setting.servers.DataServer.Document,
  5. Implements: [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.content = this.explorer.serverSettingContent;
  12. this.page = this.app.mobilePage;
  13. this.json = null;
  14. this.webServers = [];
  15. this.applicationServers = [];
  16. this.load();
  17. },
  18. load: function(){
  19. this.node = new Element("div", {"styles": this.css.centerServerDocumentNode}).inject(this.content);
  20. this.createActions();
  21. this.centerServerNode = new Element("div", {"styles": {"overflow": "hidden", "border-bottom": "0px solid #999"}}).inject(this.node);
  22. this.webServerNode = new Element("div", {"styles": {"overflow": "hidden", "border-bottom": "0px solid #999"}}).inject(this.node);
  23. this.applicationServerNode = new Element("div", {"styles": {"overflow": "hidden", "border-bottom": "0px solid #999"}}).inject(this.node);
  24. this.centerServerTitleNode = new Element("div", {"styles": this.css.mobileServerTitleNode, "text": "Center Server"}).inject(this.centerServerNode);
  25. this.webServerTitleNode = new Element("div", {"styles": this.css.mobileServerTitleNode, "text": "Web Server"}).inject(this.webServerNode);
  26. this.applicationServerTitleNode = new Element("div", {"styles": this.css.mobileServerTitleNode, "text": "Applicaton Server"}).inject(this.applicationServerNode);
  27. this.centerServerListNode = new Element("div", {"styles": this.css.mobileCenterServerListNode}).inject(this.centerServerNode);
  28. this.webServerListNode = new Element("div", {"styles": this.css.mobileServerListNode}).inject(this.webServerNode);
  29. this.applicationServerListNode = new Element("div", {"styles": this.css.mobileServerListNode}).inject(this.applicationServerNode);
  30. this.app.actions.getCenterServer(function(json){
  31. this.json = json.data;
  32. this.createCenterForm();
  33. }.bind(this));
  34. this.actions.listWebServer(function(json){
  35. json.data.each(function(serverJson){
  36. this.webServers.push(new MWF.xApplication.Setting.mobile.ServerSetting.WebServer(this, serverJson));
  37. }.bind(this));
  38. }.bind(this));
  39. this.actions.listApplicationServer(function(json){
  40. json.data.each(function(serverJson){
  41. this.applicationServers.push(new MWF.xApplication.Setting.mobile.ServerSetting.ApplicationServer(this, serverJson));
  42. }.bind(this));
  43. }.bind(this));
  44. },
  45. createActions: function(){
  46. this.actionNode = new Element("div", {"styles": this.css.applicationServerDocumentActionNode}).inject(this.node);
  47. this.saveAction = new Element("div", {"styles": this.css.applicationServerDocumentSaveNode}).inject(this.actionNode);
  48. //this.closeAction = new Element("div", {"styles": this.css.applicationServerDocumentCloseNode}).inject(this.actionNode);
  49. this.saveAction.addEvents({
  50. "mouseover": function(){this.saveAction.setStyles(this.css.applicationServerDocumentSaveNode_over);}.bind(this),
  51. "mouseout": function(){this.saveAction.setStyles(this.css.applicationServerDocumentSaveNode);}.bind(this),
  52. "mousedown": function(){this.saveAction.setStyles(this.css.applicationServerDocumentSaveNode_down);}.bind(this),
  53. "mouseup": function(){this.saveAction.setStyles(this.css.applicationServerDocumentSaveNode_over);}.bind(this),
  54. "click": function(e){this.saveDocument();}.bind(this)
  55. });
  56. },
  57. createCenterForm: function(){
  58. this.inforAreaNode = new Element("div", {"styles": this.css.applicationServerDocumentInforAreaNode}).inject(this.centerServerListNode);
  59. this.inforNode = new Element("div", {"styles": this.css.dataServerDocumentInforNode}).inject(this.inforAreaNode);
  60. var html = "<table cellSpacing='8px' width='90%' align='center'>" +
  61. "<tr><td width='160px'>proxyHost</td><td><input value='"+(this.json.proxyHost || "")+"'/></td></tr>" +
  62. "<tr><td>proxyPort</td><td><input value='"+(this.json.proxyPort || "")+"'/></td></tr>" +
  63. "</table>";
  64. this.inforNode.set("html", html);
  65. var tds = this.inforNode.getElements("td");
  66. var inputs = this.inforNode.getElements("input");
  67. tds.setStyles(this.css.applicationServerDocumentTdNode);
  68. inputs.setStyles(this.css.applicationServerDocumentInputNode);
  69. },
  70. checkSave: function(){
  71. var count = this.webServers.length+this.applicationServers.length+1;
  72. if (this.savedServers>=count){
  73. if (!this.errorServer.length){
  74. this.app.notice(this.app.lp.mobileServerSaveInfor, "success");
  75. }else{
  76. var errorText = "";
  77. this.errorServer.each(function(server){
  78. errorText = errorText+"; \n"+server.server.json.name+": "+server.message;
  79. }.bind(this));
  80. var text = this.app.lp.mobileServerSaveErrorInfor.replace(/{error}/, errorText);
  81. this.app.notice(text, "error");
  82. }
  83. }
  84. },
  85. saveDocument: function(){
  86. this.savedServers = 0;
  87. this.errorServer = [];
  88. this.webServers.each(function(ser){
  89. ser.saveDocument(function(){
  90. this.savedServers++;
  91. this.checkSave();
  92. }.bind(this), function(server, message){
  93. this.savedServers++;
  94. this.errorServer.push({"server": server, "message": message});
  95. this.checkSave();
  96. }.bind(this));
  97. }.bind(this));
  98. this.applicationServers.each(function(ser){
  99. ser.saveDocument(function(){
  100. this.savedServers++;
  101. this.checkSave();
  102. }.bind(this), function(server, message){
  103. this.savedServers++;
  104. this.errorServer.push({"server": server, "message": message});
  105. this.checkSave();
  106. }.bind(this));
  107. }.bind(this));
  108. var inputs = this.inforNode.getElements("input");
  109. this.json.proxyHost = inputs[0].get("value");
  110. this.json.proxyPort = inputs[1].get("value");
  111. this.app.actions.updateCenterServer(this.json, function(){
  112. this.savedServers++;
  113. this.checkSave();
  114. }.bind(this), function(xhr){
  115. var json = JSON.decode(xhr.responseText);
  116. this.savedServers++;
  117. this.errorServer.push({"server": {"json": this.json}, "message": json.message});
  118. this.checkSave();
  119. }.bind(this));
  120. },
  121. destroy: function(){
  122. this.webServers.each(function(ser){
  123. ser.destroy();
  124. }.bind(this));
  125. this.applicationServers.each(function(ser){
  126. ser.destroy();
  127. }.bind(this));
  128. if (this.node) this.node.destroy();
  129. MWF.release(this);
  130. },
  131. });
  132. MWF.xApplication.Setting.mobile.ServerSetting.WebServer = new Class({
  133. initialize: function(setting, json){
  134. this.setting = setting;
  135. this.app = this.setting.app;
  136. this.actions = this.app.actions;
  137. this.css = this.app.css;
  138. this.json = json;
  139. this.content = this.setting.webServerListNode;
  140. this.load();
  141. },
  142. load: function(){
  143. this.node = new Element("div", {"styles": this.css.mobileServerNode}).inject(this.content);
  144. this.createForm();
  145. },
  146. createForm: function(){
  147. this.inforAreaNode = new Element("div", {"styles": this.css.applicationServerDocumentInforAreaNode}).inject(this.node);
  148. this.inforNode = new Element("div", {"styles": this.css.dataServerDocumentInforNode}).inject(this.inforAreaNode);
  149. var html = "<table cellSpacing='8px' width='90%' align='center'>" +
  150. "<tr><td width='160px'>name</td><td>"+(this.json.name || "")+"</td></tr>" +
  151. "<tr><td width='160px'>proxyHost</td><td><input value='"+(this.json.proxyHost || "")+"'/></td></tr>" +
  152. "<tr><td>proxyPort</td><td><input value='"+(this.json.proxyPort || "")+"'/></td></tr>" +
  153. "</table>";
  154. this.inforNode.set("html", html);
  155. var tds = this.inforNode.getElements("td");
  156. var inputs = this.inforNode.getElements("input");
  157. tds.setStyles(this.css.applicationServerDocumentTdNode);
  158. inputs.setStyles(this.css.applicationServerDocumentInputNode);
  159. },
  160. destroy: function(){
  161. if (this.node) this.node.destroy();
  162. MWF.release(this);
  163. },
  164. saveDocument: function(success, error){
  165. var inputs = this.inforNode.getElements("input");
  166. this.json.proxyHost = inputs[0].get("value");
  167. this.json.proxyPort = inputs[1].get("value");
  168. this.app.actions.updateWebServer(this.json.name, this.json, function(){
  169. if (success) success();
  170. }.bind(this), function(xhr){
  171. var json = JSON.decode(xhr.responseText);
  172. if (error) error.apply(this, [this, json.message]);
  173. }.bind(this));
  174. },
  175. });
  176. MWF.xApplication.Setting.mobile.ServerSetting.ApplicationServer = new Class({
  177. Extends: MWF.xApplication.Setting.mobile.ServerSetting.WebServer,
  178. initialize: function(setting, json){
  179. this.setting = setting;
  180. this.app = this.setting.app;
  181. this.actions = this.app.actions;
  182. this.css = this.app.css;
  183. this.json = json;
  184. this.content = this.setting.applicationServerListNode;
  185. this.load();
  186. },
  187. saveDocument: function(success, error){
  188. var inputs = this.inforNode.getElements("input");
  189. this.json.proxyHost = inputs[0].get("value");
  190. this.json.proxyPort = inputs[1].get("value");
  191. this.app.actions.updateAppServer(this.json.name, this.json, function(){
  192. if (success) success();
  193. }.bind(this), function(xhr){
  194. var json = JSON.decode(xhr.responseText);
  195. if (error) error.apply(this, [this, json.message]);
  196. }.bind(this));
  197. },
  198. });