Form.js 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168
  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", "org", "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. debugger;
  77. this.data = data;
  78. this.json = data.json;
  79. this.html = data.html;
  80. this.json.mode = this.options.mode;
  81. if (!this.json.css) this.json.css = {"code":""};
  82. if (this.options.mode==="Mobile"){
  83. if (!this.json.defaultTools){
  84. this.json.defaultTools = o2.JSON.get(this.path+"toolbars.json", null,false);
  85. }
  86. if (!this.json.tools) this.json.tools=[];
  87. }
  88. this.isNewForm = (this.json.id) ? false : true;
  89. if (this.isNewForm) this.checkUUID();
  90. if(this.designer.application) this.data.json.applicationName = this.designer.application.name;
  91. if(this.designer.application) this.data.json.application = this.designer.application.id;
  92. this.container.set("html", this.html);
  93. this.loadStylesList(function(){
  94. var oldStyleValue = "";
  95. if ((!this.json.formStyleType) || !this.stylesList[this.json.formStyleType]) this.json.formStyleType="blue-simple";
  96. if (this.options.mode=="Mobile"){
  97. if (this.json.formStyleType != "defaultMobile"){
  98. oldStyleValue = this.json.formStyleType;
  99. this.json.formStyleType = "defaultMobile";
  100. }
  101. }
  102. this.loadTemplateStyles( this.stylesList[this.json.formStyleType].file, this.stylesList[this.json.formStyleType].extendFile, function( templateStyles ){
  103. //this.templateStyles = (this.stylesList && this.json.formStyleType) ? this.stylesList[this.json.formStyleType] : null;
  104. this.templateStyles = templateStyles;
  105. this.loadDomModules();
  106. if (this.json.formStyleType && this.templateStyles && this.templateStyles["form"]){
  107. this.setTemplateStyles(this.templateStyles["form"]);
  108. }
  109. this.setCustomStyles();
  110. this.node.setProperties(this.json.properties);
  111. this.setNodeEvents();
  112. if (this.options.mode=="Mobile"){
  113. if (oldStyleValue) this._setEditStyle("formStyleType", null, oldStyleValue);
  114. }
  115. this.selected();
  116. this.autoSave();
  117. this.designer.addEvent("queryClose", function(){
  118. if (this.autoSaveTimerID) window.clearInterval(this.autoSaveTimerID);
  119. }.bind(this));
  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. if( this.json.confirmStyle )delete this.json.confirmStyle;
  144. if( this.json.dialogStyle )delete this.json.dialogStyle;
  145. if( this.json.selectorStyle )delete this.json.selectorStyle;
  146. },
  147. setTemplateStyles: function(styles){
  148. if (styles.styles) this.copyStyles(styles.styles, "styles");
  149. if (styles.properties) this.copyStyles(styles.properties, "properties");
  150. if( styles.confirmStyle )this.json.confirmStyle = styles.confirmStyle;
  151. if( styles.dialogStyle )this.json.dialogStyle = styles.dialogStyle;
  152. if( styles.selectorStyle )this.json.selectorStyle = styles.selectorStyle;
  153. },
  154. loadTemplateStyles : function( file, extendFile, callback ){
  155. if( !file ){
  156. if (callback) callback({});
  157. return;
  158. }
  159. this.templateStylesList = this.templateStylesList || {};
  160. if( this.templateStylesList[file] ){
  161. if (callback) callback(this.templateStylesList[file]);
  162. return;
  163. }
  164. this.loadTemplateStyleFile( file, function( json_file ){
  165. this.loadTemplateExtendStyleFile( extendFile, function( json_extend ){
  166. this.templateStylesList[file] = Object.merge( json_file, json_extend );
  167. if (callback) callback(this.templateStylesList[file]);
  168. }.bind(this))
  169. }.bind(this))
  170. },
  171. loadTemplateStyleFile : function(file, callback ){
  172. if( !file ){
  173. if (callback) callback({});
  174. return;
  175. }
  176. var stylesUrl = "/x_component_process_FormDesigner/Module/Form/skin/"+file;
  177. MWF.getJSON(stylesUrl,{
  178. "onSuccess": function(responseJSON){
  179. //this.templateStylesList[file] = responseJSON;
  180. if (callback) callback(responseJSON);
  181. }.bind(this),
  182. "onRequestFailure": function(){
  183. if (callback) callback({});
  184. }.bind(this),
  185. "onError": function(){
  186. if (callback) callback({});
  187. }.bind(this)
  188. }
  189. );
  190. },
  191. loadTemplateExtendStyleFile : function(extendFile, callback ){
  192. if( !extendFile ){
  193. if (callback) callback({});
  194. return;
  195. }
  196. var stylesUrl = "/x_component_process_FormDesigner/Module/Form/skin/"+extendFile;
  197. MWF.getJSON(stylesUrl,{
  198. "onSuccess": function(responseJSON){
  199. //this.templateStylesList[file] = responseJSON;
  200. if (callback) callback(responseJSON);
  201. }.bind(this),
  202. "onRequestFailure": function(){
  203. if (callback) callback({});
  204. }.bind(this),
  205. "onError": function(){
  206. if (callback) callback({});
  207. }.bind(this)
  208. }
  209. );
  210. },
  211. loadStylesList: function(callback){
  212. //var stylesUrl = "/x_component_process_FormDesigner/Module/Form/template/"+((this.options.mode=="Mobile") ? "mobileStyles": "styles")+".json";
  213. //var stylesUrl = "/x_component_process_FormDesigner/Module/Form/template/"+((this.options.mode=="Mobile") ? "styles": "styles")+".json";
  214. var configUrl = "/x_component_process_FormDesigner/Module/Form/skin/config.json";
  215. MWF.getJSON(configUrl,{
  216. "onSuccess": function(responseJSON){
  217. this.stylesList = responseJSON;
  218. if (callback) callback(this.stylesList);
  219. }.bind(this),
  220. "onRequestFailure": function(){
  221. this.stylesList = {};
  222. if (callback) callback(this.stylesList);
  223. }.bind(this),
  224. "onError": function(){
  225. this.stylesList = {};
  226. if (callback) callback(this.stylesList);
  227. }.bind(this)
  228. }
  229. );
  230. },
  231. autoSave: function(){
  232. this.autoSaveCheckNode = this.designer.formToolbarNode.getElement("#MWFFormAutoSaveCheck");
  233. if (this.autoSaveCheckNode){
  234. this.autoSaveTimerID = window.setInterval(function(){
  235. if (this.autoSaveCheckNode.get("checked")){
  236. this.save();
  237. }
  238. }.bind(this), 60000);
  239. }
  240. },
  241. checkUUID: function(){
  242. this.designer.actions.getUUID(function(id){
  243. this.json.id = id;
  244. }.bind(this));
  245. },
  246. loadDomModules: function(){
  247. this.node = this.container.getFirst();
  248. this.node.set("id", this.json.id);
  249. this.node.setStyles((this.options.mode==="Mobile") ? this.css.formMobileNode : this.css.formNode);
  250. this.node.store("module", this);
  251. var id = this.json.id.replace(/\-/g, "");
  252. this.node.addClass("css"+id);
  253. this.reloadCss();
  254. var y = this.container.getStyle("height");
  255. y = (y) ? y.toInt()-2 : this.container.getSize().y-2;
  256. this.node.setStyle("min-height", ""+y+"px");
  257. this.designer.addEvent("resize", function(){
  258. var y = this.container.getStyle("height");
  259. y = (y) ? y.toInt()-2 : this.container.getSize().y-2;
  260. this.node.setStyle("min-height", ""+y+"px");
  261. }.bind(this));
  262. this.loadDomTree();
  263. },
  264. loadDomTree: function(){
  265. MWF.require("MWF.widget.Tree", function(){
  266. this.domTree = new MWF.widget.Tree(this.designer.propertyDomArea, {"style": "domtree"});
  267. this.domTree.load();
  268. this.createFormTreeNode();
  269. this.parseModules(this, this.node);
  270. }.bind(this));
  271. },
  272. createFormTreeNode: function(){
  273. var text = "<"+this.json.type+"> "+this.json.name+" ["+this.options.mode+"] ";
  274. var o = {
  275. "expand": true,
  276. "title": this.json.id,
  277. "text": "<"+this.json.type+"> "+this.json.name+" ["+this.options.mode+"] ",
  278. "icon": (this.options.mode=="Mobile") ? "mobile.png": "pc.png"
  279. };
  280. o.action = function(){
  281. if (this.module) this.module.selected();
  282. };
  283. this.treeNode = this.domTree.appendChild(o);
  284. this.treeNode.setText(text);
  285. this.treeNode.module = this;
  286. },
  287. parseModules: function(parent, dom){
  288. var subDom = dom.getFirst();
  289. while (subDom){
  290. if (subDom.get("MWFtype")){
  291. // var module = subDom.retrieve("module");
  292. // alert(subDom.get("id")+": "+module);
  293. // if (!module){
  294. var json = this.getDomjson(subDom);
  295. module = this.loadModule(json, subDom, parent);
  296. // }
  297. // if (module.moduleType=="container") this.parseModules(module, subDom);
  298. // }else{
  299. // this.parseModules(parent, subDom);
  300. }
  301. // else if (subDom.getFirst()){
  302. // subDom = subDom.getFirst();
  303. // this.parseModules(parent, subDom);
  304. // }else{
  305. // subDom = subDom.getNext();
  306. // }
  307. subDom = subDom.getNext();
  308. }
  309. },
  310. getDomjson: function(dom){
  311. var mwfType = dom.get("MWFtype");
  312. switch (mwfType) {
  313. case "form":
  314. return this.json;
  315. case "":
  316. return null;
  317. default:
  318. var id = dom.get("id");
  319. if (id){
  320. return this.json.moduleList[id];
  321. }else{
  322. return null;
  323. }
  324. }
  325. },
  326. loadModule: function(json, dom, parent){
  327. if( !json ){
  328. debugger;
  329. var module;
  330. var className = ( dom.get("MWFType") || "div" ).capitalize();
  331. this.getTemplateData(className, function(data){
  332. var moduleData = Object.clone(data);
  333. moduleData.id = dom.get("id");
  334. this.json.moduleList[dom.get("id")] = moduleData;
  335. module = new MWF["FC"+className](this);
  336. module.load(moduleData, dom, parent);
  337. }.bind(this), false);
  338. return module;
  339. }else if( MWF["FC"+json.type] ){
  340. var module = new MWF["FC"+json.type](this);
  341. module.load(json, dom, parent);
  342. //this.moduleList.push(module);
  343. return module;
  344. }else{
  345. var module = new MWF["FCDiv"](this);
  346. module.load(json, dom, parent);
  347. //this.moduleList.push(module);
  348. return module;
  349. }
  350. },
  351. setNodeEvents: function(){
  352. this.node.addEvent("click", function(e){
  353. this.selected();
  354. }.bind(this));
  355. // this._controlKeyEventFun = function(e){
  356. // if (e.control){
  357. // this.controlMode = true;
  358. // if (this.copyNode) this.copyNode.destroy();
  359. // }else{
  360. // this.controlMode = false;
  361. // // var copyNode = this._getCopyNode(this);
  362. // // copyNode.inject(this.node, "before");
  363. // }
  364. // }.bind(this);
  365. this.designer.content.addEvent("keydown", function(e){
  366. if (this.moveModule){
  367. if (e.control){
  368. this.moveModule._setControlMode(true);
  369. }else{
  370. this.moveModule._setControlMode(false);
  371. }
  372. }
  373. }.bind(this));
  374. this.designer.content.addEvent("keyup", function(e){
  375. if (this.moveModule){
  376. if (e.control){
  377. this.moveModule._setControlMode(true);
  378. }else{
  379. this.moveModule._setControlMode(false);
  380. }
  381. }
  382. }.bind(this));
  383. },
  384. createModuleImmediately: function( className, parentModule, relativeNode, position, selectDisabled, async ){
  385. var module;
  386. this.getTemplateData(className, function(data){
  387. var moduleData = Object.clone(data);
  388. module = new MWF["PC"+className](this);
  389. if( parentModule ){
  390. module.onDragModule = parentModule;
  391. if (!parentModule.Component) module.inContainer = parentModule;
  392. module.parentContainer = parentModule;
  393. module.nextModule = null;
  394. }
  395. module.createImmediately(moduleData, relativeNode, position, selectDisabled);
  396. }.bind(this), async);
  397. return module;
  398. },
  399. createModule: function(className, e){
  400. this.getTemplateData(className, function(data){
  401. var moduleData = Object.clone(data);
  402. var newTool = new MWF["FC"+className](this);
  403. newTool.create(moduleData, e);
  404. }.bind(this));
  405. },
  406. getTemplateData: function(className, callback , async){
  407. if (this.dataTemplate[className]){
  408. if (callback) callback(this.dataTemplate[className]);
  409. }else{
  410. var templateUrl = "/x_component_process_FormDesigner/Module/"+className+"/template.json";
  411. MWF.getJSON(templateUrl, function(responseJSON, responseText){
  412. this.dataTemplate[className] = responseJSON;
  413. if (callback) callback(responseJSON);
  414. }.bind(this), async);
  415. }
  416. },
  417. selected: function(){
  418. if (this.currentSelectedModule){
  419. if (this.currentSelectedModule==this){
  420. return true;
  421. }else{
  422. this.currentSelectedModule.unSelected();
  423. }
  424. }
  425. if (this.propertyMultiTd){
  426. this.propertyMultiTd.hide();
  427. this.propertyMultiTd = null;
  428. }
  429. this.unSelectedMulti();
  430. this.currentSelectedModule = this;
  431. if (this.treeNode){
  432. this.treeNode.selectNode();
  433. }
  434. this.showProperty();
  435. // this.isFocus = true;
  436. },
  437. unSelectedMulti: function(){
  438. while (this.selectedModules.length){
  439. this.selectedModules[0].unSelectedMulti();
  440. }
  441. if (this.multimoduleActionsArea) this.multimoduleActionsArea.setStyle("display", "none");
  442. },
  443. unSelectAll: function(){
  444. },
  445. _beginSelectMulti: function(){
  446. if (this.currentSelectedModule) this.currentSelectedModule.unSelected();
  447. this.unSelectedMulti();
  448. this.noSelected = true;
  449. },
  450. _completeSelectMulti: function(){
  451. if (this.selectedModules.length<2){
  452. this.selectedModules[0].selected();
  453. }else{
  454. this._showMultiActions();
  455. }
  456. },
  457. createMultimoduleActionsArea: function(){
  458. this.multimoduleActionsArea = new Element("div", {
  459. styles: {
  460. "display": "none",
  461. // "width": 18*this.options.actions.length,
  462. "position": "absolute",
  463. "background-color": "#F1F1F1",
  464. "padding": "1px",
  465. "padding-right": "0px",
  466. "border": "1px solid #AAA",
  467. "box-shadow": "0px 2px 5px #999",
  468. "z-index": 10001
  469. }
  470. }).inject(this.form.container, "after");
  471. },
  472. _showMultiActions: function(){
  473. if (!this.multimoduleActionsArea) this.createMultimoduleActionsArea();
  474. var firstModule = this._getFirstMultiSelectedModule();
  475. if (firstModule){
  476. // var module = firstModule.module;
  477. var y = firstModule.position.y-25;
  478. var x = firstModule.position.x;
  479. this.multimoduleActionsArea.setPosition({"x": x, "y": y});
  480. this.multimoduleActionsArea.setStyle("display", "block");
  481. }
  482. },
  483. _getFirstMultiSelectedModule: function(){
  484. var firstModule = null;
  485. this.selectedModules.each(function(module){
  486. var position = module.node.getPosition(module.form.node.getOffsetParent());
  487. if (!firstModule){
  488. firstModule = {"module": module, "position": position};
  489. }else{
  490. if (position.y<firstModule.position.y){
  491. firstModule = {"module": module, "position": position};
  492. }else if (position.y==firstModule.position.y){
  493. if (position.x<firstModule.position.x){
  494. firstModule = {"module": module, "position": position};
  495. }
  496. }
  497. }
  498. });
  499. return firstModule;
  500. },
  501. showProperty: function(){
  502. if (!this.property){
  503. this.property = new MWF.xApplication.process.FormDesigner.Property(this, this.designer.propertyContentArea, this.designer, {
  504. "path": this.options.propertyPath,
  505. "onPostLoad": function(){
  506. this.property.show();
  507. }.bind(this)
  508. });
  509. this.property.load();
  510. }else{
  511. this.property.show();
  512. }
  513. },
  514. hideProperty: function(){
  515. if (this.property) this.property.hide();
  516. },
  517. unSelected: function(){
  518. this.currentSelectedModule = null;
  519. this.hideProperty();
  520. },
  521. _dragIn: function(module){
  522. if (!this.Component) module.inContainer = this;
  523. module.parentContainer = this;
  524. this.node.setStyles({"border": "1px solid #ffa200"});
  525. var copyNode = module._getCopyNode();
  526. copyNode.inject(this.node);
  527. },
  528. _dragOut: function(module){
  529. module.inContainer = null;
  530. module.parentContainer = null;
  531. this.node.setStyles((this.options.mode==="Mobile") ? this.css.formMobileNode : this.css.formNode);
  532. this.node.setStyles(this.json.styles);
  533. var copyNode = module._getCopyNode();
  534. copyNode.setStyle("display", "none");
  535. },
  536. _dragDrop: function(module, flag){
  537. var f = flag || !(new Event(event)).control;
  538. if( f ){
  539. this.node.setStyles((this.options.mode==="Mobile") ? this.css.formMobileNode : this.css.formNode);
  540. this.node.setStyles(this.json.styles);
  541. }
  542. //this._hideInjectAction();
  543. },
  544. _showInjectAction : function( module ){
  545. if ( module.moveNode ){
  546. module.moveNode.setStyle("display","none");
  547. }
  548. //debugger;
  549. this.draggingModule = module;
  550. //if( !this.node.getFirst() ){
  551. // this.inject( "top" );
  552. // return;
  553. //}
  554. if( !this.injectActionArea )this._createInjectAction();
  555. this.injectActionArea.setStyle("display","block");
  556. this._setInjectActionAreaPosition();
  557. this.injectActionEffect = new Fx.Morph(this.injectActionArea, {
  558. duration: 200,
  559. transition: Fx.Transitions.Sine.easeOut
  560. });
  561. this.injectActionEffect.start(this.form.css.injectActionArea_to);
  562. },
  563. _hideInjectAction : function(){
  564. this.draggingModule = null;
  565. if( this.injectActionArea ){
  566. this.injectActionArea.setStyle("display","none");
  567. }
  568. },
  569. _createInjectAction : function(){
  570. var css = this.form.css;
  571. if( !this.injectActionArea ){
  572. this.injectActionArea = new Element("div", { styles: css.injectActionArea }).inject(this.form.container, "after");
  573. this.injectActionTopBGNode = new Element("div", { styles : css.injectActionTopBGNode }).inject( this.injectActionArea );
  574. this.injectActionLeftBGNode = new Element("div", { styles : css.injectActionLeftBGNode }).inject( this.injectActionArea );
  575. this.injectActionRightBGNode = new Element("div", { styles : css.injectActionRightBGNode }).inject( this.injectActionArea );
  576. this.injectActionBottomBGNode = new Element("div", { styles : css.injectActionBottomBGNode }).inject( this.injectActionArea );
  577. var injectActions = {};
  578. this.options.injectActions.each( function( action ){
  579. injectActions[ action.name ] = action;
  580. });
  581. if( injectActions.before )this._createInjectActionNode( injectActions.before, this.injectActionTopBGNode );
  582. if( injectActions.top )this._createInjectActionNode( injectActions.top, this.injectActionLeftBGNode );
  583. if( injectActions.bottom )this._createInjectActionNode( injectActions.bottom, this.injectActionRightBGNode );
  584. if( injectActions.after )this._createInjectActionNode( injectActions.after, this.injectActionBottomBGNode );
  585. new Element("div", {
  586. styles : css.injectActionCancelNode,
  587. events : {
  588. click : function(){
  589. this.draggingModule._dragCancel();
  590. this._dragDrop( this.node, true );
  591. this._hideInjectAction();
  592. }.bind(this),
  593. mouseover : function(){
  594. this.setStyles( css.injectActionCancelNode_over )
  595. },
  596. mouseout : function(){
  597. this.setStyles( css.injectActionCancelNode )
  598. }
  599. }
  600. }).inject(this.injectActionArea);
  601. }
  602. },
  603. _createInjectActionNode : function( action, relativeNode ){
  604. var actionNode = new Element("div", {
  605. "styles": this.css[action.styles],
  606. "title": action.title
  607. }).inject( this.injectActionArea );
  608. actionNode.addEvent(action.event, function(e){
  609. this[action.action](e);
  610. }.bind(this));
  611. actionNode.addEvents({
  612. "mouseover": function(e){
  613. relativeNode.setStyle("background", "#ddd");
  614. this.draggingModule.copyNode.setStyle("display","");
  615. this.draggingModule.copyNode.inject( this.node, action.name );
  616. }.bind(this),
  617. "mouseout": function(e){
  618. relativeNode.setStyle("background", "transparent");
  619. }.bind(this)
  620. });
  621. relativeNode.set("title",action.title);
  622. relativeNode.addEvent(action.event, function(e){
  623. this[action.action](e);
  624. }.bind(this));
  625. relativeNode.setStyle("cursor","pointer");
  626. relativeNode.addEvents({
  627. "mouseenter": function(e){
  628. relativeNode.setStyle("background", "#ddd");
  629. this.draggingModule.copyNode.setStyle("display","");
  630. this.draggingModule.copyNode.inject( this.node, action.name );
  631. }.bind(this),
  632. "mouseleave": function(e){
  633. relativeNode.setStyle("background", "transparent");
  634. //this.draggingModule.copyNode.setStyle("display","none");
  635. }.bind(this)
  636. });
  637. },
  638. _setInjectActionAreaPosition: function(){
  639. var e = new Event(event);
  640. var formOffset = this.node.getOffsetParent().getPosition();
  641. //var p = this.node.getPosition(this.form.node.getOffsetParent());
  642. var y = e.page.y - formOffset.y - 60;
  643. var x = e.page.x - formOffset.x - 60;
  644. this.injectActionArea.setPosition({"x": x, "y": y});
  645. },
  646. injectBefore : function( e ){
  647. this.inject( "before" )
  648. },
  649. injectAfter : function( e ){
  650. this.inject( "after" )
  651. },
  652. injectTop : function( e ){
  653. this.inject( "top" )
  654. },
  655. injectBottom : function( e ){
  656. this.inject( "bottom" )
  657. },
  658. inject : function( position ){
  659. if ( this.draggingModule.moveNode ){
  660. this.draggingModule.moveNode.setStyle("display","");
  661. }
  662. this.draggingModule._dragComplete( this.node, position );
  663. this._dragDrop( this.node, true );
  664. this._hideInjectAction();
  665. },
  666. _clearNoId: function(node){
  667. var subNode = node.getFirst();
  668. while (subNode){
  669. var nextNode = subNode.getNext();
  670. if (subNode.get("MWFType")){
  671. if (!subNode.get("id")){
  672. subNode.destroy();
  673. }else{
  674. if (subNode) this._clearNoId(subNode);
  675. }
  676. }else{
  677. if (subNode) this._clearNoId(subNode);
  678. }
  679. subNode = nextNode;
  680. }
  681. },
  682. _getFormData: function(){
  683. this.fireEvent("queryGetFormData");
  684. var copy = this.node.clone(true, true);
  685. copy.clearStyles(true);
  686. this.fireEvent("postGetFormData");
  687. this._clearNoId(copy);
  688. var html = copy.outerHTML;
  689. //this._clearNoDomModule();
  690. copy.destroy();
  691. this.data.json.mode = this.options.mode;
  692. this.data.html = html;
  693. return this.data;
  694. },
  695. _clearNoDomModule : function(){
  696. debugger;
  697. var existModuleList = {};
  698. Object.each( this.moduleList, function( module ){
  699. existModuleList[ module.json.id ] = true;
  700. });
  701. Object.each( this.data.json.moduleList , function( module, key ){
  702. //if( !this.node.getElement( "#" + module.id ) && !existModuleList[ module.id ] ){
  703. if( !existModuleList[ module.id ] ){
  704. delete this.data.json.moduleList[key];
  705. }
  706. }.bind(this));
  707. },
  708. preview: function(){
  709. MWF.xDesktop.requireApp("process.FormDesigner", "Preview", function(){
  710. if (this.options.mode=="Mobile"){
  711. this.previewBox = new MWF.xApplication.process.FormDesigner.Preview(this, {"size": {"x": "400", "y": 580}, "mode": "mobile"});
  712. }else{
  713. this.previewBox = new MWF.xApplication.process.FormDesigner.Preview(this);
  714. }
  715. this.previewBox.load();
  716. }.bind(this));
  717. },
  718. save: function(callback){
  719. // debugger;
  720. // this.moduleList.each(function(module){
  721. // if (module.moduleName==="subform"){
  722. // module.refreshSubform();
  723. // }
  724. // }.bind(this));
  725. this.designer.saveForm();
  726. //this._getFormData();
  727. //this.designer.actions.saveForm(this.data, function(responseJSON){
  728. // this.form.designer.notice(MWF.APPFD.LP.notice["save_success"], "ok", null, {x: "left", y:"bottom"});
  729. //
  730. // //this.json.id = responseJSON.data;
  731. // if (!this.json.name) this.treeNode.setText("<"+this.json.type+"> "+this.json.id);
  732. // this.treeNode.setTitle(this.json.id);
  733. // this.node.set("id", this.json.id);
  734. //
  735. // if (callback) callback();
  736. // //this.reload(responseJSON.data);
  737. //}.bind(this));
  738. },
  739. explode: function(){
  740. this._getFormData();
  741. MWF.require("MWF.widget.Base64", null, false);
  742. var data = MWF.widget.Base64.encode(JSON.encode(this.data));
  743. MWF.require("MWF.widget.Panel", function(){
  744. var node = new Element("div");
  745. var size = this.designer.formNode.getSize();
  746. var position = this.designer.formNode.getPosition(this.designer.formNode.getOffsetParent());
  747. var textarea = new Element("textarea", {
  748. "styles": {
  749. "border": "1px solid #999",
  750. "width": "770px",
  751. "margin-left": "14px",
  752. "margin-top": "14px",
  753. "height": "580px"
  754. },
  755. "text": JSON.encode(this.data)
  756. }).inject(node);
  757. this.explodePanel = new MWF.widget.Panel(node, {
  758. "style": "form",
  759. "isResize": false,
  760. "isMax": false,
  761. "title": "",
  762. "width": 800,
  763. "height": 660,
  764. "top": position.y,
  765. "left": position.x+3,
  766. "isExpand": false,
  767. "target": this.designer.node
  768. });
  769. this.explodePanel.load();
  770. }.bind(this));
  771. },
  772. implode: function(){
  773. MWF.xDesktop.requireApp("portal.PageDesigner", "Import", function(){
  774. MWF.FormImport.create("O2", this);
  775. }.bind(this));
  776. },
  777. // implodeJsonData: function(str){
  778. // if (str){
  779. // //try{
  780. // debugger;
  781. // var data = JSON.decode(str);
  782. // if (data){
  783. // var json = data.json;
  784. // data.id = this.data.id;
  785. // data.isNewPage = this.data.isNewPage;
  786. // json.id = this.json.id;
  787. // json.name = this.json.name;
  788. // json.application = this.json.application;
  789. // json.applicationName = this.json.applicationName;
  790. //
  791. // this.reload(data);
  792. // this.implodePanel.closePanel();
  793. // }else{
  794. // this.designer.notice(this.designer.lp.implodeError, "error");
  795. // }
  796. // // }catch(e){
  797. // // this.designer.notice(this.designer.lp.implodeError, "error");
  798. // // }
  799. // }else{
  800. // this.designer.notice(this.designer.lp.implodeEmpty, "error");
  801. // }
  802. // },
  803. implodeHTML: function(){
  804. MWF.xDesktop.requireApp("portal.PageDesigner", "Import", function(){
  805. MWF.FormImport.create("html", this, {"type": "process"});
  806. }.bind(this));
  807. },
  808. implodeOffice: function(){
  809. MWF.xDesktop.requireApp("portal.PageDesigner", "Import", function(){
  810. MWF.FormImport.create("office", this);
  811. }.bind(this));
  812. },
  813. setPropertiesOrStyles: function(name){
  814. if (name=="styles"){
  815. this.setCustomStyles();
  816. }
  817. if (name=="properties"){
  818. this.node.setProperties(this.json.properties);
  819. }
  820. },
  821. setCustomStyles: function(){
  822. var border = this.node.getStyle("border");
  823. this.node.clearStyles();
  824. this.node.setStyles((this.options.mode==="Mobile") ? this.css.formMobileNode : this.css.formNode);
  825. var y = this.container.getStyle("height");
  826. y = (y) ? y.toInt()-2 : this.container.getSize().y-2;
  827. this.node.setStyle("min-height", ""+y+"px");
  828. if (this.initialStyles) this.node.setStyles(this.initialStyles);
  829. this.node.setStyle("border", border);
  830. Object.each(this.json.styles, function(value, key){
  831. var reg = /^border\w*/ig;
  832. if (!key.test(reg)){
  833. this.node.setStyle(key, value);
  834. }
  835. }.bind(this));
  836. },
  837. _setEditStyle: function(name, obj, oldValue){
  838. if (name=="name"){
  839. var title = this.json.name || this.json.id;
  840. this.treeNode.setText("<"+this.json.type+"> "+title+" ["+this.options.mode+"] ");
  841. }
  842. if (name=="id"){
  843. if (!this.json.name) this.treeNode.setText("<"+this.json.type+"> "+this.json.id+" ["+this.options.mode+"] ");
  844. this.treeNode.setTitle(this.json.id);
  845. this.node.set("id", this.json.id);
  846. }
  847. if (name=="formStyleType"){
  848. var file = (this.stylesList && this.json.formStyleType) ? this.stylesList[this.json.formStyleType].file : null;
  849. var extendFile = (this.stylesList && this.json.formStyleType) ? this.stylesList[this.json.formStyleType].extendFile : null;
  850. this.loadTemplateStyles( file, extendFile, function( templateStyles ){
  851. //this.templateStyles = (this.stylesList && this.json.formStyleType) ? this.stylesList[this.json.formStyleType] : null;
  852. this.templateStyles = templateStyles;
  853. var oldFile, oldExtendFile;
  854. if( oldValue && this.stylesList[oldValue] ){
  855. oldFile = this.stylesList[oldValue].file;
  856. oldExtendFile = this.stylesList[oldValue].extendFile;
  857. }
  858. this.loadTemplateStyles( oldFile, oldExtendFile, function( oldTemplateStyles ){
  859. //if (oldValue) {
  860. // var oldTemplateStyles = this.stylesList[oldValue];
  861. // if (oldTemplateStyles){
  862. // if (oldTemplateStyles["form"]) this.clearTemplateStyles(oldTemplateStyles["form"]);
  863. // }
  864. //}
  865. this.json.styleConfig = (this.stylesList && this.json.formStyleType) ? this.stylesList[this.json.formStyleType] : null;
  866. if (oldTemplateStyles["form"]) this.clearTemplateStyles(oldTemplateStyles["form"]);
  867. if (this.templateStyles["form"]) this.setTemplateStyles(this.templateStyles["form"]);
  868. this.setAllStyles();
  869. this.moduleList.each(function(module){
  870. if (oldTemplateStyles[module.moduleName]){
  871. module.clearTemplateStyles(oldTemplateStyles[module.moduleName]);
  872. }
  873. module.setStyleTemplate();
  874. module.setAllStyles();
  875. }.bind(this));
  876. }.bind(this))
  877. }.bind(this))
  878. }
  879. if (name==="css"){
  880. this.reloadCss();
  881. }
  882. this._setEditStyle_custom(name, obj, oldValue);
  883. },
  884. parseCSS: function(css){
  885. var rex = /(url\(.*\))/g;
  886. var match;
  887. while ((match = rex.exec(css)) !== null) {
  888. var pic = match[0];
  889. var len = pic.length;
  890. var s = pic.substring(pic.length-2, pic.length-1);
  891. var n0 = (s==="'" || s==="\"") ? 5 : 4;
  892. var n1 = (s==="'" || s==="\"") ? 2 : 1;
  893. pic = pic.substring(n0, pic.length-n1);
  894. if ((pic.indexOf("x_processplatform_assemble_surface")!=-1 || pic.indexOf("x_portal_assemble_surface")!=-1)){
  895. var host1 = MWF.Actions.getHost("x_processplatform_assemble_surface");
  896. var host2 = MWF.Actions.getHost("x_portal_assemble_surface");
  897. if (pic.indexOf("/x_processplatform_assemble_surface")!==-1){
  898. pic = pic.replace("/x_processplatform_assemble_surface", pic+"/x_processplatform_assemble_surface");
  899. }else if (pic.indexOf("x_processplatform_assemble_surface")!==-1){
  900. pic = pic.replace("x_processplatform_assemble_surface", pic+"/x_processplatform_assemble_surface");
  901. }
  902. if (pic.indexOf("/x_portal_assemble_surface")!==-1){
  903. pic = pic.replace("/x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  904. }else if (pic.indexOf("x_portal_assemble_surface")!==-1){
  905. pic = pic.replace("x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  906. }
  907. }
  908. pic = "url('"+pic+"')";
  909. var len2 = pic.length;
  910. css = css.substring(0, match.index) + pic + css.substring(rex.lastIndex, css.length);
  911. rex.lastIndex = rex.lastIndex + (len2-len);
  912. }
  913. return css;
  914. },
  915. reloadCss: function(){
  916. cssText = (this.json.css) ? this.json.css.code : "";
  917. //var head = (document.head || document.getElementsByTagName("head")[0] || document.documentElement);
  918. var styleNode = $("style"+this.json.id);
  919. if (styleNode) styleNode.destroy();
  920. if (cssText){
  921. cssText = this.parseCSS(cssText);
  922. var rex = new RegExp("(.+)(?=\\{)", "g");
  923. var match;
  924. var id = this.json.id.replace(/\-/g, "");
  925. var prefix = ".css" + id + " ";
  926. while ((match = rex.exec(cssText)) !== null) {
  927. // var rule = prefix + match[0];
  928. // cssText = cssText.substring(0, match.index) + rule + cssText.substring(rex.lastIndex, cssText.length);
  929. // rex.lastIndex = rex.lastIndex + prefix.length;
  930. var rulesStr = match[0];
  931. if (rulesStr.indexOf(",")!=-1){
  932. var rules = rulesStr.split(/\s*,\s*/g);
  933. rules = rules.map(function(r){
  934. return prefix + r;
  935. });
  936. var rule = rules.join(", ");
  937. cssText = cssText.substring(0, match.index) + rule + cssText.substring(rex.lastIndex, cssText.length);
  938. rex.lastIndex = rex.lastIndex + (prefix.length*rules.length);
  939. }else{
  940. var rule = prefix + match[0];
  941. cssText = cssText.substring(0, match.index) + rule + cssText.substring(rex.lastIndex, cssText.length);
  942. rex.lastIndex = rex.lastIndex + prefix.length;
  943. }
  944. }
  945. var styleNode = document.createElement("style");
  946. styleNode.setAttribute("type", "text/css");
  947. styleNode.id="style"+this.json.id;
  948. styleNode.inject(this.container, "before");
  949. if(styleNode.styleSheet){
  950. var setFunc = function(){
  951. styleNode.styleSheet.cssText = cssText;
  952. };
  953. if(styleNode.styleSheet.disabled){
  954. setTimeout(setFunc, 10);
  955. }else{
  956. setFunc();
  957. }
  958. }else{
  959. var cssTextNode = document.createTextNode(cssText);
  960. styleNode.appendChild(cssTextNode);
  961. }
  962. }
  963. },
  964. setAllStyles: function(){
  965. this.setPropertiesOrStyles("styles");
  966. this.setPropertiesOrStyles("properties");
  967. this.reloadMaplist();
  968. },
  969. reloadMaplist: function(){
  970. if (this.property) Object.each(this.property.maplists, function(map, name){ map.reload(this.json[name]);}.bind(this));
  971. },
  972. _setEditStyle_custom: function(){
  973. },
  974. saveAsTemplete: function(){
  975. },
  976. isModuleExited : function( id ){
  977. for( var i=0; i<this.moduleList.length; i++ ){
  978. if(this.moduleList[i].json.id === id)return true;
  979. }
  980. return false;
  981. },
  982. checkModuleId: function(id, type, currentSubform){
  983. var fieldConflict = false;
  984. var elementConflict = false;
  985. //if (this.json.moduleList[id]){
  986. if( this.isModuleExited(id) ){
  987. elementConflict = true;
  988. if (this.options.fields.indexOf(type)!=-1 || this.options.fields.indexOf(this.json.moduleList[id].type)!=-1){
  989. fieldConflict = true;
  990. }
  991. return {"fieldConflict": fieldConflict, "elementConflict": elementConflict};
  992. }
  993. //if (this.subformList){
  994. // Object.each(this.subformList, function(subform){
  995. // if (!currentSubform || currentSubform!=subform.id){
  996. // if (subform.moduleList[id]){
  997. // elementConflict = true;
  998. // if (this.options.fields.indexOf(type)!=-1 || this.options.fields.indexOf(subform.moduleList[id].type)!=-1){
  999. // fieldConflict = true;
  1000. // }
  1001. // }
  1002. // }
  1003. // }.bind(this));
  1004. //}
  1005. var subformList = this.getAllSubformJsonObject();
  1006. if (subformList){
  1007. Object.each(subformList, function(subform){
  1008. if (!currentSubform || currentSubform!=subform.id){
  1009. if (subform.moduleList[id]){
  1010. elementConflict = true;
  1011. if (this.options.fields.indexOf(type)!=-1 || this.options.fields.indexOf(subform.moduleList[id].type)!=-1){
  1012. fieldConflict = true;
  1013. }
  1014. }
  1015. }
  1016. }.bind(this));
  1017. }
  1018. return {"fieldConflict": fieldConflict, "elementConflict": elementConflict};
  1019. },
  1020. _resetTreeNode: function(){},
  1021. clearSubformList : function( level1subformName ){
  1022. if( !this.level1Subformlist )return;
  1023. if( !this.level1Subformlist[level1subformName] )return;
  1024. delete this.level1Subformlist[level1subformName];
  1025. },
  1026. addSubformList : function( level1subformName, addedSubformId ){
  1027. if( !this.level1Subformlist ){
  1028. this.level1Subformlist = {};
  1029. }
  1030. if( !this.level1Subformlist[level1subformName] ){
  1031. this.level1Subformlist[level1subformName] = [];
  1032. }
  1033. this.level1Subformlist[level1subformName].push( addedSubformId );
  1034. },
  1035. isSubformUnique : function( checkedSubformId, level1subformName, deletedSubformId){
  1036. if( !this.level1Subformlist )return true;
  1037. var level1Subformlist = Object.clone( this.level1Subformlist );
  1038. if( deletedSubformId && level1Subformlist[deletedSubformId] )delete level1Subformlist[deletedSubformId];
  1039. for( var key in level1Subformlist ){
  1040. if( key !== level1subformName ){
  1041. if( level1Subformlist[key].contains( checkedSubformId ) ){
  1042. return false;
  1043. }
  1044. }
  1045. }
  1046. return true;
  1047. },
  1048. getAllSubformTiled : function(){
  1049. var _nestToTiled = function( form , array ){
  1050. if ( form.subformModuleList && form.subformModuleList.length){
  1051. Array.each( form.subformModuleList, function( module ){
  1052. array.push( module );
  1053. if( module.subformModule )_nestToTiled( module.subformModule, array );
  1054. }.bind(this))
  1055. }
  1056. };
  1057. var array = [];
  1058. _nestToTiled( this, array );
  1059. return array;
  1060. },
  1061. getAllSubformJsonObject : function(){
  1062. var list = this.getAllSubformTiled();
  1063. var object = {};
  1064. Array.each( list, function( subform ){
  1065. if( subform && subform.json.subformSelected && subform.subformData && subform.subformData.json){
  1066. object[ subform.json.subformSelected ] = subform.subformData.json;
  1067. }
  1068. }.bind(this));
  1069. return object;
  1070. }
  1071. // getAllFieldModuleNameList: function(){
  1072. // var moduleNameList = [];
  1073. // Object.each(this.json.moduleList, function(o, k){
  1074. // if (this.options.fields.indexOf(o.type))
  1075. // }.bind(this))
  1076. // }
  1077. });