Form.js 34 KB

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