DataServers.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. MWF.xDesktop.requireApp("Setting", "servers.ApplicationServers", null, false);
  2. MWF.xApplication.Setting.servers = MWF.xApplication.Setting.servers || {};
  3. MWF.xApplication.Setting.servers.DataServers = new Class({
  4. Extends: MWF.xApplication.Setting.servers.ApplicationServers,
  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.dataServerContent;
  13. this.page = this.app.serverPage;
  14. this.currentDoc = null;
  15. this.load();
  16. },
  17. load: function(){
  18. this.actions.listDataServer(function(json){
  19. json.data.each(function(serverJson){
  20. this.servers.push(new MWF.xApplication.Setting.servers.DataServer(this, serverJson));
  21. }.bind(this));
  22. this.createAddAction();
  23. this.setServerAreaWidth();
  24. this.setServerAreaWidthFun = this.setServerAreaWidth.bind(this);
  25. this.addEvent("resize", this.setServerAreaWidthFun);
  26. }.bind(this));
  27. },
  28. createServer: function(){
  29. var server = {
  30. "list": this,
  31. "app": this.app,
  32. "json": {
  33. "contextList": [],
  34. "planList": []
  35. },
  36. "node": this.createServerAction,
  37. "name": "",
  38. "reload": function(){
  39. this.list.servers.push(new MWF.xApplication.Setting.servers.DataServer(this.list, this.json));
  40. }
  41. }
  42. this.currentDoc = new MWF.xApplication.Setting.servers.DataServer.Document(server);
  43. },
  44. setServerAreaWidth: function(){
  45. var count = this.servers.length;
  46. var width = this.explorer.contentAreaNode.getSize().x;
  47. var nodeWidth = this.servers[0].node.getSize().x;
  48. var x1 = this.servers[0].node.getStyle("margin-left").toInt();
  49. var x2 = this.servers[0].node.getStyle("margin-right").toInt();
  50. nodeWidth = nodeWidth+x1+x2;
  51. var n = (width/nodeWidth).toInt();
  52. var w = nodeWidth*n;
  53. this.content.setStyle("width", ""+w+"px");
  54. },
  55. destroy: function(){
  56. if (this.setServerAreaWidthFun) this.app.removeEvent("resize", this.setServerAreaWidthFun);
  57. this.servers.each(function(server){
  58. server.destroy();
  59. }.bind(this));
  60. if (this.currentDoc) this.currentDoc.destroy();
  61. this.content.destroy();
  62. MWF.release(this);
  63. }
  64. });
  65. MWF.xApplication.Setting.servers.DataServer = new Class({
  66. Extends: MWF.xApplication.Setting.servers.ApplicationServer,
  67. Implements: [Events],
  68. initialize: function(list, json){
  69. this.list = list;
  70. this.explorer = this.list.explorer;
  71. this.app = this.list.app;
  72. this.json = json;
  73. this.container = this.list.content;
  74. this.css = this.app.css;
  75. this.name = this.json.name;
  76. this.load();
  77. },
  78. setServerText: function(){
  79. this.nameNode.set("text", (this.json.name || ""));
  80. this.hostNode.set("text", (this.json.host || "")+" : "+(this.json.port || ""));
  81. this.adminNode.set("text", (this.json.databaseType || ""));
  82. this.messageNode.set("text", (this.json.message || ""));
  83. },
  84. open: function(){
  85. new MWF.xApplication.Setting.servers.DataServer.Document(this);
  86. },
  87. reload: function(){
  88. this.app.actions.getDataServer(this.json.name, function(json){
  89. this.name = this.json.name;
  90. this.json = json.data;
  91. this.nameNode.set("text", this.json.name);
  92. this.hostNode.set("text", this.json.host+" : "+this.json.port);
  93. this.adminNode.set("text", this.json.databaseType);
  94. this.messageNode.set("text", this.json.message);
  95. }.bind(this));
  96. }
  97. });
  98. MWF.xApplication.Setting.servers.DataServer.Document = new Class({
  99. Extends: MWF.xApplication.Setting.servers.ApplicationServer.Document,
  100. Implements: [Events],
  101. setDocumentSize: function(){
  102. var size = this.list.page.contentNodeArea.getSize();
  103. var actionSize = this.actionNode.getSize();
  104. var h = size.y-actionSize.y;
  105. this.inforNode.setStyle("height", ""+h+"px");
  106. //this.applicationAreaNode.setStyle("height", ""+h+"px");
  107. //this.inforNode.setStyle("min-height", ""+h+"px");
  108. this.node.setStyles({
  109. "width": ""+size.x+"px",
  110. "height": ""+size.y+"px",
  111. });
  112. },
  113. createForm: function(){
  114. this.createActions();
  115. this.createBaseInfo();
  116. },
  117. createActions: function(){
  118. this.actionNode = new Element("div", {"styles": this.css.applicationServerDocumentActionNode}).inject(this.node);
  119. this.saveAction = new Element("div", {"styles": this.css.applicationServerDocumentSaveNode}).inject(this.actionNode);
  120. if (this.server.name) this.deleteAction = new Element("div", {"styles": this.css.applicationServerDocumentDeleteNode}).inject(this.actionNode);
  121. this.closeAction = new Element("div", {"styles": this.css.applicationServerDocumentCloseNode}).inject(this.actionNode);
  122. this.saveAction.addEvents({
  123. "mouseover": function(){this.saveAction.setStyles(this.css.applicationServerDocumentSaveNode_over);}.bind(this),
  124. "mouseout": function(){this.saveAction.setStyles(this.css.applicationServerDocumentSaveNode);}.bind(this),
  125. "mousedown": function(){this.saveAction.setStyles(this.css.applicationServerDocumentSaveNode_down);}.bind(this),
  126. "mouseup": function(){this.saveAction.setStyles(this.css.applicationServerDocumentSaveNode_over);}.bind(this),
  127. "click": function(e){this.saveDocument();}.bind(this)
  128. });
  129. if (this.deleteAction){
  130. this.deleteAction.addEvents({
  131. "mouseover": function(){this.deleteAction.setStyles(this.css.applicationServerDocumentDeleteNode_over);}.bind(this),
  132. "mouseout": function(){this.deleteAction.setStyles(this.css.applicationServerDocumentDeleteNode);}.bind(this),
  133. "mousedown": function(){this.deleteAction.setStyles(this.css.applicationServerDocumentDeleteNode_down);}.bind(this),
  134. "mouseup": function(){this.deleteAction.setStyles(this.css.applicationServerDocumentDeleteNode_over);}.bind(this),
  135. "click": function(e){this.deleteDocument(e);}.bind(this)
  136. });
  137. }
  138. this.closeAction.addEvents({
  139. "mouseover": function(){this.closeAction.setStyles(this.css.applicationServerDocumentCloseNode_over);}.bind(this),
  140. "mouseout": function(){this.closeAction.setStyles(this.css.applicationServerDocumentCloseNode);}.bind(this),
  141. "mousedown": function(){this.closeAction.setStyles(this.css.applicationServerDocumentCloseNode_down);}.bind(this),
  142. "mouseup": function(){this.closeAction.setStyles(this.css.applicationServerDocumentCloseNode_over);}.bind(this),
  143. "click": function(e){this.closeDocument();}.bind(this)
  144. });
  145. },
  146. createBaseInfo: 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><input value='"+(this.json.name || "")+"'/></td></tr>" +
  151. "<tr><td>description</td><td><input value='"+(this.json.description || "")+"'/></td></tr>" +
  152. "<tr><td>order</td><td><input value='"+(this.json.order || "0")+"'/></td></tr>" +
  153. "<tr><td>databaseType</td><td><select>" +
  154. "<option value='postgreSQL' "+((this.json.databaseType=="postgreSQL") ? "selected" : "")+">postgreSQL</option>" +
  155. "<option value='mysql' "+((this.json.databaseType=="mysql") ? "selected" : "")+">mysql</option>" +
  156. "<option value='db2' "+((this.json.databaseType=="db2") ? "selected" : "")+">db2</option>" +
  157. "<option value='oracle' "+((this.json.databaseType=="oracle") ? "selected" : "")+">oracle</option>" +
  158. "</select></td></tr>" +
  159. "<tr><td>host</td><td><input value='"+(this.json.host || "")+"'/></td></tr>" +
  160. "<tr><td>port</td><td><input value='"+(this.json.port || "")+"'/></td></tr>" +
  161. "<tr><td>database</td><td><input value='"+(this.json.database || "")+"'/></td></tr>" +
  162. "<tr><td>username</td><td><input value='"+(this.json.username || "")+"'/></td></tr>" +
  163. "<tr><td>password</td><td><input type='password' value='"+(this.json.password || "")+"'/></td></tr>" +
  164. "</table>";
  165. this.inforNode.set("html", html);
  166. var tds = this.inforNode.getElements("td");
  167. var inputs = this.inforNode.getElements("input");
  168. tds.setStyles(this.css.applicationServerDocumentTdNode);
  169. inputs.setStyles(this.css.applicationServerDocumentInputNode);
  170. },
  171. saveDocument: function(){
  172. var inputs = this.inforNode.getElements("input");
  173. this.json.name = inputs[0].get("value");
  174. this.json.description = inputs[1].get("value");
  175. this.json.order = inputs[2].get("value");
  176. this.json.host = inputs[3].get("value");
  177. this.json.port = inputs[4].get("value");
  178. this.json.database = inputs[5].get("value");
  179. this.json.username = inputs[6].get("value");
  180. this.json.password = inputs[7].get("value");
  181. var select = this.inforNode.getElement("select");
  182. this.json.databaseType = select.options[select.selectedIndex].value;
  183. if (this.server.name){
  184. this.app.actions.updateAppServer(this.server.name, this.json, function(){
  185. this.closeDocument();
  186. this.server.reload();
  187. }.bind(this));
  188. }else{
  189. this.app.actions.addDataServer(this.json, function(){
  190. this.closeDocument();
  191. this.server.reload();
  192. }.bind(this));
  193. }
  194. },
  195. deleteDocument: function(e){
  196. var _self = this;
  197. this.app.confirm("warn", e, this.app.lp.deleteDataServer_title, this.app.lp.deleteDataServer, "350", "120", function(){
  198. _self.app.actions.removeDataServer(_self.server.name, function(){
  199. this.closeDocument();
  200. this.server.destroy();
  201. }.bind(_self));
  202. this.close();
  203. }, function(){
  204. this.close();
  205. });
  206. }
  207. });