Tab.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  1. MWF.xApplication.process.FormDesigner.Module = MWF.xApplication.process.FormDesigner.Module || {};
  2. MWF.xDesktop.requireApp("process.FormDesigner", "Module.$Component", null, false);
  3. MWF.xDesktop.requireApp("process.FormDesigner", "Module.Tab$Page", null, false);
  4. MWF.xDesktop.requireApp("process.FormDesigner", "Module.Tab$Content", null, false);
  5. MWF.require("MWF.widget.Tab", null, false);
  6. MWF.xApplication.process.FormDesigner.Module.Tab = MWF.FCTab = new Class({
  7. Extends: MWF.FC$Component,
  8. Implements: [Options, Events],
  9. options: {
  10. "style": "default",
  11. "propertyPath": "../x_component_process_FormDesigner/Module/Tab/tab.html",
  12. "actions": [
  13. {
  14. "name": "move",
  15. "icon": "move1.png",
  16. "event": "mousedown",
  17. "action": "move",
  18. "title": MWF.APPFD.LP.formAction.move
  19. },
  20. {
  21. "name": "copy",
  22. "icon": "copy1.png",
  23. "event": "mousedown",
  24. "action": "copy",
  25. "title": MWF.APPFD.LP.formAction.copy
  26. },
  27. {
  28. "name": "add",
  29. "icon": "add.png",
  30. "event": "click",
  31. "action": "addPage",
  32. "title": MWF.APPFD.LP.formAction.add
  33. },
  34. {
  35. "name": "delete",
  36. "icon": "delete1.png",
  37. "event": "click",
  38. "action": "delete",
  39. "title": MWF.APPFD.LP.formAction["delete"]
  40. },
  41. {
  42. "name": "selectParent",
  43. "icon": "selectParent.png",
  44. "event": "click",
  45. "action": "selectParent",
  46. "title": MWF.APPFD.LP.formAction["selectParent"]
  47. }
  48. ]
  49. },
  50. initialize: function(form, options){
  51. this.setOptions(options);
  52. this.path = "../x_component_process_FormDesigner/Module/Tab/";
  53. this.cssPath = "../x_component_process_FormDesigner/Module/Tab/"+this.options.style+"/css.wcss";
  54. this._loadCss();
  55. this.moduleType = "component";
  56. this.moduleName = "tab";
  57. this.form = form;
  58. this.container = null;
  59. this.containerNode = null;
  60. this.containers = [];
  61. this.elements = [];
  62. },
  63. clearTemplateStyles: function(styles){
  64. if (styles){
  65. if (styles.styles) this.removeStyles(styles.styles, "styles");
  66. if (styles.properties) this.removeStyles(styles.properties, "properties");
  67. if (styles.tabAreaStyles) this.removeStyles(styles.tabAreaStyles, "tabNodeContainer");
  68. if (styles.contentAreaStyles) this.removeStyles(styles.contentAreaStyles, "contentNodeContainer");
  69. if (styles.tabStyles) this.removeStyles(styles.tabStyles, "tabStyles");
  70. if (styles.tabTextStyles) this.removeStyles(styles.tabTextStyles, "tabTextStyles");
  71. if (styles.tabCurrentStyles) this.removeStyles(styles.tabCurrentStyles, "tabCurrentStyles");
  72. if (styles.tabCurrentTextStyles) this.removeStyles(styles.tabCurrentTextStyles, "tabTextCurrentStyles");
  73. }
  74. },
  75. setTemplateStyles: function(styles){
  76. if (styles.styles) this.copyStyles(styles.styles, "styles");
  77. if (styles.properties) this.copyStyles(styles.properties, "properties");
  78. if (styles.tabAreaStyles) this.copyStyles(styles.tabAreaStyles, "tabNodeContainer");
  79. if (styles.contentAreaStyles) this.copyStyles(styles.contentAreaStyles, "contentNodeContainer");
  80. if (styles.tabStyles) this.copyStyles(styles.tabStyles, "tabStyles");
  81. if (styles.tabTextStyles) this.copyStyles(styles.tabTextStyles, "tabTextStyles");
  82. if (styles.tabCurrentStyles) this.copyStyles(styles.tabCurrentStyles, "tabCurrentStyles");
  83. if (styles.tabCurrentTextStyles) this.copyStyles(styles.tabCurrentTextStyles, "tabTextCurrentStyles");
  84. },
  85. _createMoveNode: function(){
  86. this.moveNode = new Element("div", {
  87. "styles": this.css.moduleNodeMove
  88. }).inject(this.form.container);
  89. var divTab1 = new Element("div", {
  90. "styles": this.css.moduleNodeMove_tab_current
  91. });
  92. var divTab2 = new Element("div", {
  93. "styles": this.css.moduleNodeMove_tab
  94. });
  95. var divContent = new Element("div", {
  96. "styles": this.css.moduleNodeMove_content
  97. });
  98. divTab1.inject(this.moveNode);
  99. divTab2.inject(this.moveNode);
  100. divContent.inject(this.moveNode);
  101. },
  102. _createNode: function(callback){
  103. this.node = new Element("div", {
  104. "id": this.json.id,
  105. "MWFType": "tab",
  106. "styles": this.css.moduleNode,
  107. "events": {
  108. "selectstart": function(e){
  109. e.preventDefault();
  110. }
  111. }
  112. }).inject(this.form.node);
  113. var style = "form";
  114. if (this.form.options.mode=="Mobile") style = "mobileForm";
  115. this.tabWidget = new MWF.widget.Tab(this.node, {"style": style});
  116. this._loadPageStyle();
  117. this.tabWidget.load();
  118. var tabNode = new Element("div");
  119. this.tabWidget.addTab(tabNode, "page1", false);
  120. tabNode = new Element("div");
  121. this.tabWidget.addTab(tabNode, "page2", false);
  122. tabNode = new Element("div");
  123. this.tabWidget.addTab(tabNode, "page3", false);
  124. tabNode = new Element("div");
  125. this.tabWidget.addTab(tabNode, "page4", false);
  126. },
  127. _createTabWidget: function(){
  128. var style = "form";
  129. if (this.form.options.mode=="Mobile") style = "mobileForm";
  130. //debugger;
  131. var menuNode = this.node.getElement(".MWFMenu");
  132. if (menuNode) menuNode.destroy();
  133. this.tabWidget = new MWF.widget.Tab(this.node, {"style": style});
  134. this._loadPageStyle();
  135. //this._setTabWidgetStyles();
  136. this.tabWidget.tabNodeContainer = this.node.getFirst();
  137. this.tabWidget.contentNodeContainer = this.tabWidget.tabNodeContainer.getNext();
  138. var lastNode = this.tabWidget.tabNodeContainer.getLast();
  139. var tmpTabDivs;
  140. if (lastNode && lastNode.hasClass("tabNodeContainerLeft")){
  141. this.tabWidget.tabNodeContainerRight = this.tabWidget.tabNodeContainer.getFirst();
  142. this.tabWidget.tabNodeContainerLeft = lastNode;
  143. this.tabWidget.tabNodeContainerArea = lastNode.getFirst();
  144. this.tabWidget.load();
  145. tmpTabDivs = this.tabWidget.tabNodeContainerArea.getChildren("div");
  146. }else{
  147. tmpTabDivs = this.tabWidget.tabNodeContainer.getChildren("div");
  148. this.tabWidget.load();
  149. }
  150. var tmpContentDivs = this.tabWidget.contentNodeContainer.getChildren();
  151. //var tmpTabDivs = this.tabWidget.tabNodeContainer.getChildren();
  152. tmpContentDivs.each(function(tmpContentDiv, idx){
  153. var tmpTabDiv = tmpTabDivs[idx];
  154. var tabPage = new MWF.widget.TabPage(tmpContentDiv.getFirst(), "", this.tabWidget, {"isClose": false});
  155. tabPage.contentNodeArea = tmpContentDiv;
  156. if (tmpTabDiv){
  157. tabPage.tabNode = tmpTabDiv;
  158. tabPage.textNode = tmpTabDiv.getFirst();
  159. if(tabPage.textNode)tabPage.closeNode = tabPage.textNode.getFirst();
  160. }
  161. tabPage.load();
  162. this.tabWidget.pages.push(tabPage);
  163. }.bind(this));
  164. },
  165. _loadPageStyle: function(){
  166. if (!this.json.tabNodeContainer || !Object.keys(this.json.tabNodeContainer).length) this.json.tabNodeContainer = Object.clone(this.tabWidget.css.tabNodeContainer);
  167. if (!this.json.contentNodeContainer || !Object.keys(this.json.contentNodeContainer).length) this.json.contentNodeContainer = Object.clone(this.tabWidget.css.contentNodeContainer);
  168. if (!this.json.tabStyles || !Object.keys(this.json.tabStyles).length) this.json.tabStyles = Object.clone(this.tabWidget.css.tabNode);
  169. if (!this.json.tabTextStyles || !Object.keys(this.json.tabTextStyles).length) this.json.tabTextStyles = Object.clone(this.tabWidget.css.tabTextNode);
  170. if (!this.json.tabCurrentStyles || !Object.keys(this.json.tabCurrentStyles).length) this.json.tabCurrentStyles = Object.clone(this.tabWidget.css.tabNodeCurrent);
  171. if (!this.json.tabTextCurrentStyles || !Object.keys(this.json.tabTextCurrentStyles).length) this.json.tabTextCurrentStyles = Object.clone(this.tabWidget.css.tabTextNodeCurrent);
  172. if (!this.json.contentNodeContainer || !Object.keys(this.json.contentNodeContainer).length) this.json.contentNodeContainer.clear = "both";
  173. this._setTabWidgetStyles();
  174. },
  175. _setTabWidgetStyles: function(){
  176. this.tabWidget.css.tabNodeContainer = this.json.tabNodeContainer;
  177. this.tabWidget.css.contentNodeContainer = this.json.contentNodeContainer;
  178. this.tabWidget.css.tabNode = this.json.tabStyles;
  179. this.tabWidget.css.tabTextNode = this.json.tabTextStyles;
  180. this.tabWidget.css.tabNodeCurrent = this.json.tabCurrentStyles;
  181. if( !this.json.contentNodeContainer || !this.json.contentNodeContainer.clear )this.tabWidget.css.contentNodeContainer.clear = "both";
  182. this.tabWidget.css.tabTextNodeCurrent = this.json.tabTextCurrentStyles;
  183. },
  184. _getElements: function(){
  185. //this.elements.push(this);
  186. if (!this.tabWidget) this._createTabWidget();
  187. this.form.getTemplateData("Tab$Page", function(data){
  188. this.tabWidget.pages.each(function(page){
  189. var tabPage = null;
  190. var json = this.form.getDomjson(page.tabNode);
  191. if (!json){
  192. var moduleData = Object.clone(data);
  193. moduleData.name = page.tabNode.get("text");
  194. tabPage = new MWF.FCTab$Page(this, page);
  195. tabPage.page = page;
  196. tabPage.load(moduleData, page.tabNode, this);
  197. }else{
  198. var moduleData = Object.clone(data);
  199. Object.merge(moduleData, json);
  200. Object.merge(json, moduleData);
  201. tabPage = new MWF.FCTab$Page(this, page);
  202. tabPage.page = page;
  203. tabPage.load(json, page.tabNode, this);
  204. }
  205. if (tabPage) this.elements.push(tabPage);
  206. }.bind(this));
  207. }.bind(this));
  208. if (!this.tabWidget.showPage) this.tabWidget.pages[0].showTabIm();
  209. },
  210. _getContainers: function(){
  211. if (!this.tabWidget) this._createTabWidget();
  212. this.form.getTemplateData("Tab$Content", function(data){
  213. this.tabWidget.pages.each(function(page){
  214. var tabContent = null;
  215. var json = this.form.getDomjson(page.contentNode);
  216. if (!json){
  217. var moduleData = Object.clone(data);
  218. tabContent = new MWF.FCTab$Content(this, page);
  219. tabContent.page = page;
  220. tabContent.load(moduleData, page.contentNode, this);
  221. }else{
  222. var moduleData = Object.clone(data);
  223. Object.merge(moduleData, json);
  224. Object.merge(json, moduleData);
  225. tabContent = new MWF.FCTab$Content(this, page);
  226. tabContent.page = page;
  227. tabContent.load(json, page.contentNode, this);
  228. }
  229. if (tabContent) this.containers.push(tabContent);
  230. }.bind(this));
  231. }.bind(this));
  232. },
  233. _setEditStyle_custom: function(name){
  234. if (name=="tabNodeContainer"){
  235. this.tabWidget.tabNodeContainer.clearStyles();
  236. this.tabWidget.tabNodeContainer.setStyles(this.json.tabNodeContainer);
  237. this._setTabWidgetStyles();
  238. }
  239. if (name=="contentNodeContainer"){
  240. this.tabWidget.contentNodeContainer.clearStyles();
  241. this.tabWidget.contentNodeContainer.setStyles(this.json.contentNodeContainer);
  242. this._setTabWidgetStyles();
  243. }
  244. if (name=="tabStyles"){
  245. this.tabWidget.pages.each(function(page){
  246. if (!page.isShow){
  247. page.tabNode.clearStyles();
  248. page.tabNode.setStyles(this.json.tabStyles);
  249. }
  250. }.bind(this));
  251. this._setTabWidgetStyles();
  252. }
  253. if (name=="tabTextStyles"){
  254. this.tabWidget.pages.each(function(page){
  255. if (!page.isShow){
  256. page.textNode.clearStyles();
  257. page.textNode.setStyles(this.json.tabTextStyles);
  258. }
  259. }.bind(this));
  260. this._setTabWidgetStyles();
  261. }
  262. if (name=="tabCurrentStyles"){
  263. this.tabWidget.pages.each(function(page){
  264. if (page.isShow){
  265. page.tabNode.clearStyles();
  266. page.tabNode.setStyles(this.json.tabCurrentStyles);
  267. }
  268. }.bind(this));
  269. this._setTabWidgetStyles();
  270. }
  271. if (name=="tabTextCurrentStyles"){
  272. this.tabWidget.pages.each(function(page){
  273. if (page.isShow){
  274. page.textNode.clearStyles();
  275. page.textNode.setStyles(this.json.tabTextCurrentStyles);
  276. }
  277. }.bind(this));
  278. this._setTabWidgetStyles();
  279. }
  280. },
  281. setTabStyles: function(){
  282. this._setEditStyle_custom("tabNodeContainer");
  283. this._setEditStyle_custom("contentNodeContainer");
  284. this._setEditStyle_custom("tabStyles");
  285. this._setEditStyle_custom("tabTextStyles");
  286. this._setEditStyle_custom("tabCurrentStyles");
  287. this._setEditStyle_custom("tabTextCurrentStyles");
  288. },
  289. setAllStyles: function(){
  290. this.setPropertiesOrStyles("styles");
  291. this.setPropertiesOrStyles("properties");
  292. this.setTabStyles();
  293. //this.tabWidget.pages.each(function(page){
  294. // //if (page.isShow){
  295. // page.tabNode.clearStyles();
  296. // //page.tabNode.setStyles(this.json.tabCurrentStyles);
  297. // //
  298. // //Object.each(this.json.tabCurrentStyles, function(v, k){
  299. // // page.tabNode.setStyle(k, v);
  300. // //}.bind(this));
  301. // //}
  302. //}.bind(this));
  303. this.reloadMaplist();
  304. },
  305. addPage: function( ev, historyCallback ){
  306. tabNode = new Element("div");
  307. var page = this.tabWidget.addTab(tabNode, "page", false);
  308. var tabPage, tabContent;
  309. this.form.getTemplateData("Tab$Page", function(data){
  310. var moduleData = Object.clone(data);
  311. moduleData.name = page.tabNode.get("text");
  312. tabPage = new MWF.FCTab$Page(this, page);
  313. tabPage.load(moduleData, page.tabNode, this);
  314. this.elements.push(tabPage);
  315. }.bind(this), false);
  316. this.form.getTemplateData("Tab$Content", function(data){
  317. var moduleData = Object.clone(data);
  318. tabContent = new MWF.FCTab$Content(this, page);
  319. tabContent.load(moduleData, page.contentNode, this);
  320. this.containers.push(tabContent);
  321. }.bind(this), false);
  322. page.showTabIm();
  323. if( historyCallback ){
  324. historyCallback( tabPage );
  325. }else{
  326. tabPage.addHistoryLog("add")
  327. }
  328. // var historyLog = {
  329. // "operation": "add",
  330. // "type": "module",
  331. // "json": Object.clone(tabPage.json),
  332. // "jsonObject": tabPage.getJson(),
  333. // "html": tabPage.node.outerHTML,
  334. // "toPath": this.form.history.getPath(tabPage.node),
  335. // "content": {
  336. // "json": Object.clone(tabContent.json),
  337. // "jsonObject": tabContent.getJson(),
  338. // "html": tabPage.page.contentNodeArea.outerHTML,
  339. // "toPath": this.form.history.getPath( tabPage.page.contentNodeArea )
  340. // }
  341. // };
  342. // if( historyCallback ){
  343. // historyCallback( historyLog, tabPage );
  344. // }else if( this.form.history ){
  345. // this.form.history.add( historyLog );
  346. // }
  347. return page;
  348. },
  349. copyComponentJsonData: function(newNode, pid){
  350. var tabNodeContainer = newNode.getFirst();
  351. //var contentNodeContainer = newNode.getLast();
  352. var contentNodeContainer = tabNodeContainer.getNext();
  353. var tmpContentDivs = contentNodeContainer.getChildren();
  354. var lastNode = tabNodeContainer.getLast();
  355. var tmpTabDivs;
  356. if (lastNode && lastNode.hasClass("tabNodeContainerLeft")){
  357. var tabNodeContainerArea = lastNode.getFirst();
  358. var menuNode = newNode.getElement(".MWFMenu");
  359. if (menuNode) menuNode.destroy();
  360. tmpTabDivs = tabNodeContainerArea.getChildren("div");
  361. }else{
  362. tmpTabDivs = tabNodeContainer.getChildren("div");
  363. }
  364. // var tmpTabDivs = tabNodeContainer.getChildren();
  365. tmpContentDivs.each(function(tmpContentDiv, idx){
  366. var newContainerJson = Object.clone(this.containers[idx].json);
  367. var newElementJson = Object.clone(this.elements[idx].json);
  368. var tmpTabDiv = tmpTabDivs[idx];
  369. newContainerJson.id = this.containers[idx]._getNewId(pid);
  370. this.form.json.moduleList[newContainerJson.id] = newContainerJson;
  371. tmpContentDiv.getFirst().set("id", newContainerJson.id);
  372. newElementJson.id = this.elements[idx]._getNewId(pid);
  373. this.form.json.moduleList[newElementJson.id] = newElementJson;
  374. tmpTabDiv.set("id", newElementJson.id);
  375. }.bind(this));
  376. },
  377. _preprocessingModuleData: function(){
  378. this.recoveryWidgetstyle = this.node.get("style");
  379. this.node.clearStyles();
  380. //if (this.initialStyles) this.node.setStyles(this.initialStyles);
  381. this.json.recoveryStyles = Object.clone(this.json.styles);
  382. if (this.json.recoveryStyles) Object.each(this.json.recoveryStyles, function(value, key){
  383. if ((value.indexOf("x_processplatform_assemble_surface")!=-1 || value.indexOf("x_portal_assemble_surface")!=-1)){
  384. //需要运行时处理
  385. }else{
  386. this.node.setStyle(key, value);
  387. delete this.json.styles[key];
  388. }
  389. }.bind(this));
  390. },
  391. _recoveryModuleData: function(){
  392. if (this.recoveryWidgetstyle) this.node.set("style", this.recoveryWidgetstyle);
  393. this.recoveryWidgetstyle = null;
  394. if (this.json.recoveryStyles) this.json.styles = this.json.recoveryStyles;
  395. this.json.recoveryStyles = null;
  396. },
  397. loadExistedNodePage: function(tabNode, contentNodeArea, tabJson, contentJson){
  398. var tabPage = new MWF.widget.TabPage(contentNodeArea.getFirst(), "", this.tabWidget, {"isClose": false});
  399. tabPage.contentNodeArea = contentNodeArea;
  400. tabPage.tabNode = tabNode;
  401. tabPage.textNode = tabNode.getFirst();
  402. if(tabPage.textNode)tabPage.closeNode = tabPage.textNode.getFirst();
  403. tabPage.loadExisted();
  404. this.tabWidget.pages.push(tabPage);
  405. var page = new MWF.FCTab$Page(this, tabPage);
  406. page.load(tabJson, tabPage.tabNode, this);
  407. this.elements.push(page);
  408. var tabContent = new MWF.FCTab$Content(this, tabPage);
  409. tabContent.load(contentJson, tabPage.contentNode, this);
  410. this.containers.push(tabContent);
  411. tabPage.showTabIm();
  412. }
  413. // setCustomStyles: function(){
  414. // this._recoveryModuleData();
  415. // //debugger;
  416. // var border = this.node.getStyle("border");
  417. // this.node.clearStyles();
  418. // this.node.setStyles(this.css.moduleNode);
  419. //
  420. // if (this.initialStyles) this.node.setStyles(this.initialStyles);
  421. // this.node.setStyle("border", border);
  422. //
  423. // if (this.json.styles) Object.each(this.json.styles, function(value, key){
  424. // if ((value.indexOf("x_processplatform_assemble_surface")!=-1 || value.indexOf("x_portal_assemble_surface")!=-1)){
  425. // var host1 = MWF.Actions.getHost("x_processplatform_assemble_surface");
  426. // var host2 = MWF.Actions.getHost("x_portal_assemble_surface");
  427. // if (value.indexOf("/x_processplatform_assemble_surface")!==-1){
  428. // value = value.replace("/x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  429. // }else if (value.indexOf("x_processplatform_assemble_surface")!==-1){
  430. // value = value.replace("x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  431. // }
  432. // if (value.indexOf("/x_portal_assemble_surface")!==-1){
  433. // value = value.replace("/x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  434. // }else if (value.indexOf("x_portal_assemble_surface")!==-1){
  435. // value = value.replace("x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  436. // }
  437. // }
  438. //
  439. // var reg = /^border\w*/ig;
  440. // if (!key.test(reg)){
  441. // if (key){
  442. // if (key.toString().toLowerCase()==="display"){
  443. // if (value.toString().toLowerCase()==="none"){
  444. // this.node.setStyle("opacity", 0.3);
  445. // }else{
  446. // this.node.setStyle("opacity", 1);
  447. // this.node.setStyle(key, value);
  448. // }
  449. // }else{
  450. // this.node.setStyle(key, value);
  451. // }
  452. // }
  453. // }
  454. // }.bind(this));
  455. // }
  456. });