Main.js 9.0 KB

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