Applications.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. MWF.xApplication.Setting.applications = MWF.xApplication.Setting.applications || {};
  2. MWF.require("MWF.widget.Mask", null, false);
  3. MWF.xApplication.Setting.applications.Applications = new Class({
  4. Extends: MWF.widget.Common,
  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.applications = [];
  12. this.content = this.explorer.applicationsContent;
  13. this.load();
  14. },
  15. load: function(){
  16. this.mask = new MWF.widget.Mask({"style": "desktop"});
  17. this.mask.loadNode(this.explorer.contentAreaNode);
  18. this.actions.listApplications(function(json){
  19. Object.each(json.data, function(value, key){
  20. this.applications.push(new MWF.xApplication.Setting.applications.Application(this, value, key));
  21. }.bind(this));
  22. if (this.mask) this.mask.hide();
  23. }.bind(this));
  24. },
  25. destroy: function(){
  26. this.applications.each(function(application){
  27. application.destroy();
  28. }.bind(this));
  29. this.content.destroy();
  30. MWF.release(this);
  31. }
  32. });
  33. MWF.xApplication.Setting.applications.Application = new Class({
  34. Implements: [Events],
  35. initialize: function(list, json, key){
  36. this.list = list
  37. this.explorer = this.list.explorer;
  38. this.app = this.list.explorer.app;
  39. this.json = json;
  40. this.key = key;
  41. this.container = this.list.content;
  42. this.css = this.app.css;
  43. this.servers = [];
  44. this.load();
  45. },
  46. load: function(){
  47. this.node = new Element("div", {"styles": this.css.applicationNode}).inject(this.container);
  48. this.nameNode = new Element("div", {"styles": this.css.applicationNameNode}).inject(this.node);
  49. this.iconNode = new Element("div", {"styles": this.css.applicationNameIconNode}).inject(this.nameNode);
  50. this.textNode = new Element("div", {"styles": this.css.applicationNameTextNode}).inject(this.nameNode);
  51. //this.textContextNode = new Element("div", {"styles": this.css.applicationNameTextContextNode}).inject(this.nameNode);
  52. //this.textPackageNode = new Element("div", {"styles": this.css.applicationNameTextPackageNode}).inject(this.nameNode);
  53. //thisAppName = this.json.context.substr(1, this.json.context.lenght);
  54. //this.textContextNode.set("text", this.key);
  55. //this.textPackageNode.set("text", this.key);
  56. this.textNode.set("text", this.key);
  57. this.serverListNode = new Element("div", {"styles": this.css.applicationServerListNode}).inject(this.node);
  58. this.weight = 0;
  59. var count = 0;
  60. this.json.each(function(server, i){
  61. if (server.weight){
  62. this.weight += server.weight.toFloat();
  63. count++;
  64. }
  65. }.bind(this));
  66. var v = 100;
  67. if (count>0){
  68. v = this.weight/count;
  69. }
  70. if (count<this.json.length){
  71. this.json.each(function(server, i){
  72. if (!server.weight) this.weight += v;
  73. }.bind(this));
  74. }
  75. this.json.each(function(server, i){
  76. if (!server.weight) server.weight = v;
  77. this.servers.push(new MWF.xApplication.Setting.applications.Application.Server(this, server));
  78. }.bind(this));
  79. },
  80. destroy: function(){
  81. this.servers.each(function(server){
  82. server.destroy();
  83. }.bind(this));
  84. this.node.destroy();
  85. MWF.release(this);
  86. }
  87. });
  88. MWF.xApplication.Setting.applications.Application.Server = new Class({
  89. initialize: function(application, json){
  90. this.application = application;
  91. this.list = this.application.list
  92. this.explorer = this.application.explorer;
  93. this.app = this.application.explorer.app;
  94. this.json = json;
  95. this.container = this.application.serverListNode;
  96. this.css = this.app.css;
  97. this.load();
  98. },
  99. load: function(){
  100. //var width = (this.json.weight/this.application.weight)*100;
  101. this.node = new Element("div", {"styles": this.css.applicationInServerNode}).inject(this.container);
  102. //this.node.setStyles({
  103. // "background-color": this.color,
  104. //// "width": width+"%"
  105. //});
  106. this.tableNode = new Element("div", {"styles": this.css.applicationInServerTableNode}).inject(this.node);
  107. var html = "<table width='100%' cellSpacing='0' cellPadding='0'><tr>" +
  108. "<td width='40px'></td>" +
  109. "<td style='padding: 0px 5px'>"+this.json.applicationServer+"</td>" +
  110. "<td style='padding: 0px 5px'>"+this.json.host+"</td>" +
  111. "<td style='padding: 0px 5px'>"+this.json.port+"</td>" +
  112. "<td style='padding: 0px 5px'>"+this.json.context+"</td>" +
  113. "<td width='80px' style='padding: 0px 5px'>"+this.json.weight+"</td>" +
  114. "<td width='40px'></td>" +
  115. "</tr></table>";
  116. this.tableNode.set("html", html);
  117. tds = this.tableNode.getElements("td");
  118. tds[0].setStyles(this.css.applicationInServerIconNode);
  119. this.editTd = tds[tds.length-1];
  120. this.editTd.setStyles(this.css.applicationInServerEditNode);
  121. this.jsonNode = new Element("div", {"styles": this.css.applicationInServerJsonNode}).inject(this.node);
  122. this.jsonButtonNode = new Element("div", {"styles": this.css.applicationInServerJsonButtonNode}).inject(this.node);
  123. var jsonStr = JSON.stringify(this.json, null, "\t");
  124. jsonHtml = jsonStr.replace(/\n|\r/g, "<br>");
  125. jsonHtml = jsonHtml.replace(/\t/g, "<font>&nbsp;&nbsp;&nbsp;&nbsp;</font>");
  126. this.jsonNode.set("html", jsonHtml);
  127. this.editTd.addEvent("click", function(){
  128. if (this.status=="edit"){
  129. this.saveWeight();
  130. }else{
  131. this.editWeight();
  132. }
  133. }.bind(this));
  134. this.jsonButtonNode.addEvent("click", function(){
  135. if (this.jsonNode.getStyle("display")=="none"){
  136. this.jsonNode.setStyle("display", "block");
  137. this.jsonButtonNode.setStyle("background", "url(/x_component_Setting/$Main/default/icon/up.png) no-repeat center center");
  138. }else{
  139. this.jsonNode.setStyle("display", "none");
  140. this.jsonButtonNode.setStyle("background", "url(/x_component_Setting/$Main/default/icon/down.png) no-repeat center center");
  141. }
  142. }.bind(this));
  143. },
  144. editWeight: function(){
  145. tds = this.tableNode.getElements("td");
  146. this.editTd.setStyles(this.css.applicationInServerSaveNode);
  147. weightTd = tds[tds.length-2];
  148. weightTd.empty();
  149. this.weightInput = new Element("input", {
  150. "styles": this.css.applicationInServerWeightInputNode,
  151. "type": "text"
  152. }).inject(weightTd);
  153. this.weightInput.set("value", this.json.weight);
  154. this.status="edit";
  155. },
  156. saveWeight: function(){
  157. var weight = this.weightInput.get("value");
  158. weight = weight.toFloat();
  159. if (isNaN(weight)) {
  160. this.app.notice(this.app.lp.saveWeightError, "error");
  161. return false;
  162. }
  163. if (weight != this.json.weight){
  164. this.json.weight = weight;
  165. this.app.actions.getAppServer(this.json.applicationServer, function(json){
  166. serverJson = json.data;
  167. thisAppName = this.json.context.substr(1, this.json.context.lenght);
  168. serverJson.planList.each(function(app){
  169. if (app.name==thisAppName){
  170. app.weight = weight;
  171. }
  172. }.bind(this));
  173. this.app.actions.updateAppServer(serverJson.name, serverJson, function(){
  174. this.saveWeightCompleted();
  175. }.bind(this));
  176. }.bind(this));
  177. }else{
  178. this.saveWeightCompleted();
  179. }
  180. },
  181. saveWeightCompleted: function(){
  182. tds = this.tableNode.getElements("td");
  183. this.editTd.setStyles(this.css.applicationInServerEditNode);
  184. weightTd = tds[tds.length-2];
  185. weightTd.empty();
  186. weightTd.set("text", this.json.weight);
  187. this.status="read";
  188. },
  189. destroy: function(){
  190. this.node.destroy();
  191. MWF.release(this);
  192. }
  193. });