Main.js 48 KB

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