Page.js 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207
  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": [
  11. "Calendar", "Checkbox", "Datagrid", "Datagrid$Title", "Datagrid$Data", "Datatable", "Datatable$Title", "Datatable$Data",
  12. "Datatemplate","Htmleditor", "TinyMCEEditor","Number", "Currency", "Office", "Orgfield", "Org", "Personfield", "Radio", "Select", "Textarea", "Textfield","Address","Combox",
  13. "Elcascader", "Elcheckbox", "Elcolorpicker", "Eldate", "Eldatetime", "Elinput", "Elnumber", "Elradio", "Elrate", "Elselect", "Elslider", "Elswitch", "ElTime"
  14. ],
  15. "injectActions" : [
  16. {
  17. "name" : "top",
  18. "styles" : "injectActionTop",
  19. "event" : "click",
  20. "action" : "injectTop",
  21. "title": MWF.APPPOD.LP.formAction["insertTop"]
  22. },
  23. {
  24. "name" : "bottom",
  25. "styles" : "injectActionBottom",
  26. "event" : "click",
  27. "action" : "injectBottom",
  28. "title": MWF.APPPOD.LP.formAction["insertBottom"]
  29. }
  30. ]
  31. },
  32. initializeBase: function(options){
  33. this.setOptions(options);
  34. this.path = "../x_component_portal_PageDesigner/Module/Page/";
  35. this.cssPath = "../x_component_portal_PageDesigner/Module/Page/"+this.options.style+"/css.wcss";
  36. this._loadCss();
  37. },
  38. initialize: function(designer, container, options){
  39. this.initializeBase(options);
  40. this.container = null;
  41. this.page = this;
  42. this.form = this;
  43. this.moduleType = "page";
  44. this.moduleList = [];
  45. this.moduleNodeList = [];
  46. this.moduleContainerNodeList = [];
  47. this.moduleElementNodeList = [];
  48. this.moduleComponentNodeList = [];
  49. // this.moduleContainerList = [];
  50. this.dataTemplate = {};
  51. this.designer = designer;
  52. this.container = container;
  53. this.selectedModules = [];
  54. },
  55. reload: function(data){
  56. this.moduleList.each(function(module){
  57. if (module.property){
  58. module.property.destroy();
  59. }
  60. }.bind(this));
  61. if (this.property) this.property.destroy();
  62. this.property = null;
  63. this.moduleList = [];
  64. this.moduleNodeList = [];
  65. this.moduleContainerNodeList = [];
  66. this.moduleElementNodeList = [];
  67. this.moduleComponentNodeList = [];
  68. this.dataTemplate = {};
  69. this.selectedModules = [];
  70. this.container.empty();
  71. this.widgetList = null;
  72. if(this.options.parentpageIdList)this.options.parentpageIdList = null;
  73. if (this.treeNode){
  74. this.domTree.empty();
  75. this.domTree.node.destroy();
  76. this.domTree = null;
  77. this.treeNode = null;
  78. }
  79. if( this.history ){
  80. this.history.destroy();
  81. this.history = null;
  82. }
  83. this.currentSelectedModule = null;
  84. this.propertyMultiTd = null;
  85. if (this.autoSaveTimerID) window.clearInterval(this.autoSaveTimerID);
  86. this.load(data);
  87. },
  88. load : function(data){
  89. this.data = data;
  90. this.json = data.json;
  91. this.html = data.html;
  92. this.json.mode = this.options.mode;
  93. if (!this.json.css) this.json.css = {"code":""};
  94. this.isNewPage = (this.json.id) ? false : true;
  95. if (this.isNewPage) this.checkUUID();
  96. if(this.designer.application) this.data.json.applicationName = this.designer.application.name;
  97. if(this.designer.application) this.data.json.application = this.designer.application.id;
  98. this.container.set("html", this.html);
  99. this.loadStylesList(function(){
  100. var oldStyleValue = "";
  101. if ((!this.json.pageStyleType) || !this.stylesList[this.json.pageStyleType]) this.json.pageStyleType="blue-simple";
  102. if (this.options.mode=="Mobile"){
  103. if (this.json.pageStyleType != "defaultMobile"){
  104. oldStyleValue = this.json.pageStyleType;
  105. this.json.pageStyleType = "defaultMobile";
  106. }
  107. }
  108. this.templateStyles = (this.stylesList && this.json.pageStyleType) ? this.stylesList[this.json.pageStyleType] : null;
  109. this.loadDomModules();
  110. if (this.json.pageStyleType){
  111. if (this.stylesList[this.json.pageStyleType]){
  112. if (this.stylesList[this.json.pageStyleType]["page"]){
  113. this.setTemplateStyles(this.stylesList[this.json.pageStyleType]["page"]);
  114. }
  115. }
  116. }
  117. this.setCustomStyles();
  118. this.node.setProperties(this.json.properties);
  119. this.setNodeEvents();
  120. if (this.options.mode=="Mobile"){
  121. if (oldStyleValue) this._setEditStyle("pageStyleType", null, oldStyleValue);
  122. }
  123. this.selected();
  124. this.autoSave();
  125. this.designer.addEvent("queryClose", function(){
  126. if (this.autoSaveTimerID) window.clearInterval(this.autoSaveTimerID);
  127. }.bind(this));
  128. this.loadHistory();
  129. this.fireEvent("postLoad");
  130. }.bind(this));
  131. },
  132. removeStyles: function(from, to){
  133. if (this.json[to]){
  134. Object.each(from, function(style, key){
  135. if (this.json[to][key] && this.json[to][key]==style){
  136. delete this.json[to][key];
  137. }
  138. }.bind(this));
  139. }
  140. },
  141. copyStyles: function(from, to){
  142. if (!this.json[to]) this.json[to] = {};
  143. Object.each(from, function(style, key){
  144. if (!this.json[to][key]) this.json[to][key] = style;
  145. }.bind(this));
  146. },
  147. clearTemplateStyles: function(styles){
  148. if (styles){
  149. if (styles.styles) this.removeStyles(styles.styles, "styles");
  150. if (styles.properties) this.removeStyles(styles.properties, "properties");
  151. }
  152. },
  153. setTemplateStyles: function(styles){
  154. if (styles.styles) this.copyStyles(styles.styles, "styles");
  155. if (styles.properties) this.copyStyles(styles.properties, "properties");
  156. },
  157. loadStylesList: function(callback){
  158. var stylesUrl = "../x_component_portal_PageDesigner/Module/Page/template/"+((this.options.mode=="Mobile") ? "styles": "styles")+".json";
  159. MWF.getJSON(stylesUrl,{
  160. "onSuccess": function(responseJSON){
  161. this.stylesList= responseJSON;
  162. if (callback) callback(this.stylesList);
  163. }.bind(this),
  164. "onRequestFailure": function(){
  165. this.stylesList = {};
  166. if (callback) callback(this.stylesList);
  167. }.bind(this),
  168. "onError": function(){
  169. this.stylesList = {};
  170. if (callback) callback(this.stylesList);
  171. }.bind(this)
  172. }
  173. );
  174. },
  175. autoSave: function(){
  176. this.autoSaveCheckNode = this.designer.pageToolbarNode.getElement("#MWFPageAutoSaveCheck");
  177. if (this.autoSaveCheckNode){
  178. this.autoSaveTimerID = window.setInterval(function(){
  179. if (this.autoSaveCheckNode.get("checked")){
  180. this.save();
  181. }
  182. }.bind(this), 60000);
  183. }
  184. },
  185. loadHistory: function(){
  186. o2.xDesktop.requireApp("process.FormDesigner", "History", function () {
  187. this.history = new MWF.xApplication.process.FormDesigner.History(this, this.designer.currentHistoryNode);
  188. this.history.load();
  189. }.bind(this));
  190. },
  191. checkPropertyHistory: function(name, oldValue, newValue, notSetEditStyle, compareName, force){
  192. if( !this.history )return null;
  193. var log = {
  194. "type": "property",
  195. "force": force,
  196. "moduleId": "form",
  197. "moduleType": "form",
  198. "notSetEditStyle": notSetEditStyle,
  199. "changeList": [
  200. {
  201. "name": name,
  202. "compareName": compareName,
  203. "fromValue": oldValue,
  204. "toValue": newValue || this.json[name]
  205. }
  206. ]
  207. };
  208. this.history.checkProperty(log, this);
  209. },
  210. checkMultiPropertyHistory: function(name, oldValueList, newValue, modules){
  211. if( !this.history )return null;
  212. var log = {
  213. "type": "multiProperty",
  214. "moduleId": "form",
  215. "changeList": modules.map(function (module, i) {
  216. return {
  217. "module": module,
  218. "name": name,
  219. "fromValue": oldValueList[i],
  220. "toValue": newValue || module.json[name]
  221. }
  222. })
  223. };
  224. this.history.checkMultiProperty(log, modules);
  225. },
  226. checkUUID: function(){
  227. this.designer.actions.getUUID(function(id){
  228. this.json.id = id;
  229. }.bind(this));
  230. },
  231. loadDomModules: function(){
  232. this.node = this.container.getFirst();
  233. this.node.set("id", this.json.id);
  234. this.node.setStyles(this.css.pageNode);
  235. this.node.store("module", this);
  236. var id = this.json.id.replace(/\-/g, "");
  237. ( this.node.get("class") || "" ).split(" ").each(function(className){
  238. if( className.indexOf("css") === 0 && className.length === 35 ){
  239. this.node.removeClass(className);
  240. }
  241. }.bind(this));
  242. this.node.addClass("css"+id);
  243. this.reloadCss();
  244. var y = this.container.getStyle("height");
  245. y = (y) ? y.toInt()-2 : this.container.getSize().y-2;
  246. this.node.setStyle("min-height", ""+y+"px");
  247. this.designer.addEvent("resize", function(){
  248. var y = this.container.getStyle("height");
  249. y = (y) ? y.toInt()-2 : this.container.getSize().y-2;
  250. this.node.setStyle("min-height", ""+y+"px");
  251. }.bind(this));
  252. this.loadDomTree();
  253. },
  254. loadDomTree: function(){
  255. MWF.require("MWF.widget.Tree", function(){
  256. this.domTree = new MWF.widget.Tree(this.designer.propertyDomArea, {"style": "domtree"});
  257. this.domTree.load();
  258. this.createPageTreeNode();
  259. this.parseModules(this, this.node);
  260. }.bind(this));
  261. },
  262. createPageTreeNode: function(){
  263. var text = "<"+this.json.type+"> "+this.json.name+" ["+this.options.mode+"] ";
  264. var o = {
  265. "expand": true,
  266. "title": this.json.id,
  267. "text": "<"+this.json.type+"> "+this.json.name+" ["+this.options.mode+"] ",
  268. "icon": (this.options.mode=="Mobile") ? "mobile.png": "pc.png"
  269. };
  270. o.action = function(){
  271. if (this.module) this.module.selected();
  272. };
  273. this.treeNode = this.domTree.appendChild(o);
  274. this.treeNode.setText(text);
  275. this.treeNode.module = this;
  276. },
  277. getModuleNodes: function (dom, ignoreMultipleModule) {
  278. var moduleNodes = [];
  279. var subDom = dom.getFirst();
  280. while (subDom) {
  281. var mwftype = subDom.get("MWFtype") || subDom.get("mwftype");
  282. if (mwftype) {
  283. if( ignoreMultipleModule ){
  284. var type = mwftype;
  285. if ( type.indexOf("$") === -1)moduleNodes.push(subDom);
  286. }else{
  287. moduleNodes.push(subDom);
  288. }
  289. moduleNodes = moduleNodes.concat(this.getModuleNodes(subDom));
  290. } else {
  291. moduleNodes = moduleNodes.concat(this.getModuleNodes(subDom));
  292. }
  293. subDom = subDom.getNext();
  294. }
  295. return moduleNodes;
  296. },
  297. // parseModules: function(parent, dom){
  298. // var tmpDom = null;
  299. // var subDom = dom.getFirst();
  300. // while (subDom){
  301. // if (subDom.get("MWFtype")){
  302. // var json = this.getDomjson(subDom);
  303. // if (json) module = this.loadModule(json, subDom, parent);
  304. // }
  305. // if (!json) tmpDom = subDom;
  306. // subDom = subDom.getNext();
  307. //
  308. // if (tmpDom){
  309. // tmpDom.destroy();
  310. // tmpDom = null;
  311. // }
  312. // }
  313. // },
  314. parseModules: function(parent, dom){
  315. var moduleNodes = [];
  316. var subDom = dom.getFirst();
  317. while (subDom){
  318. if (subDom.get("MWFtype")){
  319. var json = this.getDomjson(subDom);
  320. var moduleNode = subDom;
  321. moduleNodes.push({"dom": moduleNode, "json": json});
  322. }
  323. subDom = subDom.getNext();
  324. }
  325. moduleNodes.each(function(obj){
  326. module = this.loadModule(obj.json, obj.dom, parent);
  327. }.bind(this));
  328. },
  329. getDomjson: function(dom){
  330. var mwfType = dom.get("MWFtype");
  331. switch (mwfType) {
  332. case "page":
  333. return this.json;
  334. case "":
  335. return null;
  336. default:
  337. var id = dom.get("id");
  338. if (id){
  339. return this.json.moduleList[id];
  340. }else{
  341. return null;
  342. }
  343. }
  344. },
  345. loadModule: function(json, dom, parent){
  346. var module;
  347. if (json) {
  348. if( json.events ){
  349. module = new MWF["PC" + json.type](this);
  350. module.load(json, dom, parent);
  351. }else{
  352. var className = json.type.capitalize();
  353. this.getTemplateData(className, function(data){
  354. json.events = Object.clone(data.events);
  355. module = new MWF["PC" + json.type](this);
  356. module.load(json, dom, parent);
  357. }.bind(this), false);
  358. }
  359. }
  360. return module;
  361. },
  362. setNodeEvents: function(){
  363. this.node.addEvent("click", function(e){
  364. this.selected();
  365. }.bind(this));
  366. },
  367. createModuleImmediately: function( className, parentModule, relativeNode, position, selectDisabled, async ){
  368. var module;
  369. this.getTemplateData(className, function(data){
  370. var moduleData = Object.clone(data);
  371. module = new MWF["PC"+className](this);
  372. if( parentModule ){
  373. module.onDragModule = parentModule;
  374. if (!parentModule.Component) module.inContainer = parentModule;
  375. module.parentContainer = parentModule;
  376. module.nextModule = null;
  377. }
  378. module.createImmediately(moduleData, relativeNode, position, selectDisabled);
  379. }.bind(this), async);
  380. return module;
  381. },
  382. createModule: function(className, e){
  383. this.getTemplateData(className, function(data){
  384. var moduleData = Object.clone(data);
  385. var newTool = new MWF["PC"+className](this);
  386. newTool.create(moduleData, e);
  387. }.bind(this));
  388. },
  389. getTemplateData: function(className, callback, async){
  390. debugger;
  391. if (this.dataTemplate[className]){
  392. if (callback) callback(this.dataTemplate[className]);
  393. }else{
  394. var modulePath = ( MWF["PC"+className] && MWF["PC"+className].templateJsonPath ) || "../x_component_portal_PageDesigner/Module/";
  395. var templateUrl = modulePath + className+"/template.json";
  396. MWF.getJSON(templateUrl, function(responseJSON, responseText){
  397. this.dataTemplate[className] = responseJSON;
  398. if (callback) callback(responseJSON);
  399. }.bind(this), async);
  400. }
  401. },
  402. selected: function(){
  403. if (this.currentSelectedModule){
  404. if (this.currentSelectedModule==this){
  405. return true;
  406. }else{
  407. this.currentSelectedModule.unSelected();
  408. }
  409. }
  410. if (this.propertyMultiTd){
  411. this.propertyMultiTd.hide();
  412. this.propertyMultiTd = null;
  413. }
  414. this.unSelectedMulti();
  415. this.currentSelectedModule = this;
  416. if (this.treeNode){
  417. this.treeNode.selectNode();
  418. }
  419. this.showProperty();
  420. // this.isFocus = true;
  421. },
  422. unSelectedMulti: function(){
  423. while (this.selectedModules.length){
  424. this.selectedModules[0].unSelectedMulti();
  425. }
  426. if (this.multimoduleActionsArea) this.multimoduleActionsArea.setStyle("display", "none");
  427. },
  428. unSelectAll: function(){
  429. },
  430. _beginSelectMulti: function(){
  431. if (this.currentSelectedModule) this.currentSelectedModule.unSelected();
  432. this.unSelectedMulti();
  433. this.noSelected = true;
  434. },
  435. _completeSelectMulti: function(){
  436. if (this.selectedModules.length<2){
  437. this.selectedModules[0].selected();
  438. }else{
  439. this._showMultiActions();
  440. }
  441. },
  442. createMultimoduleActionsArea: function(){
  443. this.multimoduleActionsArea = new Element("div", {
  444. styles: {
  445. "display": "none",
  446. // "width": 18*this.options.actions.length,
  447. "position": "absolute",
  448. "background-color": "#F1F1F1",
  449. "padding": "1px",
  450. "padding-right": "0px",
  451. "border": "1px solid #AAA",
  452. "box-shadow": "0px 2px 5px #999",
  453. "z-index": 10001
  454. }
  455. }).inject(this.page.container, "after");
  456. },
  457. _showMultiActions: function(){
  458. if (!this.multimoduleActionsArea) this.createMultimoduleActionsArea();
  459. var firstModule = this._getFirstMultiSelectedModule();
  460. if (firstModule){
  461. // var module = firstModule.module;
  462. var y = firstModule.position.y-25;
  463. var x = firstModule.position.x;
  464. this.multimoduleActionsArea.setPosition({"x": x, "y": y});
  465. this.multimoduleActionsArea.setStyle("display", "block");
  466. }
  467. },
  468. _getFirstMultiSelectedModule: function(){
  469. var firstModule = null;
  470. this.selectedModules.each(function(module){
  471. var position = module.node.getPosition(module.form.node.getOffsetParent());
  472. if (!firstModule){
  473. firstModule = {"module": module, "position": position};
  474. }else{
  475. if (position.y<firstModule.position.y){
  476. firstModule = {"module": module, "position": position};
  477. }else if (position.y==firstModule.position.y){
  478. if (position.x<firstModule.position.x){
  479. firstModule = {"module": module, "position": position};
  480. }
  481. }
  482. }
  483. });
  484. return firstModule;
  485. },
  486. showProperty: function(callback){
  487. if (!this.property){
  488. this.property = new MWF.xApplication.process.FormDesigner.Property(this, this.designer.propertyContentArea, this.designer, {
  489. "path": this.options.propertyPath,
  490. "onPostLoad": function(){
  491. this.property.show();
  492. if (callback) callback();
  493. }.bind(this)
  494. });
  495. this.property.load();
  496. }else{
  497. this.property.show();
  498. if (callback) callback();
  499. }
  500. },
  501. hideProperty: function(){
  502. if (this.property) this.property.hide();
  503. },
  504. unSelected: function(){
  505. this.currentSelectedModule = null;
  506. this.hideProperty();
  507. },
  508. _dragIn: function(module){
  509. if (!this.Component) module.inContainer = this;
  510. module.parentContainer = this;
  511. this.node.setStyles({"border": "1px solid #ffa200"});
  512. var copyNode = module._getCopyNode();
  513. copyNode.inject(this.node);
  514. },
  515. _dragOut: function(module){
  516. module.inContainer = null;
  517. module.parentContainer = null;
  518. this.node.setStyles(this.css.pageNode);
  519. this.node.setStyles(this.json.styles);
  520. var copyNode = module._getCopyNode();
  521. copyNode.setStyle("display", "none");
  522. },
  523. _dragDrop: function(module, flag){
  524. var f = flag || !(window.event || {}).ctrlKey;
  525. if( f ){
  526. this.node.setStyles(this.css.pageNode);
  527. this.node.setStyles(this.json.styles);
  528. }
  529. },
  530. _showInjectAction : function( module ){
  531. if ( module.moveNode ){
  532. module.moveNode.setStyle("display","none");
  533. }
  534. //debugger;
  535. this.draggingModule = module;
  536. //if( !this.node.getFirst() ){
  537. // this.inject( "top" );
  538. // return;
  539. //}
  540. if( !this.injectActionArea )this._createInjectAction();
  541. this.injectActionArea.setStyle("display","block");
  542. this._setInjectActionAreaPosition();
  543. this.injectActionEffect = new Fx.Morph(this.injectActionArea, {
  544. duration: 200,
  545. transition: Fx.Transitions.Sine.easeOut
  546. });
  547. this.injectActionEffect.start(this.form.css.injectActionArea_to);
  548. },
  549. _hideInjectAction : function(){
  550. this.draggingModule = null;
  551. if( this.injectActionArea ){
  552. this.injectActionArea.setStyle("display","none");
  553. }
  554. },
  555. _createInjectAction : function(){
  556. var css = this.form.css;
  557. if( !this.injectActionArea ){
  558. this.injectActionArea = new Element("div", { styles: css.injectActionArea }).inject(this.form.container, "after");
  559. this.injectActionTopBGNode = new Element("div", { styles : css.injectActionTopBGNode }).inject( this.injectActionArea );
  560. this.injectActionLeftBGNode = new Element("div", { styles : css.injectActionLeftBGNode }).inject( this.injectActionArea );
  561. this.injectActionRightBGNode = new Element("div", { styles : css.injectActionRightBGNode }).inject( this.injectActionArea );
  562. this.injectActionBottomBGNode = new Element("div", { styles : css.injectActionBottomBGNode }).inject( this.injectActionArea );
  563. var injectActions = {};
  564. this.options.injectActions.each( function( action ){
  565. injectActions[ action.name ] = action;
  566. });
  567. if( injectActions.before )this._createInjectActionNode( injectActions.before, this.injectActionTopBGNode );
  568. if( injectActions.top )this._createInjectActionNode( injectActions.top, this.injectActionLeftBGNode );
  569. if( injectActions.bottom )this._createInjectActionNode( injectActions.bottom, this.injectActionRightBGNode );
  570. if( injectActions.after )this._createInjectActionNode( injectActions.after, this.injectActionBottomBGNode );
  571. new Element("div", {
  572. styles : css.injectActionCancelNode,
  573. events : {
  574. click : function(){
  575. this.draggingModule._dragCancel();
  576. this._dragDrop( this.node, true );
  577. this._hideInjectAction();
  578. }.bind(this),
  579. mouseover : function(){
  580. this.setStyles( css.injectActionCancelNode_over )
  581. },
  582. mouseout : function(){
  583. this.setStyles( css.injectActionCancelNode )
  584. }
  585. }
  586. }).inject(this.injectActionArea);
  587. }
  588. },
  589. _createInjectActionNode : function( action, relativeNode ){
  590. var actionNode = new Element("div", {
  591. "styles": this.css[action.styles],
  592. "title": action.title
  593. }).inject( this.injectActionArea );
  594. actionNode.addEvent(action.event, function(e){
  595. this[action.action](e);
  596. }.bind(this));
  597. actionNode.addEvents({
  598. "mouseover": function(e){
  599. relativeNode.setStyle("background", "#ddd");
  600. this.draggingModule.copyNode.setStyle("display","");
  601. this.draggingModule.copyNode.inject( this.node, action.name );
  602. }.bind(this),
  603. "mouseout": function(e){
  604. relativeNode.setStyle("background", "transparent");
  605. }.bind(this)
  606. });
  607. relativeNode.set("title",action.title);
  608. relativeNode.addEvent(action.event, function(e){
  609. this[action.action](e);
  610. }.bind(this));
  611. relativeNode.setStyle("cursor","pointer");
  612. relativeNode.addEvents({
  613. "mouseenter": function(e){
  614. relativeNode.setStyle("background", "#ddd");
  615. this.draggingModule.copyNode.setStyle("display","");
  616. this.draggingModule.copyNode.inject( this.node, action.name );
  617. }.bind(this),
  618. "mouseleave": function(e){
  619. relativeNode.setStyle("background", "transparent");
  620. //this.draggingModule.copyNode.setStyle("display","none");
  621. }.bind(this)
  622. });
  623. },
  624. _setInjectActionAreaPosition: function(){
  625. var e = window.event || {};
  626. var formOffset = this.node.getOffsetParent().getPosition();
  627. //var p = this.node.getPosition(this.form.node.getOffsetParent());
  628. var y = e.pageY - formOffset.y - 60;
  629. var x = e.pageX - formOffset.x - 60;
  630. this.injectActionArea.setPosition({"x": x, "y": y});
  631. },
  632. injectBefore : function( e ){
  633. this.inject( "before" )
  634. },
  635. injectAfter : function( e ){
  636. this.inject( "after" )
  637. },
  638. injectTop : function( e ){
  639. this.inject( "top" )
  640. },
  641. injectBottom : function( e ){
  642. this.inject( "bottom" )
  643. },
  644. inject : function( position ){
  645. if ( this.draggingModule.moveNode ){
  646. this.draggingModule.moveNode.setStyle("display","");
  647. }
  648. this.draggingModule._dragComplete( this.node, position );
  649. this._dragDrop( this.node, true );
  650. this._hideInjectAction();
  651. },
  652. _resetTreeNode: function(){},
  653. _clearNoId: function(node){
  654. var subNode = node.getFirst();
  655. while (subNode){
  656. var nextNode = subNode.getNext();
  657. if (subNode.get("MWFType")){
  658. if (!subNode.get("id")){
  659. subNode.destroy();
  660. }else{
  661. if (subNode) this._clearNoId(subNode);
  662. }
  663. }else{
  664. if (subNode) this._clearNoId(subNode);
  665. }
  666. subNode = nextNode;
  667. }
  668. },
  669. _getPageData: function(){
  670. this.fireEvent("queryGetPageData");
  671. var copy = this.node.clone(true, true);
  672. copy.clearStyles(true);
  673. this.fireEvent("postGetPageData");
  674. this._clearNoId(copy);
  675. var html = copy.outerHTML;
  676. copy.destroy();
  677. this.data.json.mode = this.options.mode;
  678. this.data.html = html;
  679. return this.data;
  680. },
  681. preview: function(){
  682. if( this.designer.currentDesignerMode === "Mobile" ){
  683. var url = "../x_desktop/portalmobile.html?id="+this.json.application+"&page="+this.json.id;
  684. window.open(o2.filterUrl(url));
  685. }else{
  686. var url = "../x_desktop/portal.html?id="+this.json.application+"&page="+this.json.id;
  687. window.open(o2.filterUrl(url));
  688. }
  689. // MWF.xDesktop.requireApp("process.FormDesigner", "Preview", function(){
  690. //
  691. // if (this.options.mode=="Mobile"){
  692. // this.previewBox = new MWF.xApplication.process.FormDesigner.Preview(this, {"size": {"x": "340", "y": 580, "layout":"mobile"}});
  693. // }else{
  694. // this.previewBox = new MWF.xApplication.process.FormDesigner.Preview(this);
  695. // }
  696. // this.previewBox.load();
  697. //
  698. // }.bind(this));
  699. },
  700. save: function(callback){
  701. this.designer.savePage();
  702. },
  703. explode: function(){
  704. this._getPageData();
  705. MWF.require("MWF.widget.Base64", null, false);
  706. var data = MWF.widget.Base64.encode(JSON.encode(this.data));
  707. MWF.require("MWF.widget.Panel", function(){
  708. var node = new Element("div");
  709. var size = this.designer.pageNode.getSize();
  710. var position = this.designer.pageNode.getPosition(this.designer.pageNode.getOffsetParent());
  711. var textarea = new Element("textarea", {
  712. "styles": {
  713. "border": "1px solid #999",
  714. "width": "770px",
  715. "margin-left": "14px",
  716. "margin-top": "14px",
  717. "height": "580px"
  718. },
  719. "text": JSON.encode(this.data)
  720. }).inject(node);
  721. this.explodePanel = new MWF.widget.Panel(node, {
  722. "style": "page",
  723. "isResize": false,
  724. "isMax": false,
  725. "title": "",
  726. "width": 800,
  727. "height": 660,
  728. "top": position.y,
  729. "left": position.x+3,
  730. "isExpand": false,
  731. "target": this.designer.node
  732. });
  733. this.explodePanel.load();
  734. }.bind(this));
  735. },
  736. implode: function(){
  737. MWF.xDesktop.requireApp("portal.PageDesigner", "Import", function(){
  738. MWF.FormImport.create("O2", this);
  739. }.bind(this));
  740. // MWF.require("MWF.widget.Panel", function(){
  741. // var node = new Element("div");
  742. // var size = this.designer.pageNode.getSize();
  743. // var position = this.designer.pageNode.getPosition(this.designer.pageNode.getOffsetParent());
  744. //
  745. // var textarea = new Element("textarea", {
  746. // "styles": {
  747. // "border": "1px solid #999",
  748. // "width": "770px",
  749. // "margin-left": "14px",
  750. // "margin-top": "14px",
  751. // "height": "540px"
  752. // }
  753. // }).inject(node);
  754. // var button = new Element("div", {
  755. // "styles": {
  756. // "margin": "10px auto",
  757. // "width": "100px",
  758. // "border-radius": "8px",
  759. // "height": "30px",
  760. // "line-height": "30px",
  761. // "text-align": "center",
  762. // "cursor": "pointer",
  763. // "color": "#ffffff",
  764. // "background-color": "#4c6b87"
  765. // },
  766. // "text": "OK"
  767. // }).inject(node);
  768. // button.addEvent("click", function(e){
  769. // var _self = this;
  770. // this.designer.confirm("warn", e, this.designer.lp.implodeConfirmTitle, this.designer.lp.implodeConfirmText, 300, 120, function(){
  771. // var str = textarea.get("value");
  772. // _self.implodeJsonData(str);
  773. // this.close();
  774. // }, function(){
  775. // this.close();
  776. // });
  777. // }.bind(this));
  778. //
  779. // this.implodePanel = new MWF.widget.Panel(node, {
  780. // "style": "page",
  781. // "isResize": false,
  782. // "isMax": false,
  783. // "title": "",
  784. // "width": 800,
  785. // "height": 660,
  786. // "top": position.y,
  787. // "left": position.x+3,
  788. // "isExpand": false,
  789. // "target": this.designer.node
  790. // });
  791. //
  792. // this.implodePanel.load();
  793. // }.bind(this));
  794. },
  795. // implodeJsonData: function(str){
  796. // if (str){
  797. // //try{
  798. // debugger;
  799. // var data = JSON.decode(str);
  800. // if (data){
  801. // var json = data.json;
  802. // data.id = this.data.id;
  803. // data.isNewPage = this.data.isNewPage;
  804. // json.id = this.json.id;
  805. // json.name = this.json.name;
  806. // json.application = this.json.application;
  807. // json.applicationName = this.json.applicationName;
  808. //
  809. // this.reload(data);
  810. // this.implodePanel.closePanel();
  811. // }else{
  812. // this.designer.notice(this.designer.lp.implodeError, "error");
  813. // }
  814. // // }catch(e){
  815. // // this.designer.notice(this.designer.lp.implodeError, "error");
  816. // // }
  817. // }else{
  818. // this.designer.notice(this.designer.lp.implodeEmpty, "error");
  819. // }
  820. // },
  821. implodeHTML: function(){
  822. MWF.xDesktop.requireApp("portal.PageDesigner", "Import", function(){
  823. MWF.FormImport.create("html", this);
  824. }.bind(this));
  825. },
  826. implodeOffice: function(){
  827. MWF.xDesktop.requireApp("portal.PageDesigner", "Import", function(){
  828. MWF.FormImport.create("office", this);
  829. }.bind(this));
  830. },
  831. deletePropertiesOrStyles: function(name, key){
  832. if (name=="styles"){
  833. try{
  834. if( key && this.json.styles[key] ){
  835. delete this.json.styles[key];
  836. }
  837. this.setCustomStyles();
  838. }catch(e){}
  839. }
  840. if (name=="properties"){
  841. try{
  842. this.node.removeProperty(key);
  843. }catch(e){}
  844. }
  845. },
  846. setPropertiesOrStyles: function(name){
  847. if (name==="styles"){
  848. this.setCustomStyles();
  849. }
  850. if (name==="properties"){
  851. this.node.setProperties(this.json.properties);
  852. }
  853. },
  854. setCustomStyles: function(){
  855. var border = this.node.getStyle("border");
  856. this.node.clearStyles();
  857. this.node.setStyles(this.css.pageNode);
  858. var y = this.container.getSize().y-2;
  859. this.node.setStyle("min-height", ""+y+"px");
  860. if (this.initialStyles) this.node.setStyles(this.initialStyles);
  861. this.node.setStyle("border", border);
  862. Object.each(this.json.styles, function(value, key){
  863. var reg = /^border\w*/ig;
  864. if (!key.test(reg)){
  865. this.node.setStyle(key, value);
  866. }
  867. }.bind(this));
  868. },
  869. _setEditStyle: function(name, obj, oldValue){
  870. if (name=="name"){
  871. var title = this.json.name || this.json.id;
  872. this.treeNode.setText("<"+this.json.type+"> "+title+" ["+this.options.mode+"] ");
  873. }
  874. if (name=="id"){
  875. if (!this.json.name) this.treeNode.setText("<"+this.json.type+"> "+this.json.id+" ["+this.options.mode+"] ");
  876. this.treeNode.setTitle(this.json.id);
  877. this.node.set("id", this.json.id);
  878. }
  879. if (name=="pageStyleType"){
  880. this.templateStyles = (this.stylesList && this.json.pageStyleType) ? this.stylesList[this.json.pageStyleType] : null;
  881. if (oldValue) {
  882. var oldTemplateStyles = this.stylesList[oldValue];
  883. if (oldTemplateStyles){
  884. if (oldTemplateStyles["page"]) this.clearTemplateStyles(oldTemplateStyles["page"]);
  885. }
  886. }
  887. if (this.templateStyles){
  888. if (this.templateStyles["page"]) this.setTemplateStyles(this.templateStyles["page"]);
  889. }
  890. this.setAllStyles();
  891. this.moduleList.each(function(module){
  892. if (oldTemplateStyles){
  893. module.clearTemplateStyles(oldTemplateStyles[module.moduleName]);
  894. }
  895. module.setStyleTemplate();
  896. module.setAllStyles();
  897. }.bind(this));
  898. }
  899. if (name==="css"){
  900. this.reloadCss();
  901. }
  902. this._setEditStyle_custom(name, obj, oldValue);
  903. },
  904. parseCSS: function(css){
  905. var rex = /(url\(.*\))/g;
  906. var match;
  907. while ((match = rex.exec(css)) !== null) {
  908. var pic = match[0];
  909. var len = pic.length;
  910. var s = pic.substring(pic.length-2, pic.length-1);
  911. var n0 = (s==="'" || s==="\"") ? 5 : 4;
  912. var n1 = (s==="'" || s==="\"") ? 2 : 1;
  913. pic = pic.substring(n0, pic.length-n1);
  914. if ((pic.indexOf("x_processplatform_assemble_surface")!=-1 || pic.indexOf("x_portal_assemble_surface")!=-1)){
  915. var host1 = MWF.Actions.getHost("x_processplatform_assemble_surface");
  916. var host2 = MWF.Actions.getHost("x_portal_assemble_surface");
  917. if (pic.indexOf("/x_processplatform_assemble_surface")!==-1){
  918. pic = pic.replace("/x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  919. }else if (pic.indexOf("x_processplatform_assemble_surface")!==-1){
  920. pic = pic.replace("x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  921. }
  922. if (pic.indexOf("/x_portal_assemble_surface")!==-1){
  923. pic = pic.replace("/x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  924. }else if (pic.indexOf("x_portal_assemble_surface")!==-1){
  925. pic = pic.replace("x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  926. }
  927. pic = o2.filterUrl(pic);
  928. }
  929. pic = "url('"+pic+"')";
  930. var len2 = pic.length;
  931. css = css.substring(0, match.index) + pic + css.substring(rex.lastIndex, css.length);
  932. rex.lastIndex = rex.lastIndex + (len2-len);
  933. }
  934. return css;
  935. },
  936. reloadCss: function(){
  937. var cssText = (this.json.css) ? this.json.css.code : "";
  938. //var head = (document.head || document.getElementsByTagName("head")[0] || document.documentElement);
  939. var styleNode = $("design_style"+this.json.id);
  940. if (styleNode) styleNode.destroy();
  941. if (cssText){
  942. //删除注释
  943. cssText = cssText.replace(/\/\*[\s\S]*?\*\/\n|([^:]|^)\/\/.*\n$/g, '').replace(/\\n/, '');
  944. cssText = this.parseCSS(cssText);
  945. var rex = new RegExp("(.+)(?=\\{)", "g");
  946. var match;
  947. var id = this.json.id.replace(/\-/g, "");
  948. var prefix = ".css" + id + " ";
  949. while ((match = rex.exec(cssText)) !== null) {
  950. var rulesStr = match[0];
  951. var startWith = rulesStr.substring(0, 1);
  952. if (startWith === "@" || startWith === ":" || rulesStr.indexOf("%") !== -1) {
  953. }else if (rulesStr.trim()==='from' || rulesStr.trim()==='to'){
  954. } else {
  955. if (rulesStr.indexOf(",")!=-1){
  956. //var rules = rulesStr.split(/\s*,\s*/g);
  957. var rules = rulesStr.split(/,/g);
  958. rules = rules.map(function(r){
  959. return prefix + r;
  960. });
  961. var rule = rules.join(",");
  962. cssText = cssText.substring(0, match.index) + rule + cssText.substring(rex.lastIndex, cssText.length);
  963. rex.lastIndex = rex.lastIndex + (prefix.length*rules.length);
  964. }else{
  965. var rule = prefix + match[0];
  966. cssText = cssText.substring(0, match.index) + rule + cssText.substring(rex.lastIndex, cssText.length);
  967. rex.lastIndex = rex.lastIndex + prefix.length;
  968. }
  969. }
  970. }
  971. var styleNode = document.createElement("style");
  972. styleNode.setAttribute("type", "text/css");
  973. styleNode.id="design_style"+this.json.id;
  974. styleNode.inject(this.container, "before");
  975. if(styleNode.styleSheet){
  976. var setFunc = function(){
  977. styleNode.styleSheet.cssText = cssText;
  978. };
  979. if(styleNode.styleSheet.disabled){
  980. setTimeout(setFunc, 10);
  981. }else{
  982. setFunc();
  983. }
  984. }else{
  985. var cssTextNode = document.createTextNode(cssText);
  986. styleNode.appendChild(cssTextNode);
  987. }
  988. }
  989. },
  990. setAllStyles: function(){
  991. this.setPropertiesOrStyles("styles");
  992. this.setPropertiesOrStyles("properties");
  993. this.reloadMaplist();
  994. },
  995. reloadMaplist: function(){
  996. if (this.property) Object.each(this.property.maplists, function(map, name){ map.reload(this.json[name]);}.bind(this));
  997. },
  998. _setEditStyle_custom: function(){
  999. },
  1000. saveAsTemplete: function(){
  1001. },
  1002. checkModuleId: function(id, type, currentSubform){
  1003. var fieldConflict = false;
  1004. var elementConflict = false;
  1005. if (this.json.moduleList[id]){
  1006. elementConflict = true;
  1007. if (this.options.fields.indexOf(type)!=-1 || this.options.fields.indexOf(this.json.moduleList[id].type)!=-1){
  1008. fieldConflict = true;
  1009. }
  1010. return {"fieldConflict": fieldConflict, "elementConflict": elementConflict};
  1011. }
  1012. // if (this.subformList){
  1013. // Object.each(this.subformList, function(subform){
  1014. // if (!currentSubform || currentSubform!=subform.id){
  1015. // if (subform.moduleList[id]){
  1016. // elementConflict = true;
  1017. // if (this.options.fields.indexOf(type)!=-1 || this.options.fields.indexOf(subform.moduleList[id].type)!=-1){
  1018. // fieldConflict = true;
  1019. // }
  1020. // }
  1021. // }
  1022. // }.bind(this));
  1023. // }
  1024. return {"fieldConflict": fieldConflict, "elementConflict": elementConflict};
  1025. },
  1026. //脚本附签上的脚本编辑器
  1027. addScriptJsEditor: function (propertyName, jsEditor) {
  1028. if( !this.scriptJsEditors )this.scriptJsEditors = {};
  1029. this.scriptJsEditors[propertyName] = jsEditor;
  1030. },
  1031. getScriptJsEditor: function (propertyName) {
  1032. if( !this.scriptJsEditors ){
  1033. return null;
  1034. }else{
  1035. return this.scriptJsEditors[propertyName];
  1036. }
  1037. },
  1038. showFormVersion: function(){
  1039. this.versionNode = new Element("div");
  1040. this.dlg = o2.DL.open({
  1041. "title": MWF.APPFD.LP.version["title"],
  1042. "content": this.versionNode,
  1043. "offset": {"y": -100},
  1044. "isMax": false,
  1045. "width": 500,
  1046. "height": 300,
  1047. "buttonList": [
  1048. {
  1049. "type": "cancel",
  1050. "text": MWF.APPFD.LP.version["close"],
  1051. "action": function(){ this.close(); }
  1052. }
  1053. ],
  1054. "onPostShow": function(){
  1055. this.loadVersionList();
  1056. }.bind(this),
  1057. "onPostClose": function(){
  1058. this.dlg = null;
  1059. }.bind(this)
  1060. });
  1061. },
  1062. loadVersionList : function(){
  1063. var tableHtml = "<table width='100%' cellspacing='0' cellpadding='3' style='margin-top: 1px'><tr>" +
  1064. "<th>"+MWF.APPPOD.LP.version["no"]+"</th>" +
  1065. "<th>"+MWF.APPPOD.LP.version["person"]+"</th>" +
  1066. "<th>"+MWF.APPPOD.LP.version["updateTime"]+"</th>" +
  1067. "<th>"+MWF.APPPOD.LP.version["op"]+"</th>" +
  1068. "</tr></table>";
  1069. this.versionNode.set("html", tableHtml);
  1070. this.versionTable = this.versionNode.getElement("table");
  1071. o2.Actions.load("x_portal_assemble_designer").PageVersionAction.listWithPage(this.form.json.id, function(json){
  1072. this.versionList = json.data;
  1073. this.versionList.sort(function (a, b) {
  1074. return new Date(b.updateTime) - new Date(a.updateTime)
  1075. });
  1076. this.versionList.each(function (version,index) {
  1077. var node = new Element("tr").inject(this.versionTable);
  1078. var html = "<td>"+(index+1)+"</td>" +
  1079. "<td>"+version.person+"</td>" +
  1080. "<td>"+version.updateTime+"</td>" +
  1081. "<td></td>";
  1082. node.set("html", html);
  1083. var actionNode = new Element("div",{"styles":{
  1084. "width": "60px",
  1085. "padding": "0px 3px",
  1086. "border-radius": "20px",
  1087. "cursor" : "pointer",
  1088. "color": "#ffffff",
  1089. "background-color": "#4A90E2",
  1090. "float": "left",
  1091. "margin-right": "2px",
  1092. "text-align": "center",
  1093. "font-weight": "100"
  1094. }}).inject(node.getLast("td"));
  1095. actionNode.set("text", MWF.APPPOD.LP.version["resume"]);
  1096. actionNode.addEvent("click",function (e) {
  1097. var _self = this;
  1098. this.designer.confirm("warn", e, MWF.APPPOD.LP.version["resumeConfirm"], MWF.APPPOD.LP.version["resumeInfo"], 460, 120, function(){
  1099. _self.resumeForm(version);
  1100. this.close();
  1101. }, function(){
  1102. this.close();
  1103. });
  1104. }.bind(this));
  1105. }.bind(this))
  1106. }.bind(this));
  1107. },
  1108. resumeForm : function(version){
  1109. o2.Actions.load("x_portal_assemble_designer").PageVersionAction.get(version.id, function( json ){
  1110. var formData = JSON.parse(json.data.data);
  1111. //this.action.FormAction.update(version.form, formData,function( json ){
  1112. this.designer.notice(MWF.APPPOD.LP.version["resumeSuccess"]);
  1113. var data = JSON.decode(MWF.decodeJsonString(formData.data));
  1114. data.isNewForm = false;
  1115. this.reload(data);
  1116. this.dlg.close();
  1117. //}.bind(this), null, false);
  1118. }.bind(this), null, false);
  1119. }
  1120. });