Main.js 48 KB

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