Page.js 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983
  1. MWF.xApplication.portal.PageDesigner.Module = MWF.xApplication.portal.PageDesigner.Module || {};
  2. MWF.require("MWF.widget.Common", null, false);
  3. MWF.xApplication.portal.PageDesigner.Module.Page = MWF.PCPage = new Class({
  4. Extends: MWF.widget.Common,
  5. Implements: [Options, Events],
  6. options: {
  7. "style": "default",
  8. "propertyPath": "../x_component_portal_PageDesigner/Module/Page/page.html",
  9. "mode": "PC",
  10. "fields": ["Calendar", "Checkbox", "Datagrid", "Datagrid$Title", "Datagrid$Data", "Htmleditor", "Number", "Office", "Orgfield", "Org", "Personfield", "Radio", "Select", "Textarea", "Textfield"],
  11. "injectActions" : [
  12. {
  13. "name" : "top",
  14. "styles" : "injectActionTop",
  15. "event" : "click",
  16. "action" : "injectTop",
  17. "title": MWF.APPPD.LP.formAction["insertTop"]
  18. },
  19. {
  20. "name" : "bottom",
  21. "styles" : "injectActionBottom",
  22. "event" : "click",
  23. "action" : "injectBottom",
  24. "title": MWF.APPPD.LP.formAction["insertBottom"]
  25. }
  26. ]
  27. },
  28. initializeBase: function(options){
  29. this.setOptions(options);
  30. this.path = "../x_component_portal_PageDesigner/Module/Page/";
  31. this.cssPath = "../x_component_portal_PageDesigner/Module/Page/"+this.options.style+"/css.wcss";
  32. this._loadCss();
  33. },
  34. initialize: function(designer, container, options){
  35. this.initializeBase(options);
  36. this.container = null;
  37. this.page = this;
  38. this.form = this;
  39. this.moduleType = "page";
  40. this.moduleList = [];
  41. this.moduleNodeList = [];
  42. this.moduleContainerNodeList = [];
  43. this.moduleElementNodeList = [];
  44. this.moduleComponentNodeList = [];
  45. // this.moduleContainerList = [];
  46. this.dataTemplate = {};
  47. this.designer = designer;
  48. this.container = container;
  49. this.selectedModules = [];
  50. },
  51. reload: function(data){
  52. this.moduleList.each(function(module){
  53. if (module.property){
  54. module.property.destroy();
  55. }
  56. }.bind(this));
  57. if (this.property) this.property.destroy();
  58. this.property = null;
  59. this.moduleList = [];
  60. this.moduleNodeList = [];
  61. this.moduleContainerNodeList = [];
  62. this.moduleElementNodeList = [];
  63. this.moduleComponentNodeList = [];
  64. this.dataTemplate = {};
  65. this.selectedModules = [];
  66. this.container.empty();
  67. if (this.treeNode){
  68. this.domTree.empty();
  69. this.domTree.node.destroy();
  70. this.domTree = null;
  71. this.treeNode = null;
  72. }
  73. this.currentSelectedModule = null;
  74. this.propertyMultiTd = null;
  75. if (this.autoSaveTimerID) window.clearInterval(this.autoSaveTimerID);
  76. this.load(data);
  77. },
  78. load : function(data){
  79. this.data = data;
  80. this.json = data.json;
  81. this.html = data.html;
  82. this.json.mode = this.options.mode;
  83. if (!this.json.css) this.json.css = {"code":""};
  84. this.isNewPage = (this.json.id) ? false : true;
  85. if (this.isNewPage) this.checkUUID();
  86. if(this.designer.application) this.data.json.applicationName = this.designer.application.name;
  87. if(this.designer.application) this.data.json.application = this.designer.application.id;
  88. this.container.set("html", this.html);
  89. this.loadStylesList(function(){
  90. var oldStyleValue = "";
  91. if ((!this.json.pageStyleType) || !this.stylesList[this.json.pageStyleType]) this.json.pageStyleType="blue-simple";
  92. if (this.options.mode=="Mobile"){
  93. if (this.json.pageStyleType != "defaultMobile"){
  94. oldStyleValue = this.json.pageStyleType;
  95. this.json.pageStyleType = "defaultMobile";
  96. }
  97. }
  98. this.templateStyles = (this.stylesList && this.json.pageStyleType) ? this.stylesList[this.json.pageStyleType] : null;
  99. this.loadDomModules();
  100. if (this.json.pageStyleType){
  101. if (this.stylesList[this.json.pageStyleType]){
  102. if (this.stylesList[this.json.pageStyleType]["page"]){
  103. this.setTemplateStyles(this.stylesList[this.json.pageStyleType]["page"]);
  104. }
  105. }
  106. }
  107. this.setCustomStyles();
  108. this.node.setProperties(this.json.properties);
  109. this.setNodeEvents();
  110. if (this.options.mode=="Mobile"){
  111. if (oldStyleValue) this._setEditStyle("pageStyleType", null, oldStyleValue);
  112. }
  113. this.selected();
  114. this.autoSave();
  115. this.designer.addEvent("queryClose", function(){
  116. if (this.autoSaveTimerID) window.clearInterval(this.autoSaveTimerID);
  117. }.bind(this));
  118. this.fireEvent("postLoad");
  119. }.bind(this));
  120. },
  121. removeStyles: function(from, to){
  122. if (this.json[to]){
  123. Object.each(from, function(style, key){
  124. if (this.json[to][key] && this.json[to][key]==style){
  125. delete this.json[to][key];
  126. }
  127. }.bind(this));
  128. }
  129. },
  130. copyStyles: function(from, to){
  131. if (!this.json[to]) this.json[to] = {};
  132. Object.each(from, function(style, key){
  133. if (!this.json[to][key]) this.json[to][key] = style;
  134. }.bind(this));
  135. },
  136. clearTemplateStyles: function(styles){
  137. if (styles){
  138. if (styles.styles) this.removeStyles(styles.styles, "styles");
  139. if (styles.properties) this.removeStyles(styles.properties, "properties");
  140. }
  141. },
  142. setTemplateStyles: function(styles){
  143. if (styles.styles) this.copyStyles(styles.styles, "styles");
  144. if (styles.properties) this.copyStyles(styles.properties, "properties");
  145. },
  146. loadStylesList: function(callback){
  147. var stylesUrl = "../x_component_portal_PageDesigner/Module/Page/template/"+((this.options.mode=="Mobile") ? "styles": "styles")+".json";
  148. MWF.getJSON(stylesUrl,{
  149. "onSuccess": function(responseJSON){
  150. this.stylesList= responseJSON;
  151. if (callback) callback(this.stylesList);
  152. }.bind(this),
  153. "onRequestFailure": function(){
  154. this.stylesList = {};
  155. if (callback) callback(this.stylesList);
  156. }.bind(this),
  157. "onError": function(){
  158. this.stylesList = {};
  159. if (callback) callback(this.stylesList);
  160. }.bind(this)
  161. }
  162. );
  163. },
  164. autoSave: function(){
  165. this.autoSaveCheckNode = this.designer.pageToolbarNode.getElement("#MWFPageAutoSaveCheck");
  166. if (this.autoSaveCheckNode){
  167. this.autoSaveTimerID = window.setInterval(function(){
  168. if (this.autoSaveCheckNode.get("checked")){
  169. this.save();
  170. }
  171. }.bind(this), 60000);
  172. }
  173. },
  174. checkUUID: function(){
  175. this.designer.actions.getUUID(function(id){
  176. this.json.id = id;
  177. }.bind(this));
  178. },
  179. loadDomModules: function(){
  180. this.node = this.container.getFirst();
  181. this.node.set("id", this.json.id);
  182. this.node.setStyles(this.css.pageNode);
  183. this.node.store("module", this);
  184. var id = this.json.id.replace(/\-/g, "");
  185. this.node.addClass("css"+id);
  186. this.reloadCss();
  187. var y = this.container.getStyle("height");
  188. y = (y) ? y.toInt()-2 : this.container.getSize().y-2;
  189. this.node.setStyle("min-height", ""+y+"px");
  190. this.designer.addEvent("resize", function(){
  191. var y = this.container.getStyle("height");
  192. y = (y) ? y.toInt()-2 : this.container.getSize().y-2;
  193. this.node.setStyle("min-height", ""+y+"px");
  194. }.bind(this));
  195. this.loadDomTree();
  196. },
  197. loadDomTree: function(){
  198. MWF.require("MWF.widget.Tree", function(){
  199. this.domTree = new MWF.widget.Tree(this.designer.propertyDomArea, {"style": "domtree"});
  200. this.domTree.load();
  201. this.createPageTreeNode();
  202. this.parseModules(this, this.node);
  203. }.bind(this));
  204. },
  205. createPageTreeNode: function(){
  206. var text = "<"+this.json.type+"> "+this.json.name+" ["+this.options.mode+"] ";
  207. var o = {
  208. "expand": true,
  209. "title": this.json.id,
  210. "text": "<"+this.json.type+"> "+this.json.name+" ["+this.options.mode+"] ",
  211. "icon": (this.options.mode=="Mobile") ? "mobile.png": "pc.png"
  212. };
  213. o.action = function(){
  214. if (this.module) this.module.selected();
  215. };
  216. this.treeNode = this.domTree.appendChild(o);
  217. this.treeNode.setText(text);
  218. this.treeNode.module = this;
  219. },
  220. parseModules: function(parent, dom){
  221. var tmpDom = null;
  222. var subDom = dom.getFirst();
  223. while (subDom){
  224. if (subDom.get("MWFtype")){
  225. // var module = subDom.retrieve("module");
  226. // alert(subDom.get("id")+": "+module);
  227. // if (!module){
  228. var json = this.getDomjson(subDom);
  229. if (json) module = this.loadModule(json, subDom, parent);
  230. // }
  231. // if (module.moduleType=="container") this.parseModules(module, subDom);
  232. // }else{
  233. // this.parseModules(parent, subDom);
  234. }
  235. // else if (subDom.getFirst()){
  236. // subDom = subDom.getFirst();
  237. // this.parseModules(parent, subDom);
  238. // }else{
  239. // subDom = subDom.getNext();
  240. // }
  241. if (!json) tmpDom = subDom;
  242. subDom = subDom.getNext();
  243. if (tmpDom){
  244. tmpDom.destroy();
  245. tmpDom = null;
  246. }
  247. }
  248. },
  249. getDomjson: function(dom){
  250. var mwfType = dom.get("MWFtype");
  251. switch (mwfType) {
  252. case "page":
  253. return this.json;
  254. case "":
  255. return null;
  256. default:
  257. var id = dom.get("id");
  258. if (id){
  259. return this.json.moduleList[id];
  260. }else{
  261. return null;
  262. }
  263. }
  264. },
  265. loadModule: function(json, dom, parent){
  266. if (json) {
  267. var module = new MWF["PC" + json.type](this);
  268. module.load(json, dom, parent);
  269. return module;
  270. }
  271. },
  272. setNodeEvents: function(){
  273. this.node.addEvent("click", function(e){
  274. this.selected();
  275. }.bind(this));
  276. },
  277. createModuleImmediately: function( className, parentModule, relativeNode, position, selectDisabled, async ){
  278. var module;
  279. this.getTemplateData(className, function(data){
  280. var moduleData = Object.clone(data);
  281. module = new MWF["PC"+className](this);
  282. if( parentModule ){
  283. module.onDragModule = parentModule;
  284. if (!parentModule.Component) module.inContainer = parentModule;
  285. module.parentContainer = parentModule;
  286. module.nextModule = null;
  287. }
  288. module.createImmediately(moduleData, relativeNode, position, selectDisabled);
  289. }.bind(this), async);
  290. return module;
  291. },
  292. createModule: function(className, e){
  293. this.getTemplateData(className, function(data){
  294. var moduleData = Object.clone(data);
  295. var newTool = new MWF["PC"+className](this);
  296. newTool.create(moduleData, e);
  297. }.bind(this));
  298. },
  299. getTemplateData: function(className, callback, async){
  300. if (this.dataTemplate[className]){
  301. if (callback) callback(this.dataTemplate[className]);
  302. }else{
  303. var templateUrl = "../x_component_portal_PageDesigner/Module/"+className+"/template.json";
  304. MWF.getJSON(templateUrl, function(responseJSON, responseText){
  305. this.dataTemplate[className] = responseJSON;
  306. if (callback) callback(responseJSON);
  307. }.bind(this), async);
  308. }
  309. },
  310. selected: function(){
  311. if (this.currentSelectedModule){
  312. if (this.currentSelectedModule==this){
  313. return true;
  314. }else{
  315. this.currentSelectedModule.unSelected();
  316. }
  317. }
  318. if (this.propertyMultiTd){
  319. this.propertyMultiTd.hide();
  320. this.propertyMultiTd = null;
  321. }
  322. this.unSelectedMulti();
  323. this.currentSelectedModule = this;
  324. if (this.treeNode){
  325. this.treeNode.selectNode();
  326. }
  327. this.showProperty();
  328. // this.isFocus = true;
  329. },
  330. unSelectedMulti: function(){
  331. while (this.selectedModules.length){
  332. this.selectedModules[0].unSelectedMulti();
  333. }
  334. if (this.multimoduleActionsArea) this.multimoduleActionsArea.setStyle("display", "none");
  335. },
  336. unSelectAll: function(){
  337. },
  338. _beginSelectMulti: function(){
  339. if (this.currentSelectedModule) this.currentSelectedModule.unSelected();
  340. this.unSelectedMulti();
  341. this.noSelected = true;
  342. },
  343. _completeSelectMulti: function(){
  344. if (this.selectedModules.length<2){
  345. this.selectedModules[0].selected();
  346. }else{
  347. this._showMultiActions();
  348. }
  349. },
  350. createMultimoduleActionsArea: function(){
  351. this.multimoduleActionsArea = new Element("div", {
  352. styles: {
  353. "display": "none",
  354. // "width": 18*this.options.actions.length,
  355. "position": "absolute",
  356. "background-color": "#F1F1F1",
  357. "padding": "1px",
  358. "padding-right": "0px",
  359. "border": "1px solid #AAA",
  360. "box-shadow": "0px 2px 5px #999",
  361. "z-index": 10001
  362. }
  363. }).inject(this.page.container, "after");
  364. },
  365. _showMultiActions: function(){
  366. if (!this.multimoduleActionsArea) this.createMultimoduleActionsArea();
  367. var firstModule = this._getFirstMultiSelectedModule();
  368. if (firstModule){
  369. // var module = firstModule.module;
  370. var y = firstModule.position.y-25;
  371. var x = firstModule.position.x;
  372. this.multimoduleActionsArea.setPosition({"x": x, "y": y});
  373. this.multimoduleActionsArea.setStyle("display", "block");
  374. }
  375. },
  376. _getFirstMultiSelectedModule: function(){
  377. var firstModule = null;
  378. this.selectedModules.each(function(module){
  379. var position = module.node.getPosition(module.form.node.getOffsetParent());
  380. if (!firstModule){
  381. firstModule = {"module": module, "position": position};
  382. }else{
  383. if (position.y<firstModule.position.y){
  384. firstModule = {"module": module, "position": position};
  385. }else if (position.y==firstModule.position.y){
  386. if (position.x<firstModule.position.x){
  387. firstModule = {"module": module, "position": position};
  388. }
  389. }
  390. }
  391. });
  392. return firstModule;
  393. },
  394. showProperty: function(){
  395. if (!this.property){
  396. this.property = new MWF.xApplication.process.FormDesigner.Property(this, this.designer.propertyContentArea, this.designer, {
  397. "path": this.options.propertyPath,
  398. "onPostLoad": function(){
  399. this.property.show();
  400. }.bind(this)
  401. });
  402. this.property.load();
  403. }else{
  404. this.property.show();
  405. }
  406. },
  407. hideProperty: function(){
  408. if (this.property) this.property.hide();
  409. },
  410. unSelected: function(){
  411. this.currentSelectedModule = null;
  412. this.hideProperty();
  413. },
  414. _dragIn: function(module){
  415. if (!this.Component) module.inContainer = this;
  416. module.parentContainer = this;
  417. this.node.setStyles({"border": "1px solid #ffa200"});
  418. var copyNode = module._getCopyNode();
  419. copyNode.inject(this.node);
  420. },
  421. _dragOut: function(module){
  422. module.inContainer = null;
  423. module.parentContainer = null;
  424. this.node.setStyles(this.css.pageNode);
  425. this.node.setStyles(this.json.styles);
  426. var copyNode = module._getCopyNode();
  427. copyNode.setStyle("display", "none");
  428. },
  429. _dragDrop: function(module, flag){
  430. var f = flag || !(new Event(event)).control;
  431. if( f ){
  432. this.node.setStyles(this.css.pageNode);
  433. this.node.setStyles(this.json.styles);
  434. }
  435. },
  436. _showInjectAction : function( module ){
  437. if ( module.moveNode ){
  438. module.moveNode.setStyle("display","none");
  439. }
  440. //debugger;
  441. this.draggingModule = module;
  442. //if( !this.node.getFirst() ){
  443. // this.inject( "top" );
  444. // return;
  445. //}
  446. if( !this.injectActionArea )this._createInjectAction();
  447. this.injectActionArea.setStyle("display","block");
  448. this._setInjectActionAreaPosition();
  449. this.injectActionEffect = new Fx.Morph(this.injectActionArea, {
  450. duration: 200,
  451. transition: Fx.Transitions.Sine.easeOut
  452. });
  453. this.injectActionEffect.start(this.form.css.injectActionArea_to);
  454. },
  455. _hideInjectAction : function(){
  456. this.draggingModule = null;
  457. if( this.injectActionArea ){
  458. this.injectActionArea.setStyle("display","none");
  459. }
  460. },
  461. _createInjectAction : function(){
  462. var css = this.form.css;
  463. if( !this.injectActionArea ){
  464. this.injectActionArea = new Element("div", { styles: css.injectActionArea }).inject(this.form.container, "after");
  465. this.injectActionTopBGNode = new Element("div", { styles : css.injectActionTopBGNode }).inject( this.injectActionArea );
  466. this.injectActionLeftBGNode = new Element("div", { styles : css.injectActionLeftBGNode }).inject( this.injectActionArea );
  467. this.injectActionRightBGNode = new Element("div", { styles : css.injectActionRightBGNode }).inject( this.injectActionArea );
  468. this.injectActionBottomBGNode = new Element("div", { styles : css.injectActionBottomBGNode }).inject( this.injectActionArea );
  469. var injectActions = {};
  470. this.options.injectActions.each( function( action ){
  471. injectActions[ action.name ] = action;
  472. });
  473. if( injectActions.before )this._createInjectActionNode( injectActions.before, this.injectActionTopBGNode );
  474. if( injectActions.top )this._createInjectActionNode( injectActions.top, this.injectActionLeftBGNode );
  475. if( injectActions.bottom )this._createInjectActionNode( injectActions.bottom, this.injectActionRightBGNode );
  476. if( injectActions.after )this._createInjectActionNode( injectActions.after, this.injectActionBottomBGNode );
  477. new Element("div", {
  478. styles : css.injectActionCancelNode,
  479. events : {
  480. click : function(){
  481. this.draggingModule._dragCancel();
  482. this._dragDrop( this.node, true );
  483. this._hideInjectAction();
  484. }.bind(this),
  485. mouseover : function(){
  486. this.setStyles( css.injectActionCancelNode_over )
  487. },
  488. mouseout : function(){
  489. this.setStyles( css.injectActionCancelNode )
  490. }
  491. }
  492. }).inject(this.injectActionArea);
  493. }
  494. },
  495. _createInjectActionNode : function( action, relativeNode ){
  496. var actionNode = new Element("div", {
  497. "styles": this.css[action.styles],
  498. "title": action.title
  499. }).inject( this.injectActionArea );
  500. actionNode.addEvent(action.event, function(e){
  501. this[action.action](e);
  502. }.bind(this));
  503. actionNode.addEvents({
  504. "mouseover": function(e){
  505. relativeNode.setStyle("background", "#ddd");
  506. this.draggingModule.copyNode.setStyle("display","");
  507. this.draggingModule.copyNode.inject( this.node, action.name );
  508. }.bind(this),
  509. "mouseout": function(e){
  510. relativeNode.setStyle("background", "transparent");
  511. }.bind(this)
  512. });
  513. relativeNode.set("title",action.title);
  514. relativeNode.addEvent(action.event, function(e){
  515. this[action.action](e);
  516. }.bind(this));
  517. relativeNode.setStyle("cursor","pointer");
  518. relativeNode.addEvents({
  519. "mouseenter": function(e){
  520. relativeNode.setStyle("background", "#ddd");
  521. this.draggingModule.copyNode.setStyle("display","");
  522. this.draggingModule.copyNode.inject( this.node, action.name );
  523. }.bind(this),
  524. "mouseleave": function(e){
  525. relativeNode.setStyle("background", "transparent");
  526. //this.draggingModule.copyNode.setStyle("display","none");
  527. }.bind(this)
  528. });
  529. },
  530. _setInjectActionAreaPosition: function(){
  531. var e = new Event(event);
  532. var formOffset = this.node.getOffsetParent().getPosition();
  533. //var p = this.node.getPosition(this.form.node.getOffsetParent());
  534. var y = e.page.y - formOffset.y - 60;
  535. var x = e.page.x - formOffset.x - 60;
  536. this.injectActionArea.setPosition({"x": x, "y": y});
  537. },
  538. injectBefore : function( e ){
  539. this.inject( "before" )
  540. },
  541. injectAfter : function( e ){
  542. this.inject( "after" )
  543. },
  544. injectTop : function( e ){
  545. this.inject( "top" )
  546. },
  547. injectBottom : function( e ){
  548. this.inject( "bottom" )
  549. },
  550. inject : function( position ){
  551. if ( this.draggingModule.moveNode ){
  552. this.draggingModule.moveNode.setStyle("display","");
  553. }
  554. this.draggingModule._dragComplete( this.node, position );
  555. this._dragDrop( this.node, true );
  556. this._hideInjectAction();
  557. },
  558. _resetTreeNode: function(){},
  559. _clearNoId: function(node){
  560. var subNode = node.getFirst();
  561. while (subNode){
  562. var nextNode = subNode.getNext();
  563. if (subNode.get("MWFType")){
  564. if (!subNode.get("id")){
  565. subNode.destroy();
  566. }else{
  567. if (subNode) this._clearNoId(subNode);
  568. }
  569. }else{
  570. if (subNode) this._clearNoId(subNode);
  571. }
  572. subNode = nextNode;
  573. }
  574. },
  575. _getPageData: function(){
  576. this.fireEvent("queryGetPageData");
  577. var copy = this.node.clone(true, true);
  578. copy.clearStyles(true);
  579. this.fireEvent("postGetPageData");
  580. this._clearNoId(copy);
  581. var html = copy.outerHTML;
  582. copy.destroy();
  583. this.data.json.mode = this.options.mode;
  584. this.data.html = html;
  585. return this.data;
  586. },
  587. preview: function(){
  588. var url = "../x_desktop/portal.html?id="+this.json.application+"&page="+this.json.id;
  589. window.open(o2.filterUrl(url));
  590. // MWF.xDesktop.requireApp("process.FormDesigner", "Preview", function(){
  591. //
  592. // if (this.options.mode=="Mobile"){
  593. // this.previewBox = new MWF.xApplication.process.FormDesigner.Preview(this, {"size": {"x": "340", "y": 580, "layout":"mobile"}});
  594. // }else{
  595. // this.previewBox = new MWF.xApplication.process.FormDesigner.Preview(this);
  596. // }
  597. // this.previewBox.load();
  598. //
  599. // }.bind(this));
  600. },
  601. save: function(callback){
  602. this.designer.savePage();
  603. },
  604. explode: function(){
  605. this._getPageData();
  606. MWF.require("MWF.widget.Base64", null, false);
  607. var data = MWF.widget.Base64.encode(JSON.encode(this.data));
  608. MWF.require("MWF.widget.Panel", function(){
  609. var node = new Element("div");
  610. var size = this.designer.pageNode.getSize();
  611. var position = this.designer.pageNode.getPosition(this.designer.pageNode.getOffsetParent());
  612. var textarea = new Element("textarea", {
  613. "styles": {
  614. "border": "1px solid #999",
  615. "width": "770px",
  616. "margin-left": "14px",
  617. "margin-top": "14px",
  618. "height": "580px"
  619. },
  620. "text": JSON.encode(this.data)
  621. }).inject(node);
  622. this.explodePanel = new MWF.widget.Panel(node, {
  623. "style": "page",
  624. "isResize": false,
  625. "isMax": false,
  626. "title": "",
  627. "width": 800,
  628. "height": 660,
  629. "top": position.y,
  630. "left": position.x+3,
  631. "isExpand": false,
  632. "target": this.designer.node
  633. });
  634. this.explodePanel.load();
  635. }.bind(this));
  636. },
  637. implode: function(){
  638. MWF.xDesktop.requireApp("portal.PageDesigner", "Import", function(){
  639. MWF.FormImport.create("O2", this);
  640. }.bind(this));
  641. // MWF.require("MWF.widget.Panel", function(){
  642. // var node = new Element("div");
  643. // var size = this.designer.pageNode.getSize();
  644. // var position = this.designer.pageNode.getPosition(this.designer.pageNode.getOffsetParent());
  645. //
  646. // var textarea = new Element("textarea", {
  647. // "styles": {
  648. // "border": "1px solid #999",
  649. // "width": "770px",
  650. // "margin-left": "14px",
  651. // "margin-top": "14px",
  652. // "height": "540px"
  653. // }
  654. // }).inject(node);
  655. // var button = new Element("div", {
  656. // "styles": {
  657. // "margin": "10px auto",
  658. // "width": "100px",
  659. // "border-radius": "8px",
  660. // "height": "30px",
  661. // "line-height": "30px",
  662. // "text-align": "center",
  663. // "cursor": "pointer",
  664. // "color": "#ffffff",
  665. // "background-color": "#4c6b87"
  666. // },
  667. // "text": "OK"
  668. // }).inject(node);
  669. // button.addEvent("click", function(e){
  670. // var _self = this;
  671. // this.designer.confirm("warn", e, this.designer.lp.implodeConfirmTitle, this.designer.lp.implodeConfirmText, 300, 120, function(){
  672. // var str = textarea.get("value");
  673. // _self.implodeJsonData(str);
  674. // this.close();
  675. // }, function(){
  676. // this.close();
  677. // });
  678. // }.bind(this));
  679. //
  680. // this.implodePanel = new MWF.widget.Panel(node, {
  681. // "style": "page",
  682. // "isResize": false,
  683. // "isMax": false,
  684. // "title": "",
  685. // "width": 800,
  686. // "height": 660,
  687. // "top": position.y,
  688. // "left": position.x+3,
  689. // "isExpand": false,
  690. // "target": this.designer.node
  691. // });
  692. //
  693. // this.implodePanel.load();
  694. // }.bind(this));
  695. },
  696. // implodeJsonData: function(str){
  697. // if (str){
  698. // //try{
  699. // debugger;
  700. // var data = JSON.decode(str);
  701. // if (data){
  702. // var json = data.json;
  703. // data.id = this.data.id;
  704. // data.isNewPage = this.data.isNewPage;
  705. // json.id = this.json.id;
  706. // json.name = this.json.name;
  707. // json.application = this.json.application;
  708. // json.applicationName = this.json.applicationName;
  709. //
  710. // this.reload(data);
  711. // this.implodePanel.closePanel();
  712. // }else{
  713. // this.designer.notice(this.designer.lp.implodeError, "error");
  714. // }
  715. // // }catch(e){
  716. // // this.designer.notice(this.designer.lp.implodeError, "error");
  717. // // }
  718. // }else{
  719. // this.designer.notice(this.designer.lp.implodeEmpty, "error");
  720. // }
  721. // },
  722. implodeHTML: function(){
  723. MWF.xDesktop.requireApp("portal.PageDesigner", "Import", function(){
  724. MWF.FormImport.create("html", this);
  725. }.bind(this));
  726. },
  727. implodeOffice: function(){
  728. MWF.xDesktop.requireApp("portal.PageDesigner", "Import", function(){
  729. MWF.FormImport.create("office", this);
  730. }.bind(this));
  731. },
  732. deletePropertiesOrStyles: function(name, key){
  733. if (name=="styles"){
  734. try{
  735. if( key && this.json.styles[key] ){
  736. delete this.json.styles[key];
  737. }
  738. this.setCustomStyles();
  739. }catch(e){}
  740. }
  741. if (name=="properties"){
  742. try{
  743. this.node.removeProperty(key);
  744. }catch(e){}
  745. }
  746. },
  747. setPropertiesOrStyles: function(name){
  748. if (name==="styles"){
  749. this.setCustomStyles();
  750. }
  751. if (name==="properties"){
  752. this.node.setProperties(this.json.properties);
  753. }
  754. },
  755. setCustomStyles: function(){
  756. var border = this.node.getStyle("border");
  757. this.node.clearStyles();
  758. this.node.setStyles(this.css.pageNode);
  759. var y = this.container.getSize().y-2;
  760. this.node.setStyle("min-height", ""+y+"px");
  761. if (this.initialStyles) this.node.setStyles(this.initialStyles);
  762. this.node.setStyle("border", border);
  763. Object.each(this.json.styles, function(value, key){
  764. var reg = /^border\w*/ig;
  765. if (!key.test(reg)){
  766. this.node.setStyle(key, value);
  767. }
  768. }.bind(this));
  769. },
  770. _setEditStyle: function(name, obj, oldValue){
  771. if (name=="name"){
  772. var title = this.json.name || this.json.id;
  773. this.treeNode.setText("<"+this.json.type+"> "+title+" ["+this.options.mode+"] ");
  774. }
  775. if (name=="id"){
  776. if (!this.json.name) this.treeNode.setText("<"+this.json.type+"> "+this.json.id+" ["+this.options.mode+"] ");
  777. this.treeNode.setTitle(this.json.id);
  778. this.node.set("id", this.json.id);
  779. }
  780. if (name=="pageStyleType"){
  781. this.templateStyles = (this.stylesList && this.json.pageStyleType) ? this.stylesList[this.json.pageStyleType] : null;
  782. if (oldValue) {
  783. var oldTemplateStyles = this.stylesList[oldValue];
  784. if (oldTemplateStyles){
  785. if (oldTemplateStyles["page"]) this.clearTemplateStyles(oldTemplateStyles["page"]);
  786. }
  787. }
  788. if (this.templateStyles){
  789. if (this.templateStyles["page"]) this.setTemplateStyles(this.templateStyles["page"]);
  790. }
  791. this.setAllStyles();
  792. this.moduleList.each(function(module){
  793. if (oldTemplateStyles){
  794. module.clearTemplateStyles(oldTemplateStyles[module.moduleName]);
  795. }
  796. module.setStyleTemplate();
  797. module.setAllStyles();
  798. }.bind(this));
  799. }
  800. if (name==="css"){
  801. this.reloadCss();
  802. }
  803. this._setEditStyle_custom(name, obj, oldValue);
  804. },
  805. parseCSS: function(css){
  806. var rex = /(url\(.*\))/g;
  807. var match;
  808. while ((match = rex.exec(css)) !== null) {
  809. var pic = match[0];
  810. var len = pic.length;
  811. var s = pic.substring(pic.length-2, pic.length-1);
  812. var n0 = (s==="'" || s==="\"") ? 5 : 4;
  813. var n1 = (s==="'" || s==="\"") ? 2 : 1;
  814. pic = pic.substring(n0, pic.length-n1);
  815. if ((pic.indexOf("x_processplatform_assemble_surface")!=-1 || pic.indexOf("x_portal_assemble_surface")!=-1)){
  816. var host1 = MWF.Actions.getHost("x_processplatform_assemble_surface");
  817. var host2 = MWF.Actions.getHost("x_portal_assemble_surface");
  818. if (pic.indexOf("/x_processplatform_assemble_surface")!==-1){
  819. pic = pic.replace("/x_processplatform_assemble_surface", pic+"/x_processplatform_assemble_surface");
  820. }else if (pic.indexOf("x_processplatform_assemble_surface")!==-1){
  821. pic = pic.replace("x_processplatform_assemble_surface", pic+"/x_processplatform_assemble_surface");
  822. }
  823. if (pic.indexOf("/x_portal_assemble_surface")!==-1){
  824. pic = pic.replace("/x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  825. }else if (pic.indexOf("x_portal_assemble_surface")!==-1){
  826. pic = pic.replace("x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  827. }
  828. pic = o2.filterUrl(pic);
  829. }
  830. pic = "url('"+pic+"')";
  831. var len2 = pic.length;
  832. css = css.substring(0, match.index) + pic + css.substring(rex.lastIndex, css.length);
  833. rex.lastIndex = rex.lastIndex + (len2-len);
  834. }
  835. return css;
  836. },
  837. reloadCss: function(){
  838. cssText = (this.json.css) ? this.json.css.code : "";
  839. //var head = (document.head || document.getElementsByTagName("head")[0] || document.documentElement);
  840. var styleNode = $("style"+this.json.id);
  841. if (styleNode) styleNode.destroy();
  842. if (cssText){
  843. cssText = this.parseCSS(cssText);
  844. var rex = new RegExp("(.+)(?=\\{)", "g");
  845. var match;
  846. var id = this.json.id.replace(/\-/g, "");
  847. while ((match = rex.exec(cssText)) !== null) {
  848. var prefix = ".css" + id + " ";
  849. var rule = prefix + match[0];
  850. cssText = cssText.substring(0, match.index) + rule + cssText.substring(rex.lastIndex, cssText.length);
  851. rex.lastIndex = rex.lastIndex + prefix.length;
  852. }
  853. var styleNode = document.createElement("style");
  854. styleNode.setAttribute("type", "text/css");
  855. styleNode.id="style"+this.json.id;
  856. styleNode.inject(this.container, "before");
  857. if(styleNode.styleSheet){
  858. var setFunc = function(){
  859. styleNode.styleSheet.cssText = cssText;
  860. };
  861. if(styleNode.styleSheet.disabled){
  862. setTimeout(setFunc, 10);
  863. }else{
  864. setFunc();
  865. }
  866. }else{
  867. var cssTextNode = document.createTextNode(cssText);
  868. styleNode.appendChild(cssTextNode);
  869. }
  870. }
  871. },
  872. setAllStyles: function(){
  873. this.setPropertiesOrStyles("styles");
  874. this.setPropertiesOrStyles("properties");
  875. this.reloadMaplist();
  876. },
  877. reloadMaplist: function(){
  878. if (this.property) Object.each(this.property.maplists, function(map, name){ map.reload(this.json[name]);}.bind(this));
  879. },
  880. _setEditStyle_custom: function(){
  881. },
  882. saveAsTemplete: function(){
  883. },
  884. checkModuleId: function(id, type, currentSubform){
  885. var fieldConflict = false;
  886. var elementConflict = false;
  887. if (this.json.moduleList[id]){
  888. elementConflict = true;
  889. if (this.options.fields.indexOf(type)!=-1 || this.options.fields.indexOf(this.json.moduleList[id].type)!=-1){
  890. fieldConflict = true;
  891. }
  892. return {"fieldConflict": fieldConflict, "elementConflict": elementConflict};
  893. }
  894. // if (this.subformList){
  895. // Object.each(this.subformList, function(subform){
  896. // if (!currentSubform || currentSubform!=subform.id){
  897. // if (subform.moduleList[id]){
  898. // elementConflict = true;
  899. // if (this.options.fields.indexOf(type)!=-1 || this.options.fields.indexOf(subform.moduleList[id].type)!=-1){
  900. // fieldConflict = true;
  901. // }
  902. // }
  903. // }
  904. // }.bind(this));
  905. // }
  906. return {"fieldConflict": fieldConflict, "elementConflict": elementConflict};
  907. }
  908. });