Elcontainer.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. MWF.xApplication.process.FormDesigner.Module = MWF.xApplication.process.FormDesigner.Module || {};
  2. MWF.xDesktop.requireApp("process.FormDesigner", "Module.$ElComponent", null, false);
  3. MWF.xApplication.process.FormDesigner.Module.Elcontainer = MWF.FCElcontainer = new Class({
  4. Extends: MWF.FC$Component,
  5. Implements: [Options, Events],
  6. options: {
  7. "style": "default",
  8. "propertyPath": "../x_component_process_FormDesigner/Module/Elcontainer/elcontainer.html",
  9. "layoutTemplates": {
  10. "side-header-main-footer":"<el-container>\n" +
  11. " <el-aside></el-aside>\n" +
  12. " <el-container>\n" +
  13. " <el-header></el-header>\n" +
  14. " <el-main></el-main>\n" +
  15. " <el-footer></el-footer>\n" +
  16. " </el-container>\n" +
  17. "</el-container>",
  18. "header-main": "<el-container>\n" +
  19. " <el-header></el-header>\n" +
  20. " <el-main></el-main>\n" +
  21. "</el-container>",
  22. "header-main-footer": "<el-container>\n" +
  23. " <el-header></el-header>\n" +
  24. " <el-main></el-main>\n" +
  25. " <el-footer></el-footer>\n" +
  26. "</el-container>",
  27. "header-side-main": "<el-container>\n" +
  28. " <el-header></el-header>\n" +
  29. " <el-container>\n" +
  30. " <el-aside></el-aside>\n" +
  31. " <el-main></el-main>\n" +
  32. " </el-container>\n" +
  33. "</el-container>",
  34. "header-side-main-footer":"<el-container>\n" +
  35. " <el-header></el-header>\n" +
  36. " <el-container>\n" +
  37. " <el-aside></el-aside>\n" +
  38. " <el-container>\n" +
  39. " <el-main></el-main>\n" +
  40. " <el-footer></el-footer>\n" +
  41. " </el-container>\n" +
  42. " </el-container>\n" +
  43. "</el-container>",
  44. "header-footer-side-main":"<el-container>\n" +
  45. " <el-header></el-header>\n" +
  46. " <el-container>\n" +
  47. " <el-aside></el-aside>\n" +
  48. " <el-container>\n" +
  49. " <el-main></el-main>\n" +
  50. " </el-container>\n" +
  51. " </el-container>\n" +
  52. " <el-footer></el-footer>\n" +
  53. "</el-container>",
  54. "footer-side-header-main":"<el-container>\n" +
  55. " <el-container>\n" +
  56. " <el-aside></el-aside>\n" +
  57. " <el-container>\n" +
  58. " <el-header></el-header>\n" +
  59. " <el-main></el-main>\n" +
  60. " </el-container>\n" +
  61. " </el-container>\n" +
  62. " <el-footer></el-footer>\n" +
  63. "</el-container>",
  64. "side-header-main": "<el-container>\n" +
  65. " <el-aside></el-aside>\n" +
  66. " <el-container>\n" +
  67. " <el-header></el-header>\n" +
  68. " <el-main></el-main>\n" +
  69. " </el-container>\n" +
  70. "</el-container>"
  71. }
  72. },
  73. _initModuleType: function(){
  74. this.className = "Elcontainer"
  75. this.moduleType = "component";
  76. this.moduleName = "elcontainer";
  77. },
  78. initialize: function(form, options){
  79. this.setOptions(options);
  80. this._initModuleType();
  81. this.path = "../x_component_process_FormDesigner/Module/"+this.className+"/";
  82. this.cssPath = "../x_component_process_FormDesigner/Module/"+this.className+"/"+this.options.style+"/css.wcss";
  83. this._loadCss();
  84. this.form = form;
  85. this.container = null;
  86. this.containerNode = null;
  87. this.isPropertyLoaded = false;
  88. this.containers = [];
  89. this.elements = [];
  90. //this._dragMoveComplete = this._dragComplete;
  91. },
  92. _dragMoveComplete: MWF.FC$Component.prototype._dragComplete,
  93. _createMoveNode: function(){
  94. var html = "<section class=\"el-container\" style='height: 100%'>";
  95. html += "<aside class=\"el-aside\" style=\"width: 40px; background-color: #D3DCE6\"></aside>";
  96. html += "<section class=\"el-container is-vertical\">";
  97. html += "<header class=\"el-header\" style=\"height: 20px; background-color: #B3C0D1\"></header>";
  98. html += "<main class=\"el-main\"></main>";
  99. html += "<footer class=\"el-footer\" style=\"height: 20px; background-color: #B3C0D1\"></footer>";
  100. html += "</section>";
  101. html += "</section>";
  102. // var tableHTML = "<table border=\"0\" cellpadding=\"0\" cellspacing=\"2\" width=\"100%\" align=\"center\">";
  103. // tableHTML += "<tr><td></td><td></td><td></td></tr>";
  104. // tableHTML += "<tr><td></td><td></td><td></td></tr>";
  105. // tableHTML += "<tr><td></td><td></td><td></td></tr>";
  106. // tableHTML += "</table>";
  107. this.moveNode = new Element("div", {
  108. "html": html
  109. }).inject(this.form.container);
  110. // this.moveNode = divNode.getFirst();
  111. // this.moveNode.inject(divNode, "after");
  112. // divNode.destroy();
  113. this.moveNode.setStyles(this.css.moduleNodeMove);
  114. },
  115. _createElementHtml: function(){
  116. //var html = "<el-container>";
  117. var html = "";
  118. html += " <el-aside></el-aside>";
  119. html += " <el-container>";
  120. html += " <el-header></el-header>";
  121. html += " <el-main></el-main>";
  122. html += " <el-footer></el-footer>";
  123. html += " </el-container>";
  124. //html += "</el-container>";
  125. return html;
  126. },
  127. _createNode: function(callback){
  128. var module = this;
  129. var url = this.path+"elcontainerCreate.html";
  130. MWF.require("MWF.widget.Dialog", function(){
  131. var size = $(document.body).getSize();
  132. var x = size.x/2-395;
  133. var y = size.y/2-280;
  134. var dlg = new MWF.DL({
  135. "title": "Create Elcontainer",
  136. "style": "user",
  137. "top": y,
  138. "left": x-40,
  139. "fromTop":size.y/2-65,
  140. "fromLeft": size.x/2,
  141. "width": 790,
  142. "height": 560,
  143. "isResize": false,
  144. "url": url,
  145. "lp": MWF.xApplication.process.FormDesigner.LP.propertyTemplate,
  146. "container": layout.desktop.node,
  147. "buttonList": [
  148. {
  149. "text": MWF.APPFD.LP.button.ok,
  150. "action": function(){
  151. var value = this.editor.getValue();
  152. module._createElcontainerNode(callback, value);
  153. this.close();
  154. }
  155. },
  156. {
  157. "text": MWF.APPFD.LP.button.cancel,
  158. "type": "cancel",
  159. "action": function(){
  160. module._dragCancel();
  161. this.close();
  162. }
  163. }
  164. ],
  165. "onPostShow": function(){
  166. module._loadCreateHtmlEditor(this);
  167. module._loadCreateLayoutSelect(this);
  168. }
  169. });
  170. dlg.show();
  171. });
  172. },
  173. _loadCreateHtmlEditor: function(dlg){
  174. var codeNode = dlg.content.getElement(".MWFVueCode");
  175. o2.require("o2.widget.JavascriptEditor", function(){
  176. dlg.editor = new o2.widget.JavascriptEditor(codeNode, {
  177. "option": {
  178. value: this.options.layoutTemplates["side-header-main-footer"],
  179. mode: "html",
  180. "lineNumbers": false
  181. },
  182. });
  183. dlg.editor.load();
  184. }.bind(this));
  185. },
  186. _loadCreateLayoutSelect: function(dlg){
  187. var imgs = dlg.content.getElements("img");
  188. imgs.each(function(img){
  189. img.addEvent("click", function(){
  190. imgs.removeClass("mainColor_border");
  191. imgs.setStyle("border-color", "#ffffff");
  192. img.addClass("mainColor_border");
  193. img.setStyle("border-color", "#4A90E2");
  194. dlg.editor.setValue(this.options.layoutTemplates[img.get("name")]);
  195. }.bind(this));
  196. }.bind(this));
  197. },
  198. _createElcontainerNode: function(callback, value){
  199. var node = new Element("div", {
  200. "html": value
  201. });
  202. this.node = node.getFirst();
  203. this.node.dispose();
  204. node.destroy();
  205. this.node.set({
  206. "MWFType": this.moduleName,
  207. "id": this.json.id,
  208. "styles": this.css.moduleNode,
  209. "events": {
  210. "selectstart": function(){
  211. return false;
  212. }
  213. }
  214. });
  215. this._loadVue(function(){
  216. this._mountVueApp(callback);
  217. }.bind(this));
  218. },
  219. _loadVue: function(callback){
  220. if (!window.Vue){
  221. o2.load(["vue", "elementui"], { "sequence": true }, callback);
  222. }else{
  223. if (callback) callback();
  224. }
  225. },
  226. _mountVueApp: function(callback){
  227. if (!this.vueApp) this.vueApp = this._createVueExtend(callback);
  228. try{
  229. this.vm = new Vue(this.vueApp);
  230. this.vm.$o2module = this;
  231. this.vm.$o2callback = callback;
  232. this.vm.$mount(this.node);
  233. }catch(e){
  234. this.node.store("module", this);
  235. this._loadVueCss();
  236. if (callback) callback();
  237. }
  238. },
  239. _createVueExtend: function(callback){
  240. var _self = this;
  241. return {
  242. data: this._createVueData(),
  243. mounted: function(){
  244. _self._afterMounted(this.$el);
  245. if (callback) callback();
  246. }
  247. };
  248. },
  249. _createVueData: function(callback){
  250. return {};
  251. },
  252. _afterMounted: function(el){
  253. this.node = el;
  254. this.node.store("module", this);
  255. },
  256. _dragComplete: function(){
  257. if (!this.node){
  258. this._createNode(function(){
  259. this._dragMoveComplete();
  260. }.bind(this));
  261. }else{
  262. this._dragMoveComplete();
  263. }
  264. },
  265. _getElements: function(){
  266. this.elements = [];
  267. },
  268. _getContainerDoms: function(dom){
  269. var node = dom.getFirst();
  270. while (node){
  271. var tag = node.tagName.toString().toLowerCase();
  272. if (tag!=="section" || !node.get("mwftype")){
  273. switch (tag){
  274. case "aside":
  275. this.asideNodes.push(node);
  276. break;
  277. case "header":
  278. this.headerNodes.push(node);
  279. break;
  280. case "main":
  281. this.mainNodes.push(node);
  282. break;
  283. case "footer":
  284. this.footerNodes.push(node);
  285. break;
  286. default:
  287. this._getContainerDoms(node);
  288. }
  289. }
  290. node = node.getNext();
  291. }
  292. },
  293. _getContainers: function(){
  294. if (!this.containers || !this.containers.length)this.containers = [];
  295. this.asideNodes = [];
  296. this.headerNodes = [];
  297. this.mainNodes = [];
  298. this.footerNodes = [];
  299. this._getContainerDoms(this.node);
  300. // var asides = this.node.getElements("aside");
  301. // var headers = this.node.getElements("header");
  302. // var mains = this.node.getElements("main");
  303. // var footers = this.node.getElements("footer");
  304. this.form.getTemplateData("Elcontainer$Container", function(data){
  305. this.asideNodes.each(function(aside){
  306. this._createContainer(aside, data, "Elcontainer$Aside");
  307. }.bind(this));
  308. this.headerNodes.each(function(header){
  309. this._createContainer(header, data, "Elcontainer$Header");
  310. }.bind(this));
  311. this.mainNodes.each(function(main){
  312. this._createContainer(main, data, "Elcontainer$Main");
  313. }.bind(this));
  314. this.footerNodes.each(function(footer){
  315. this._createContainer(footer, data, "Elcontainer$Footer");
  316. }.bind(this));
  317. }.bind(this));
  318. },
  319. _createContainer: function(node, data, className){
  320. data.type = className;
  321. var json = this.form.getDomjson(node);
  322. var container = null;
  323. if (!json){
  324. var moduleData = Object.clone(data);
  325. container = new MWF["FC"+className](this.form);
  326. container.container = this;
  327. container.load(moduleData, node, this);
  328. container.node.set({
  329. "MWFType": container.moduleName,
  330. "id": container.json.id
  331. });
  332. }else{
  333. var moduleData = Object.clone(data);
  334. Object.merge(moduleData, json);
  335. Object.merge(json, moduleData);
  336. container = new MWF["FC"+className](this.form);
  337. container.container = this;
  338. container.load(json, node, this);
  339. container.node.set({
  340. "MWFType": container.moduleName,
  341. "id": container.json.id
  342. });
  343. }
  344. this.containers.push(container);
  345. }
  346. });