Form.js 43 KB

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