Main.js 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264
  1. MWF.APPPS = MWF.xApplication.portal.SourceDesigner;
  2. MWF.APPPS.options = {
  3. "multitask": true,
  4. "executable": false
  5. };
  6. MWF.xDesktop.requireApp("portal.PortalManager", "Actions.RestActions", null, false);
  7. MWF.xDesktop.requireApp("portal.SourceDesigner", "Module.Package", null, false);
  8. MWF.xApplication.portal.SourceDesigner.Main = new Class({
  9. Extends: MWF.xApplication.Common.Main,
  10. Implements: [Options, Events],
  11. options: {
  12. "style": "default",
  13. "template": "template.json",
  14. "templateId": "",
  15. "name": "portal.SourceDesigner",
  16. "icon": "icon.png",
  17. "title": MWF.APPPS.LP.title,
  18. "appTitle": MWF.APPPS.LP.title,
  19. "id": "",
  20. "actions": null,
  21. "category": null,
  22. "processData": null
  23. },
  24. onQueryLoad: function(){
  25. this.shortcut = true;
  26. if (this.status){
  27. this.options.id = this.status.id;
  28. }
  29. if (!this.options.id){
  30. this.options.desktopReload = false;
  31. this.options.title = this.options.title + "-"+MWF.APPPS.LP.newSource;
  32. }
  33. this.actions = new MWF.xApplication.portal.PortalManager.Actions.RestActions();
  34. this.lp = MWF.xApplication.portal.SourceDesigner.LP;
  35. },
  36. loadApplication: function(callback){
  37. this.createNode();
  38. if (!this.options.isRefresh){
  39. this.maxSize(function(){
  40. this.openPage();
  41. }.bind(this));
  42. }else{
  43. this.openPage();
  44. }
  45. this.addKeyboardEvents();
  46. if (callback) callback();
  47. },
  48. addKeyboardEvents: function(){
  49. this.addEvent("copy", function(){
  50. this.copyModule();
  51. }.bind(this));
  52. this.addEvent("paste", function(){
  53. this.pasteModule();
  54. }.bind(this));
  55. this.addEvent("cut", function(){
  56. this.cutModule();
  57. }.bind(this));
  58. this.addEvent("keySave", function(e){
  59. this.keySave(e);
  60. }.bind(this));
  61. this.addEvent("keyDelete", function(e){
  62. this.keyDelete(e);
  63. }.bind(this));
  64. },
  65. keySave: function(e){
  66. if (this.shortcut) {
  67. if (this.page) this.savePage();
  68. e.preventDefault();
  69. }
  70. },
  71. keyDelete: function(e){
  72. if (this.page){
  73. if (this.shortcut){
  74. if (this.page.currentSelectedModule){
  75. var module = this.page.currentSelectedModule;
  76. if (module.moduleType!="page" && module.moduleName.indexOf("$")==-1){
  77. module["delete"](module.node);
  78. }
  79. }
  80. }
  81. }
  82. },
  83. copyModule: function(){
  84. if (this.shortcut) {
  85. if (this.page) {
  86. if (this.page.currentSelectedModule) {
  87. var module = this.page.currentSelectedModule;
  88. if (module.moduleType != "page" && module.moduleName.indexOf("$") == -1) {
  89. var html = module.getHtml();
  90. var json = module.getJson();
  91. MWF.clipboard.data = {
  92. "type": "source",
  93. "data": {
  94. "html": html,
  95. "json": json
  96. }
  97. };
  98. } else {
  99. MWF.clipboard.data = null;
  100. }
  101. }
  102. }
  103. }
  104. },
  105. cutModule: function(){
  106. if (this.shortcut) {
  107. if (this.page) {
  108. if (this.page.currentSelectedModule) {
  109. var module = this.page.currentSelectedModule;
  110. if (module.moduleType != "source" && module.moduleName.indexOf("$") == -1) {
  111. this.copyModule();
  112. module.destroy();
  113. module.page.selected();
  114. }
  115. }
  116. }
  117. }
  118. },
  119. pasteModule: function(){
  120. if (this.shortcut) {
  121. if (this.page) {
  122. if (MWF.clipboard.data) {
  123. if (MWF.clipboard.data.type == "source") {
  124. var html = MWF.clipboard.data.data.html;
  125. var json = Object.clone(MWF.clipboard.data.data.json);
  126. var tmpNode = new Element("div", {
  127. "styles": {"display": "none"},
  128. "html": html
  129. }).inject(this.content);
  130. Object.each(json, function (moduleJson) {
  131. var oid = moduleJson.id;
  132. var id = moduleJson.id;
  133. var idx = 1;
  134. while (this.page.json.moduleList[id]) {
  135. id = oid + "_" + idx;
  136. idx++;
  137. }
  138. if (oid != id) {
  139. moduleJson.id = id;
  140. var moduleNode = tmpNode.getElementById(oid);
  141. if (moduleNode) moduleNode.set("id", id);
  142. }
  143. this.page.json.moduleList[moduleJson.id] = moduleJson;
  144. }.bind(this));
  145. delete json;
  146. var injectNode = this.page.node;
  147. var where = "bottom";
  148. var parent = this.page;
  149. if (this.page.currentSelectedModule) {
  150. var toModule = this.page.currentSelectedModule;
  151. injectNode = toModule.node;
  152. parent = toModule;
  153. if (toModule.moduleType != "container" && toModule.moduleType != "source") {
  154. where = "after";
  155. parent = toModule.parentContainer;
  156. }
  157. }
  158. var copyModuleNode = tmpNode.getFirst();
  159. while (copyModuleNode) {
  160. copyModuleNode.inject(injectNode, where);
  161. var copyModuleJson = this.page.getDomjson(copyModuleNode);
  162. module = this.page.loadModule(copyModuleJson, copyModuleNode, parent);
  163. module._setEditStyle_custom("id");
  164. module.selected();
  165. copyModuleNode = tmpNode.getFirst();
  166. }
  167. tmpNode.destroy();
  168. delete tmpNode;
  169. }
  170. }
  171. }
  172. }
  173. },
  174. createNode: function(){
  175. this.content.setStyle("overflow", "hidden");
  176. this.node = new Element("div", {
  177. "styles": {"width": "100%", "height": "100%", "overflow": "hidden"}
  178. }).inject(this.content);
  179. },
  180. openPage: function(){
  181. this.initOptions();
  182. this.loadNodes();
  183. this.loadToolbar();
  184. this.loadPageNode();
  185. this.loadProperty();
  186. this.loadTools();
  187. this.resizeNode();
  188. this.addEvent("resize", this.resizeNode.bind(this));
  189. this.loadPage();
  190. if (this.toolbarContentNode){
  191. this.setScrollBar(this.toolbarContentNode, null, {
  192. "V": {"x": 0, "y": 0},
  193. "H": {"x": 0, "y": 0}
  194. });
  195. MWF.require("MWF.widget.ScrollBar", function(){
  196. new MWF.widget.ScrollBar(this.propertyDomScrollArea, {
  197. "style":"default", "where": "before", "distance": 30, "friction": 4, "indent": false, "axis": {"x": false, "y": true}
  198. });
  199. }.bind(this));
  200. }
  201. },
  202. initOptions: function(){
  203. this.toolsData = null;
  204. this.toolbarMode = "all";
  205. this.tools = [];
  206. this.toolbarDecrease = 0;
  207. this.designNode = null;
  208. this.page = null;
  209. },
  210. loadNodes: function(){
  211. this.toolbarNode = new Element("div", {
  212. "styles": this.css.toolbarNode,
  213. "events": {"selectstart": function(e){e.preventDefault();}}
  214. }).inject(this.node);
  215. this.propertyNode = new Element("div", {
  216. "styles": this.css.propertyNode
  217. }).inject(this.node);
  218. this.pageNode = new Element("div", {
  219. "styles": this.css.pageNode
  220. }).inject(this.node);
  221. if (this.options.style=="bottom") this.propertyNode.inject(this.pageNode, "after");
  222. },
  223. //loadToolbar----------------------
  224. loadToolbar: function(){
  225. this.toolbarTitleNode = new Element("div", {
  226. "styles": this.css.toolbarTitleNode,
  227. "text": MWF.APPPS.LP.tools
  228. }).inject(this.toolbarNode);
  229. this.toolbarTitleActionNode = new Element("div", {
  230. "styles": this.css.toolbarTitleActionNode,
  231. "events": {
  232. "click": function(e){
  233. this.switchToolbarMode();
  234. }.bind(this)
  235. }
  236. }).inject(this.toolbarNode);
  237. this.toolbarContentNode = new Element("div", {
  238. "styles": this.css.toolbarContentNode,
  239. "events": {
  240. "selectstart": function(e){
  241. e.preventDefault();
  242. e.stopPropagation();
  243. }
  244. }
  245. }).inject(this.toolbarNode);
  246. },
  247. switchToolbarMode: function(){
  248. if (this.toolbarMode=="all"){
  249. var size = this.toolbarNode.getSize();
  250. this.toolbarDecrease = (size.x.toFloat())-60;
  251. this.tools.each(function(node){
  252. node.getLast().setStyle("display", "none");
  253. });
  254. this.toolbarTitleNode.set("text", "");
  255. this.toolbarNode.setStyle("width", "60px");
  256. var pageMargin = this.pageNode.getStyle("margin-left").toFloat();
  257. pageMargin = pageMargin - this.toolbarDecrease;
  258. this.pageNode.setStyle("margin-left", ""+pageMargin+"px");
  259. this.toolbarTitleActionNode.setStyles(this.css.toolbarTitleActionNodeRight);
  260. this.toolbarMode="simple";
  261. }else{
  262. sizeX = 60 + this.toolbarDecrease;
  263. var pageMargin = this.pageNode.getStyle("margin-left").toFloat();
  264. pageMargin = pageMargin + this.toolbarDecrease;
  265. this.toolbarNode.setStyle("width", ""+sizeX+"px");
  266. this.pageNode.setStyle("margin-left", ""+pageMargin+"px");
  267. this.tools.each(function(node){
  268. node.getLast().setStyle("display", "block");
  269. });
  270. this.toolbarTitleNode.set("text", MWF.APPPS.LP.tools);
  271. this.toolbarTitleActionNode.setStyles(this.css.toolbarTitleActionNode);
  272. this.toolbarMode="all";
  273. }
  274. },
  275. //loadPageNode------------------------------
  276. loadPageNode: function(){
  277. this.pageToolbarNode = new Element("div", {
  278. "styles": this.css.pageToolbarNode
  279. }).inject(this.pageNode);
  280. this.loadPageToolbar();
  281. this.pageContentNode = new Element("div", {
  282. "styles": this.css.pageContentNode
  283. }).inject(this.pageNode);
  284. this.loadPageContent(function(){
  285. if (this.designDcoument) this.designDcoument.body.setStyles(this.css.designBody);
  286. if (this.designNode) this.designNode.setStyles(this.css.designNode);
  287. }.bind(this));
  288. },
  289. loadDesignerActionNode: function(){
  290. this.pcDesignerActionNode = this.pageToolbarNode.getElement("#MWFPCDesignerAction");
  291. this.mobileDesignerActionNode = this.pageToolbarNode.getElement("#MWFMobileDesignerAction");
  292. this.currentDesignerMode = "PC";
  293. this.pcDesignerActionNode.setStyles(this.css.designerActionNode_current);
  294. this.mobileDesignerActionNode.setStyles(this.css.designerActionNode);
  295. var iconNode = new Element("div", {"styles": this.css.designerActionPcIconNode}).inject(this.pcDesignerActionNode);
  296. iconNode = new Element("div", {"styles": this.css.designerActionMobileIconNode}).inject(this.mobileDesignerActionNode);
  297. var textNode = new Element("div", {"styles": this.css.designerActiontextNode, "text": "PC"}).inject(this.pcDesignerActionNode);
  298. textNode = new Element("div", {"styles": this.css.designerActiontextNode, "text": "Mobile"}).inject(this.mobileDesignerActionNode);
  299. this.pcDesignerActionNode.addEvent("click", function(){
  300. if (this.currentDesignerMode!="PC"){
  301. this.changeDesignerModeToPC();
  302. }
  303. }.bind(this));
  304. this.mobileDesignerActionNode.addEvent("click", function(){
  305. if (this.currentDesignerMode=="PC"){
  306. this.changeDesignerModeToMobile();
  307. }
  308. }.bind(this));
  309. },
  310. changeDesignerModeToPC: function(){
  311. this.pcDesignerActionNode.setStyles(this.css.designerActionNode_current);
  312. this.mobileDesignerActionNode.setStyles(this.css.designerActionNode);
  313. this.designMobileNode.setStyle("display", "none");
  314. this.designNode.setStyle("display", "block");
  315. if (this.page.currentSelectedModule){
  316. if (this.page.currentSelectedModule==this){
  317. return true;
  318. }else{
  319. this.page.currentSelectedModule.unSelected();
  320. }
  321. }
  322. if (this.page.propertyMultiTd){
  323. this.page.propertyMultiTd.hide();
  324. this.page.propertyMultiTd = null;
  325. }
  326. this.page.unSelectedMulti();
  327. this.page = this.pcPage;
  328. this.currentDesignerMode = "PC";
  329. },
  330. changeDesignerModeToMobile: function(){
  331. this.pcDesignerActionNode.setStyles(this.css.designerActionNode);
  332. this.mobileDesignerActionNode.setStyles(this.css.designerActionNode_current);
  333. this.designMobileNode.setStyle("display", "block");
  334. this.designNode.setStyle("display", "none");
  335. if (this.page.currentSelectedModule){
  336. if (this.page.currentSelectedModule==this){
  337. return true;
  338. }else{
  339. this.page.currentSelectedModule.unSelected();
  340. }
  341. }
  342. if (this.page.propertyMultiTd){
  343. this.page.propertyMultiTd.hide();
  344. this.page.propertyMultiTd = null;
  345. }
  346. this.page.unSelectedMulti();
  347. if (!this.mobilePage){
  348. this.mobilePage = new MWF.PSCPage(this, this.designMobileNode, {"mode": "Mobile"});
  349. this.mobilePage.load(this.pageMobileData);
  350. }
  351. this.page = this.mobilePage;
  352. this.currentDesignerMode = "Mobile";
  353. },
  354. loadPageToolbar: function(callback){
  355. this.getToolbarHTML(function(toolbarNode){
  356. var spans = toolbarNode.getElements("span");
  357. spans.each(function(item, idx){
  358. var img = item.get("MWFButtonImage");
  359. if (img){
  360. item.set("MWFButtonImage", this.path+""+this.options.style+"/pageToolbar/"+img);
  361. }
  362. }.bind(this));
  363. $(toolbarNode).inject(this.pageToolbarNode);
  364. MWF.require("MWF.widget.Toolbar", function(){
  365. this.pageToolbar = new MWF.widget.Toolbar(toolbarNode, {"style": "ProcessCategory"}, this);
  366. this.pageToolbar.load();
  367. this.loadDesignerActionNode();
  368. if (callback) callback();
  369. }.bind(this));
  370. }.bind(this));
  371. },
  372. getToolbarHTML: function(callback){
  373. var toolbarUrl = this.path+this.options.style+"/pageToolbars.html";
  374. var r = new Request.HTML({
  375. url: toolbarUrl,
  376. method: "get",
  377. onSuccess: function(responseTree, responseElements, responseHTML, responseJavaScript){
  378. var toolbarNode = responseTree[0];
  379. if (callback) callback(toolbarNode);
  380. }.bind(this),
  381. onFailure: function(xhr){
  382. this.notice("request processToolbars error: "+xhr.responseText, "error");
  383. }.bind(this)
  384. });
  385. r.send();
  386. },
  387. loadPageContent: function(callback){
  388. this.designNode = new Element("div", {
  389. "styles": this.css.designNode
  390. }).inject(this.pageContentNode);
  391. this.designMobileNode = new Element("div", {
  392. "styles": this.css.designMobileNode
  393. }).inject(this.pageContentNode);
  394. },
  395. reloadPropertyStyles: function(){
  396. //MWF.release(this.css);
  397. this.css = null;
  398. this.cssPath = "/x_component_"+this.options.name.replace(/\./g, "_")+"/$Main/"+this.options.style+"/css.wcss";
  399. this._loadCss();
  400. if (this.options.style=="bottom"){
  401. this.propertyNode.inject(this.pageNode, "after");
  402. this.propertyTitleNode.setStyle("cursor", "row-resize");
  403. this.loadPropertyResizeBottom();
  404. }else{
  405. this.propertyNode.inject(this.pageNode, "before");
  406. this.propertyTitleNode.setStyle("cursor", "default");
  407. if (this.propertyResizeBottom) this.propertyResizeBottom.detach();
  408. }
  409. this.pageNode.clearStyles(false);
  410. this.pageNode.setStyles(this.css.pageNode);
  411. this.propertyNode.clearStyles(false);
  412. this.propertyNode.setStyles(this.css.propertyNode);
  413. this.propertyTitleNode.clearStyles(false);
  414. this.propertyTitleNode.setStyles(this.css.propertyTitleNode);
  415. this.propertyResizeBar.clearStyles(false);
  416. this.propertyResizeBar.setStyles(this.css.propertyResizeBar);
  417. this.propertyContentNode.clearStyles(false);
  418. this.propertyContentNode.setStyles(this.css.propertyContentNode);
  419. this.propertyDomContentArea.clearStyles(false);
  420. this.propertyDomContentArea.setStyles(this.css.propertyDomContentArea);
  421. this.propertyDomScrollArea.clearStyles(false);
  422. this.propertyDomScrollArea.setStyles(this.css.propertyDomScrollArea);
  423. this.propertyDomArea.clearStyles(false);
  424. this.propertyDomArea.setStyles(this.css.propertyDomArea);
  425. this.propertyContentArea.clearStyles(false);
  426. this.propertyContentArea.setStyles(this.css.propertyContentArea);
  427. this.propertyContentResizeNode.clearStyles(false);
  428. this.propertyContentResizeNode.setStyles(this.css.propertyContentResizeNode);
  429. this.propertyTitleActionNode.clearStyles(false);
  430. this.propertyTitleActionNode.setStyles(this.css.propertyTitleActionNode);
  431. this.resizeNode();
  432. },
  433. //loadProperty------------------------
  434. loadProperty: function(){
  435. this.propertyTitleActionNode = new Element("div", {
  436. "styles": this.css.propertyTitleActionNode
  437. }).inject(this.propertyNode);
  438. this.propertyTitleActionNode.addEvent("click", function(){
  439. this.options.style = (this.options.style=="default") ? "bottom" : "default";
  440. MWF.UD.putData("pageDesignerStyle", {"style": this.options.style});
  441. this.reloadPropertyStyles();
  442. }.bind(this));
  443. this.propertyTitleNode = new Element("div", {
  444. "styles": this.css.propertyTitleNode,
  445. "text": MWF.APPPS.LP.property
  446. }).inject(this.propertyNode);
  447. if (this.options.style=="bottom"){
  448. this.propertyTitleNode.setStyle("cursor", "row-resize");
  449. this.loadPropertyResizeBottom();
  450. }
  451. this.propertyResizeBar = new Element("div", {
  452. "styles": this.css.propertyResizeBar
  453. }).inject(this.propertyNode);
  454. this.loadPropertyResize();
  455. this.propertyContentNode = new Element("div", {
  456. "styles": this.css.propertyContentNode
  457. }).inject(this.propertyNode);
  458. this.propertyDomContentArea = new Element("div", {
  459. "styles": this.css.propertyDomContentArea
  460. }).inject(this.propertyContentNode);
  461. this.propertyDomScrollArea = new Element("div", {
  462. "styles": this.css.propertyDomScrollArea
  463. }).inject(this.propertyDomContentArea);
  464. this.propertyDomArea = new Element("div", {
  465. "styles": this.css.propertyDomArea
  466. }).inject(this.propertyDomScrollArea);
  467. this.propertyDomPercent = 0.3;
  468. this.propertyContentResizeNode = new Element("div", {
  469. "styles": this.css.propertyContentResizeNode
  470. }).inject(this.propertyContentNode);
  471. this.propertyContentArea = new Element("div", {
  472. "styles": this.css.propertyContentArea
  473. }).inject(this.propertyContentNode);
  474. this.loadPropertyContentResize();
  475. },
  476. loadPropertyResizeBottom: function(){
  477. if (!this.propertyResizeBottom){
  478. this.propertyResizeBottom = new Drag(this.propertyTitleNode,{
  479. "snap": 1,
  480. "onStart": function(el, e){
  481. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  482. var y = (Browser.name=="firefox") ? e.event.clientY : e.event.y;
  483. el.store("position", {"x": x, "y": y});
  484. var size = this.propertyNode.getSize();
  485. el.store("initialWidth", size.x);
  486. el.store("initialHeight", size.y);
  487. }.bind(this),
  488. "onDrag": function(el, e){
  489. // var x = e.event.x;
  490. var y = (Browser.name=="firefox") ? e.event.clientY : e.event.y;
  491. var bodySize = this.content.getSize();
  492. var position = el.retrieve("position");
  493. var initialHeight = el.retrieve("initialHeight").toFloat();
  494. var dy = position.y.toFloat()-y.toFloat();
  495. var height = initialHeight+dy;
  496. if (height> bodySize.y/1.5) height = bodySize.y/1.5;
  497. if (height<40) height = 40;
  498. var percent = 1-(height/bodySize.y);
  499. this.resizeNode(percent);
  500. //var pageNodeHeight = bodySize.y-height;
  501. //this.pageNode.setStyle("height", ""+pageNodeHeight+"px");
  502. //this.propertyNode.setStyle("height", ""+height+"px");
  503. }.bind(this)
  504. });
  505. }else{
  506. this.propertyResizeBottom.attach();
  507. }
  508. },
  509. loadPropertyResize: function(){
  510. // var size = this.propertyNode.getSize();
  511. // var position = this.propertyResizeBar.getPosition();
  512. this.propertyResize = new Drag(this.propertyResizeBar,{
  513. "snap": 1,
  514. "onStart": function(el, e){
  515. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  516. var y = (Browser.name=="firefox") ? e.event.clientY : e.event.y;
  517. el.store("position", {"x": x, "y": y});
  518. var size = this.propertyNode.getSize();
  519. el.store("initialWidth", size.x);
  520. }.bind(this),
  521. "onDrag": function(el, e){
  522. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  523. // var y = e.event.y;
  524. var bodySize = this.content.getSize();
  525. var position = el.retrieve("position");
  526. var initialWidth = el.retrieve("initialWidth").toFloat();
  527. var dx = position.x.toFloat()-x.toFloat();
  528. var width = initialWidth+dx;
  529. if (width> bodySize.x/2) width = bodySize.x/2;
  530. if (width<40) width = 40;
  531. this.pageNode.setStyle("margin-right", width+1);
  532. this.propertyNode.setStyle("width", width);
  533. }.bind(this)
  534. });
  535. },
  536. propertyResizeDragTopBottom: function(el, e){
  537. var size = this.propertyContentNode.getSize();
  538. // var x = e.event.x;
  539. var y = e.event.y;
  540. var position = el.retrieve("position");
  541. var dy = y.toFloat()-position.y.toFloat();
  542. var initialHeight = el.retrieve("initialHeight").toFloat();
  543. var height = initialHeight+dy;
  544. if (height<40) height = 40;
  545. if (height> size.y-40) height = size.y-40;
  546. this.propertyDomPercent = height/size.y;
  547. this.setPropertyContentResize();
  548. },
  549. propertyResizeDragLeftRight: function(el, e){
  550. var size = this.propertyContentNode.getSize();
  551. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  552. //var y = e.event.y;
  553. var position = el.retrieve("position");
  554. var dx = x.toFloat()-position.x.toFloat();
  555. var initialWidth = el.retrieve("initialWidth").toFloat();
  556. var width = initialWidth+dx;
  557. if (width<40) width = 40;
  558. if (width> size.x-40) width = size.x-40;
  559. this.propertyDomPercent = width/size.x;
  560. this.setPropertyContentResizeBottom();
  561. },
  562. loadPropertyContentResize: function(){
  563. this.propertyContentResize = new Drag(this.propertyContentResizeNode, {
  564. "snap": 1,
  565. "onStart": function(el, e){
  566. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  567. var y = (Browser.name=="firefox") ? e.event.clientY : e.event.y;
  568. el.store("position", {"x": x, "y": y});
  569. var size = this.propertyDomContentArea.getSize();
  570. el.store("initialHeight", size.y);
  571. el.store("initialWidth", size.x);
  572. }.bind(this),
  573. "onDrag": function(el, e){
  574. if (this.options.style=="bottom"){
  575. this.propertyResizeDragLeftRight(el, e);
  576. }else{
  577. this.propertyResizeDragTopBottom(el, e);
  578. }
  579. }.bind(this)
  580. });
  581. },
  582. setPropertyContentResizeBottom: function(){
  583. var size = this.propertyContentNode.getSize();
  584. var resizeNodeSize = this.propertyContentResizeNode.getSize();
  585. var width = size.x-resizeNodeSize.x-6;
  586. var domWidth = this.propertyDomPercent*width;
  587. var contentMargin = domWidth+resizeNodeSize.x+6;
  588. this.propertyDomContentArea.setStyle("width", ""+domWidth+"px");
  589. this.propertyContentArea.setStyle("margin-left", ""+contentMargin+"px");
  590. },
  591. setPropertyContentResize: function(){
  592. var size = this.propertyContentNode.getSize();
  593. var resizeNodeSize = this.propertyContentResizeNode.getSize();
  594. var height = size.y-resizeNodeSize.y;
  595. var domHeight = this.propertyDomPercent*height;
  596. var contentHeight = height-domHeight;
  597. this.propertyDomContentArea.setStyle("height", ""+domHeight+"px");
  598. this.propertyDomScrollArea.setStyle("height", ""+domHeight+"px");
  599. this.propertyContentArea.setStyle("height", ""+contentHeight+"px");
  600. if (this.page){
  601. if (this.page.currentSelectedModule){
  602. if (this.page.currentSelectedModule.property){
  603. var tab = this.page.currentSelectedModule.property.propertyTab;
  604. if (tab){
  605. var tabTitleSize = tab.tabNodeContainer.getSize();
  606. tab.pages.each(function(page){
  607. var topMargin = page.contentNodeArea.getStyle("margin-top").toFloat();
  608. var bottomMargin = page.contentNodeArea.getStyle("margin-bottom").toFloat();
  609. var tabContentNodeAreaHeight = contentHeight - topMargin - bottomMargin - tabTitleSize.y.toFloat()-15;
  610. page.contentNodeArea.setStyle("height", tabContentNodeAreaHeight);
  611. }.bind(this));
  612. }
  613. }
  614. }
  615. }
  616. },
  617. //loadTools------------------------------
  618. loadTools: function(){
  619. var designer = this;
  620. this.getTools(function(){
  621. Object.each(this.toolsData, function(value, key){
  622. var toolNode = new Element("div", {
  623. "styles": this.css.toolbarToolNode,
  624. "title": value.text,
  625. "events": {
  626. "mouseover": function(e){
  627. try {
  628. this.setStyles(designer.css.toolbarToolNodeOver);
  629. }catch(e){
  630. this.setStyles(designer.css.toolbarToolNodeOverCSS2);
  631. };
  632. },
  633. "mouseout": function(e){
  634. try {
  635. this.setStyles(designer.css.toolbarToolNode);
  636. }catch(e){};
  637. },
  638. "mousedown": function(e){
  639. try {
  640. this.setStyles(designer.css.toolbarToolNodeDown);
  641. }catch(e){
  642. this.setStyles(designer.css.toolbarToolNodeDownCSS2);
  643. };
  644. },
  645. "mouseup": function(e){
  646. try {
  647. this.setStyles(designer.css.toolbarToolNodeUp);
  648. }catch(e){
  649. this.setStyles(designer.css.toolbarToolNodeUpCSS2);
  650. };
  651. }
  652. }
  653. }).inject(this.toolbarContentNode);
  654. toolNode.store("toolClass", value.className);
  655. var iconNode = new Element("div", {
  656. "styles": this.css.toolbarToolIconNode
  657. }).inject(toolNode);
  658. iconNode.setStyle("background-image", "url("+this.path+this.options.style+"/icon/"+value.icon+")");
  659. var textNode = new Element("div", {
  660. "styles": this.css.toolbarToolTextNode,
  661. "text": value.text
  662. });
  663. textNode.inject(toolNode);
  664. // var designer = this;
  665. toolNode.addEvent("mousedown", function(e){
  666. var className = this.retrieve("toolClass");
  667. designer.page.createModule(className, e);
  668. });
  669. this.tools.push(toolNode);
  670. }.bind(this));
  671. }.bind(this));
  672. },
  673. getTools: function(callback){
  674. if (this.toolsData){
  675. if (callback) callback();
  676. }else{
  677. var toolsDataUrl = this.path+this.options.style+"/tools.json";
  678. var r = new Request.JSON({
  679. url: toolsDataUrl,
  680. secure: false,
  681. async: false,
  682. method: "get",
  683. noCache: true,
  684. onSuccess: function(responseJSON, responseText){
  685. this.toolsData = responseJSON;
  686. if (callback) callback();
  687. }.bind(this),
  688. onError: function(text, error){
  689. this.notice("request tools data error: "+error, "error");
  690. }.bind(this)
  691. });
  692. r.send();
  693. }
  694. },
  695. //resizeNode------------------------------------------------
  696. resizeNodeLeftRight: function(){
  697. var nodeSize = this.node.getSize();
  698. this.toolbarNode.setStyle("height", ""+nodeSize.y+"px");
  699. this.pageNode.setStyle("height", ""+nodeSize.y+"px");
  700. this.propertyNode.setStyle("height", ""+nodeSize.y+"px");
  701. //nodeSize = {"x": nodeSize.x, "y": nodeSize.y*0.6};
  702. var pageToolbarMarginTop = this.pageToolbarNode.getStyle("margin-top").toFloat();
  703. var pageToolbarMarginBottom = this.pageToolbarNode.getStyle("margin-bottom").toFloat();
  704. var allPageToolberSize = this.pageToolbarNode.getComputedSize();
  705. var y = nodeSize.y - allPageToolberSize.totalHeight - pageToolbarMarginTop - pageToolbarMarginBottom;
  706. this.pageContentNode.setStyle("height", ""+y+"px");
  707. if (this.designNode){
  708. var designMarginTop = this.designNode.getStyle("margin-top").toFloat();
  709. var designMarginBottom = this.designNode.getStyle("margin-bottom").toFloat();
  710. y = nodeSize.y - allPageToolberSize.totalHeight - pageToolbarMarginTop - pageToolbarMarginBottom - designMarginTop - designMarginBottom;
  711. this.designNode.setStyle("height", ""+y+"px");
  712. }
  713. var titleSize = this.toolbarTitleNode.getSize();
  714. var titleMarginTop = this.toolbarTitleNode.getStyle("margin-top").toFloat();
  715. var titleMarginBottom = this.toolbarTitleNode.getStyle("margin-bottom").toFloat();
  716. var titlePaddingTop = this.toolbarTitleNode.getStyle("padding-top").toFloat();
  717. var titlePaddingBottom = this.toolbarTitleNode.getStyle("padding-bottom").toFloat();
  718. y = titleSize.y+titleMarginTop+titleMarginBottom+titlePaddingTop+titlePaddingBottom;
  719. y = nodeSize.y-y;
  720. this.toolbarContentNode.setStyle("height", ""+y+"px");
  721. titleSize = this.propertyTitleNode.getSize();
  722. titleMarginTop = this.propertyTitleNode.getStyle("margin-top").toFloat();
  723. titleMarginBottom = this.propertyTitleNode.getStyle("margin-bottom").toFloat();
  724. titlePaddingTop = this.propertyTitleNode.getStyle("padding-top").toFloat();
  725. titlePaddingBottom = this.propertyTitleNode.getStyle("padding-bottom").toFloat();
  726. y = titleSize.y+titleMarginTop+titleMarginBottom+titlePaddingTop+titlePaddingBottom;
  727. y = nodeSize.y-y;
  728. this.propertyContentNode.setStyle("height", ""+y+"px");
  729. this.propertyResizeBar.setStyle("height", ""+y+"px");
  730. },
  731. resizeNodeTopBottom: function(percent){
  732. var nodeSize = this.node.getSize();
  733. this.toolbarNode.setStyle("height", ""+nodeSize.y+"px");
  734. var percentNumber = percent || 0.6
  735. var designerHeight = nodeSize.y*percentNumber;
  736. var propertyHeight = nodeSize.y - designerHeight;
  737. this.pageNode.setStyle("height", ""+designerHeight+"px");
  738. this.propertyNode.setStyle("height", ""+propertyHeight+"px");
  739. var pageToolbarMarginTop = this.pageToolbarNode.getStyle("margin-top").toFloat();
  740. var pageToolbarMarginBottom = this.pageToolbarNode.getStyle("margin-bottom").toFloat();
  741. var allPageToolberSize = this.pageToolbarNode.getComputedSize();
  742. var y = designerHeight - allPageToolberSize.totalHeight - pageToolbarMarginTop - pageToolbarMarginBottom;
  743. // this.pageContentNode.setStyle("height", ""+designerHeight+"px");
  744. if (this.designNode){
  745. var designMarginTop = this.designNode.getStyle("margin-top").toFloat();
  746. var designMarginBottom = this.designNode.getStyle("margin-bottom").toFloat();
  747. y = designerHeight - allPageToolberSize.totalHeight - pageToolbarMarginTop - pageToolbarMarginBottom - designMarginTop - designMarginBottom;
  748. this.designNode.setStyle("height", ""+y+"px");
  749. }
  750. var titleSize = this.toolbarTitleNode.getSize();
  751. var titleMarginTop = this.toolbarTitleNode.getStyle("margin-top").toFloat();
  752. var titleMarginBottom = this.toolbarTitleNode.getStyle("margin-bottom").toFloat();
  753. var titlePaddingTop = this.toolbarTitleNode.getStyle("padding-top").toFloat();
  754. var titlePaddingBottom = this.toolbarTitleNode.getStyle("padding-bottom").toFloat();
  755. y = titleSize.y+titleMarginTop+titleMarginBottom+titlePaddingTop+titlePaddingBottom;
  756. y = nodeSize.y-y;
  757. this.toolbarContentNode.setStyle("height", ""+y+"px");
  758. titleSize = this.propertyTitleNode.getSize();
  759. titleMarginTop = this.propertyTitleNode.getStyle("margin-top").toFloat();
  760. titleMarginBottom = this.propertyTitleNode.getStyle("margin-bottom").toFloat();
  761. titlePaddingTop = this.propertyTitleNode.getStyle("padding-top").toFloat();
  762. titlePaddingBottom = this.propertyTitleNode.getStyle("padding-bottom").toFloat();
  763. y = titleSize.y+titleMarginTop+titleMarginBottom+titlePaddingTop+titlePaddingBottom;
  764. y = propertyHeight-y;
  765. this.propertyContentNode.setStyle("height", ""+y+"px");
  766. this.propertyResizeBar.setStyle("height", ""+y+"px");
  767. this.propertyDomContentArea.setStyle("height", ""+y+"px");
  768. this.propertyDomScrollArea.setStyle("height", ""+y+"px");
  769. this.propertyContentResizeNode.setStyle("height", ""+y+"px");
  770. this.propertyContentArea.setStyle("height", ""+y+"px");
  771. if (this.page){
  772. if (this.page.currentSelectedModule){
  773. if (this.page.currentSelectedModule.property){
  774. var tab = this.page.currentSelectedModule.property.propertyTab;
  775. if (tab){
  776. var tabTitleSize = tab.tabNodeContainer.getSize();
  777. tab.pages.each(function(page){
  778. var topMargin = page.contentNodeArea.getStyle("margin-top").toFloat();
  779. var bottomMargin = page.contentNodeArea.getStyle("margin-bottom").toFloat();
  780. var tabContentNodeAreaHeight = y - topMargin - bottomMargin - tabTitleSize.y.toFloat()-15;
  781. page.contentNodeArea.setStyle("height", tabContentNodeAreaHeight);
  782. }.bind(this));
  783. }
  784. }
  785. }
  786. }
  787. },
  788. resizeNode: function(percent){
  789. if (this.options.style=="bottom"){
  790. this.resizeNodeTopBottom(percent);
  791. this.setPropertyContentResizeBottom();
  792. }else{
  793. this.resizeNodeLeftRight(percent);
  794. this.setPropertyContentResize();
  795. }
  796. },
  797. //loadPage------------------------------------------
  798. loadPage: function(){
  799. this.getPageData(function(){
  800. this.pcPage = new MWF.PSCPage(this, this.designNode);
  801. this.pcPage.load(this.pageData);
  802. this.page = this.pcPage;
  803. }.bind(this));
  804. },
  805. getPageData: function(callback){
  806. if (!this.options.id){
  807. if (this.options.templateId){
  808. this.loadNewPageDataFromTemplate(callback);
  809. }else{
  810. this.loadNewPageData(callback);
  811. }
  812. }else{
  813. this.loadPageData(callback);
  814. }
  815. },
  816. loadNewPageData: function(callback){
  817. var url = "/x_component_portal_PageDesigner/Module/Page/template/"+this.options.template;
  818. MWF.getJSON(url, {
  819. "onSuccess": function(obj){
  820. this.pageData = obj.pcData;
  821. this.pageData.id="";
  822. this.pageData.isNewPage = true;
  823. this.pageMobileData = obj.mobileData;
  824. this.pageMobileData.id="";
  825. this.pageMobileData.isNewPage = true;
  826. if (callback) callback();
  827. }.bind(this),
  828. "onerror": function(text){
  829. this.notice(text, "error");
  830. }.bind(this),
  831. "onRequestFailure": function(xhr){
  832. this.notice(xhr.responseText, "error");
  833. }.bind(this)
  834. });
  835. },
  836. loadNewPageDataFromTemplate: function(callback){
  837. this.actions.getSourceTemplate(this.options.templateId, function(page){
  838. if (page){
  839. this.pageData = JSON.decode(MWF.decodeJsonString(page.data.data));
  840. this.pageData.isNewPage = true;
  841. this.pageData.json.id = "";
  842. if (page.data.mobileData){
  843. this.pageMobileData = JSON.decode(MWF.decodeJsonString(page.data.mobileData));
  844. this.pageMobileData.isNewPage = true;
  845. this.pageMobileData.json.id = "";
  846. }else{
  847. this.pageMobileData = Object.clone(this.pageData);
  848. }
  849. if (callback) callback();
  850. }
  851. }.bind(this));
  852. },
  853. loadPageData: function(callback){
  854. this.actions.getSource(this.options.id, function(page){
  855. if (page){
  856. this.pageData = JSON.decode(MWF.decodeJsonString(page.data.data));
  857. this.pageData.isNewPage = false;
  858. this.pageData.json.id = page.data.id;
  859. if (page.data.mobileData){
  860. this.pageMobileData = JSON.decode(MWF.decodeJsonString(page.data.mobileData));
  861. this.pageMobileData.isNewPage = false;
  862. this.pageMobileData.json.id = page.data.id;
  863. }else{
  864. this.pageMobileData = Object.clone(this.pageData);
  865. }
  866. this.setTitle(this.options.appTitle + "-"+this.pageData.json.name);
  867. this.taskitem.setText(this.options.appTitle + "-"+this.pageData.json.name);
  868. this.options.appTitle = this.options.appTitle + "-"+this.pageData.json.name;
  869. if (!this.application){
  870. this.actions.getApplication(page.data.portal, function(json){
  871. this.application = {"name": json.data.name, "id": json.data.id};
  872. if (callback) callback();
  873. }.bind(this));
  874. }else{
  875. if (callback) callback();
  876. }
  877. }
  878. }.bind(this));
  879. },
  880. getFieldList: function(){
  881. dataTypes = {
  882. "string": ["htmledit", "radio", "select", "textarea", "textfield"],
  883. "person": ["personfield"],
  884. "date": ["calender"],
  885. "number": ["number"],
  886. "array": ["checkbox"]
  887. };
  888. fieldList = [];
  889. this.pcPage.moduleList.each(function(moudle){
  890. var key = "";
  891. for (k in dataTypes){
  892. if (dataTypes[k].indexOf(moudle.moduleName.toLowerCase())!=-1){
  893. key = k;
  894. break;
  895. }
  896. }
  897. if (key){
  898. fieldList.push({
  899. "name": moudle.json.id,
  900. "dataType": key
  901. });
  902. }
  903. }.bind(this));
  904. return fieldList;
  905. },
  906. savePage: function(){
  907. if (!this.isSave){
  908. var pcData, mobileData;
  909. if (this.pcPage){
  910. this.pcPage._getPageData();
  911. pcData = this.pcPage.data;
  912. }
  913. if (this.mobilePage){
  914. this.mobilePage._getPageData();
  915. mobileData = this.mobilePage.data;
  916. }else{
  917. if (this.pageMobileData) mobileData = this.pageMobileData;
  918. }
  919. this.isSave = true;
  920. var fieldList = this.getFieldList();
  921. this.actions.saveSource(pcData, mobileData, fieldList, function(responseJSON){
  922. this.notice(MWF.APPPS.LP.notice["save_success"], "ok", null, {x: "left", y:"bottom"});
  923. if (!this.pcPage.json.name) this.pcPage.treeNode.setText("<"+this.json.type+"> "+this.json.id);
  924. this.pcPage.treeNode.setTitle(this.pcPage.json.id);
  925. this.pcPage.node.set("id", this.pcPage.json.id);
  926. if (this.mobilePage){
  927. if (!this.mobilePage.json.name) this.mobilePage.treeNode.setText("<"+this.mobilePage.json.type+"> "+this.mobilePage.json.id);
  928. this.mobilePage.treeNode.setTitle(this.mobilePage.json.id);
  929. this.mobilePage.node.set("id", this.mobilePage.json.id+"_"+this.options.mode);
  930. }
  931. var name = this.pcPage.json.name;
  932. if (this.pcPage.data.isNewPage) this.setTitle(this.options.appTitle + "-"+name);
  933. this.pcPage.data.isNewPage = false;
  934. if (this.mobilePage) this.mobilePage.data.isNewPage = false;
  935. this.options.desktopReload = true;
  936. this.options.id = this.pcPage.json.id;
  937. this.isSave = false;
  938. }.bind(this), function(xhr, text, error){
  939. this.isSave = false;
  940. var errorText = error+":"+text;
  941. if (xhr) errorText = xhr.responseText;
  942. MWF.xDesktop.notice("error", {x: "right", y:"top"}, "request json error: "+errorText);
  943. }.bind(this));
  944. }else{
  945. MWF.xDesktop.notice("info", {x: "right", y:"top"}, this.lp.isSave);
  946. }
  947. },
  948. previewPage: function(){
  949. this.page.preview();
  950. },
  951. pageExplode: function(){
  952. this.page.explode();
  953. },
  954. recordStatus: function(){
  955. return {"id": this.options.id};
  956. },
  957. onPostClose: function(){
  958. if (this.pcPage){
  959. MWF.release(this.pcPage.moduleList);
  960. MWF.release(this.pcPage.moduleNodeList);
  961. MWF.release(this.pcPage.moduleContainerNodeList);
  962. MWF.release(this.pcPage.moduleElementNodeList);
  963. MWF.release(this.pcPage.moduleComponentNodeList);
  964. MWF.release(this.pcPage);
  965. }
  966. if (this.mobilePage){
  967. MWF.release(this.mobilePage.moduleList);
  968. MWF.release(this.mobilePage.moduleNodeList);
  969. MWF.release(this.mobilePage.moduleContainerNodeList);
  970. MWF.release(this.mobilePage.moduleElementNodeList);
  971. MWF.release(this.mobilePage.moduleComponentNodeList);
  972. MWF.release(this.mobilePage);
  973. }
  974. },
  975. setTemplatePageNode: function(pageNode){
  976. var html = "<table align=\"center\" width=\"100%\" height=\"90%\" border=\"0\" cellPadding=\"0\" cellSpacing=\"0\">" +
  977. "<tr><td colSpan=\"2\" style=\"height: 50px; line-height: 60px; text-align: center; font-size: 24px; font-weight: bold\">" +
  978. this.lp.saveTemplate+"</td></tr>" +
  979. "<tr><td style=\"height: 40px;\" width=\"80px\">" +this.lp.templateName+"</td><td>"+
  980. "<input value=\""+this.pcPage.json.name+"\" type=\"text\" style=\"width: 98%; height: 22px; border: 1px solid #cccccc\"/>"+"</td></tr>" +
  981. "<tr><td style=\"height: 40px;\">" +this.lp.templateCategory+"</td><td>"+
  982. "<select style=\"width: 30%; height: 24px; border: 1px solid #cccccc\"></select>"+
  983. "<input type=\"text\" style=\"width: 68%; height: 22px; border: 1px solid #cccccc\"/>"+"</td></tr>" +
  984. "<tr><td style=\"height: 40px;\">" +this.lp.templateDescription+"</td><td>"+
  985. "<textarea type=\"text\" style=\"width: 98%; height: 44px; border: 1px solid #cccccc\">"+this.pcPage.json.description+"</textarea>"+"</td></tr>" +
  986. "<tr><td colSpan=\"2\" id=\"page_templatePreview\">" +
  987. "<div style=\"position: relative; width: 180px; height: 180px; margin: 20px auto 0px auto; overflow: hidden\"></div>" +
  988. "</td></tr>" +
  989. "</table>";
  990. pageNode.set("html", html);
  991. var tds = pageNode.getElements("td");
  992. var iconNode = tds[tds.length-1].getFirst();
  993. var previewNode = this.pcPage.node.clone();
  994. previewNode.setStyles({
  995. "transform-origin": "0px 0px",
  996. "transform": "scale(0.15,0.15)",
  997. "position": "absolute",
  998. "top": "0px",
  999. "left": "0px"
  1000. }).inject(iconNode);
  1001. return iconNode;
  1002. },
  1003. setCategorySelect: function(categorySelect){
  1004. if (categorySelect){
  1005. new Element("option", {"value": "$newCategory","text": this.lp.newCategory}).inject(categorySelect);
  1006. this.actions.listPageTemplateCategory(function(json){
  1007. json.data.each(function(category){
  1008. new Element("option", {"value": category.name,"text": category.name}).inject(categorySelect);
  1009. }.bind(this));
  1010. }.bind(this));
  1011. }
  1012. },
  1013. setTemplateActions: function(markNode, areaNode, pageNode, iconNode, nameNode, categorySelect, newCategoryNode, descriptionNode){
  1014. var actionAreaNode= new Element("div", {
  1015. "styles": this.css.templateActionNode
  1016. }).inject(pageNode);
  1017. var cancelActionNode = new Element("div", {
  1018. "styles": this.css.templateCancelActionNode,
  1019. "text": this.lp.cancel,
  1020. "events":{
  1021. "click": function(){
  1022. markNode.destroy();
  1023. areaNode.destroy();
  1024. }
  1025. }
  1026. }).inject(actionAreaNode);
  1027. var saveActionNode = new Element("div", {
  1028. "styles": this.css.templateSaveActionNode,
  1029. "text": this.lp.save,
  1030. "events":{
  1031. "click": function(){
  1032. this.saveTemplate(markNode, areaNode, iconNode, nameNode, categorySelect, newCategoryNode, descriptionNode);
  1033. }.bind(this)
  1034. }
  1035. }).inject(actionAreaNode);
  1036. },
  1037. saveTemplate: function(markNode, areaNode, iconNode, nameNode, categorySelect, newCategoryNode, descriptionNode){
  1038. var pcData, mobileData;
  1039. if (this.pcPage){
  1040. this.pcPage._getPageData();
  1041. pcData = this.pcPage.data;
  1042. }
  1043. if (this.mobilePage){
  1044. this.mobilePage._getPageData();
  1045. mobileData = this.mobilePage.data;
  1046. }
  1047. var name = nameNode.get("value");
  1048. var category = (categorySelect.options[categorySelect.selectedIndex].value=="$newCategory") ? newCategoryNode.get("value") : categorySelect.options[categorySelect.selectedIndex].value;
  1049. var description = descriptionNode.get("value");
  1050. if (!name){
  1051. this.notice(MWF.APPPS.LP.notice["saveTemplate_inputName"], "error", nameNode, {x: "left", y:"top"});
  1052. return false;
  1053. }
  1054. if (categorySelect.options[categorySelect.selectedIndex].value=="$newCategory" && !newCategoryNode.get("value")){
  1055. this.notice(MWF.APPPS.LP.notice["saveTemplate_inputCategory"], "error", categorySelect, {x: "left", y:"top"});
  1056. return false;
  1057. }
  1058. var data = {
  1059. "name": name,
  1060. "category": category,
  1061. "description": description,
  1062. "outline": iconNode.get("html")
  1063. };
  1064. this.actions.addPageTemplate(pcData, mobileData, data, function(){
  1065. this.notice(MWF.APPPS.LP.notice["saveTemplate_success"], "ok", null, {x: "left", y:"bottom"});
  1066. markNode.destroy();
  1067. areaNode.destroy();
  1068. }.bind(this), function(xhr, text, error){
  1069. var errorText = error+":"+text;
  1070. if (xhr) errorText = xhr.responseText;
  1071. MWF.xDesktop.notice("error", {x: "right", y:"top"}, "request json error: "+errorText);
  1072. });
  1073. },
  1074. createTemplateSaveNode: function(){
  1075. var markNode = new Element("div", {
  1076. "styles": this.css.templateMarkNode,
  1077. "events": {
  1078. "mouseover": function(e){e.stopPropagation();},
  1079. "mouseout": function(e){e.stopPropagation();}
  1080. }
  1081. }).inject(this.content);
  1082. var areaNode = new Element("div", {
  1083. "styles": this.css.templateAreaNode
  1084. }).inject(this.content);
  1085. var createNode = new Element("div", {
  1086. "styles": this.css.templateInfoNode
  1087. }).inject(areaNode);
  1088. var pageNode = new Element("div", {
  1089. "styles": this.css.templatePageNode
  1090. }).inject(createNode);
  1091. var iconNode = this.setTemplatePageNode(pageNode);
  1092. var nodes = pageNode.getElements("input");
  1093. var nameNode = nodes[0];
  1094. var newCategoryNode = nodes[1];
  1095. var descriptionNode = pageNode.getElement("textarea");
  1096. var categorySelect = pageNode.getElement("select");
  1097. this.setCategorySelect(categorySelect);
  1098. this.setTemplateActions(markNode, areaNode, pageNode, iconNode, nameNode, categorySelect, newCategoryNode, descriptionNode);
  1099. },
  1100. savePageAsTemplate: function(){
  1101. if (!this.isSave){
  1102. this.createTemplateSaveNode();
  1103. }else{
  1104. MWF.xDesktop.notice("info", {x: "right", y:"top"}, this.lp.isSave);
  1105. }
  1106. }
  1107. });