Component.js 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. MWF.require("MWF.widget.UUID", null, false);
  2. //MWF.xDesktop.requireApp("AppDesigner", "Actions.RestActions", null, false);
  3. MWF.xApplication.AppDesigner.Component = new Class({
  4. Extends: MWF.widget.Common,
  5. Implements: [Options, Events],
  6. options: {
  7. "style": "default"
  8. },
  9. initialize: function(data, propertyNode, designer, options){
  10. this.setOptions(options);
  11. this.module = module;
  12. this.form = module.form;
  13. this.data = module.json;
  14. this.htmlPath = this.options.path;
  15. this.designer = designer;
  16. this.propertyNode = propertyNode;
  17. },
  18. onQueryLoad: function(){
  19. this.lp = MWF.xApplication.AppDesigner.LP;
  20. },
  21. loadApplication: function(callback){
  22. if (!this.options.isRefresh){
  23. this.maxSize(function(){
  24. this.loadDesigner();
  25. }.bind(this));
  26. }else{
  27. this.loadDesigner();
  28. }
  29. },
  30. loadDesigner: function(){
  31. this.createNode();
  32. this.loadLayout();
  33. this.loadListToolBar();
  34. this.loadDesignerToolBar();
  35. this.loadDesignerTab();
  36. MWF.UD.getDataJson("appDesigner", function(components){
  37. this.components = components;
  38. }.bind(this));
  39. },
  40. loadLayout: function(){
  41. this.leftAreaNode = new Element("div", {"styles": this.css.leftAreaNode}).inject(this.node);
  42. this.rightAreaNode = new Element("div", {"styles": this.css.rightAreaNode}).inject(this.node);
  43. this.loadLeftAreaLayout();
  44. this.loadRightAreaLayout();
  45. this.setLayoutSize();
  46. this.addEvent("resize", this.setLayoutSize.bind(this));
  47. //this.windowDesignerNode = new Element("div", {"styles": this.css.designerAreaNode}).inject(this.designerAreaNode);
  48. //this.propertyDesignerNode = new Element("div", {"styles": this.css.designerAreaNode}).inject(this.designerAreaNode);
  49. },
  50. loadLeftAreaLayout: function(){
  51. this.leftAreaResizeNode = new Element("div", {"styles": this.css.leftAreaResizeNode}).inject(this.leftAreaNode);
  52. this.appListAreaNode = new Element("div", {"styles": this.css.appListAreaNode}).inject(this.leftAreaNode);
  53. this.appListToolbarNode = new Element("div", {"styles": this.css.appListToolbarNode}).inject(this.appListAreaNode);
  54. this.appListScrollNode = new Element("div", {"styles": this.css.appListScrollNode}).inject(this.appListAreaNode);
  55. this.appListContentNode = new Element("div", {"styles": this.css.appListContentNode}).inject(this.appListScrollNode);
  56. },
  57. loadRightAreaLayout: function(){
  58. this.designerToolbarNode = new Element("div", {"styles": this.css.designerToolbarNode}).inject(this.rightAreaNode);
  59. this.designerTabAreaNode = new Element("div", {"styles": this.css.designerTabAreaNode}).inject(this.rightAreaNode);
  60. },
  61. setLayoutSize: function(){
  62. var size = this.node.getSize();
  63. var toolbarSize = this.appListToolbarNode.getSize();
  64. var y = size.y-toolbarSize.y;
  65. this.appListScrollNode.setStyle("height", ""+y+"px");
  66. this.designerTabAreaNode.setStyle("height", ""+y+"px");
  67. },
  68. createNode: function(){
  69. this.content.setStyle("overflow", "hidden");
  70. this.node = new Element("div", {
  71. "styles": {"width": "100%", "height": "100%", "overflow": "hidden"}
  72. }).inject(this.content);
  73. },
  74. loadListToolBar: function(callback){
  75. var toolbarUrl = this.path+"listToolbar.html";
  76. this.getToolbarHTML(toolbarUrl, function(toolbarNode){
  77. var spans = toolbarNode.getElements("span");
  78. spans.each(function(item, idx){
  79. var img = item.get("MWFButtonImage");
  80. if (img){
  81. item.set("MWFButtonImage", this.path+""+this.options.style+"/icon/listToolbar/"+img);
  82. }
  83. }.bind(this));
  84. toolbarNode.inject(this.appListToolbarNode);
  85. MWF.require("MWF.widget.Toolbar", function(){
  86. this.listToolbar = new MWF.widget.Toolbar(toolbarNode, {"style": "designer"}, this);
  87. this.listToolbar.load();
  88. this.listToolbar.childrenButton[this.listToolbar.childrenButton.length-1].node.setStyle("float", "right");
  89. if (callback) callback();
  90. }.bind(this));
  91. }.bind(this));
  92. },
  93. loadDesignerToolBar: function(callback){
  94. var toolbarUrl = this.path+"designerToolbar.html";
  95. this.getToolbarHTML(toolbarUrl, function(toolbarNode){
  96. var spans = toolbarNode.getElements("span");
  97. spans.each(function(item, idx){
  98. var img = item.get("MWFButtonImage");
  99. if (img){
  100. item.set("MWFButtonImage", this.path+""+this.options.style+"/icon/designerToolbar/"+img);
  101. }
  102. }.bind(this));
  103. toolbarNode.inject(this.designerToolbarNode);
  104. MWF.require("MWF.widget.Toolbar", function(){
  105. this.designerToolbar = new MWF.widget.Toolbar(toolbarNode, {"style": "designer"}, this);
  106. this.designerToolbar.load();
  107. if (callback) callback();
  108. }.bind(this));
  109. }.bind(this));
  110. },
  111. getToolbarHTML: function(toolbarUrl, callback){
  112. var r = new Request.HTML({
  113. url: toolbarUrl,
  114. method: "get",
  115. onSuccess: function(responseTree, responseElements, responseHTML, responseJavaScript){
  116. var toolbarNode = responseTree[0];
  117. if (callback) callback(toolbarNode);
  118. }.bind(this),
  119. onFailure: function(xhr){
  120. this.notice("request processToolbars error: "+xhr.responseText, "error");
  121. }.bind(this)
  122. });
  123. r.send();
  124. },
  125. loadDesignerTab: function(){
  126. MWF.require("MWF.widget.Tab", function(){
  127. this.designerTab = new MWF.widget.Tab(this.designerTabAreaNode, {"style": "script"});
  128. this.designerTab.load();
  129. }.bind(this), false);
  130. },
  131. createComponent: function(){
  132. MWF.require("MWF.xDesktop.Dialog", function(){
  133. var width = 600;
  134. var height = 230;
  135. var p = MWF.getCenterPosition(this.content, width, height);
  136. var _self = this;
  137. var dlg = new MWF.xDesktop.Dialog({
  138. "title": this.lp.create,
  139. "style": "appDesigner",
  140. "top": p.y-100,
  141. "left": p.x,
  142. "fromTop": p.y-100,
  143. "fromLeft": p.x,
  144. "width": width,
  145. "height": height,
  146. "url": this.path+"create.html",
  147. "container": this.content,
  148. "isClose": true,
  149. "onPostShow": function(){
  150. $("createComponent_okButton").addEvent("click", function(){
  151. _self.doCreateComponent(this);
  152. }.bind(this));
  153. $("createComponent_cancelButton").addEvent("click", function(){
  154. this.close();
  155. }.bind(this));
  156. }
  157. });
  158. dlg.show();
  159. }.bind(this));
  160. },
  161. createComponentCheck: function(name, title, path, dlg){
  162. if (!name || !title || path){
  163. this.notice(this.lp.createComponent_input, "error", dlg.node);
  164. return false;
  165. }
  166. for (var i=0; i<this.components.length; i++){
  167. var component = this.components[i];
  168. if (component.name == name){
  169. this.notice(this.lp.createComponent_nameExist, "error", dlg.node);
  170. return false;
  171. }
  172. if (component.title == title){
  173. this.notice(this.lp.createComponent_titleExist, "error", dlg.node);
  174. return false;
  175. }
  176. if (component.path == path){
  177. this.notice(this.lp.createComponent_pathExist, "error", dlg.node);
  178. return false;
  179. }
  180. }
  181. return true;
  182. },
  183. doCreateComponent: function(dlg){
  184. var name = $("createComponent_name").get("value");
  185. var title = $("createComponent_title").get("value");
  186. var path = $("createComponent_path").get("value");
  187. var checked = this.createComponentCheck(name, title, path, dlg);
  188. if (checked){
  189. var data = {
  190. "name": name,
  191. "title": title,
  192. "path": path,
  193. "context": "x_component_"+path.replace(/\./g, "_"),
  194. "id": (new MWF.widget.UUID).toString()
  195. }
  196. this.components.push(data);
  197. MWF.UD.putData("appDesigner", this.components, function(){
  198. this.doCreateComponentModules(data);
  199. }.bind(this));
  200. dlg.close();
  201. }
  202. },
  203. doCreateComponentModules: function(data){
  204. //this.appListContentNode
  205. var mainData = this.getCreateComponentMainData(data);
  206. this.appListContentNode
  207. },
  208. getCreateComponentMainData: function(data){
  209. var mainData = null;
  210. var url = "/x_component_"+data.path.replace(/\./g, "_")+"/template/Main.json";
  211. MWF.getJSON(url, function(json){
  212. mainData = json;
  213. }, false);
  214. mainData.options.name = data.path;
  215. mainData.options.title = data.path;
  216. return mainData;
  217. }
  218. });