Datas.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. MWF.xApplication.Setting.applications = MWF.xApplication.Setting.applications || {};
  2. //MWF.xDesktop.requireApp("Setting", "applications.Applications", null, false);
  3. MWF.require("MWF.widget.Mask", null, false);
  4. MWF.xApplication.Setting.applications.Datas = new Class({
  5. //Extends: MWF.xApplication.Setting.applications.Applications,
  6. Implements: [Options, Events],
  7. initialize: function(explorer){
  8. this.explorer = explorer;
  9. this.app = this.explorer.app;
  10. this.actions = this.app.actions;
  11. this.css = this.app.css;
  12. this.items = [];
  13. this.content = this.explorer.datasContent;
  14. this.dataJson = null;
  15. this.mappingJson = null;
  16. this.load();
  17. },
  18. load: function(){
  19. this.mask = new MWF.widget.Mask({"style": "desktop"});
  20. this.mask.loadNode(this.explorer.contentAreaNode);
  21. this.actions.listDataMappings(function(mappingJson){
  22. this.mappingJson = mappingJson.data;
  23. this.loadDatas();
  24. }.bind(this));
  25. this.actions.listDatas(function(json){
  26. this.dataJson = json.data;
  27. this.loadDatas();
  28. }.bind(this));
  29. },
  30. loadDatas: function(){
  31. if (this.dataJson && this.mappingJson){
  32. Object.each(this.dataJson, function(value, key){
  33. this.items.push(new MWF.xApplication.Setting.applications.Data(this, value, key));
  34. }.bind(this));
  35. if (this.mask) this.mask.hide();
  36. }
  37. },
  38. destroy: function(){
  39. this.items.each(function(item){
  40. item.destroy();
  41. }.bind(this));
  42. this.content.destroy();
  43. MWF.release(this);
  44. }
  45. });
  46. MWF.xApplication.Setting.applications.Data = 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.dataJson = 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.dataNameIconNode}).inject(this.nameNode);
  64. this.textNode = new Element("div", {"styles": this.css.applicationNameTextNode}).inject(this.nameNode);
  65. this.textNode.set("text", this.key);
  66. this.serverListNode = new Element("div", {"styles": this.css.applicationServerListNode}).inject(this.node);
  67. this.dataJson.each(function(server, i){
  68. var mappingServer = this.mappingJson[i];
  69. this.servers.push(new MWF.xApplication.Setting.applications.Data.Server(this, server, mappingServer));
  70. }.bind(this));
  71. },
  72. destroy: function(){
  73. this.servers.each(function(server){
  74. server.destroy();
  75. }.bind(this));
  76. this.node.destroy();
  77. MWF.release(this);
  78. }
  79. });
  80. MWF.xApplication.Setting.applications.Data.Server = new Class({
  81. initialize: function(data, json, mappingJson){
  82. this.data = data;
  83. this.list = this.data.list
  84. this.explorer = this.data.explorer;
  85. this.app = this.data.explorer.app;
  86. this.json = json;
  87. this.mappingJson = mappingJson;
  88. this.container = this.data.serverListNode;
  89. this.css = this.app.css;
  90. this.load();
  91. },
  92. load: function(){
  93. this.node = new Element("div", {"styles": this.css.applicationInServerNode}).inject(this.container);
  94. this.tableNode = new Element("div", {"styles": this.css.applicationInServerTableNode}).inject(this.node);
  95. var html = "<table width='100%' cellSpacing='0' cellPadding='0'><tr>" +
  96. "<td width='40px'></td>" +
  97. "<td style='padding: 0px 5px'>"+this.json.dataServer+"</td>" +
  98. "<td style='padding: 0px 5px'>"+this.mappingJson.url+"</td>" +
  99. "<td style='padding: 0px 5px'>"+this.mappingJson.username+"</td>" +
  100. "<td style='padding: 0px 5px'>"+this.mappingJson.password+"</td>"+
  101. "</tr></table>";
  102. this.tableNode.set("html", html);
  103. tds = this.tableNode.getElements("td");
  104. tds[0].setStyles(this.css.applicationInServerIconNode);
  105. this.jsonNode = new Element("div", {"styles": this.css.applicationInServerJsonNode}).inject(this.node);
  106. this.dataJsonNode = new Element("div", {"styles": this.css.dataInServerDataJsonNode}).inject(this.jsonNode);
  107. this.mappingJsonNode = new Element("div", {"styles": this.css.dataInServerMappingJsonNode}).inject(this.jsonNode);
  108. this.jsonButtonNode = new Element("div", {"styles": this.css.applicationInServerJsonButtonNode}).inject(this.node);
  109. var jsonStr = JSON.stringify(this.json, null, "\t");
  110. jsonHtml = jsonStr.replace(/\n|\r/g, "<br>");
  111. jsonHtml = jsonHtml.replace(/\t/g, "<font>&nbsp;&nbsp;&nbsp;&nbsp;</font>");
  112. this.dataJsonNode.set("html", "<div style='font-weight: bold'>Data</div>"+jsonHtml);
  113. var mappingJsonStr = JSON.stringify(this.mappingJson, null, "\t");
  114. mappingJsonHtml = mappingJsonStr.replace(/\n|\r/g, "<br>");
  115. mappingJsonHtml = mappingJsonHtml.replace(/\t/g, "<font>&nbsp;&nbsp;&nbsp;&nbsp;</font>");
  116. this.mappingJsonNode.set("html", "<div style='font-weight: bold'>DataMappings</div>"+mappingJsonHtml);
  117. this.jsonButtonNode.addEvent("click", function(){
  118. if (this.jsonNode.getStyle("display")=="none"){
  119. this.jsonNode.setStyle("display", "block");
  120. this.jsonButtonNode.setStyle("background", "url(/x_component_Setting/$Main/default/icon/up.png) no-repeat center center");
  121. }else{
  122. this.jsonNode.setStyle("display", "none");
  123. this.jsonButtonNode.setStyle("background", "url(/x_component_Setting/$Main/default/icon/down.png) no-repeat center center");
  124. }
  125. }.bind(this));
  126. },
  127. destroy: function(){
  128. this.node.destroy();
  129. MWF.release(this);
  130. }
  131. });