Form.js 43 KB

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