Main.js 81 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090
  1. MWF.APPPOD = MWF.xApplication.portal.PageDesigner;
  2. MWF.APPPOD.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": "page.json",
  15. "templateId": "",
  16. "name": "portal.PageDesigner",
  17. "icon": "icon.png",
  18. "title": MWF.APPPOD.LP.title,
  19. "appTitle": MWF.APPPOD.LP.title,
  20. "id": "",
  21. "actions": null,
  22. "category": null,
  23. "processData": null,
  24. "mvcStyle": "style.css"
  25. },
  26. onQueryLoad: function(){
  27. this._loadCss();
  28. this.shortcut = true;
  29. if (this.status){
  30. this.options.id = this.status.id;
  31. }
  32. if (!this.options.id){
  33. this.options.desktopReload = false;
  34. this.options.title = this.options.title + "-"+MWF.APPPOD.LP.newPage;
  35. }
  36. if( this.options.application ){
  37. if( !this.application )this.application = this.options.application;
  38. }
  39. this.actions = MWF.Actions.get("x_portal_assemble_designer");
  40. //this.actions = new MWF.xApplication.portal.PortalManager.Actions.RestActions();
  41. this.lp = MWF.xApplication.portal.PageDesigner.LP;
  42. },
  43. loadApplication: function(callback){
  44. this.createNode();
  45. if (!this.options.isRefresh){
  46. this.maxSize(function(){
  47. this.openPage();
  48. }.bind(this));
  49. }else{
  50. this.openPage();
  51. }
  52. this.addKeyboardEvents();
  53. if (callback) callback();
  54. },
  55. addKeyboardEvents: function(){
  56. this.addEvent("copy", function(){
  57. this.copyModule();
  58. }.bind(this));
  59. this.addEvent("paste", function(e){
  60. if( e.target && e.target.tagName && e.target.tagName.toLowerCase() === "textarea" )return;
  61. this.pasteModule();
  62. e.preventDefault();
  63. }.bind(this));
  64. this.addEvent("cut", function(){
  65. this.cutModule();
  66. }.bind(this));
  67. this.addEvent("keySave", function(e){
  68. this.keySave(e);
  69. }.bind(this));
  70. this.addEvent("keyDelete", function(e){
  71. this.keyDelete(e);
  72. }.bind(this));
  73. },
  74. keySave: function(e){
  75. if (this.shortcut) {
  76. if (this.page) this.savePage();
  77. e.preventDefault();
  78. }
  79. },
  80. keyDelete: function(e){
  81. if (this.page){
  82. if (this.shortcut){
  83. if (this.page.currentSelectedModule){
  84. var module = this.page.currentSelectedModule;
  85. if (module.moduleType!="page" && module.moduleName.indexOf("$")==-1){
  86. module["delete"](module.node);
  87. }
  88. }
  89. }
  90. }
  91. },
  92. copyModule: function(){
  93. if (this.shortcut) {
  94. if (this.page) {
  95. if (this.page.currentSelectedModule) {
  96. var module = this.page.currentSelectedModule;
  97. if (module.moduleType != "page" && module.moduleName.indexOf("$") == -1) {
  98. this.page.fireEvent("queryGetPageData", [module.node]);
  99. var html = module.getHtml();
  100. var json = module.getJson();
  101. this.page.fireEvent("postGetPageData", [module.node]);
  102. MWF.clipboard.data = {
  103. "type": "page",
  104. "data": {
  105. "html": html,
  106. "json": json
  107. }
  108. };
  109. } else {
  110. MWF.clipboard.data = null;
  111. }
  112. }
  113. }
  114. }
  115. },
  116. cutModule: function(){
  117. if (this.shortcut) {
  118. if (this.page) {
  119. if (this.page.currentSelectedModule) {
  120. var module = this.page.currentSelectedModule;
  121. if (module.moduleType != "page" && module.moduleName.indexOf("$") == -1) {
  122. this.copyModule();
  123. // module.destroy();
  124. // module.page.selected();
  125. var _page = module.form;
  126. if( _page.history ){
  127. module.addHistoryLog("cut");
  128. }
  129. module.destroy();
  130. _page.currentSelectedModule = null;
  131. _page.selected();
  132. _page = null;
  133. }
  134. }
  135. }
  136. }
  137. },
  138. pasteModule: function(){
  139. if (this.shortcut) {
  140. if (this.page) {
  141. if (MWF.clipboard.data) {
  142. if (MWF.clipboard.data.type == "page") {
  143. var datatemplateJsons = [];
  144. var idMap = {};
  145. var html = MWF.clipboard.data.data.html;
  146. var json = Object.clone(MWF.clipboard.data.data.json);
  147. var tmpNode = new Element("div", {
  148. "styles": {"display": "none"},
  149. "html": html
  150. }).inject(this.content);
  151. Object.each(json, function (moduleJson) {
  152. var oid = moduleJson.id;
  153. var id = moduleJson.id;
  154. var idx = 1;
  155. while (this.page.json.moduleList[id]) {
  156. id = oid + "_" + idx;
  157. idx++;
  158. }
  159. if (oid != id) {
  160. idMap[oid] = id;
  161. moduleJson.id = id;
  162. var moduleNode = tmpNode.getElementById(oid);
  163. if (moduleNode) moduleNode.set("id", id);
  164. }
  165. if( moduleJson.type === "Datatemplate" )datatemplateJsons.push(moduleJson);
  166. this.page.json.moduleList[moduleJson.id] = moduleJson;
  167. }.bind(this));
  168. delete json;
  169. datatemplateJsons.each(function (json) {
  170. this.checkDatatemplateRelativeId(json, idMap);
  171. }.bind(this));
  172. var injectNode = this.page.node;
  173. var where = "bottom";
  174. var parent = this.page;
  175. if (this.page.currentSelectedModule) {
  176. var toModule = this.page.currentSelectedModule;
  177. injectNode = toModule.node;
  178. parent = toModule;
  179. if (toModule.moduleType != "container" && toModule.moduleType != "page") {
  180. where = "after";
  181. parent = toModule.parentContainer;
  182. }
  183. }
  184. var moduleList = [];
  185. var copyModuleNode = tmpNode.getFirst();
  186. while (copyModuleNode) {
  187. copyModuleNode.inject(injectNode, where);
  188. var copyModuleJson = this.page.getDomjson(copyModuleNode);
  189. module = this.page.loadModule(copyModuleJson, copyModuleNode, parent);
  190. module._setEditStyle_custom("id");
  191. module.selected();
  192. moduleList.push( module );
  193. copyModuleNode = tmpNode.getFirst();
  194. }
  195. tmpNode.destroy();
  196. delete tmpNode;
  197. if( this.page.history && moduleList.length){
  198. moduleList[0].addHistoryLog("paste", moduleList);
  199. }
  200. }
  201. }
  202. }
  203. }
  204. },
  205. createNode: function(){
  206. this.content.setStyle("overflow", "hidden");
  207. this.node = new Element("div", {
  208. "styles": {"width": "100%", "height": "100%", "overflow": "hidden"}
  209. }).inject(this.content);
  210. },
  211. openPage: function(){
  212. this.initOptions();
  213. this.loadNodes();
  214. this.loadToolbar();
  215. this.loadPageNode();
  216. this.loadProperty();
  217. //this.loadTools();
  218. this.loadTools(function(){
  219. this.resizeNode();
  220. this.addEvent("resize", this.resizeNode.bind(this));
  221. }.bind(this));
  222. // this.resizeNode();
  223. // this.addEvent("resize", this.resizeNode.bind(this));
  224. this.loadPage();
  225. if (this.toolbarContentNode){
  226. this.setScrollBar(this.toolbarContentNode, null, {
  227. "V": {"x": 0, "y": 0},
  228. "H": {"x": 0, "y": 0}
  229. });
  230. }
  231. MWF.require("MWF.widget.ScrollBar", function(){
  232. new MWF.widget.ScrollBar(this.propertyDomScrollArea, {
  233. "style":"default", "where": "before", "distance": 30, "friction": 4, "indent": false, "axis": {"x": false, "y": true}
  234. });
  235. }.bind(this));
  236. MWF.require("MWF.widget.ScrollBar", function(){
  237. new MWF.widget.ScrollBar(this.historyScrollArea, {
  238. "style":"default", "where": "before", "distance": 30, "friction": 4, "indent": false, "axis": {"x": false, "y": true}
  239. });
  240. }.bind(this));
  241. },
  242. initOptions: function(){
  243. this.toolsData = null;
  244. this.toolbarMode = "all";
  245. this.tools = [];
  246. this.toolGroups = [];
  247. this.toolbarDecrease = 0;
  248. this.designNode = null;
  249. this.page = null;
  250. },
  251. loadNodes: function(){
  252. this.toolbarNode = new Element("div", {
  253. "styles": this.css.toolbarNode,
  254. "events": {"selectstart": function(e){e.preventDefault();}}
  255. }).inject(this.node);
  256. this.propertyNode = new Element("div", {
  257. "styles": this.css.propertyNode
  258. }).inject(this.node);
  259. this.pageNode = new Element("div", {
  260. "styles": this.css.pageNode
  261. }).inject(this.node);
  262. if (this.options.style=="bottom") this.propertyNode.inject(this.pageNode, "after");
  263. },
  264. //loadToolbar----------------------
  265. loadToolbar: function(){
  266. this.toolbarTitleNode = new Element("div", {
  267. "styles": this.css.toolbarTitleNode,
  268. "text": MWF.APPPOD.LP.tools
  269. }).inject(this.toolbarNode);
  270. this.toolbarTitleActionNode = new Element("div", {
  271. "styles": this.css.toolbarTitleActionNode,
  272. "events": {
  273. "click": function(e){
  274. this.switchToolbarMode();
  275. }.bind(this)
  276. }
  277. }).inject(this.toolbarNode);
  278. this.toolbarTitleCategoryActionNode = new Element("div", {
  279. "styles": this.css.toolbarTitleCategoryActionNode
  280. }).inject(this.toolbarNode);
  281. this.categoryActionMenu = new o2.xDesktop.Menu(this.toolbarTitleCategoryActionNode, {
  282. "event": "click", "style": "flatUser", "offsetX": 0, "offsetY": 0, "container": this.node,
  283. "onQueryShow": this.showCategoryMenu.bind(this)
  284. });
  285. this.categoryActionMenu.load();
  286. this.toolbarGroupContentNode = new Element("div", {"styles": this.css.toolbarGroupContentNode}).inject(this.toolbarNode);
  287. this.toolbarGroupContentNode.addEvent("selectstart", function(e){
  288. e.preventDefault();
  289. e.stopPropagation();
  290. });
  291. // this.toolbarContentNode = new Element("div", {
  292. // "styles": this.css.toolbarContentNode,
  293. // "events": {
  294. // "selectstart": function(e){
  295. // e.preventDefault();
  296. // e.stopPropagation();
  297. // }
  298. // }
  299. // }).inject(this.toolbarNode);
  300. },
  301. showCategoryMenu: function(){
  302. this.categoryActionMenu.items.each(function(item){
  303. debugger;
  304. if (this.currentToolGroup && this.currentToolGroup.data.text==item.options.text){
  305. item.setDisable(true);
  306. var imgDiv = item.item.getFirst();
  307. var img = imgDiv.getElement("img");
  308. if (!img) img = new Element("img", {"styles": item.menu.css.menuItemImg}).inject(imgDiv);
  309. img.set("src", this.path+this.options.style+"/check.png");
  310. }else{
  311. item.setDisable(false);
  312. var imgDiv = item.item.getFirst();
  313. var img = imgDiv.getElement("img");
  314. if (img) img.destroy();
  315. }
  316. }.bind(this));
  317. },
  318. switchToolbarMode: function(){
  319. if (this.toolbarMode=="all"){
  320. var size = this.toolbarNode.getSize();
  321. this.toolbarDecrease = (size.x.toFloat())-60;
  322. this.tools.each(function(node){
  323. node.getLast().setStyle("display", "none");
  324. });
  325. this.toolbarTitleNode.set("text", "");
  326. this.toolbarNode.setStyle("width", "60px");
  327. var pageMargin = this.pageNode.getStyle("margin-left").toFloat();
  328. pageMargin = pageMargin - this.toolbarDecrease;
  329. this.pageNode.setStyle("margin-left", ""+pageMargin+"px");
  330. this.toolbarTitleActionNode.setStyles(this.css.toolbarTitleActionNodeRight);
  331. this.toolbarGroupContentNode.getElements(".o2formModuleTools").hide();
  332. this.toolbarMode="simple";
  333. }else{
  334. sizeX = 60 + this.toolbarDecrease;
  335. var pageMargin = this.pageNode.getStyle("margin-left").toFloat();
  336. pageMargin = pageMargin + this.toolbarDecrease;
  337. this.toolbarNode.setStyle("width", ""+sizeX+"px");
  338. this.pageNode.setStyle("margin-left", ""+pageMargin+"px");
  339. this.tools.each(function(node){
  340. node.getLast().setStyle("display", "block");
  341. });
  342. this.toolbarTitleNode.set("text", MWF.APPPOD.LP.tools);
  343. this.toolbarTitleActionNode.setStyles(this.css.toolbarTitleActionNode);
  344. this.toolbarGroupContentNode.getElements(".o2formModuleTools").show();
  345. this.toolbarMode="all";
  346. }
  347. },
  348. //loadPageNode------------------------------
  349. loadPageNode: function(){
  350. this.pageToolbarNode = new Element("div", {
  351. "styles": this.css.pageToolbarNode
  352. }).inject(this.pageNode);
  353. this.loadPageToolbar();
  354. this.pageContentNode = new Element("div", {
  355. "styles": this.css.pageContentNode
  356. }).inject(this.pageNode);
  357. this.loadPageContent(function(){
  358. if (this.designDcoument) this.designDcoument.body.setStyles(this.css.designBody);
  359. if (this.designNode) this.designNode.setStyles(this.css.designNode);
  360. }.bind(this));
  361. },
  362. loadDesignerActionNode: function(){
  363. this.pcDesignerActionNode = this.pageToolbarNode.getElement("#MWFPCDesignerAction");
  364. this.mobileDesignerActionNode = this.pageToolbarNode.getElement("#MWFMobileDesignerAction");
  365. this.currentDesignerMode = "PC";
  366. this.pcDesignerActionNode.setStyles(this.css.designerActionNode_current);
  367. this.mobileDesignerActionNode.setStyles(this.css.designerActionNode);
  368. var iconNode = new Element("div", {"styles": this.css.designerActionPcIconNode}).inject(this.pcDesignerActionNode);
  369. iconNode = new Element("div", {"styles": this.css.designerActionMobileIconNode}).inject(this.mobileDesignerActionNode);
  370. var textNode = new Element("div", {"styles": this.css.designerActiontextNode, "text": "PC"}).inject(this.pcDesignerActionNode);
  371. textNode = new Element("div", {"styles": this.css.designerActiontextNode, "text": "Mobile"}).inject(this.mobileDesignerActionNode);
  372. this.pcDesignerActionNode.addEvent("click", function(){
  373. if (this.currentDesignerMode!="PC"){
  374. this.changeDesignerModeToPC();
  375. }
  376. }.bind(this));
  377. this.mobileDesignerActionNode.addEvent("click", function(){
  378. if (this.currentDesignerMode=="PC"){
  379. this.changeDesignerModeToMobile();
  380. }
  381. }.bind(this));
  382. },
  383. changeDesignerModeToPC: function(){
  384. this.pcDesignerActionNode.setStyles(this.css.designerActionNode_current);
  385. this.mobileDesignerActionNode.setStyles(this.css.designerActionNode);
  386. this.designMobileNode.setStyle("display", "none");
  387. this.designNode.setStyle("display", "block");
  388. if (this.page.currentSelectedModule){
  389. if (this.page.currentSelectedModule==this){
  390. return true;
  391. }else{
  392. this.page.currentSelectedModule.unSelected();
  393. }
  394. }
  395. if (this.page.propertyMultiTd){
  396. this.page.propertyMultiTd.hide();
  397. this.page.propertyMultiTd = null;
  398. }
  399. this.page.unSelectedMulti();
  400. if (this.page.designTabPageScriptAreaNode) this.page.designTabPageScriptAreaNode.hide();
  401. this.page = this.pcPage;
  402. if ((this.scriptPage && this.scriptPage.isShow) || this.scriptPanel){
  403. this.loadAllScript();
  404. }
  405. this.currentDesignerMode = "PC";
  406. this.historyArea.show();
  407. this.historyAreaMobile.hide();
  408. this.currentHistoryNode = this.historyArea;
  409. },
  410. changeDesignerModeToMobile: function(){
  411. this.pcDesignerActionNode.setStyles(this.css.designerActionNode);
  412. this.mobileDesignerActionNode.setStyles(this.css.designerActionNode_current);
  413. this.designMobileNode.setStyle("display", "block");
  414. this.designNode.setStyle("display", "none");
  415. if (this.page.currentSelectedModule){
  416. if (this.page.currentSelectedModule==this){
  417. return true;
  418. }else{
  419. this.page.currentSelectedModule.unSelected();
  420. }
  421. }
  422. if (this.page.propertyMultiTd){
  423. this.page.propertyMultiTd.hide();
  424. this.page.propertyMultiTd = null;
  425. }
  426. this.page.unSelectedMulti();
  427. if (!this.mobilePage){
  428. this.designMobileNode.set("id", "designMobileNode");
  429. this.mobilePage = new MWF.PCPage(this, this.designMobileNode, {"mode": "Mobile"});
  430. if (!Object.keys(this.pageMobileData.json.moduleList).length){
  431. this.pageMobileData = Object.clone(this.pageData);
  432. }
  433. this.mobilePage.load(this.pageMobileData);
  434. // this.mobilePage = new MWF.PCPage(this, this.designMobileNode, {"mode": "Mobile"});
  435. // this.mobilePage.load(this.pageMobileData);
  436. }
  437. if (this.page.designTabPageScriptAreaNode) this.page.designTabPageScriptAreaNode.hide();
  438. this.page = this.mobilePage;
  439. //if (this.page.designTabPageScriptAreaNode && this.page.designTabPageScriptAreaNode.isDisplayed()){
  440. if ((this.scriptPage && this.scriptPage.isShow) || this.scriptPanel){
  441. this.loadAllScript();
  442. }
  443. this.currentDesignerMode = "Mobile";
  444. this.historyArea.hide();
  445. this.historyAreaMobile.show();
  446. this.currentHistoryNode = this.historyAreaMobile;
  447. },
  448. loadPageToolbar: function(callback){
  449. this.getToolbarHTML(function(toolbarNode){
  450. var spans = toolbarNode.getElements("span");
  451. spans.each(function(item, idx){
  452. var img = item.get("MWFButtonImage");
  453. if (img){
  454. item.set("MWFButtonImage", this.path+""+this.options.style+"/pageToolbar/"+img);
  455. }
  456. }.bind(this));
  457. $(toolbarNode).inject(this.pageToolbarNode);
  458. MWF.require("MWF.widget.Toolbar", function(){
  459. this.pageToolbar = new MWF.widget.Toolbar(toolbarNode, {"style": "ProcessCategory"}, this);
  460. this.pageToolbar.load();
  461. this.loadDesignerActionNode();
  462. if (callback) callback();
  463. }.bind(this));
  464. }.bind(this));
  465. },
  466. getToolbarHTML: function(callback){
  467. var toolbarUrl = this.path+this.options.style+"/pageToolbars.html";
  468. MWF.getRequestText(toolbarUrl, function(responseText, responseXML){
  469. var htmlString = responseText;
  470. htmlString = o2.bindJson(htmlString, {"lp": this.lp.formToolbar});
  471. var temp = new Element('div').set('html', htmlString);
  472. if (callback) callback( temp.childNodes[0] );
  473. }.bind(this));
  474. },
  475. loadPageContent: function(callback){
  476. MWF.require("MWF.widget.Tab", null, false);
  477. this.designTabNode = new Element("div").inject(this.pageContentNode);
  478. this.designTab = new MWF.widget.Tab(this.designTabNode, {"style": "design"});
  479. this.designTab.load();
  480. this.designTabPageAreaNode = Element("div");
  481. this.designNode = new Element("div", {
  482. "styles": this.css.designNode
  483. }).inject(this.designTabPageAreaNode);
  484. this.designMobileNode = new Element("div", {
  485. "styles": this.css.designMobileNode
  486. }).inject(this.designTabPageAreaNode);
  487. this.designTabScriptAreaNode = Element("div", {"styles": this.css.designTabScriptAreaNode});
  488. // this.designTabScriptPcAreaNode = Element("div", {"styles": this.css.designTabScriptPcAreaNode}).inject(this.designTabScriptAreaNode);
  489. // this.designTabScriptMobileAreaNode = Element("div", {"styles": this.css.designTabScriptMobileAreaNode}).inject(this.designTabScriptAreaNode);
  490. //this.designTabHtmlAreaNode = Element("div", {"styles": this.css.designTabHtmlAreaNode});
  491. //this.designTabCssAreaNode = Element("div", {"styles": this.css.designTabScriptAreaNode});
  492. this.designPage = this.designTab.addTab(this.designTabPageAreaNode, this.lp.design);
  493. this.scriptPage = this.designTab.addTab(this.designTabScriptAreaNode, this.lp.script);
  494. //this.htmlPage = this.designTab.addTab(this.designTabHtmlAreaNode, this.lp.html);
  495. //this.cssPage = this.designTab.addTab(this.designTabCssAreaNode, this.lp.css);
  496. this.setScriptPageEvent();
  497. this.designPage.showTabIm();
  498. // this.cssPage.addEvent("postShow", function(){
  499. // this.loadCssPage();
  500. // this.fireEvent("resize");
  501. // }.bind(this));
  502. // this.htmlPage.addEvent("postShow", function(){
  503. // this.loadHtmlPage();
  504. // this.fireEvent("resize");
  505. // }.bind(this));
  506. this.scriptPage.addEvent("postShow", function(){
  507. this.checkLoadAllScript();
  508. this.fireEvent("resize");
  509. }.bind(this));
  510. this.designPage.addEvent("postShow", function(){
  511. this.fireEvent("resize");
  512. }.bind(this));
  513. // this.designNode = new Element("div#designNode", {
  514. // "styles": this.css.designNode
  515. // }).inject(this.pageContentNode);
  516. //
  517. // this.designMobileNode = new Element("div", {
  518. // "styles": this.css.designMobileNode
  519. // }).inject(this.pageContentNode);
  520. },
  521. /*
  522. loadCssPage: function(){
  523. if (!this.cssPageLoaded){
  524. if (!this.page.json.css || typeOf(this.page.json.css)!=="object") this.page.json.css = {"code": "", "html": ""};
  525. var cssContent = this.page.json.css
  526. MWF.require("MWF.widget.CssArea", function(){
  527. var cssArea = new MWF.widget.CssArea(this.designTabCssAreaNode, {
  528. "title": "CSS",
  529. "maxObj": this.content,
  530. "isload": true,
  531. "onChange": function(){
  532. if (!this.page.json.css) this.page.json.css = {"code": "", "html": ""};
  533. var json = cssArea.toJson();
  534. this.page.json.css.code = json.code;
  535. cssArea.isChanged = true;
  536. //this.data[name].html = json.html;
  537. }.bind(this),
  538. "onBlur": function(){
  539. if (cssArea.isChanged){
  540. this.page._setEditStyle("css", null, "");
  541. cssArea.isChanged = false;
  542. }
  543. }.bind(this),
  544. "onSave": function(){
  545. if (cssArea.isChanged){
  546. this.page._setEditStyle("css", null, "");
  547. cssArea.isChanged = false;
  548. }
  549. this.saveForm();
  550. }.bind(this),
  551. "style": "page"
  552. });
  553. cssArea.load(cssContent);
  554. //cssArea.loadEditor(cssContent);
  555. }.bind(this));
  556. this.cssPageLoaded = true;
  557. }
  558. },
  559. loadHtmlPage: function(){
  560. if (!this.htmlPageLoaded){
  561. MWF.widget.ace.load(function(){
  562. ace.require("ace/ext/language_tools");
  563. this.htmlEditor = ace.edit(this.designTabHtmlAreaNode);
  564. this.htmlEditor.session.setMode("ace/mode/html");
  565. this.htmlEditor.setTheme("ace/theme/eclipse");
  566. this.htmlEditor.setOptions({
  567. enableBasicAutocompletion: true,
  568. enableSnippets: true,
  569. enableLiveAutocompletion: false
  570. });
  571. debugger;
  572. o2.load("JSBeautifier_html", function(){
  573. this.htmlEditor.setValue(html_beautify(this.page.node.get("html")));
  574. }.bind(this));
  575. // var Mode = require('ace/mode/html').Mode;
  576. // this.htmlEditor.getSession().setMode(new Mode());
  577. //this.htmlEditor.focus();
  578. //this.htmlEditor.navigateFileStart();
  579. this.htmlEditor.commands.addCommand({
  580. name: 'save',
  581. bindKey: {win: 'Ctrl-S', mac: 'Command-S'},
  582. exec: function(htmlEditor) {
  583. this.fireEvent("save");
  584. }.bind(this),
  585. readOnly: false // false if this command should not apply in readOnly mode
  586. });
  587. this.htmlEditor.commands.addCommand({
  588. name: 'help',
  589. bindKey: {win: 'Ctrl-Q|Ctrl-Alt-Space|Ctrl-Space|Alt-/', mac: 'Command-Q'},
  590. exec: function(editor, e, e1) {
  591. this.fireEvent("reference", [editor, e, e1]);
  592. }.bind(this),
  593. readOnly: false // false if this command should not apply in readOnly mode
  594. });
  595. this.node.addEvent("keydown", function(e){
  596. e.stopPropagation();
  597. });
  598. }.bind(this));
  599. }
  600. },
  601. */
  602. createScriptPanel: function(p, s){
  603. MWF.require("MWF.widget.Panel", function(){
  604. this.scriptPanel = new MWF.widget.Panel(this.designTabScriptAreaNode, {
  605. "title": this.lp.script,
  606. "minLeft": "500",
  607. "minTop": "1",
  608. "style": "page",
  609. "target": this.content,
  610. "limitMove": false,
  611. "isClose": false,
  612. "width": s.x,
  613. "height": s.y,
  614. "top": p.y,
  615. "left": p.x,
  616. "onPostLoad": function(){
  617. this.loadAllScript();
  618. this.fireEvent("resize");
  619. }.bind(this),
  620. "onResize": function(){
  621. this.fireEvent("resize");
  622. }.bind(this),
  623. "onDrag": function(el, e){
  624. if (el.getStyle("top").toInt()<0) el.setStyle("top", "0px");
  625. if (!this.scriptPage.tab.tabNodeContainer.isOutside(e)){
  626. this.scriptPage.tabNode.show();
  627. this.scriptPanel.container.setStyle("opacity", "0.5");
  628. }else{
  629. this.scriptPage.tabNode.hide();
  630. this.scriptPanel.container.setStyle("opacity", "1");
  631. }
  632. }.bind(this),
  633. "onCompleteMove": function(el, e){
  634. if (!this.scriptPage.tab.tabNodeContainer.isOutside(e)){
  635. this.scriptPage.tabNode.show();
  636. this.designTabScriptAreaNode.inject(this.designTab.contentNodeContainer.getLast());
  637. this.fireEvent("resize");
  638. this.scriptPage.showTabIm();
  639. this.scriptPanel.closePanel();
  640. this.scriptPanel = null;
  641. }
  642. }.bind(this)
  643. });
  644. this.scriptPanel.load();
  645. }.bind(this));
  646. },
  647. createScriptPageDragNode: function(e){
  648. var size = this.scriptPage.tab.contentNodeContainer.getSize();
  649. var position = this.scriptPage.tab.contentNodeContainer.getPosition(this.content);
  650. if (!this.scriptPageContentDrag){
  651. var dragNode = new Element("div", {"styles": this.css.scriptPageDragNode}).inject(this.content);
  652. this.scriptPageContentDrag = new Drag.Move(dragNode, {
  653. "droppables": [this.scriptPage.tab.tabNodeContainer],
  654. "onEnter": function(el, drop){
  655. this.scriptPage.tabNode.show();
  656. this.designTabScriptAreaNode.show();
  657. // this.scriptPageContentDrag.stop();
  658. // this.scriptPageContentDrag.detach();
  659. this.scriptPageContentDrag = null;
  660. dragNode.destroy();
  661. this.scriptPageDrag.start(e);
  662. }.bind(this),
  663. "onComplete": function(el, e){
  664. if (this.scriptPage.tab.tabNodeContainer.isOutside(e)){
  665. this.createScriptPanel(dragNode.getPosition(this.content), dragNode.getSize());
  666. this.designPage.showTabIm();
  667. }
  668. this.scriptPageContentDrag = null;
  669. if (dragNode) dragNode.destroy();
  670. this.designTabScriptAreaNode.show();
  671. }.bind(this)
  672. });
  673. }
  674. var tabPosition = this.scriptPage.tabNode.getPosition();
  675. var dx = e.page.x-tabPosition.x;
  676. var dy = e.page.y-tabPosition.y;
  677. this.scriptPage.tabNode.hide();
  678. this.designTabScriptAreaNode.hide();
  679. var w = size.x*0.7;
  680. var h = size.y*0.7;
  681. var x = position.x+dx;
  682. var y = position.y+dy-20;
  683. dragNode.setStyles({
  684. "width": ""+w+"px",
  685. "height": ""+h+"px",
  686. "top": ""+y+"px",
  687. "left": ""+x+"px"
  688. });
  689. this.scriptPageContentDrag.start(e);
  690. },
  691. setScriptPageEvent: function(){
  692. this.scriptPageDrag = new Drag(this.scriptPage.tabNode, {
  693. "snap": 20,
  694. "onStart": function(el,e){
  695. el.setStyle("position", "static");
  696. },
  697. "onDrag": function(el,e){
  698. if (this.scriptPage.tab.tabNodeContainer.isOutside(e)){
  699. this.scriptPageDrag.stop();
  700. el.setStyle("left", "auto");
  701. this.createScriptPageDragNode(e);
  702. }
  703. }.bind(this),
  704. "onComplete": function(el){
  705. el.setStyle("left", "auto");
  706. //el.setStyle("position", "relative");
  707. }.bind(this)
  708. });
  709. },
  710. checkLoadAllScript: function(){
  711. if (this.page || this.form){
  712. this.loadAllScript();
  713. }else{
  714. this.designPage.showTabIm();
  715. }
  716. },
  717. loadAllScript: function(){
  718. var page = (this.page || this.form);
  719. if (!page.designTabPageScriptAreaNode) page.designTabPageScriptAreaNode = Element("div", {"styles": this.css.designTabScriptPcAreaNode}).inject(this.designTabScriptAreaNode);
  720. page.designTabPageScriptAreaNode.show();
  721. if (!page.scriptDesigner){
  722. MWF.xDesktop.requireApp("portal.PageDesigner", "Script", function(){
  723. page.scriptDesigner = new MWF.xApplication.portal.PageDesigner.Script(this, page.designTabPageScriptAreaNode, page.json);
  724. // var moduleJson = this.pageData.json;
  725. // if (moduleJson.jsheader){
  726. // if (moduleJson.jsheader.code){
  727. //
  728. // }
  729. // }
  730. }.bind(this));
  731. }
  732. },
  733. loadAllPcScript: function(){
  734. if (!this.pcScriptDesigner){
  735. MWF.xDesktop.requireApp("portal.PageDesigner", "Script", function(){
  736. this.pcScriptDesigner = new MWF.xApplication.portal.PageDesigner.Script(this, this.designTabScriptPcAreaNode, this.pageData.json);
  737. // var moduleJson = this.pageData.json;
  738. // if (moduleJson.jsheader){
  739. // if (moduleJson.jsheader.code){
  740. //
  741. // }
  742. // }
  743. }.bind(this));
  744. }
  745. },
  746. loadAllMobileScript: function(){
  747. //this.pageMobileData
  748. },
  749. reloadPropertyStyles: function(){
  750. //MWF.release(this.css);
  751. this.css = null;
  752. this.cssPath = "../x_component_"+this.options.name.replace(/\./g, "_")+"/$Main/"+this.options.style+"/css.wcss";
  753. this._loadCss();
  754. if (this.options.style=="bottom"){
  755. this.propertyNode.inject(this.pageNode, "after");
  756. this.propertyTitleNode.setStyle("cursor", "row-resize");
  757. this.loadPropertyResizeBottom();
  758. }else{
  759. this.propertyNode.inject(this.pageNode, "before");
  760. this.propertyTitleNode.setStyle("cursor", "default");
  761. if (this.propertyResizeBottom) this.propertyResizeBottom.detach();
  762. }
  763. this.pageNode.clearStyles(false);
  764. this.pageNode.setStyles(this.css.pageNode);
  765. this.propertyNode.clearStyles(false);
  766. this.propertyNode.setStyles(this.css.propertyNode);
  767. this.propertyTitleNode.clearStyles(false);
  768. this.propertyTitleNode.setStyles(this.css.propertyTitleNode);
  769. this.propertyResizeBar.clearStyles(false);
  770. this.propertyResizeBar.setStyles(this.css.propertyResizeBar);
  771. this.propertyContentNode.clearStyles(false);
  772. this.propertyContentNode.setStyles(this.css.propertyContentNode);
  773. this.propertyDomContentArea.clearStyles(false);
  774. this.propertyDomContentArea.setStyles(this.css.propertyDomContentArea);
  775. this.propertyDomScrollArea.clearStyles(false);
  776. this.propertyDomScrollArea.setStyles(this.css.propertyDomScrollArea);
  777. this.propertyDomArea.clearStyles(false);
  778. this.propertyDomArea.setStyles(this.css.propertyDomArea);
  779. this.propertyContentArea.clearStyles(false);
  780. this.propertyContentArea.setStyles(this.css.propertyContentArea);
  781. this.propertyContentResizeNode.clearStyles(false);
  782. this.propertyContentResizeNode.setStyles(this.css.propertyContentResizeNode);
  783. this.propertyTitleActionNode.clearStyles(false);
  784. this.propertyTitleActionNode.setStyles(this.css.propertyTitleActionNode);
  785. this.resizeNode();
  786. },
  787. //loadProperty------------------------
  788. loadProperty: function(){
  789. this.propertyTitleActionNode = new Element("div", {
  790. "styles": this.css.propertyTitleActionNode
  791. }).inject(this.propertyNode);
  792. this.propertyTitleActionNode.addEvent("click", function(){
  793. this.options.style = (this.options.style=="default") ? "bottom" : "default";
  794. MWF.UD.putData("pageDesignerStyle", {"style": this.options.style});
  795. this.reloadPropertyStyles();
  796. }.bind(this));
  797. this.propertyTitleNode = new Element("div", {
  798. "styles": this.css.propertyTitleNode,
  799. "text": MWF.APPPOD.LP.property
  800. }).inject(this.propertyNode);
  801. if (this.options.style=="bottom"){
  802. this.propertyTitleNode.setStyle("cursor", "row-resize");
  803. this.loadPropertyResizeBottom();
  804. }
  805. this.propertyResizeBar = new Element("div", {
  806. "styles": this.css.propertyResizeBar
  807. }).inject(this.propertyNode);
  808. this.loadPropertyResize();
  809. this.propertyContentNode = new Element("div", {
  810. "styles": this.css.propertyContentNode
  811. }).inject(this.propertyNode);
  812. this.propertyDomContentArea = new Element("div", {
  813. "styles": this.css.propertyDomContentArea
  814. }).inject(this.propertyContentNode);
  815. this.propertyDomTabArea = new Element("div").inject(this.propertyDomContentArea);
  816. //this.propertyDomScrollArea = new Element("div", {
  817. // "styles": this.css.propertyDomScrollArea
  818. //}).inject(this.propertyDomContentArea);
  819. //this.propertyDomArea = new Element("div", {
  820. // "styles": this.css.propertyDomArea
  821. //}).inject(this.propertyDomScrollArea);
  822. this.loadPropertyTab();
  823. this.propertyDomPercent = 0.4;
  824. this.propertyContentResizeNode = new Element("div", {
  825. "styles": this.css.propertyContentResizeNode
  826. }).inject(this.propertyContentNode);
  827. this.propertyContentArea = new Element("div", {
  828. "styles": this.css.propertyContentArea
  829. }).inject(this.propertyContentNode);
  830. this.loadPropertyContentResize();
  831. },
  832. loadPropertyTab: function (callback) {
  833. var _self = this;
  834. MWF.require("MWF.widget.Tab", null, false);
  835. this.propertyDomTab = new MWF.widget.Tab(this.propertyDomTabArea, {"style": "formPropertyList"});
  836. this.propertyDomTab.load();
  837. this.tabDomNode = Element("div");
  838. this.propertyDomScrollArea = new Element("div", {
  839. "styles": this.css.propertyDomScrollArea
  840. }).inject(this.tabDomNode);
  841. this.propertyDomArea = new Element("div", {
  842. "styles": this.css.propertyDomArea
  843. }).inject(this.propertyDomScrollArea);
  844. this.tabHistoryNode = Element("div");
  845. this.historyScrollArea = new Element("div", {
  846. "styles": this.css.propertyDomScrollArea
  847. }).inject(this.tabHistoryNode);
  848. this.historyArea = new Element("div", {
  849. "styles": this.css.propertyDomArea
  850. }).inject(this.historyScrollArea);
  851. this.historyAreaMobile = new Element("div", {
  852. "styles": this.css.propertyDomArea
  853. }).inject(this.historyScrollArea);
  854. this.historyAreaMobile.hide();
  855. this.currentHistoryNode = this.historyArea;
  856. this.domPage = this.propertyDomTab.addTab(this.tabDomNode, this.lp.componentTree);
  857. this.historyPage = this.propertyDomTab.addTab(this.tabHistoryNode, this.lp.history);
  858. this.domPage.showTabIm();
  859. this.domPage.addEvent("postShow", function () {
  860. var module = this.page.currentSelectedModule;
  861. if (module && module.treeNode){
  862. (new Fx.Scroll(this.propertyDomScrollArea)).toElement(module.treeNode.node);
  863. }
  864. }.bind(this));
  865. // this.runPage.addEvent("postShow", function () {
  866. // this.selected();
  867. // }.bind(this));
  868. },
  869. loadPropertyResizeBottom: function(){
  870. if (!this.propertyResizeBottom){
  871. this.propertyResizeBottom = new Drag(this.propertyTitleNode,{
  872. "snap": 1,
  873. "onStart": function(el, e){
  874. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  875. var y = (Browser.name=="firefox") ? e.event.clientY : e.event.y;
  876. el.store("position", {"x": x, "y": y});
  877. var size = this.propertyNode.getSize();
  878. el.store("initialWidth", size.x);
  879. el.store("initialHeight", size.y);
  880. }.bind(this),
  881. "onDrag": function(el, e){
  882. // var x = e.event.x;
  883. var y = (Browser.name=="firefox") ? e.event.clientY : e.event.y;
  884. var bodySize = this.content.getSize();
  885. var position = el.retrieve("position");
  886. var initialHeight = el.retrieve("initialHeight").toFloat();
  887. var dy = position.y.toFloat()-y.toFloat();
  888. var height = initialHeight+dy;
  889. if (height> bodySize.y/1.5) height = bodySize.y/1.5;
  890. if (height<40) height = 40;
  891. var percent = 1-(height/bodySize.y);
  892. this.resizeNode(percent);
  893. //var pageNodeHeight = bodySize.y-height;
  894. //this.pageNode.setStyle("height", ""+pageNodeHeight+"px");
  895. //this.propertyNode.setStyle("height", ""+height+"px");
  896. }.bind(this)
  897. });
  898. }else{
  899. this.propertyResizeBottom.attach();
  900. }
  901. },
  902. loadPropertyResize: function(){
  903. // var size = this.propertyNode.getSize();
  904. // var position = this.propertyResizeBar.getPosition();
  905. this.propertyResize = new Drag(this.propertyResizeBar,{
  906. "snap": 1,
  907. "onStart": function(el, e){
  908. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  909. var y = (Browser.name=="firefox") ? e.event.clientY : e.event.y;
  910. el.store("position", {"x": x, "y": y});
  911. var size = this.propertyNode.getSize();
  912. el.store("initialWidth", size.x);
  913. }.bind(this),
  914. "onDrag": function(el, e){
  915. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  916. // var y = e.event.y;
  917. var bodySize = this.content.getSize();
  918. var position = el.retrieve("position");
  919. var initialWidth = el.retrieve("initialWidth").toFloat();
  920. var dx = position.x.toFloat()-x.toFloat();
  921. var width = initialWidth+dx;
  922. if (width> bodySize.x/2) width = bodySize.x/2;
  923. if (width<40) width = 40;
  924. this.pageNode.setStyle("margin-right", width+1);
  925. this.propertyNode.setStyle("width", width);
  926. }.bind(this)
  927. });
  928. },
  929. propertyResizeDragTopBottom: function(el, e){
  930. var size = this.propertyContentNode.getSize();
  931. // var x = e.event.x;
  932. var y = e.event.y;
  933. var position = el.retrieve("position");
  934. var dy = y.toFloat()-position.y.toFloat();
  935. var initialHeight = el.retrieve("initialHeight").toFloat();
  936. var height = initialHeight+dy;
  937. if (height<40) height = 40;
  938. if (height> size.y-40) height = size.y-40;
  939. this.propertyDomPercent = height/size.y;
  940. this.setPropertyContentResize();
  941. },
  942. propertyResizeDragLeftRight: function(el, e){
  943. var size = this.propertyContentNode.getSize();
  944. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  945. //var y = e.event.y;
  946. var position = el.retrieve("position");
  947. var dx = x.toFloat()-position.x.toFloat();
  948. var initialWidth = el.retrieve("initialWidth").toFloat();
  949. var width = initialWidth+dx;
  950. if (width<40) width = 40;
  951. if (width> size.x-40) width = size.x-40;
  952. this.propertyDomPercent = width/size.x;
  953. this.setPropertyContentResizeBottom();
  954. },
  955. loadPropertyContentResize: function(){
  956. this.propertyContentResize = new Drag(this.propertyContentResizeNode, {
  957. "snap": 1,
  958. "onStart": function(el, e){
  959. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  960. var y = (Browser.name=="firefox") ? e.event.clientY : e.event.y;
  961. el.store("position", {"x": x, "y": y});
  962. var size = this.propertyDomContentArea.getSize();
  963. el.store("initialHeight", size.y);
  964. el.store("initialWidth", size.x);
  965. }.bind(this),
  966. "onDrag": function(el, e){
  967. if (this.options.style=="bottom"){
  968. this.propertyResizeDragLeftRight(el, e);
  969. }else{
  970. this.propertyResizeDragTopBottom(el, e);
  971. }
  972. }.bind(this)
  973. });
  974. },
  975. setPropertyContentResizeBottom: function(){
  976. var size = this.propertyContentNode.getSize();
  977. var resizeNodeSize = this.propertyContentResizeNode.getSize();
  978. var width = size.x-resizeNodeSize.x-6;
  979. var domWidth = this.propertyDomPercent*width;
  980. var contentMargin = domWidth+resizeNodeSize.x+6;
  981. this.propertyDomContentArea.setStyle("width", ""+domWidth+"px");
  982. this.propertyContentArea.setStyle("margin-left", ""+contentMargin+"px");
  983. },
  984. setPropertyContentResize: function(){
  985. var size = this.propertyContentNode.getSize();
  986. var resizeNodeSize = this.propertyContentResizeNode.getSize();
  987. var height = size.y-resizeNodeSize.y;
  988. var domHeight = this.propertyDomPercent*height;
  989. var contentHeight = height-domHeight;
  990. this.propertyDomContentArea.setStyle("height", ""+domHeight+"px");
  991. this.propertyDomScrollArea.setStyle("height", ""+(domHeight-28)+"px");
  992. this.historyScrollArea.setStyle("height", ""+(domHeight-28)+"px");
  993. this.propertyContentArea.setStyle("height", ""+contentHeight+"px");
  994. if (this.page){
  995. if (this.page.currentSelectedModule){
  996. if (this.page.currentSelectedModule.property){
  997. var tab = this.page.currentSelectedModule.property.propertyTab;
  998. if (tab){
  999. var tabTitleSize = tab.tabNodeContainer.getSize();
  1000. tab.pages.each(function(page){
  1001. var topMargin = page.contentNodeArea.getStyle("margin-top").toFloat();
  1002. var bottomMargin = page.contentNodeArea.getStyle("margin-bottom").toFloat();
  1003. var tabContentNodeAreaHeight = contentHeight - topMargin - bottomMargin - tabTitleSize.y.toFloat()-15;
  1004. page.contentNodeArea.setStyle("height", tabContentNodeAreaHeight);
  1005. }.bind(this));
  1006. }
  1007. }
  1008. }
  1009. }
  1010. },
  1011. //loadTools------------------------------
  1012. loadTools: function(callback){
  1013. o2.loadCss("../o2_lib/vue/element/index.css");
  1014. this.getToolResource(function(){
  1015. this.toolsGroupData.forEach(function(o){
  1016. //var o = this.toolsGroupData[key];
  1017. this.toolGroups.push(new MWF.xApplication.portal.PageDesigner.ToolsGroup(o, this, o.name === this.currentUserDefaultTool));
  1018. }, this);
  1019. if (callback) callback();
  1020. }.bind(this));
  1021. },
  1022. getToolResource: function(callback){
  1023. var check = function () {
  1024. var list = this.toolsGroupData.filter(function(o){
  1025. return o.name === this.currentUserDefaultTool
  1026. }.bind(this));
  1027. if( list.length < 1 )this.currentUserDefaultTool = "default";
  1028. callback();
  1029. }.bind(this);
  1030. this.getGroups(function(){
  1031. if(this.toolsGroupData && this.currentUserDefaultTool )check();
  1032. }.bind(this));
  1033. this.getDefaultTool(function(){
  1034. if(this.toolsGroupData && this.currentUserDefaultTool )check();
  1035. }.bind(this));
  1036. },
  1037. getGroups: function(callback){
  1038. if (this.toolsGroupData){
  1039. if (callback) callback();
  1040. }else{
  1041. var toolsGroupDataUrl = this.path+this.options.style+"/toolsGroup.json";
  1042. o2.JSON.get(toolsGroupDataUrl, function(responseJSON){
  1043. this.toolsGroupData = responseJSON;
  1044. if (callback) callback();
  1045. }.bind(this));
  1046. }
  1047. },
  1048. getDefaultTool: function(callback){
  1049. if( typeOf(this.currentUserDefaultTool) === "string" ){
  1050. if (callback) callback();
  1051. }else{
  1052. o2.UD.getDataJson("portalTools", function (json) {
  1053. this.currentUserDefaultTool = (json && json.defaultTool) || "default";
  1054. if (callback) callback();
  1055. }.bind(this));
  1056. }
  1057. },
  1058. setDefaultTool: function(defaultTools, callback){
  1059. o2.UD.getDataJson("portalTools", function (json) {
  1060. if(!json)json = {};
  1061. json.defaultTool = defaultTools;
  1062. o2.UD.putData("portalTools", json, function () {
  1063. if (callback) callback();
  1064. }.bind(this));
  1065. }.bind(this));
  1066. },
  1067. // loadTools: function(){
  1068. // var designer = this;
  1069. // this.getTools(function(){
  1070. // Object.each(this.toolsData, function(value, key){
  1071. // var toolNode = new Element("div", {
  1072. // "styles": this.css.toolbarToolNode,
  1073. // "title": value.text,
  1074. // "events": {
  1075. // "mouseover": function(e){
  1076. // try {
  1077. // this.setStyles(designer.css.toolbarToolNodeOver);
  1078. // }catch(e){
  1079. // this.setStyles(designer.css.toolbarToolNodeOverCSS2);
  1080. // };
  1081. // },
  1082. // "mouseout": function(e){
  1083. // try {
  1084. // this.setStyles(designer.css.toolbarToolNode);
  1085. // }catch(e){};
  1086. // },
  1087. // "mousedown": function(e){
  1088. // try {
  1089. // this.setStyles(designer.css.toolbarToolNodeDown);
  1090. // }catch(e){
  1091. // this.setStyles(designer.css.toolbarToolNodeDownCSS2);
  1092. // };
  1093. // },
  1094. // "mouseup": function(e){
  1095. // try {
  1096. // this.setStyles(designer.css.toolbarToolNodeUp);
  1097. // }catch(e){
  1098. // this.setStyles(designer.css.toolbarToolNodeUpCSS2);
  1099. // };
  1100. // }
  1101. // }
  1102. // }).inject(this.toolbarContentNode);
  1103. // toolNode.store("toolClass", value.className);
  1104. //
  1105. // var iconNode = new Element("div", {
  1106. // "styles": this.css.toolbarToolIconNode
  1107. // }).inject(toolNode);
  1108. // iconNode.setStyle("background-image", "url("+this.path+this.options.style+"/icon/"+value.icon+")");
  1109. //
  1110. // var textNode = new Element("div", {
  1111. // "styles": this.css.toolbarToolTextNode,
  1112. // "text": value.text
  1113. // });
  1114. // textNode.inject(toolNode);
  1115. //
  1116. // // var designer = this;
  1117. // toolNode.addEvent("mousedown", function(e){
  1118. //
  1119. // var className = this.retrieve("toolClass");
  1120. // designer.page.createModule(className, e);
  1121. // });
  1122. //
  1123. // this.tools.push(toolNode);
  1124. // }.bind(this));
  1125. // }.bind(this));
  1126. // },
  1127. // getTools: function(callback){
  1128. //
  1129. // if (this.toolsData){
  1130. // if (callback) callback();
  1131. // }else{
  1132. // var toolsDataUrl = this.path+this.options.style+"/tools.json";
  1133. // var r = new Request.JSON({
  1134. // url: toolsDataUrl,
  1135. // secure: false,
  1136. // async: false,
  1137. // method: "get",
  1138. // noCache: true,
  1139. // onSuccess: function(responseJSON, responseText){
  1140. // this.toolsData = responseJSON;
  1141. // if (callback) callback();
  1142. // }.bind(this),
  1143. // onError: function(text, error){
  1144. // debugger;
  1145. // this.notice("request tools data error: "+error, "error");
  1146. // }.bind(this)
  1147. // });
  1148. // r.send();
  1149. // }
  1150. // },
  1151. //resizeNode------------------------------------------------
  1152. resizeNodeLeftRight: function(){
  1153. var nodeSize = this.node.getSize();
  1154. this.toolbarNode.setStyle("height", ""+nodeSize.y+"px");
  1155. this.pageNode.setStyle("height", ""+nodeSize.y+"px");
  1156. this.propertyNode.setStyle("height", ""+nodeSize.y+"px");
  1157. //nodeSize = {"x": nodeSize.x, "y": nodeSize.y*0.6};
  1158. var pageToolbarMarginTop = this.pageToolbarNode.getStyle("margin-top").toFloat();
  1159. var pageToolbarMarginBottom = this.pageToolbarNode.getStyle("margin-bottom").toFloat();
  1160. var allPageToolberSize = this.pageToolbarNode.getComputedSize();
  1161. var y = nodeSize.y - allPageToolberSize.totalHeight - pageToolbarMarginTop - pageToolbarMarginBottom;
  1162. this.pageContentNode.setStyle("height", ""+y+"px");
  1163. var tabSize = this.designTab.tabNodeContainer.getComputedSize();
  1164. var tabMarginTop = this.designTab.tabNodeContainer.getStyle("margin-top").toFloat();
  1165. var tabMarginBottom = this.designTab.tabNodeContainer.getStyle("margin-bottom").toFloat();
  1166. y = y-tabSize.totalHeight-tabMarginTop-tabMarginBottom;
  1167. this.designTab.contentNodeContainer.setStyle("height", ""+y+"px");
  1168. if (this.designNode){
  1169. var designMarginTop = this.designNode.getStyle("margin-top").toFloat();
  1170. var designMarginBottom = this.designNode.getStyle("margin-bottom").toFloat();
  1171. y = y - designMarginTop - designMarginBottom;
  1172. this.designNode.setStyle("height", ""+y+"px");
  1173. }
  1174. var titleSize = this.toolbarTitleNode.getSize();
  1175. var titleMarginTop = this.toolbarTitleNode.getStyle("margin-top").toFloat();
  1176. var titleMarginBottom = this.toolbarTitleNode.getStyle("margin-bottom").toFloat();
  1177. var titlePaddingTop = this.toolbarTitleNode.getStyle("padding-top").toFloat();
  1178. var titlePaddingBottom = this.toolbarTitleNode.getStyle("padding-bottom").toFloat();
  1179. y = titleSize.y+titleMarginTop+titleMarginBottom+titlePaddingTop+titlePaddingBottom;
  1180. y = nodeSize.y-y;
  1181. this.toolbarGroupContentNode.setStyle("height", ""+y+"px");
  1182. var groupHeight = 0;
  1183. var contentHeight = y-groupHeight-5;
  1184. this.toolGroups.each(function(g){
  1185. g.setContentHeight(contentHeight);
  1186. });
  1187. //this.toolbarContentNode.setStyle("height", ""+y+"px");
  1188. titleSize = this.propertyTitleNode.getSize();
  1189. titleMarginTop = this.propertyTitleNode.getStyle("margin-top").toFloat();
  1190. titleMarginBottom = this.propertyTitleNode.getStyle("margin-bottom").toFloat();
  1191. titlePaddingTop = this.propertyTitleNode.getStyle("padding-top").toFloat();
  1192. titlePaddingBottom = this.propertyTitleNode.getStyle("padding-bottom").toFloat();
  1193. y = titleSize.y+titleMarginTop+titleMarginBottom+titlePaddingTop+titlePaddingBottom;
  1194. y = nodeSize.y-y;
  1195. this.propertyContentNode.setStyle("height", ""+y+"px");
  1196. this.propertyResizeBar.setStyle("height", ""+y+"px");
  1197. },
  1198. resizeNodeTopBottom: function(percent){
  1199. var nodeSize = this.node.getSize();
  1200. this.toolbarNode.setStyle("height", ""+nodeSize.y+"px");
  1201. var percentNumber = percent || 0.6;
  1202. var designerHeight = nodeSize.y*percentNumber;
  1203. var propertyHeight = nodeSize.y - designerHeight;
  1204. this.pageNode.setStyle("height", ""+designerHeight+"px");
  1205. this.propertyNode.setStyle("height", ""+propertyHeight+"px");
  1206. var pageToolbarMarginTop = this.pageToolbarNode.getStyle("margin-top").toFloat();
  1207. var pageToolbarMarginBottom = this.pageToolbarNode.getStyle("margin-bottom").toFloat();
  1208. var allPageToolberSize = this.pageToolbarNode.getComputedSize();
  1209. var y = designerHeight - allPageToolberSize.totalHeight - pageToolbarMarginTop - pageToolbarMarginBottom;
  1210. // this.pageContentNode.setStyle("height", ""+designerHeight+"px");
  1211. var tabSize = this.designTab.tabNodeContainer.getComputedSize();
  1212. var tabMarginTop = this.designTab.tabNodeContainer.getStyle("margin-top").toFloat();
  1213. var tabMarginBottom = this.designTab.tabNodeContainer.getStyle("margin-bottom").toFloat();
  1214. y = y-tabSize.totalHeight-tabMarginTop-tabMarginBottom;
  1215. this.designTab.contentNodeContainer.setStyle("height", ""+y+"px");
  1216. if (this.designNode){
  1217. var designMarginTop = this.designNode.getStyle("margin-top").toFloat();
  1218. var designMarginBottom = this.designNode.getStyle("margin-bottom").toFloat();
  1219. y = y - designMarginTop - designMarginBottom;
  1220. this.designNode.setStyle("height", ""+y+"px");
  1221. }
  1222. var titleSize = this.toolbarTitleNode.getSize();
  1223. var titleMarginTop = this.toolbarTitleNode.getStyle("margin-top").toFloat();
  1224. var titleMarginBottom = this.toolbarTitleNode.getStyle("margin-bottom").toFloat();
  1225. var titlePaddingTop = this.toolbarTitleNode.getStyle("padding-top").toFloat();
  1226. var titlePaddingBottom = this.toolbarTitleNode.getStyle("padding-bottom").toFloat();
  1227. y = titleSize.y+titleMarginTop+titleMarginBottom+titlePaddingTop+titlePaddingBottom;
  1228. y = nodeSize.y-y;
  1229. this.toolbarGroupContentNode.setStyle("height", ""+y+"px");
  1230. var groupHeight = 0;
  1231. // this.toolGroups.each(function(g){
  1232. // groupHeight += g.toolbarGroupTitleNode.getSize().y;
  1233. // });
  1234. var contentHeight = y-groupHeight-5;
  1235. this.toolGroups.each(function(g){
  1236. g.setContentHeight(contentHeight);
  1237. });
  1238. //this.toolbarContentNode.setStyle("height", ""+y+"px");
  1239. titleSize = this.propertyTitleNode.getSize();
  1240. titleMarginTop = this.propertyTitleNode.getStyle("margin-top").toFloat();
  1241. titleMarginBottom = this.propertyTitleNode.getStyle("margin-bottom").toFloat();
  1242. titlePaddingTop = this.propertyTitleNode.getStyle("padding-top").toFloat();
  1243. titlePaddingBottom = this.propertyTitleNode.getStyle("padding-bottom").toFloat();
  1244. y = titleSize.y+titleMarginTop+titleMarginBottom+titlePaddingTop+titlePaddingBottom;
  1245. y = propertyHeight-y;
  1246. this.propertyContentNode.setStyle("height", ""+y+"px");
  1247. this.propertyResizeBar.setStyle("height", ""+y+"px");
  1248. this.propertyDomContentArea.setStyle("height", ""+y+"px");
  1249. this.propertyDomScrollArea.setStyle("height", ""+(y-28)+"px");
  1250. this.historyScrollArea.setStyle("height", ""+(y-28)+"px");
  1251. this.propertyContentResizeNode.setStyle("height", ""+y+"px");
  1252. this.propertyContentArea.setStyle("height", ""+y+"px");
  1253. if (this.page){
  1254. if (this.page.currentSelectedModule){
  1255. if (this.page.currentSelectedModule.property){
  1256. var tab = this.page.currentSelectedModule.property.propertyTab;
  1257. if (tab){
  1258. var tabTitleSize = tab.tabNodeContainer.getSize();
  1259. tab.pages.each(function(page){
  1260. var topMargin = page.contentNodeArea.getStyle("margin-top").toFloat();
  1261. var bottomMargin = page.contentNodeArea.getStyle("margin-bottom").toFloat();
  1262. var tabContentNodeAreaHeight = y - topMargin - bottomMargin - tabTitleSize.y.toFloat()-15;
  1263. page.contentNodeArea.setStyle("height", tabContentNodeAreaHeight);
  1264. }.bind(this));
  1265. }
  1266. }
  1267. }
  1268. }
  1269. },
  1270. resizeNode: function(percent){
  1271. if (this.options.style=="bottom"){
  1272. this.resizeNodeTopBottom(percent);
  1273. this.setPropertyContentResizeBottom();
  1274. }else{
  1275. this.resizeNodeLeftRight(percent);
  1276. this.setPropertyContentResize();
  1277. }
  1278. },
  1279. //loadPage------------------------------------------
  1280. loadPage: function(){
  1281. this.getPageData(function(){
  1282. this.pcPage = new MWF.PCPage(this, this.designNode, {
  1283. "onPostLoad": function(){
  1284. this.fireEvent("postPageLoad");
  1285. }.bind(this)
  1286. });
  1287. this.pcPage.load(this.pageData);
  1288. this.page = this.pcPage;
  1289. }.bind(this));
  1290. },
  1291. getPageData: function(callback){
  1292. if (!this.options.id){
  1293. if (this.options.templateId){
  1294. this.loadNewPageDataFromTemplate(callback);
  1295. }else{
  1296. this.loadNewPageData(callback);
  1297. }
  1298. }else{
  1299. this.loadPageData(callback);
  1300. }
  1301. },
  1302. loadNewPageData: function(callback){
  1303. var url = "../x_component_portal_PageDesigner/Module/Page/template/"+this.options.template;
  1304. MWF.getJSON(url, {
  1305. "onSuccess": function(obj){
  1306. this.pageData = obj.pcData;
  1307. this.pageData.id="";
  1308. this.pageData.isNewPage = true;
  1309. this.pageMobileData = obj.mobileData;
  1310. this.pageMobileData.id="";
  1311. this.pageMobileData.isNewPage = true;
  1312. if (callback) callback();
  1313. }.bind(this),
  1314. "onerror": function(text){
  1315. this.notice(text, "error");
  1316. }.bind(this),
  1317. "onRequestFailure": function(xhr){
  1318. this.notice(xhr.responseText, "error");
  1319. }.bind(this)
  1320. });
  1321. },
  1322. getPageTemplate : function(templateId, callback){
  1323. this.actions.getPageTemplate(templateId, function(page){
  1324. if(callback)callback(page);
  1325. }.bind(this))
  1326. },
  1327. loadNewPageDataFromTemplate: function(callback){
  1328. this.getPageTemplate(this.options.templateId, function(page){
  1329. if (page){
  1330. this.pageData = JSON.decode(MWF.decodeJsonString(page.data.data));
  1331. this.pageData.isNewPage = true;
  1332. this.pageData.json.id = "";
  1333. if (page.data.mobileData){
  1334. this.pageMobileData = JSON.decode(MWF.decodeJsonString(page.data.mobileData));
  1335. this.pageMobileData.isNewPage = true;
  1336. this.pageMobileData.json.id = "";
  1337. }else{
  1338. this.pageMobileData = Object.clone(this.pageData);
  1339. }
  1340. if (callback) callback();
  1341. }
  1342. }.bind(this));
  1343. },
  1344. getPage : function(id, callback){
  1345. this.actions.getPage(id, function(page){
  1346. if(callback)callback(page);
  1347. }.bind(this))
  1348. },
  1349. getApplication : function(portal, callback){
  1350. this.actions.getApplication(portal, function(page){
  1351. if(callback)callback(page);
  1352. }.bind(this))
  1353. },
  1354. loadPageData: function(callback){
  1355. this.getPage(this.options.id, function(page){
  1356. if (page){
  1357. this.pageData = JSON.decode(MWF.decodeJsonString(page.data.data));
  1358. this.pageData.isNewPage = false;
  1359. this.pageData.json.id = page.data.id;
  1360. if (page.data.mobileData){
  1361. this.pageMobileData = JSON.decode(MWF.decodeJsonString(page.data.mobileData));
  1362. this.pageMobileData.isNewPage = false;
  1363. this.pageMobileData.json.id = page.data.id;
  1364. }else{
  1365. this.pageMobileData = Object.clone(this.pageData);
  1366. }
  1367. this.setTitle(this.options.appTitle + "-"+this.pageData.json.name);
  1368. if (this.taskitem) this.taskitem.setText(this.options.appTitle + "-"+this.pageData.json.name);
  1369. this.options.appTitle = this.options.appTitle + "-"+this.pageData.json.name;
  1370. if (!this.application){
  1371. this.getApplication(page.data.portal, function(json){
  1372. this.application = {"name": json.data.name, "id": json.data.id};
  1373. if (callback) callback();
  1374. }.bind(this));
  1375. }else{
  1376. if (callback) callback();
  1377. }
  1378. }
  1379. }.bind(this));
  1380. },
  1381. getFieldList: function(){
  1382. dataTypes = {
  1383. "string": ["htmledit", "radio", "select", "textarea", "textfield"],
  1384. "person": ["personfield","org"],
  1385. "date": ["calender"],
  1386. "number": ["number"],
  1387. "array": ["checkbox"]
  1388. };
  1389. fieldList = [];
  1390. this.pcPage.moduleList.each(function(moudle){
  1391. var key = "";
  1392. for (k in dataTypes){
  1393. if (dataTypes[k].indexOf(moudle.moduleName.toLowerCase())!=-1){
  1394. key = k;
  1395. break;
  1396. }
  1397. }
  1398. if (key){
  1399. fieldList.push({
  1400. "name": moudle.json.id,
  1401. "dataType": key
  1402. });
  1403. }
  1404. }.bind(this));
  1405. return fieldList;
  1406. },
  1407. getWidgetList: function(data){
  1408. widgetList = [];
  1409. Object.each(data.moduleList, function(moudle){
  1410. if (moudle.type.toLowerCase()=="widget"){
  1411. if (moudle.widgetType == "select" && moudle.widgetSelected ){
  1412. widgetList.push(moudle.widgetSelected);
  1413. }
  1414. }
  1415. }.bind(this));
  1416. return widgetList;
  1417. },
  1418. saveForm: function(){
  1419. this.savePage()
  1420. },
  1421. _savePage : function(pcData, mobileData, fieldList, success, failure ){
  1422. this.actions.savePage(pcData, mobileData, fieldList, function(responseJSON){
  1423. success(responseJSON)
  1424. }.bind(this), function(xhr, text, error){
  1425. failure(xhr, text, error)
  1426. }.bind(this));
  1427. },
  1428. savePage: function(){
  1429. if (!this.isSave){
  1430. var pcData, mobileData;
  1431. if (this.pcPage){
  1432. this.pcPage._getPageData();
  1433. this.pcPage.json.widgetList = this.getWidgetList(this.pcPage.json);
  1434. pcData = this.pcPage.data;
  1435. }
  1436. if (this.mobilePage){
  1437. this.mobilePage._getPageData();
  1438. this.mobilePage.json.widgetList = this.getWidgetList(this.mobilePage.json);
  1439. mobileData = this.mobilePage.data;
  1440. }else{
  1441. if (this.pageMobileData) mobileData = this.pageMobileData;
  1442. }
  1443. this.isSave = true;
  1444. var fieldList = this.getFieldList();
  1445. this._savePage(pcData, mobileData, fieldList, function(responseJSON){
  1446. this.notice(MWF.APPPOD.LP.notice["save_success"], "ok", null, {x: "left", y:"bottom"});
  1447. if (!this.pcPage.json.name) this.pcPage.treeNode.setText("<"+this.json.type+"> "+this.json.id);
  1448. this.pcPage.treeNode.setTitle(this.pcPage.json.id);
  1449. this.pcPage.node.set("id", this.pcPage.json.id);
  1450. if (this.mobilePage){
  1451. if (!this.mobilePage.json.name) this.mobilePage.treeNode.setText("<"+this.mobilePage.json.type+"> "+this.mobilePage.json.id);
  1452. this.mobilePage.treeNode.setTitle(this.mobilePage.json.id);
  1453. this.mobilePage.node.set("id", this.mobilePage.json.id+"_"+this.options.mode);
  1454. }
  1455. var name = this.pcPage.json.name;
  1456. if (this.pcPage.data.isNewPage) this.setTitle(this.options.appTitle + "-"+name);
  1457. this.pcPage.data.isNewPage = false;
  1458. if (this.mobilePage) this.mobilePage.data.isNewPage = false;
  1459. this.options.desktopReload = true;
  1460. this.options.id = this.pcPage.json.id;
  1461. if (pcData) pcData.isNewPage = false;
  1462. if (mobileData) mobileData.isNewPage = false;
  1463. this.isSave = false;
  1464. }.bind(this), function(xhr, text, error){
  1465. this.isSave = false;
  1466. var errorText = error+":"+text;
  1467. if (xhr) errorText = xhr.responseText;
  1468. MWF.xDesktop.notice("error", {x: "right", y:"top"}, "request json error: "+errorText);
  1469. }.bind(this));
  1470. }else{
  1471. MWF.xDesktop.notice("info", {x: "right", y:"top"}, this.lp.isSave);
  1472. }
  1473. },
  1474. previewPage: function(){
  1475. this.savePage();
  1476. this.page.preview();
  1477. },
  1478. printPage: function(){
  1479. this.previewPage();
  1480. },
  1481. pageExplode: function(){
  1482. this.page.explode();
  1483. },
  1484. pageImplode: function(){
  1485. this.page.implode();
  1486. },
  1487. htmlImplode: function(){
  1488. this.page.implodeHTML();
  1489. },
  1490. officeImplode: function(){
  1491. this.page.implodeOffice();
  1492. },
  1493. pageHelp: function(){
  1494. //widnow.open("http://www.o2oa.io");
  1495. },
  1496. recordStatus: function(){
  1497. return {"id": this.options.id};
  1498. },
  1499. showFormVersion: function(){
  1500. this.page.showFormVersion();
  1501. },
  1502. onPostClose: function(){
  1503. if (this.pcPage){
  1504. MWF.release(this.pcPage.moduleList);
  1505. MWF.release(this.pcPage.moduleNodeList);
  1506. MWF.release(this.pcPage.moduleContainerNodeList);
  1507. MWF.release(this.pcPage.moduleElementNodeList);
  1508. MWF.release(this.pcPage.moduleComponentNodeList);
  1509. MWF.release(this.pcPage);
  1510. }
  1511. if (this.mobilePage){
  1512. MWF.release(this.mobilePage.moduleList);
  1513. MWF.release(this.mobilePage.moduleNodeList);
  1514. MWF.release(this.mobilePage.moduleContainerNodeList);
  1515. MWF.release(this.mobilePage.moduleElementNodeList);
  1516. MWF.release(this.mobilePage.moduleComponentNodeList);
  1517. MWF.release(this.mobilePage);
  1518. }
  1519. },
  1520. setTemplatePageNode: function(pageNode){
  1521. var html = "<table align=\"center\" width=\"100%\" height=\"90%\" border=\"0\" cellPadding=\"0\" cellSpacing=\"0\">" +
  1522. "<tr><td colSpan=\"2\" style=\"height: 50px; line-height: 60px; text-align: center; font-size: 24px; font-weight: bold\">" +
  1523. this.lp.saveTemplate+"</td></tr>" +
  1524. "<tr><td style=\"height: 40px;\" width=\"80px\">" +this.lp.templateName+"</td><td>"+
  1525. "<input value=\""+this.pcPage.json.name+"\" type=\"text\" style=\"width: 98%; height: 22px; border: 1px solid #cccccc\"/>"+"</td></tr>" +
  1526. "<tr><td style=\"height: 40px;\">" +this.lp.templateCategory+"</td><td>"+
  1527. "<select style=\"width: 30%; height: 24px; border: 1px solid #cccccc\"></select>"+
  1528. "<input type=\"text\" style=\"width: 68%; height: 22px; border: 1px solid #cccccc\"/>"+"</td></tr>" +
  1529. "<tr><td style=\"height: 40px;\">" +this.lp.templateDescription+"</td><td>"+
  1530. "<textarea type=\"text\" style=\"width: 98%; height: 44px; border: 1px solid #cccccc\">"+this.pcPage.json.description+"</textarea>"+"</td></tr>" +
  1531. "<tr><td colSpan=\"2\" id=\"page_templatePreview\">" +
  1532. "<div style=\"position: relative; width: 180px; height: 180px; margin: 20px auto 0px auto; overflow: hidden\"></div>" +
  1533. "</td></tr>" +
  1534. "</table>";
  1535. pageNode.set("html", html);
  1536. var tds = pageNode.getElements("td");
  1537. var iconNode = tds[tds.length-1].getFirst();
  1538. var previewNode = this.pcPage.node.clone();
  1539. previewNode.setStyles({
  1540. "transform-origin": "0px 0px",
  1541. "transform": "scale(0.15,0.15)",
  1542. "position": "absolute",
  1543. "top": "0px",
  1544. "left": "0px"
  1545. }).inject(iconNode);
  1546. return iconNode;
  1547. },
  1548. setCategorySelect: function(categorySelect){
  1549. if (categorySelect){
  1550. new Element("option", {"value": "$newCategory","text": this.lp.newCategory}).inject(categorySelect);
  1551. this.actions.listPageTemplateCategory(function(json){
  1552. json.data.each(function(category){
  1553. new Element("option", {"value": category.name,"text": category.name}).inject(categorySelect);
  1554. }.bind(this));
  1555. }.bind(this));
  1556. }
  1557. },
  1558. setTemplateActions: function(markNode, areaNode, pageNode, iconNode, nameNode, categorySelect, newCategoryNode, descriptionNode){
  1559. var actionAreaNode= new Element("div", {
  1560. "styles": this.css.templateActionNode
  1561. }).inject(pageNode);
  1562. var cancelActionNode = new Element("div", {
  1563. "styles": this.css.templateCancelActionNode,
  1564. "text": this.lp.cancel,
  1565. "events":{
  1566. "click": function(){
  1567. markNode.destroy();
  1568. areaNode.destroy();
  1569. }
  1570. }
  1571. }).inject(actionAreaNode);
  1572. var saveActionNode = new Element("div", {
  1573. "styles": this.css.templateSaveActionNode,
  1574. "text": this.lp.save,
  1575. "events":{
  1576. "click": function(){
  1577. this.saveTemplate(markNode, areaNode, iconNode, nameNode, categorySelect, newCategoryNode, descriptionNode);
  1578. }.bind(this)
  1579. }
  1580. }).inject(actionAreaNode);
  1581. },
  1582. addPageTemplate : function(pcData, mobileData, data, success, failure){
  1583. this.actions.addPageTemplate( pcData, mobileData, data, function(json){
  1584. if(success)success(json);
  1585. }.bind(this), function(xhr, text, error){
  1586. if(failure)failure(xhr, text, error);
  1587. }.bind(this))
  1588. },
  1589. saveTemplate: function(markNode, areaNode, iconNode, nameNode, categorySelect, newCategoryNode, descriptionNode){
  1590. var pcData, mobileData;
  1591. if (this.pcPage){
  1592. this.pcPage._getPageData();
  1593. pcData = this.pcPage.data;
  1594. }
  1595. if (this.mobilePage){
  1596. this.mobilePage._getPageData();
  1597. mobileData = this.mobilePage.data;
  1598. }
  1599. var name = nameNode.get("value");
  1600. var category = (categorySelect.options[categorySelect.selectedIndex].value=="$newCategory") ? newCategoryNode.get("value") : categorySelect.options[categorySelect.selectedIndex].value;
  1601. var description = descriptionNode.get("value");
  1602. if (!name){
  1603. this.notice(MWF.APPPOD.LP.notice["saveTemplate_inputName"], "error", nameNode, {x: "left", y:"top"});
  1604. return false;
  1605. }
  1606. if (categorySelect.options[categorySelect.selectedIndex].value=="$newCategory" && !newCategoryNode.get("value")){
  1607. this.notice(MWF.APPPOD.LP.notice["saveTemplate_inputCategory"], "error", categorySelect, {x: "left", y:"top"});
  1608. return false;
  1609. }
  1610. var data = {
  1611. "name": name,
  1612. "category": category,
  1613. "description": description,
  1614. "outline": iconNode.get("html")
  1615. };
  1616. this.addPageTemplate(pcData, mobileData, data, function(){
  1617. this.notice(MWF.APPPOD.LP.notice["saveTemplate_success"], "ok", null, {x: "left", y:"bottom"});
  1618. markNode.destroy();
  1619. areaNode.destroy();
  1620. }.bind(this), function(xhr, text, error){
  1621. var errorText = error+":"+text;
  1622. if (xhr) errorText = xhr.responseText;
  1623. MWF.xDesktop.notice("error", {x: "right", y:"top"}, "request json error: "+errorText);
  1624. });
  1625. },
  1626. createTemplateSaveNode: function(){
  1627. var markNode = new Element("div", {
  1628. "styles": this.css.templateMarkNode,
  1629. "events": {
  1630. "mouseover": function(e){e.stopPropagation();},
  1631. "mouseout": function(e){e.stopPropagation();}
  1632. }
  1633. }).inject(this.content);
  1634. var areaNode = new Element("div", {
  1635. "styles": this.css.templateAreaNode
  1636. }).inject(this.content);
  1637. var createNode = new Element("div", {
  1638. "styles": this.css.templateInfoNode
  1639. }).inject(areaNode);
  1640. var pageNode = new Element("div", {
  1641. "styles": this.css.templatePageNode
  1642. }).inject(createNode);
  1643. var iconNode = this.setTemplatePageNode(pageNode);
  1644. var nodes = pageNode.getElements("input");
  1645. var nameNode = nodes[0];
  1646. var newCategoryNode = nodes[1];
  1647. var descriptionNode = pageNode.getElement("textarea");
  1648. var categorySelect = pageNode.getElement("select");
  1649. this.setCategorySelect(categorySelect);
  1650. this.setTemplateActions(markNode, areaNode, pageNode, iconNode, nameNode, categorySelect, newCategoryNode, descriptionNode);
  1651. },
  1652. savePageAsTemplate: function(){
  1653. if (!this.isSave){
  1654. this.createTemplateSaveNode();
  1655. }else{
  1656. MWF.xDesktop.notice("info", {x: "right", y:"top"}, this.lp.isSave);
  1657. }
  1658. },
  1659. styleBrush: function(status, bt){
  1660. if (status==="on"){
  1661. var module = this.page.currentSelectedModule;
  1662. if (module && module.json.type!=="Form"){
  1663. this.page.brushStyle = module.json.styles;
  1664. this.brushCursor = new Element("div", {"styles": {
  1665. "position": "absolute",
  1666. "width": "16px",
  1667. "height": "16px",
  1668. "z-index": 20000,
  1669. "background": "url("+this.path+this.options.style+"/pageToolbar/wand.png)"
  1670. }}).inject(this.content);
  1671. this.brushCursorMoveFun = this.brushCursorMove.bind(this);
  1672. this.contentPosition = this.content.getPosition();
  1673. this.content.addEvent("mousemove", this.brushCursorMoveFun);
  1674. //this.designNode.setStyle("cursor", "url(/"+this.path+this.options.style+"/pageToolbar/brush.png)");
  1675. }else{
  1676. bt.off();
  1677. }
  1678. }else{
  1679. this.page.brushStyle = null;
  1680. if (this.brushCursorMoveFun) this.content.removeEvent("mousemove", this.brushCursorMoveFun);
  1681. if (this.brushCursor){
  1682. this.brushCursor.destroy();
  1683. this.brushCursor = null;
  1684. }
  1685. }
  1686. },
  1687. brushCursorMove: function(e){
  1688. if (this.brushCursor){
  1689. // var x = e.event.layerX+10;
  1690. // var y = e.event.layerY+10;
  1691. var x = e.page.x-this.contentPosition.x+10;
  1692. var y = e.page.y-this.contentPosition.y+10;
  1693. this.brushCursor.setStyles({
  1694. "left": ""+x+"px",
  1695. "top": ""+y+"px"
  1696. });
  1697. }
  1698. },
  1699. checkDatatemplateRelativeId: function( json, idMap ){
  1700. ["outerAddActionId","outerDeleteActionId","outerSelectAllId",
  1701. "addActionId","deleteActionId","sequenceId","selectorId"].each(function(key){
  1702. var str = json[key];
  1703. if(str){
  1704. var strArr;
  1705. if( str.indexOf("/") > -1 ) {
  1706. strArr = str.split("/");
  1707. }else if(str.indexOf(".*.") > -1){
  1708. strArr = str.split(".*.");
  1709. }
  1710. if(strArr){
  1711. strArr = strArr.map(function (s) {
  1712. return idMap[s] || s;
  1713. });
  1714. json[key] = strArr.join("/");
  1715. }else{
  1716. if( str && idMap[str] ){
  1717. json[key] = idMap[str];
  1718. }
  1719. }
  1720. }
  1721. }.bind(this));
  1722. }
  1723. });
  1724. MWF.xApplication.portal.PageDesigner.ToolsGroup = new Class({
  1725. Implements: [Events],
  1726. initialize: function(data, app, showing){
  1727. this.data = data;
  1728. this.app = app;
  1729. this.css = this.app.css;
  1730. this.tools = [];
  1731. this.showing = showing;
  1732. this.load();
  1733. },
  1734. load: function(){
  1735. this.toolbarGroupNode = new Element("div", {
  1736. "styles": this.css.toolbarGroupNode,
  1737. }).inject(this.app.toolbarGroupContentNode);
  1738. this.toolbarContentNode = new Element("div", {
  1739. "styles": this.css.toolbarContentNode,
  1740. }).inject(this.toolbarGroupNode);
  1741. this.loadTools();
  1742. if (this.toolbarContentNode){
  1743. this.app.setScrollBar(this.toolbarContentNode, null, {
  1744. "V": {"x": 0, "y": 0},
  1745. "H": {"x": 0, "y": 0}
  1746. }, function(scrollBar){
  1747. this.scrollBar = scrollBar;
  1748. }.bind(this));
  1749. }
  1750. this.toolbarContentNode.setStyle("height", "0px");
  1751. this.toolbarContentNode.hide();
  1752. var memuItem = this.app.categoryActionMenu.addMenuItem(this.data.text, "click", function(){this.show();}.bind(this));
  1753. },
  1754. setContentHeight: function(height){
  1755. this.height = height;
  1756. if (this.isShow){
  1757. this.toolbarContentNode.setStyle("height", ""+this.height+"px");
  1758. }
  1759. },
  1760. show: function(notSetDefault){
  1761. if (this.app.currentToolGroup != this){
  1762. if (this.app.currentToolGroup) this.app.currentToolGroup.hide();
  1763. this.toolbarContentNode.show();
  1764. this.toolbarContentNode.setStyle("height", this.height);
  1765. if (this.scrollBar && this.scrollBar.scrollVAreaNode) this.scrollBar.scrollVAreaNode.show();
  1766. this.app.currentToolGroup = this;
  1767. this.isShow = true;
  1768. if (this.app.toolbarMode=="all") this.app.toolbarTitleNode.set("text", this.data.text);
  1769. if(!notSetDefault)this.app.setDefaultTool( this.data.name );
  1770. }
  1771. },
  1772. hide: function(){
  1773. if (this.app.currentToolGroup==this) this.app.currentToolGroup = null;
  1774. this.toolbarContentNode.hide();
  1775. if (this.scrollBar && this.scrollBar.scrollVAreaNode) this.scrollBar.scrollVAreaNode.hide();
  1776. this.isShow = false;
  1777. },
  1778. loadTools: function(){
  1779. var designer = this.app;
  1780. var group = this;
  1781. this.getTools(function(){
  1782. Object.each(this.toolsData, function(value, key){
  1783. var toolNode = new Element("div", {
  1784. "styles": this.css.toolbarToolNode,
  1785. "title": value.text,
  1786. "events": {
  1787. "mouseover": function(e){
  1788. try {
  1789. this.setStyles(designer.css.toolbarToolNodeOver);
  1790. }catch(e){
  1791. this.setStyles(designer.css.toolbarToolNodeOverCSS2);
  1792. };
  1793. },
  1794. "mouseout": function(e){
  1795. try {
  1796. this.setStyles(designer.css.toolbarToolNode);
  1797. }catch(e){};
  1798. },
  1799. "mousedown": function(e){
  1800. try {
  1801. this.setStyles(designer.css.toolbarToolNodeDown);
  1802. }catch(e){
  1803. this.setStyles(designer.css.toolbarToolNodeDownCSS2);
  1804. };
  1805. },
  1806. "mouseup": function(e){
  1807. try {
  1808. this.setStyles(designer.css.toolbarToolNodeUp);
  1809. }catch(e){
  1810. this.setStyles(designer.css.toolbarToolNodeUpCSS2);
  1811. };
  1812. }
  1813. }
  1814. }).inject(this.toolbarContentNode);
  1815. toolNode.store("toolClass", value.className);
  1816. var iconNode = new Element("div", {
  1817. "styles": this.css.toolbarToolIconNode
  1818. }).inject(toolNode);
  1819. if (value.icon) iconNode.setStyle("background-image", "url("+this.app.path+this.app.options.style+"/icon/"+value.icon+")");
  1820. if (value.fontIcon){
  1821. iconNode.addClass("mainColor_color");
  1822. iconNode.set("html", "<i class=\""+value.fontIcon+"\"></i>");
  1823. }
  1824. var textNode = new Element("div.o2formModuleTools", {
  1825. "styles": this.css.toolbarToolTextNode,
  1826. "text": value.text
  1827. });
  1828. textNode.inject(toolNode);
  1829. toolNode.addEvent("mousedown", function(e){
  1830. var className = this.retrieve("toolClass");
  1831. designer.page.createModule(className, e, group.data.name);
  1832. });
  1833. this.tools.push(toolNode);
  1834. }.bind(this));
  1835. //if (this.data.name==="default") this.show();
  1836. if( this.showing )this.show( true );
  1837. }.bind(this));
  1838. },
  1839. getTools: function(callback){
  1840. if (this.toolsData){
  1841. if (callback) callback();
  1842. }else{
  1843. var toolsDataUrl = this.app.path+this.app.options.style+"/"+this.data.json;
  1844. o2.JSON.get(toolsDataUrl, function(responseJSON){
  1845. this.toolsData = responseJSON;
  1846. if (!this.app.toolsData){
  1847. this.app.toolsData = this.toolsData;
  1848. }else{
  1849. this.app.toolsData = Object.merge(this.app.toolsData, this.toolsData)
  1850. }
  1851. if (callback) callback();
  1852. }.bind(this));
  1853. }
  1854. },
  1855. });