Main.js 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290
  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.savePage();
  962. this.page.preview();
  963. },
  964. printPage: function(){
  965. this.previewPage();
  966. },
  967. pageExplode: function(){
  968. this.page.explode();
  969. },
  970. pageImplode: function(){
  971. this.page.implode();
  972. },
  973. htmlImplode: function(){
  974. this.page.implodeHTML();
  975. },
  976. pageHelp: function(){
  977. //widnow.open("http://www.o2oa.io");
  978. },
  979. recordStatus: function(){
  980. return {"id": this.options.id};
  981. },
  982. onPostClose: function(){
  983. if (this.pcPage){
  984. MWF.release(this.pcPage.moduleList);
  985. MWF.release(this.pcPage.moduleNodeList);
  986. MWF.release(this.pcPage.moduleContainerNodeList);
  987. MWF.release(this.pcPage.moduleElementNodeList);
  988. MWF.release(this.pcPage.moduleComponentNodeList);
  989. MWF.release(this.pcPage);
  990. }
  991. if (this.mobilePage){
  992. MWF.release(this.mobilePage.moduleList);
  993. MWF.release(this.mobilePage.moduleNodeList);
  994. MWF.release(this.mobilePage.moduleContainerNodeList);
  995. MWF.release(this.mobilePage.moduleElementNodeList);
  996. MWF.release(this.mobilePage.moduleComponentNodeList);
  997. MWF.release(this.mobilePage);
  998. }
  999. },
  1000. setTemplatePageNode: function(pageNode){
  1001. var html = "<table align=\"center\" width=\"100%\" height=\"90%\" border=\"0\" cellPadding=\"0\" cellSpacing=\"0\">" +
  1002. "<tr><td colSpan=\"2\" style=\"height: 50px; line-height: 60px; text-align: center; font-size: 24px; font-weight: bold\">" +
  1003. this.lp.saveTemplate+"</td></tr>" +
  1004. "<tr><td style=\"height: 40px;\" width=\"80px\">" +this.lp.templateName+"</td><td>"+
  1005. "<input value=\""+this.pcPage.json.name+"\" type=\"text\" style=\"width: 98%; height: 22px; border: 1px solid #cccccc\"/>"+"</td></tr>" +
  1006. "<tr><td style=\"height: 40px;\">" +this.lp.templateCategory+"</td><td>"+
  1007. "<select style=\"width: 30%; height: 24px; border: 1px solid #cccccc\"></select>"+
  1008. "<input type=\"text\" style=\"width: 68%; height: 22px; border: 1px solid #cccccc\"/>"+"</td></tr>" +
  1009. "<tr><td style=\"height: 40px;\">" +this.lp.templateDescription+"</td><td>"+
  1010. "<textarea type=\"text\" style=\"width: 98%; height: 44px; border: 1px solid #cccccc\">"+this.pcPage.json.description+"</textarea>"+"</td></tr>" +
  1011. "<tr><td colSpan=\"2\" id=\"page_templatePreview\">" +
  1012. "<div style=\"position: relative; width: 180px; height: 180px; margin: 20px auto 0px auto; overflow: hidden\"></div>" +
  1013. "</td></tr>" +
  1014. "</table>";
  1015. pageNode.set("html", html);
  1016. var tds = pageNode.getElements("td");
  1017. var iconNode = tds[tds.length-1].getFirst();
  1018. var previewNode = this.pcPage.node.clone();
  1019. previewNode.setStyles({
  1020. "transform-origin": "0px 0px",
  1021. "transform": "scale(0.15,0.15)",
  1022. "position": "absolute",
  1023. "top": "0px",
  1024. "left": "0px"
  1025. }).inject(iconNode);
  1026. return iconNode;
  1027. },
  1028. setCategorySelect: function(categorySelect){
  1029. if (categorySelect){
  1030. new Element("option", {"value": "$newCategory","text": this.lp.newCategory}).inject(categorySelect);
  1031. this.actions.listPageTemplateCategory(function(json){
  1032. json.data.each(function(category){
  1033. new Element("option", {"value": category.name,"text": category.name}).inject(categorySelect);
  1034. }.bind(this));
  1035. }.bind(this));
  1036. }
  1037. },
  1038. setTemplateActions: function(markNode, areaNode, pageNode, iconNode, nameNode, categorySelect, newCategoryNode, descriptionNode){
  1039. var actionAreaNode= new Element("div", {
  1040. "styles": this.css.templateActionNode
  1041. }).inject(pageNode);
  1042. var cancelActionNode = new Element("div", {
  1043. "styles": this.css.templateCancelActionNode,
  1044. "text": this.lp.cancel,
  1045. "events":{
  1046. "click": function(){
  1047. markNode.destroy();
  1048. areaNode.destroy();
  1049. }
  1050. }
  1051. }).inject(actionAreaNode);
  1052. var saveActionNode = new Element("div", {
  1053. "styles": this.css.templateSaveActionNode,
  1054. "text": this.lp.save,
  1055. "events":{
  1056. "click": function(){
  1057. this.saveTemplate(markNode, areaNode, iconNode, nameNode, categorySelect, newCategoryNode, descriptionNode);
  1058. }.bind(this)
  1059. }
  1060. }).inject(actionAreaNode);
  1061. },
  1062. saveTemplate: function(markNode, areaNode, iconNode, nameNode, categorySelect, newCategoryNode, descriptionNode){
  1063. var pcData, mobileData;
  1064. if (this.pcPage){
  1065. this.pcPage._getPageData();
  1066. pcData = this.pcPage.data;
  1067. }
  1068. if (this.mobilePage){
  1069. this.mobilePage._getPageData();
  1070. mobileData = this.mobilePage.data;
  1071. }
  1072. var name = nameNode.get("value");
  1073. var category = (categorySelect.options[categorySelect.selectedIndex].value=="$newCategory") ? newCategoryNode.get("value") : categorySelect.options[categorySelect.selectedIndex].value;
  1074. var description = descriptionNode.get("value");
  1075. if (!name){
  1076. this.notice(MWF.APPPD.LP.notice["saveTemplate_inputName"], "error", nameNode, {x: "left", y:"top"});
  1077. return false;
  1078. }
  1079. if (categorySelect.options[categorySelect.selectedIndex].value=="$newCategory" && !newCategoryNode.get("value")){
  1080. this.notice(MWF.APPPD.LP.notice["saveTemplate_inputCategory"], "error", categorySelect, {x: "left", y:"top"});
  1081. return false;
  1082. }
  1083. var data = {
  1084. "name": name,
  1085. "category": category,
  1086. "description": description,
  1087. "outline": iconNode.get("html")
  1088. };
  1089. this.actions.addPageTemplate(pcData, mobileData, data, function(){
  1090. this.notice(MWF.APPPD.LP.notice["saveTemplate_success"], "ok", null, {x: "left", y:"bottom"});
  1091. markNode.destroy();
  1092. areaNode.destroy();
  1093. }.bind(this), function(xhr, text, error){
  1094. var errorText = error+":"+text;
  1095. if (xhr) errorText = xhr.responseText;
  1096. MWF.xDesktop.notice("error", {x: "right", y:"top"}, "request json error: "+errorText);
  1097. });
  1098. },
  1099. createTemplateSaveNode: function(){
  1100. var markNode = new Element("div", {
  1101. "styles": this.css.templateMarkNode,
  1102. "events": {
  1103. "mouseover": function(e){e.stopPropagation();},
  1104. "mouseout": function(e){e.stopPropagation();}
  1105. }
  1106. }).inject(this.content);
  1107. var areaNode = new Element("div", {
  1108. "styles": this.css.templateAreaNode
  1109. }).inject(this.content);
  1110. var createNode = new Element("div", {
  1111. "styles": this.css.templateInfoNode
  1112. }).inject(areaNode);
  1113. var pageNode = new Element("div", {
  1114. "styles": this.css.templatePageNode
  1115. }).inject(createNode);
  1116. var iconNode = this.setTemplatePageNode(pageNode);
  1117. var nodes = pageNode.getElements("input");
  1118. var nameNode = nodes[0];
  1119. var newCategoryNode = nodes[1];
  1120. var descriptionNode = pageNode.getElement("textarea");
  1121. var categorySelect = pageNode.getElement("select");
  1122. this.setCategorySelect(categorySelect);
  1123. this.setTemplateActions(markNode, areaNode, pageNode, iconNode, nameNode, categorySelect, newCategoryNode, descriptionNode);
  1124. },
  1125. savePageAsTemplate: function(){
  1126. if (!this.isSave){
  1127. this.createTemplateSaveNode();
  1128. }else{
  1129. MWF.xDesktop.notice("info", {x: "right", y:"top"}, this.lp.isSave);
  1130. }
  1131. }
  1132. });