Main.js 84 KB

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