Storages.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. MWF.xApplication.Setting.applications = MWF.xApplication.Setting.applications || {};
  2. MWF.require("MWF.widget.Mask", null, false);
  3. MWF.xApplication.Setting.applications.Storages = new Class({
  4. Implements: [Options, Events],
  5. initialize: function(explorer){
  6. this.explorer = explorer;
  7. this.app = this.explorer.app;
  8. this.actions = this.app.actions;
  9. this.css = this.app.css;
  10. this.items = [];
  11. this.content = this.explorer.storagesContent;
  12. this.storageJson = null;
  13. this.mappingJson = null;
  14. this.page = this.app.applicationPage;
  15. this.load();
  16. },
  17. load: function(){
  18. this.mask = new MWF.widget.Mask({"style": "desktop"});
  19. this.mask.loadNode(this.explorer.contentAreaNode);
  20. this.actions.listStorageMappings(function(mappingJson){
  21. this.mappingJson = mappingJson.data;
  22. this.loadStorages();
  23. }.bind(this));
  24. this.actions.listStorages(function(json){
  25. this.storageJson = json.data;
  26. this.loadStorages();
  27. }.bind(this));
  28. },
  29. loadStorages: function(){
  30. if (this.storageJson && this.mappingJson){
  31. Object.each(this.storageJson, function(value, key){
  32. this.items.push(new MWF.xApplication.Setting.applications.Storage(this, value, key));
  33. }.bind(this));
  34. if (this.mask) this.mask.hide();
  35. }
  36. },
  37. destroy: function(){
  38. this.items.each(function(item){
  39. item.destroy();
  40. }.bind(this));
  41. if (this.currentDoc) this.currentDoc.destroy();
  42. this.content.destroy();
  43. MWF.release(this);
  44. }
  45. });
  46. MWF.xApplication.Setting.applications.Storage = new Class({
  47. Implements: [Events],
  48. initialize: function(list, json, key){
  49. this.list = list
  50. this.explorer = this.list.explorer;
  51. this.app = this.list.explorer.app;
  52. this.json = json;
  53. this.mappingJson = this.list.mappingJson[key];
  54. this.key = key;
  55. this.container = this.list.content;
  56. this.css = this.app.css;
  57. this.servers = [];
  58. this.load();
  59. },
  60. load: function(){
  61. this.node = new Element("div", {"styles": this.css.applicationNode}).inject(this.container);
  62. this.nameNode = new Element("div", {"styles": this.css.applicationNameNode}).inject(this.node);
  63. this.iconNode = new Element("div", {"styles": this.css.storageNameIconNode}).inject(this.nameNode);
  64. this.addNode = new Element("div", {"styles": this.css.storageNameAddNode, "text": "add"}).inject(this.nameNode);
  65. this.textNode = new Element("div", {"styles": this.css.applicationNameTextNode}).inject(this.nameNode);
  66. this.textNode.set("text", this.key);
  67. this.serverListNode = new Element("div", {"styles": this.css.applicationServerListNode}).inject(this.node);
  68. this.json.each(function(server, i){
  69. var mappingServer = this.mappingJson[i];
  70. this.servers.push(new MWF.xApplication.Setting.applications.Storage.Server(this, server, mappingServer));
  71. }.bind(this));
  72. this.addNode.addEvent("click", function(){
  73. var server = {
  74. "storage": this,
  75. "list": this.list,
  76. "app": this.app,
  77. "explorer": this.explorer,
  78. "json": {
  79. "weight": "",
  80. "storageServer": "",
  81. "order": "",
  82. "enable": true
  83. },
  84. "mappingJson": {
  85. "storageServiceType": "ftp",
  86. "enable": true,
  87. "weight": "",
  88. "name": "",
  89. "ftpHost": "",
  90. "ftpPort": "",
  91. "ftpUsername": "",
  92. "ftpPassword": "",
  93. "ftpPath": ""
  94. },
  95. "node": this.addNode,
  96. "container": this.serverListNode,
  97. "name": "",
  98. "reload": function(){
  99. this.app.actions.getStorageServer(this.json.storageServer, function(json){
  100. debugger;
  101. this.mappingJson.storageServiceType = json.data.storageServiceType;
  102. this.mappingJson.enable = this.json.enable;
  103. this.mappingJson.weight = this.json.weight;
  104. this.mappingJson.name = this.json.storageServer;
  105. this.mappingJson.ftpHost = json.data.host;
  106. this.mappingJson.ftpPort = json.data.port;
  107. this.mappingJson.ftpUsername = json.data.username;
  108. this.mappingJson.ftpPassword = json.data.password;
  109. this.mappingJson.ftpPath = json.data.path;
  110. this.storage.servers.push(new MWF.xApplication.Setting.applications.Storage.Server(this.storage, this.json, this.mappingJson));
  111. }.bind(this));
  112. }
  113. }
  114. this.currentDoc = new MWF.xApplication.Setting.applications.Storage.Server.Document(server);
  115. }.bind(this));
  116. },
  117. destroy: function(){
  118. this.servers.each(function(server){
  119. server.destroy();
  120. }.bind(this));
  121. this.node.destroy();
  122. MWF.release(this);
  123. }
  124. });
  125. MWF.xApplication.Setting.applications.Storage.Server = new Class({
  126. initialize: function(storage, json, mappingJson){
  127. this.storage = storage;
  128. this.list = this.storage.list
  129. this.explorer = this.storage.explorer;
  130. this.app = this.storage.explorer.app;
  131. this.json = json;
  132. this.mappingJson = mappingJson;
  133. this.container = this.storage.serverListNode;
  134. this.css = this.app.css;
  135. this.name = this.json.storageServer;
  136. this.load();
  137. },
  138. load: function(){
  139. this.node = new Element("div", {"styles": this.css.applicationInServerNode}).inject(this.container);
  140. this.tableNode = new Element("div", {"styles": this.css.applicationInServerTableNode}).inject(this.node);
  141. var html = "<table width='100%' cellSpacing='0' cellPadding='0'><tr>" +
  142. "<td style='width: 40px'></td>" +
  143. "<td style='padding: 0px 5px'>"+this.json.storageServer+"</td>" +
  144. "<td style='padding: 0px 5px'>"+this.json.enable+"</td>" +
  145. "<td style='padding: 0px 5px'>"+this.mappingJson.storageServiceType+"</td>" +
  146. "<td style='padding: 0px 5px'>"+this.mappingJson.ftpPort+"</td>"+
  147. "<td style='padding: 0px 5px'>"+this.mappingJson.ftpUsername+"</td>"+
  148. "<td style='padding: 0px 5px'>"+this.mappingJson.ftpPassword+"</td>"+
  149. "<td width='80px' style='padding: 0px 5px'>"+this.json.weight+"</td>"+
  150. "<td width='40px'></td>" +
  151. "</tr></table>";
  152. this.tableNode.set("html", html);
  153. tds = this.tableNode.getElements("td");
  154. tds[0].setStyles(this.css.applicationInServerIconNode);
  155. this.editTd = tds[tds.length-1];
  156. this.editTd.setStyles(this.css.applicationInServerEditNode);
  157. this.jsonNode = new Element("div", {"styles": this.css.applicationInServerJsonNode}).inject(this.node);
  158. this.dataJsonNode = new Element("div", {"styles": this.css.dataInServerDataJsonNode}).inject(this.jsonNode);
  159. this.mappingJsonNode = new Element("div", {"styles": this.css.dataInServerMappingJsonNode}).inject(this.jsonNode);
  160. this.jsonButtonNode = new Element("div", {"styles": this.css.applicationInServerJsonButtonNode}).inject(this.node);
  161. var jsonStr = JSON.stringify(this.json, null, "\t");
  162. jsonHtml = jsonStr.replace(/\n|\r/g, "<br>");
  163. jsonHtml = jsonHtml.replace(/\t/g, "<font>&nbsp;&nbsp;&nbsp;&nbsp;</font>");
  164. this.dataJsonNode.set("html", "<div style='font-weight: bold'>Data</div>"+jsonHtml);
  165. var mappingJsonStr = JSON.stringify(this.mappingJson, null, "\t");
  166. mappingJsonHtml = mappingJsonStr.replace(/\n|\r/g, "<br>");
  167. mappingJsonHtml = mappingJsonHtml.replace(/\t/g, "<font>&nbsp;&nbsp;&nbsp;&nbsp;</font>");
  168. this.mappingJsonNode.set("html", "<div style='font-weight: bold'>DataMappings</div>"+mappingJsonHtml);
  169. this.editTd.addEvent("click", function(){
  170. this.open();
  171. }.bind(this));
  172. this.jsonButtonNode.addEvent("click", function(){
  173. if (this.jsonNode.getStyle("display")=="none"){
  174. this.jsonNode.setStyle("display", "block");
  175. this.jsonButtonNode.setStyle("background", "url(/x_component_Setting/$Main/default/icon/up.png) no-repeat center center");
  176. }else{
  177. this.jsonNode.setStyle("display", "none");
  178. this.jsonButtonNode.setStyle("background", "url(/x_component_Setting/$Main/default/icon/down.png) no-repeat center center");
  179. }
  180. }.bind(this));
  181. },
  182. open: function(){
  183. this.list.currentDoc = new MWF.xApplication.Setting.applications.Storage.Server.Document(this);
  184. },
  185. reload: function(){
  186. this.name = this.json.storageServer;
  187. this.node.destroy();
  188. this.load();
  189. },
  190. destroy: function(){
  191. this.node.destroy();
  192. MWF.release(this);
  193. }
  194. });
  195. MWF.xApplication.Setting.applications.Storage.Server.Document = new Class({
  196. Implements: [Events],
  197. initialize: function(server){
  198. this.server = server;
  199. this.list = this.server.list
  200. this.app = this.server.app;
  201. this.json = this.server.json;
  202. this.mappingJson = this.server.mappingJson;
  203. this.container = this.list.explorer.container;
  204. this.css = this.app.css;
  205. this.load();
  206. },
  207. load: function(){
  208. this.node = new Element("div", {"styles": this.css.applicationServerDocumentNode}).inject(this.container);
  209. this.setNodeSize();
  210. this.show();
  211. //this.createForm();
  212. },
  213. setNodeSize: function(){
  214. var size = this.server.node.getSize();
  215. var position = this.server.node.getPosition(this.server.node.getOffsetParent());
  216. this.node.setStyles({
  217. "width": ""+size.x+"px",
  218. "height": ""+size.y+"px",
  219. "top": ""+position.y+"px",
  220. "left": ""+position.x+"px"
  221. });
  222. },
  223. show: function(){
  224. var size = this.list.page.contentNodeArea.getSize();
  225. var position = this.list.page.contentNodeArea.getPosition(this.list.page.contentNodeArea.getOffsetParent());
  226. var css = {
  227. "width": ""+size.x+"px",
  228. "height": ""+size.y+"px",
  229. "top": ""+position.y+"px",
  230. "left": ""+position.x+"px"
  231. }
  232. this.morph = new Fx.Morph(this.node,{
  233. "duration": 100,
  234. "transition": Fx.Transitions.Sine.easeOut
  235. });
  236. this.morph.start(css).chain(function(){
  237. this.list.content.setStyle("display", "none");
  238. this.createForm();
  239. this.setDocumentSizeFun = this.setDocumentSize.bind(this);
  240. this.setDocumentSize();
  241. this.app.addEvent("resize", this.setDocumentSizeFun);
  242. }.bind(this));
  243. },
  244. setDocumentSize: function(){
  245. var size = this.list.page.contentNodeArea.getSize();
  246. var actionSize = this.actionNode.getSize();
  247. var h = size.y-actionSize.y;
  248. this.inforNode.setStyle("height", ""+h+"px");
  249. //this.applicationAreaNode.setStyle("height", ""+h+"px");
  250. //this.inforNode.setStyle("min-height", ""+h+"px");
  251. this.node.setStyles({
  252. "width": ""+size.x+"px",
  253. "height": ""+size.y+"px",
  254. });
  255. },
  256. createForm: function(){
  257. this.createActions();
  258. this.createBaseInfo();
  259. },
  260. createActions: function(){
  261. this.actionNode = new Element("div", {"styles": this.css.applicationServerDocumentActionNode}).inject(this.node);
  262. this.saveAction = new Element("div", {"styles": this.css.applicationServerDocumentSaveNode}).inject(this.actionNode);
  263. if (this.server.name) this.deleteAction = new Element("div", {"styles": this.css.applicationServerDocumentDeleteNode}).inject(this.actionNode);
  264. this.closeAction = new Element("div", {"styles": this.css.applicationServerDocumentCloseNode}).inject(this.actionNode);
  265. this.saveAction.addEvents({
  266. "mouseover": function(){this.saveAction.setStyles(this.css.applicationServerDocumentSaveNode_over);}.bind(this),
  267. "mouseout": function(){this.saveAction.setStyles(this.css.applicationServerDocumentSaveNode);}.bind(this),
  268. "mousedown": function(){this.saveAction.setStyles(this.css.applicationServerDocumentSaveNode_down);}.bind(this),
  269. "mouseup": function(){this.saveAction.setStyles(this.css.applicationServerDocumentSaveNode_over);}.bind(this),
  270. "click": function(e){this.saveDocument();}.bind(this)
  271. });
  272. if (this.deleteAction){
  273. this.deleteAction.addEvents({
  274. "mouseover": function(){this.deleteAction.setStyles(this.css.applicationServerDocumentDeleteNode_over);}.bind(this),
  275. "mouseout": function(){this.deleteAction.setStyles(this.css.applicationServerDocumentDeleteNode);}.bind(this),
  276. "mousedown": function(){this.deleteAction.setStyles(this.css.applicationServerDocumentDeleteNode_down);}.bind(this),
  277. "mouseup": function(){this.deleteAction.setStyles(this.css.applicationServerDocumentDeleteNode_over);}.bind(this),
  278. "click": function(e){this.deleteDocument(e);}.bind(this)
  279. });
  280. }
  281. this.closeAction.addEvents({
  282. "mouseover": function(){this.closeAction.setStyles(this.css.applicationServerDocumentCloseNode_over);}.bind(this),
  283. "mouseout": function(){this.closeAction.setStyles(this.css.applicationServerDocumentCloseNode);}.bind(this),
  284. "mousedown": function(){this.closeAction.setStyles(this.css.applicationServerDocumentCloseNode_down);}.bind(this),
  285. "mouseup": function(){this.closeAction.setStyles(this.css.applicationServerDocumentCloseNode_over);}.bind(this),
  286. "click": function(e){this.closeDocument();}.bind(this)
  287. });
  288. },
  289. createBaseInfo: function(){
  290. this.inforAreaNode = new Element("div", {"styles": this.css.applicationServerDocumentInforAreaNode}).inject(this.node);
  291. this.inforNode = new Element("div", {"styles": this.css.dataServerDocumentInforNode}).inject(this.inforAreaNode);
  292. var html = "<table cellSpacing='8px' width='90%' align='center'>" +
  293. "<tr><td width='160px'>storageType</td><td>"+this.server.storage.key+"</td></tr>" +
  294. "<tr><td>enable</td><td><select>" +
  295. "</select></td></tr>" +
  296. "<tr><td>weight</td><td><input value='"+(this.json.weight || "")+"'/></td></tr>" +
  297. "<tr><td>order</td><td><input value='"+(this.json.order || "")+"'/></td></tr>" +
  298. "<tr><td>enable</td><td><select>" +
  299. "<option value='true' "+((this.json.enable) ? "selected" : "")+">true</option>" +
  300. "<option value='false' "+((!this.json.enable) ? "selected" : "")+">false</option>" +
  301. "</select></td></tr>" +
  302. "</table>";
  303. this.inforNode.set("html", html);
  304. var tds = this.inforNode.getElements("td");
  305. var inputs = this.inforNode.getElements("input");
  306. tds.setStyles(this.css.applicationServerDocumentTdNode);
  307. inputs.setStyles(this.css.applicationServerDocumentInputNode);
  308. var select = this.inforNode.getElement("select");
  309. this.app.actions.listStorageServer(function(json){
  310. json.data.each(function(server){
  311. var option = new Element("option", {"value": server.name, "text": server.name}).inject(select);
  312. if (server.name==this.json.storageServer) option.set("selected", true);
  313. }.bind(this));
  314. }.bind(this));
  315. },
  316. closeDocument: function(){
  317. this.node.empty();
  318. this.list.content.setStyle("display", "block");
  319. var size = this.server.node.getSize();
  320. var position = this.server.node.getPosition(this.server.node.getOffsetParent());
  321. var css = {
  322. "width": ""+size.x+"px",
  323. "height": ""+size.y+"px",
  324. "top": ""+position.y+"px",
  325. "left": ""+position.x+"px"
  326. }
  327. this.morph.start(css).chain(function(){
  328. this.destroy();
  329. }.bind(this));
  330. },
  331. destroy: function(){
  332. this.app.removeEvent("resize", this.setDocumentSizeFun);
  333. this.node.destroy();
  334. this.list.currentDoc = null;
  335. MWF.release(this);
  336. },
  337. saveDocument: function(){
  338. var inputs = this.inforNode.getElements("input");
  339. this.json.weight = inputs[0].get("value");
  340. this.json.order = inputs[1].get("value");
  341. var selects = this.inforNode.getElements("select");
  342. this.json.storageServer = selects[0].options[selects[0].selectedIndex].value;
  343. var str = selects[1].options[selects[1].selectedIndex].value;
  344. this.json.enable = (str=="true") ? true : false;
  345. if (this.server.name){
  346. this.app.actions.updateStorage(this.server.storage.key, this.server.name, this.json, function(){
  347. this.closeDocument();
  348. this.server.reload();
  349. }.bind(this));
  350. }else{
  351. this.app.actions.addStorage(this.server.storage.key, this.json, function(){
  352. this.closeDocument();
  353. this.server.reload();
  354. }.bind(this));
  355. }
  356. },
  357. deleteDocument: function(e){
  358. var _self = this;
  359. this.app.confirm("warn", e, this.app.lp.deleteStorage_title, this.app.lp.deleteStorage, "350", "120", function(){
  360. _self.app.actions.removeStorage(_self.server.storage.key, _self.server.name, function(){
  361. this.closeDocument();
  362. this.server.destroy();
  363. }.bind(_self));
  364. this.close();
  365. }, function(){
  366. this.close();
  367. });
  368. }
  369. });