Page.js 33 KB

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