Subpage.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  1. MWF.xApplication.portal.PageDesigner.Module = MWF.xApplication.portal.PageDesigner.Module || {};
  2. MWF.xDesktop.requireApp("process.FormDesigner", "Module.$Element", null, false);
  3. MWF.xApplication.portal.PageDesigner.Module.Subpage = MWF.PCSubpage = new Class({
  4. Extends: MWF.FC$Element,
  5. Implements: [Options, Events],
  6. options: {
  7. "style": "default",
  8. "propertyPath": "../x_component_portal_PageDesigner/Module/Subpage/subpage.html",
  9. "actions": [
  10. {
  11. "name": "move",
  12. "icon": "move1.png",
  13. "event": "mousedown",
  14. "action": "move",
  15. "title": MWF.APPPOD.LP.formAction.move
  16. },
  17. {
  18. "name": "delete",
  19. "icon": "delete1.png",
  20. "event": "click",
  21. "action": "delete",
  22. "title": MWF.APPPOD.LP.formAction["delete"]
  23. },
  24. {
  25. "name": "selectParent",
  26. "icon": "selectParent.png",
  27. "event": "click",
  28. "action": "selectParent",
  29. "title": MWF.APPFD.LP.formAction["selectParent"]
  30. }
  31. // {
  32. // "name": "styleBrush",
  33. // "icon": "styleBrush.png",
  34. // "event": "click",
  35. // "action": "styleBrush",
  36. // "title": MWF.APPPOD.LP.formAction["styleBrush"]
  37. // }
  38. ]
  39. },
  40. initialize: function(page, options){
  41. this.setOptions(options);
  42. this.path = "../x_component_portal_PageDesigner/Module/Subpage/";
  43. this.cssPath = "../x_component_portal_PageDesigner/Module/Subpage/"+this.options.style+"/css.wcss";
  44. this._loadCss();
  45. this.moduleType = "element";
  46. this.moduleName = "subpage";
  47. this.page = page;
  48. this.form = page;
  49. this.container = null;
  50. this.containerNode = null;
  51. },
  52. load : function(json, node, parent){
  53. this.json = json;
  54. this.node= node;
  55. this.node.store("module", this);
  56. //this.node.empty();
  57. this.node.setStyles(this.css.moduleNode);
  58. //this._loadNodeStyles();
  59. this._initModule();
  60. if (this.json.subpageSelected && this.json.subpageSelected!=="none" && this.json.subpageType!=="script"){
  61. this.redoSelectedSubpage(this.json.subpageSelected, null, "");
  62. }else{
  63. this.node.empty();
  64. this.loadIcon();
  65. }
  66. this._loadTreeNode(parent);
  67. this.setCustomStyles();
  68. this.parentContainer = this.treeNode.parentNode.module;
  69. this._setEditStyle_custom("id");
  70. this.parseModules();
  71. this.json.moduleName = this.moduleName;
  72. this.node.addEvent("click", function(){
  73. this.refreshSubpage();
  74. }.bind(this));
  75. this.node.addEvent("dblclick", function(e){
  76. this.openSubpage(e);
  77. }.bind(this));
  78. },
  79. _initModule: function(){
  80. if (!this.json.isSaved) this.setStyleTemplate();
  81. this.setPropertiesOrStyles("styles");
  82. this.setPropertiesOrStyles("inputStyles");
  83. this.setPropertiesOrStyles("properties");
  84. this._setNodeProperty();
  85. if (!this.page.isSubpage) this._createIconAction();
  86. this._setNodeEvent();
  87. this.json.isSaved = true;
  88. this.queryGetPageDataFun = this.queryGetPageData.bind(this);
  89. this.postGetPageDataFun = this.postGetPageData.bind(this);
  90. this.page.addEvent("queryGetPageData", this.queryGetPageDataFun);
  91. this.page.addEvent("postGetPageData", this.postGetPageDataFun);
  92. },
  93. openSubpage: function(e){
  94. if (this.json.subpageSelected && this.json.subpageSelected!=="none" && this.json.subpageType!=="script"){
  95. layout.desktop.openApplication(e, "portal.PageDesigner", {"id": this.json.subpageSelected, "appId": "PageDesigner"+this.json.subpageSelected});
  96. }
  97. },
  98. _createMoveNode: function(){
  99. this.moveNode = new Element("div", {
  100. "MWFType": "subpage",
  101. "id": this.json.id,
  102. "styles": this.css.moduleNodeMove,
  103. "events": {
  104. "selectstart": function(){
  105. return false;
  106. }
  107. }
  108. }).inject(this.page.container);
  109. },
  110. _createNode: function(){
  111. this.node = this.moveNode.clone(true, true);
  112. this.node.setStyles(this.css.moduleNode);
  113. this.node.set("id", this.json.id);
  114. this.node.addEvent("selectstart", function(){
  115. return false;
  116. });
  117. // debugger;
  118. // if (this.json.subpageSelected && this.json.subpageSelected!="none" && this.json.subpageType!=="script"){
  119. // this.redoSelectedSubpage(this.json.subpageSelected, $(this.property.data.pid+"selectSubpage").getElement("select"), "");
  120. // }else{
  121. this.loadIcon();
  122. // }
  123. this.node.addEvent("click", function(){
  124. this.refreshSubpage();
  125. }.bind(this));
  126. },
  127. postGetPageData: function(node){
  128. if (!node || node.contains(this.node)) this.show();
  129. },
  130. queryGetPageData: function(node){
  131. if (!node || node.contains(this.node)) this.hide();
  132. },
  133. hide: function(){
  134. this.node.empty();
  135. },
  136. show: function(){
  137. if (this.subpageData ){
  138. this.subpageModule = new MWF.PCSubpage.Page(this.page, this.node, {
  139. parentpageIdList : this.getParentpageIdList(),
  140. level : this.getLevel()
  141. });
  142. this.subpageModule.subpageSelector = this.getSubpageSelector();
  143. this.subpageModule.subpageSelectedValue = this.getSubpageSelectedValue();
  144. this.subpageModule.level1Subpage = this.getLevel1Subpage();
  145. this.subpageModule.load(this.subpageData);
  146. }else{
  147. this.node.empty();
  148. this.loadIcon();
  149. }
  150. },
  151. "delete": function(e){
  152. var module = this;
  153. this.page.designer.shortcut = false;
  154. this.page.designer.confirm("warn", module.node, MWF.APPPOD.LP.notice.deleteElementTitle, MWF.APPPOD.LP.notice.deleteElement, 300, 120, function(){
  155. if (this.queryGetPageDataFun) module.page.removeEvent("queryGetPageData", this.queryGetPageDataFun);
  156. if (this.postGetPageDataFun) module.page.removeEvent("postGetPageData", this.postGetPageDataFun);
  157. module.destroy();
  158. module.page.selected();
  159. module.page.designer.shortcut = true;
  160. this.close();
  161. }, function(){
  162. module.page.designer.shortcut = true;
  163. this.close();
  164. }, null);
  165. },
  166. getLevel : function(){
  167. return ( this.page.options.level1 || 0 ) + 1;
  168. },
  169. getLevel1Subpage : function(){
  170. return this.page.level1Subpage || this;
  171. },
  172. getSubpageSelector : function(){
  173. return this.subpageSelector || this.page.subpageSelector;
  174. },
  175. getSubpageSelectedValue : function(){
  176. return this.subpageSelectedValue || this.page.subpageSelectedValue;
  177. },
  178. checkSubpageNested : function( id ){
  179. if( this.page.options.parentpageIdList ){
  180. return !this.page.options.parentpageIdList.contains( id );
  181. }
  182. return true;
  183. },
  184. getParentpageIdList : function(){
  185. var parentpageIdList;
  186. if( this.page.options.parentpageIdList ){
  187. parentpageIdList = Array.clone( this.page.options.parentpageIdList );
  188. parentpageIdList.push( this.page.json.id )
  189. }else{
  190. parentpageIdList = [ this.page.json.id ];
  191. }
  192. return parentpageIdList;
  193. },
  194. refreshSubpage: function(){
  195. if (this.json.subpageSelected && this.json.subpageSelected!=="none" && this.json.subpageType!=="script"){
  196. MWF.Actions.get("x_portal_assemble_designer").getPage(this.json.subpageSelected, function(json){
  197. if (this.subpageData.updateTime!==json.data.updateTime){
  198. var select = null;
  199. if (this.property){
  200. select = $(this.property.data.pid+"selectSubpage").getElement("select");
  201. }
  202. this.clearSubpageList(this.json.subpageSelected);
  203. this.reloadSubpage(json.data, select, "");
  204. }
  205. }.bind(this));
  206. }
  207. },
  208. loadIcon: function(){
  209. this.iconNode = new Element("div", {
  210. "styles": this.css.iconNode
  211. }).inject(this.node);
  212. new Element("div", {
  213. "styles": this.css.iconNodeIcon
  214. }).inject(this.iconNode);
  215. new Element("div", {
  216. "styles": this.css.iconNodeText,
  217. "text": "Subpage"
  218. }).inject(this.iconNode);
  219. },
  220. _loadNodeStyles: function(){
  221. this.iconNode = this.node.getElement("div").setStyles(this.css.iconNode);
  222. this.iconNode.getFirst("div").setStyles(this.css.iconNodeIcon);
  223. this.iconNode.getLast("div").setStyles(this.css.iconNodeText);
  224. },
  225. _setEditStyle: function(name, input, oldValue){
  226. if (name==="subpageSelected"){
  227. if (this.json.subpageSelected!==oldValue){
  228. this.redoSelectedSubpage(name, input, oldValue);
  229. }
  230. }
  231. if (name==="subpageType"){
  232. if (this.json.subpageType!==oldValue){
  233. if (this.json.subpageType !== "script"){
  234. this.redoSelectedSubpage(name, $(this.property.data.pid+"selectSubpage").getElement("select"), "");
  235. }
  236. if (this.json.subpageType === "script"){
  237. this.subpageData = null;
  238. this.clearSubpageList(this.json.subpageSelected);
  239. this.node.empty();
  240. this.loadIcon();
  241. }
  242. }
  243. }
  244. },
  245. redoSelectedSubpage: function(name, input, oldValue){
  246. if (this.json.subpageSelected==="none") this.json.subpageSelected="";
  247. if (this.json.subpageSelected && this.json.subpageSelected!=="none"){
  248. if(input)this.subpageSelector = input;
  249. if( !input )input = this.getSubpageSelector();
  250. if( oldValue )this.subpageSelectedValue = oldValue;
  251. if( !oldValue )oldValue = this.getSubpageSelectedValue() || "";
  252. var level1Subpage = this.getLevel1Subpage();
  253. if( !this.checkSubpageNested(this.json.subpageSelected) ){
  254. //var p = this.node.getPosition(document.body);
  255. //this.page.designer.alert("error", {
  256. // "event": {
  257. // "x": p.x + 150,
  258. // "y": p.y + 80
  259. // }
  260. //}, this.page.designer.lp.subpageNestedTitle, this.page.designer.lp.subpageNestedInfor, 400, 120);
  261. this.page.designer.notice( this.page.designer.lp.subpageNestedInfor, "error", level1Subpage.node );
  262. level1Subpage.json.subpageSelected = oldValue;
  263. if (input) {
  264. for (var i = 0; i < input.options.length; i++) {
  265. if (input.options[i].value === oldValue || (input.options[i].value==="none" && !oldValue ) ) {
  266. input.options[i].set("selected", true);
  267. break;
  268. }
  269. }
  270. }
  271. if( !oldValue ){
  272. level1Subpage.node.empty();
  273. level1Subpage.loadIcon();
  274. }else{
  275. level1Subpage.refreshSubpage();
  276. }
  277. }else{
  278. MWF.Actions.get("x_portal_assemble_designer").getPage(this.json.subpageSelected, function(json){
  279. this.reloadSubpage(json.data, input, oldValue);
  280. }.bind(this));
  281. }
  282. }else{
  283. this.subpageData = null;
  284. this.clearSubpageList(oldValue);
  285. this.node.empty();
  286. this.loadIcon();
  287. }
  288. },
  289. clearSubpageList: function(pageName){
  290. if (!this.page.subpageList) this.page.subpageList = {};
  291. if (pageName) if (this.page.subpageList[pageName]) delete this.page.subpageList[pageName];
  292. },
  293. addSubpageList: function(){
  294. if (!this.page.subpageList) this.page.subpageList = {};
  295. this.page.subpageList[this.json.subpageSelected] = Object.clone(this.subpageData.json);
  296. },
  297. getSubpageData: function(data){
  298. var subpageDataStr = null;
  299. if (this.page.options.mode !== "Mobile"){
  300. subpageDataStr = data.data;
  301. }else{
  302. subpageDataStr = data.mobileData;
  303. }
  304. this.subpageData = null;
  305. if (subpageDataStr){
  306. this.subpageData = JSON.decode(MWF.decodeJsonString(subpageDataStr));
  307. this.subpageData.updateTime = data.updateTime;
  308. }
  309. },
  310. reloadSubpage: function(data, input, oldValue){
  311. this.getSubpageData(data);
  312. if (this.subpageData){
  313. var oldSubpageData = (this.page.subpageList && oldValue) ? this.page.subpageList[oldValue] : null;
  314. this.clearSubpageList(oldValue);
  315. if (this.checkSubpage(data, input)){
  316. this.node.empty();
  317. this.loadSubpage();
  318. this.addSubpageList();
  319. }else{
  320. if (oldSubpageData){
  321. if (!this.page.subpageList) this.page.subpageList = {};
  322. this.page.subpageList[oldValue] = oldSubpageData;
  323. }else{
  324. this.clearSubpageList(oldValue);
  325. this.node.empty();
  326. this.loadIcon();
  327. }
  328. this.json.subpageSelected = oldValue;
  329. if (!oldValue){
  330. if (input) input.options[0].set("selected", true);
  331. }else{
  332. if (input){
  333. for (var i=0; i<input.options.length; i++){
  334. if (input.options[i].value===oldValue){
  335. input.options[i].set("selected", true);
  336. break;
  337. }
  338. }
  339. }
  340. }
  341. }
  342. }else{
  343. this.json.subpageSelected = oldValue;
  344. if (input){
  345. if (!oldValue){
  346. input.options[0].set("selected", true);
  347. }else{
  348. for (var i=0; i<input.options.length; i++){
  349. if (input.options[i].value===oldValue){
  350. input.options[i].set("selected", true);
  351. break;
  352. }
  353. }
  354. }
  355. }
  356. }
  357. },
  358. regetSubpageData: function(){
  359. var flag = false;
  360. if (this.json.subpageSelected && this.json.subpageSelected!=="none" && this.json.subpageType!=="script"){
  361. MWF.Actions.get("x_portal_assemble_designer").getPage(this.json.subpageSelected, function(json){
  362. if (!this.subpageData || this.subpageData.updateTime!==json.data.updateTime){
  363. this.getSubpageData(json.data);
  364. flag = true;
  365. }
  366. }.bind(this), null, false);
  367. }
  368. return flag;
  369. },
  370. getConflictFields: function(){
  371. var moduleNames = [];
  372. if (this.subpageData){
  373. Object.each(this.subpageData.json.moduleList, function(o, key){
  374. var check = this.page.checkModuleId(key, o.type, this.subpageData.json.id);
  375. if (check.fieldConflict){
  376. moduleNames.push(key)
  377. }else if (check.elementConflict){
  378. o.changeId = this.json.id+"_"+key;
  379. }
  380. }.bind(this));
  381. }
  382. return moduleNames;
  383. },
  384. checkSubpage: function(data, input){
  385. var moduleNames = this.getConflictFields();
  386. // Object.each(this.subpageData.json.moduleList, function(o, key){
  387. // var check = this.page.checkModuleId(key, o.type, this.subpageData.json.id);
  388. // if (check.fieldConflict){
  389. // moduleNames.push(key)
  390. // }else if (check.elementConflict){
  391. // o.changeId = this.json.id+"_"+key;
  392. // }
  393. // }.bind(this));
  394. if (moduleNames.length){
  395. var txt = this.page.designer.lp.subpageNameConflictInfor;
  396. txt = txt.replace("{name}", moduleNames.join(", "));
  397. //var p = (input) ? input.getPosition() : this.node.getPosition();
  398. // var p = this.node.getPosition(document.body);
  399. // this.page.designer.alert("error", {
  400. // "event": {
  401. // "x": p.x+150,
  402. // "y": p.y+80
  403. // }
  404. // }, this.page.designer.lp.subpageNameConflictTitle, txt, 400, 200);
  405. this.page.designer.notice(txt, "error", this.node);
  406. return false;
  407. }
  408. return true;
  409. },
  410. loadSubpage: function(data) {
  411. this.subpageData.json.style = this.page.json.style;
  412. this.subpageData.json.properties = this.page.json.properties;
  413. this.subpageData.json.jsheader = {"code": "", "html": ""};
  414. this.subpageData.json.events = {};
  415. this.subpageData.json.pageStyleType = this.page.json.pageStyleType;
  416. //this.subpageData.json.id = this.json.id;
  417. this.subpageModule = new MWF.PCSubpage.Page(this.page, this.node,{
  418. parentpageIdList : this.getParentpageIdList(),
  419. level : this.getLevel()
  420. });
  421. this.subpageModule.subpageSelector = this.getSubpageSelector();
  422. this.subpageModule.subpageSelectedValue = this.getSubpageSelectedValue();
  423. this.subpageModule.level1Subpage = this.getLevel1Subpage();
  424. this.subpageModule.load(this.subpageData);
  425. //this.createRefreshNode();
  426. },
  427. destroy: function(){
  428. this.page.moduleList.erase(this);
  429. this.page.moduleNodeList.erase(this.node);
  430. this.page.moduleElementNodeList.erase(this.node);
  431. this.clearSubpageList(this.json.subpageSelected);
  432. this.node.destroy();
  433. this.actionArea.destroy();
  434. delete this.page.json.moduleList[this.json.id];
  435. this.json = null;
  436. delete this.json;
  437. this.treeNode.destroy();
  438. }
  439. });
  440. MWF.xApplication.portal.PageDesigner.Module.Subpage.Page = new Class({
  441. Extends: MWF.PCPage,
  442. initialize: function(page, container, options){
  443. this.setOptions(options);
  444. this.toppage = page.toppage || page;
  445. this.parentpage = page;
  446. this.parentform = page;
  447. this.css = this.parentpage.css;
  448. this.container = container;
  449. this.form = this;
  450. this.page = this;
  451. this.isSubpage = true;
  452. this.isSubform = true;
  453. this.moduleType = "subpage";
  454. this.moduleList = [];
  455. this.moduleNodeList = [];
  456. this.moduleContainerNodeList = [];
  457. this.moduleElementNodeList = [];
  458. this.moduleComponentNodeList = [];
  459. // this.moduleContainerList = [];
  460. this.dataTemplate = {};
  461. this.designer = this.parentpage.designer;
  462. this.selectedModules = [];
  463. },
  464. load : function(data){
  465. this.data = data;
  466. this.json = data.json;
  467. this.html = data.html;
  468. this.json.mode = this.options.mode;
  469. this.container.set("html", this.html);
  470. this.loadDomModules();
  471. //this.setCustomStyles();
  472. //this.node.setProperties(this.json.properties);
  473. //this.setNodeEvents();
  474. if (this.options.mode==="Mobile"){
  475. if (oldStyleValue) this._setEditStyle("pageStyleType", null, oldStyleValue);
  476. }
  477. },
  478. loadDomModules: function(){
  479. this.node = this.container.getFirst();
  480. this.node.set("id", this.json.id);
  481. this.node.setStyles((this.options.mode==="Mobile") ? this.css.pageMobileNode : this.css.pageNode);
  482. this.node.store("module", this);
  483. this.loadDomTree();
  484. },
  485. loadDomTree: function(){
  486. this.createPageTreeNode();
  487. this.parseModules(this, this.node);
  488. },
  489. createPageTreeNode: function(){
  490. this.treeNode = {
  491. "insertChild": function(){return this;},
  492. "appendChild": function(){return this;},
  493. "selectNode": function(){},
  494. "node": null,
  495. "parentNode": {}
  496. };
  497. this.treeNode.module = this;
  498. }
  499. });