Form.js 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293
  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 = json.type.capitalize();
  363. this.getTemplateData(className, function(data){
  364. var moduleData = Object.clone(data);
  365. Object.merge(moduleData, json);
  366. Object.merge(json, moduleData);
  367. module = new MWF["FC"+json.type](this);
  368. module.load(json, dom, parent);
  369. }.bind(this), false);
  370. return module;
  371. }else{
  372. var module;
  373. var className = json.type.capitalize();
  374. this.getTemplateData(className, function(data){
  375. var moduleData = Object.clone(data);
  376. Object.merge(moduleData, json);
  377. Object.merge(json, moduleData);
  378. module = new MWF["FCDiv"](this);
  379. module.load(json, dom, parent);
  380. }.bind(this), false);
  381. return module;
  382. }
  383. },
  384. setNodeEvents: function(){
  385. this.node.addEvent("click", function(e){
  386. this.selected();
  387. }.bind(this));
  388. // this._controlKeyEventFun = function(e){
  389. // if (e.control){
  390. // this.controlMode = true;
  391. // if (this.copyNode) this.copyNode.destroy();
  392. // }else{
  393. // this.controlMode = false;
  394. // // var copyNode = this._getCopyNode(this);
  395. // // copyNode.inject(this.node, "before");
  396. // }
  397. // }.bind(this);
  398. this.designer.content.addEvent("keydown", function(e){
  399. if (this.moveModule){
  400. if (e.control){
  401. this.moveModule._setControlMode(true);
  402. }else{
  403. this.moveModule._setControlMode(false);
  404. }
  405. }
  406. }.bind(this));
  407. this.designer.content.addEvent("keyup", function(e){
  408. if (this.moveModule){
  409. if (e.control){
  410. this.moveModule._setControlMode(true);
  411. }else{
  412. this.moveModule._setControlMode(false);
  413. }
  414. }
  415. }.bind(this));
  416. },
  417. createModuleImmediately: function( className, parentModule, relativeNode, position, selectDisabled, async ){
  418. var module;
  419. this.getTemplateData(className, function(data){
  420. var moduleData = Object.clone(data);
  421. module = new MWF["PC"+className](this);
  422. if( parentModule ){
  423. module.onDragModule = parentModule;
  424. if (!parentModule.Component) module.inContainer = parentModule;
  425. module.parentContainer = parentModule;
  426. module.nextModule = null;
  427. }
  428. module.createImmediately(moduleData, relativeNode, position, selectDisabled);
  429. }.bind(this), async);
  430. return module;
  431. },
  432. createModule: function(className, e){
  433. this.getTemplateData(className, function(data){
  434. var moduleData = Object.clone(data);
  435. var newTool = new MWF["FC"+className](this);
  436. newTool.create(moduleData, e);
  437. }.bind(this));
  438. },
  439. getTemplateData: function(className, callback , async){
  440. if (this.dataTemplate[className]){
  441. if (callback) callback(this.dataTemplate[className]);
  442. }else{
  443. var templateUrl = "../x_component_process_FormDesigner/Module/"+className+"/template.json";
  444. MWF.getJSON(templateUrl, function(responseJSON, responseText){
  445. this.dataTemplate[className] = responseJSON;
  446. if (callback) callback(responseJSON);
  447. }.bind(this), async);
  448. }
  449. },
  450. selected: function(){
  451. if (this.currentSelectedModule){
  452. if (this.currentSelectedModule==this){
  453. return true;
  454. }else{
  455. this.currentSelectedModule.unSelected();
  456. }
  457. }
  458. if (this.propertyMultiTd){
  459. this.propertyMultiTd.hide();
  460. this.propertyMultiTd = null;
  461. }
  462. this.unSelectedMulti();
  463. this.currentSelectedModule = this;
  464. if (this.treeNode){
  465. this.treeNode.selectNode();
  466. }
  467. this.showProperty();
  468. // this.isFocus = true;
  469. },
  470. unSelectedMulti: function(){
  471. while (this.selectedModules.length){
  472. this.selectedModules[0].unSelectedMulti();
  473. }
  474. if (this.multimoduleActionsArea) this.multimoduleActionsArea.setStyle("display", "none");
  475. },
  476. unSelectAll: function(){
  477. },
  478. _beginSelectMulti: function(){
  479. if (this.currentSelectedModule) this.currentSelectedModule.unSelected();
  480. this.unSelectedMulti();
  481. this.noSelected = true;
  482. },
  483. _completeSelectMulti: function(){
  484. if (this.selectedModules.length<2){
  485. this.selectedModules[0].selected();
  486. }else{
  487. this._showMultiActions();
  488. }
  489. },
  490. createMultimoduleActionsArea: function(){
  491. this.multimoduleActionsArea = new Element("div", {
  492. styles: {
  493. "display": "none",
  494. // "width": 18*this.options.actions.length,
  495. "position": "absolute",
  496. "background-color": "#F1F1F1",
  497. "padding": "1px",
  498. "padding-right": "0px",
  499. "border": "1px solid #AAA",
  500. "box-shadow": "0px 2px 5px #999",
  501. "z-index": 10001
  502. }
  503. }).inject(this.form.container, "after");
  504. },
  505. _showMultiActions: function(){
  506. if (!this.multimoduleActionsArea) this.createMultimoduleActionsArea();
  507. var firstModule = this._getFirstMultiSelectedModule();
  508. if (firstModule){
  509. // var module = firstModule.module;
  510. var y = firstModule.position.y-25;
  511. var x = firstModule.position.x;
  512. this.multimoduleActionsArea.setPosition({"x": x, "y": y});
  513. this.multimoduleActionsArea.setStyle("display", "block");
  514. }
  515. },
  516. _getFirstMultiSelectedModule: function(){
  517. var firstModule = null;
  518. this.selectedModules.each(function(module){
  519. var position = module.node.getPosition(module.form.node.getOffsetParent());
  520. if (!firstModule){
  521. firstModule = {"module": module, "position": position};
  522. }else{
  523. if (position.y<firstModule.position.y){
  524. firstModule = {"module": module, "position": position};
  525. }else if (position.y==firstModule.position.y){
  526. if (position.x<firstModule.position.x){
  527. firstModule = {"module": module, "position": position};
  528. }
  529. }
  530. }
  531. });
  532. return firstModule;
  533. },
  534. showProperty: function(){
  535. if (!this.property){
  536. this.property = new MWF.xApplication.process.FormDesigner.Property(this, this.designer.propertyContentArea, this.designer, {
  537. "path": this.options.propertyPath,
  538. "onPostLoad": function(){
  539. this.property.show();
  540. }.bind(this)
  541. });
  542. this.property.load();
  543. }else{
  544. this.property.show();
  545. }
  546. },
  547. hideProperty: function(){
  548. if (this.property) this.property.hide();
  549. },
  550. unSelected: function(){
  551. this.currentSelectedModule = null;
  552. this.hideProperty();
  553. },
  554. _dragIn: function(module){
  555. if (!this.Component) module.inContainer = this;
  556. module.parentContainer = this;
  557. this.node.setStyles({"border": "1px solid #ffa200"});
  558. var copyNode = module._getCopyNode();
  559. copyNode.inject(this.node);
  560. },
  561. _dragOut: function(module){
  562. module.inContainer = null;
  563. module.parentContainer = null;
  564. this.node.setStyles((this.options.mode==="Mobile") ? this.css.formMobileNode : this.css.formNode);
  565. this.node.setStyles(this.json.styles);
  566. var copyNode = module._getCopyNode();
  567. copyNode.setStyle("display", "none");
  568. },
  569. _dragDrop: function(module, flag){
  570. var f = flag || !(new Event(event)).control;
  571. if( f ){
  572. this.node.setStyles((this.options.mode==="Mobile") ? this.css.formMobileNode : this.css.formNode);
  573. this.node.setStyles(this.json.styles);
  574. }
  575. //this._hideInjectAction();
  576. },
  577. _showInjectAction : function( module ){
  578. if ( module.moveNode ){
  579. module.moveNode.setStyle("display","none");
  580. }
  581. //debugger;
  582. this.draggingModule = module;
  583. //if( !this.node.getFirst() ){
  584. // this.inject( "top" );
  585. // return;
  586. //}
  587. if( !this.injectActionArea )this._createInjectAction();
  588. this.injectActionArea.setStyle("display","block");
  589. this._setInjectActionAreaPosition();
  590. this.injectActionEffect = new Fx.Morph(this.injectActionArea, {
  591. duration: 200,
  592. transition: Fx.Transitions.Sine.easeOut
  593. });
  594. this.injectActionEffect.start(this.form.css.injectActionArea_to);
  595. },
  596. _hideInjectAction : function(){
  597. this.draggingModule = null;
  598. if( this.injectActionArea ){
  599. this.injectActionArea.setStyle("display","none");
  600. }
  601. },
  602. _createInjectAction : function(){
  603. var css = this.form.css;
  604. if( !this.injectActionArea ){
  605. this.injectActionArea = new Element("div", { styles: css.injectActionArea }).inject(this.form.container, "after");
  606. this.injectActionTopBGNode = new Element("div", { styles : css.injectActionTopBGNode }).inject( this.injectActionArea );
  607. this.injectActionLeftBGNode = new Element("div", { styles : css.injectActionLeftBGNode }).inject( this.injectActionArea );
  608. this.injectActionRightBGNode = new Element("div", { styles : css.injectActionRightBGNode }).inject( this.injectActionArea );
  609. this.injectActionBottomBGNode = new Element("div", { styles : css.injectActionBottomBGNode }).inject( this.injectActionArea );
  610. var injectActions = {};
  611. this.options.injectActions.each( function( action ){
  612. injectActions[ action.name ] = action;
  613. });
  614. if( injectActions.before )this._createInjectActionNode( injectActions.before, this.injectActionTopBGNode );
  615. if( injectActions.top )this._createInjectActionNode( injectActions.top, this.injectActionLeftBGNode );
  616. if( injectActions.bottom )this._createInjectActionNode( injectActions.bottom, this.injectActionRightBGNode );
  617. if( injectActions.after )this._createInjectActionNode( injectActions.after, this.injectActionBottomBGNode );
  618. new Element("div", {
  619. styles : css.injectActionCancelNode,
  620. events : {
  621. click : function(){
  622. this.draggingModule._dragCancel();
  623. this._dragDrop( this.node, true );
  624. this._hideInjectAction();
  625. }.bind(this),
  626. mouseover : function(){
  627. this.setStyles( css.injectActionCancelNode_over )
  628. },
  629. mouseout : function(){
  630. this.setStyles( css.injectActionCancelNode )
  631. }
  632. }
  633. }).inject(this.injectActionArea);
  634. }
  635. },
  636. _createInjectActionNode : function( action, relativeNode ){
  637. var actionNode = new Element("div", {
  638. "styles": this.css[action.styles],
  639. "title": action.title
  640. }).inject( this.injectActionArea );
  641. actionNode.addEvent(action.event, function(e){
  642. this[action.action](e);
  643. }.bind(this));
  644. actionNode.addEvents({
  645. "mouseover": function(e){
  646. relativeNode.setStyle("background", "#ddd");
  647. this.draggingModule.copyNode.setStyle("display","");
  648. this.draggingModule.copyNode.inject( this.node, action.name );
  649. }.bind(this),
  650. "mouseout": function(e){
  651. relativeNode.setStyle("background", "transparent");
  652. }.bind(this)
  653. });
  654. relativeNode.set("title",action.title);
  655. relativeNode.addEvent(action.event, function(e){
  656. this[action.action](e);
  657. }.bind(this));
  658. relativeNode.setStyle("cursor","pointer");
  659. relativeNode.addEvents({
  660. "mouseenter": function(e){
  661. relativeNode.setStyle("background", "#ddd");
  662. this.draggingModule.copyNode.setStyle("display","");
  663. this.draggingModule.copyNode.inject( this.node, action.name );
  664. }.bind(this),
  665. "mouseleave": function(e){
  666. relativeNode.setStyle("background", "transparent");
  667. //this.draggingModule.copyNode.setStyle("display","none");
  668. }.bind(this)
  669. });
  670. },
  671. _setInjectActionAreaPosition: function(){
  672. var e = new Event(event);
  673. var formOffset = this.node.getOffsetParent().getPosition();
  674. //var p = this.node.getPosition(this.form.node.getOffsetParent());
  675. var y = e.page.y - formOffset.y - 60;
  676. var x = e.page.x - formOffset.x - 60;
  677. this.injectActionArea.setPosition({"x": x, "y": y});
  678. },
  679. injectBefore : function( e ){
  680. this.inject( "before" )
  681. },
  682. injectAfter : function( e ){
  683. this.inject( "after" )
  684. },
  685. injectTop : function( e ){
  686. this.inject( "top" )
  687. },
  688. injectBottom : function( e ){
  689. this.inject( "bottom" )
  690. },
  691. inject : function( position ){
  692. if ( this.draggingModule.moveNode ){
  693. this.draggingModule.moveNode.setStyle("display","");
  694. }
  695. this.draggingModule._dragComplete( this.node, position );
  696. this._dragDrop( this.node, true );
  697. this._hideInjectAction();
  698. },
  699. // _clearSubform: function(node){
  700. // var subNode = node.getFirst();
  701. // while (subNode){
  702. // var nextNode = subNode.getNext();
  703. // if (subNode.get("MWFType")){
  704. // if ( subNode.get("MWFType") === "subform" ){
  705. // subNode.destroy();
  706. // }else{
  707. // if (subNode) this._clearSubform(subNode);
  708. // }
  709. // }else{
  710. // if (subNode) this._clearSubform(subNode);
  711. // }
  712. // subNode = nextNode;
  713. // }
  714. // },
  715. _clearNoId: function(node){
  716. var subNode = node.getFirst();
  717. while (subNode){
  718. var nextNode = subNode.getNext();
  719. if (subNode.get("MWFType")){
  720. if (!subNode.get("id")){
  721. subNode.destroy();
  722. }else{
  723. if (subNode) this._clearNoId(subNode);
  724. }
  725. }else{
  726. if (subNode) this._clearNoId(subNode);
  727. }
  728. subNode = nextNode;
  729. }
  730. },
  731. _copyFormJson: function(initial, final){
  732. var data = final || {};
  733. Object.keys(initial).each(function(k){
  734. var t = typeOf(initial[k]);
  735. switch (t) {
  736. case "object":
  737. var s = JSON.stringify(initial[k], null, "\t");
  738. if (/((?:\:\s*)((\".+\")|(\d+)|(\[.+\])))/.test(s)){
  739. //data[k] = {};
  740. data[k] = this._copyFormJson(initial[k], data[k]);
  741. }
  742. break;
  743. default :
  744. if (initial[k]) data[k] = initial[k];
  745. }
  746. }.bind(this));
  747. return data;
  748. },
  749. _preprocessingModuleData: function(){
  750. //var html = this.node.innerHTML;
  751. this.moduleList.each(function(module){
  752. module._preprocessingModuleData();
  753. });
  754. // return {
  755. // "json": this.data.json,
  756. // "html": this.node.outerHTML
  757. // }
  758. },
  759. _recoveryModuleData: function(){
  760. this.moduleList.each(function(module){
  761. //module._recoveryModuleData();
  762. module.setCustomStyles();
  763. if (module.setCustomInputStyles) module.setCustomInputStyles();
  764. });
  765. },
  766. _getFormData: function(callback){
  767. debugger;
  768. this.fireEvent("queryGetFormData");
  769. this._preprocessingModuleData();
  770. var copy = this.node.clone(true, true);
  771. copy.clearStyles();
  772. this.fireEvent("postGetFormData");
  773. this._clearNoId(copy);
  774. var html = copy.outerHTML;
  775. //this._clearNoDomModule();
  776. copy.destroy();
  777. this.data.json.mode = this.options.mode;
  778. this.data.html = html;
  779. debugger;
  780. var data = this._copyFormJson(this.data);
  781. this._recoveryModuleData();
  782. //@todo 预先整理表单样式
  783. // var tmpFormNode = new Element("div", {
  784. // "opacity": 0
  785. // }).inject(this.designer.content);
  786. // MWF.xDesktop.requireApp("process.Xform2", "Form_", null, false);
  787. // this.appForm = new MWF.APPForm_(tmpFormNode, this.data, {
  788. // "onAfterLoad": function(){
  789. // var preprocessHtml = tmpFormNode.get("html");
  790. // this.data.preprocessHtml = preprocessHtml;
  791. //
  792. // if (callback) callback();
  793. // }.bind(this)
  794. // });
  795. // this.appForm.businessData = {};
  796. // this.appForm.load();
  797. return data;
  798. //return this.data;
  799. },
  800. _clearNoDomModule : function(){
  801. debugger;
  802. var existModuleList = {};
  803. Object.each( this.moduleList, function( module ){
  804. existModuleList[ module.json.id ] = true;
  805. });
  806. Object.each( this.data.json.moduleList , function( module, key ){
  807. //if( !this.node.getElement( "#" + module.id ) && !existModuleList[ module.id ] ){
  808. if( !existModuleList[ module.id ] ){
  809. delete this.data.json.moduleList[key];
  810. }
  811. }.bind(this));
  812. },
  813. preview: function(){
  814. MWF.xDesktop.requireApp("process.FormDesigner", "Preview", function(){
  815. if (this.options.mode=="Mobile"){
  816. this.previewBox = new MWF.xApplication.process.FormDesigner.Preview(this, {"size": {"x": "400", "y": 580}, "mode": "mobile"});
  817. }else{
  818. this.previewBox = new MWF.xApplication.process.FormDesigner.Preview(this);
  819. }
  820. this.previewBox.load();
  821. }.bind(this));
  822. },
  823. save: function(callback){
  824. // debugger;
  825. // this.moduleList.each(function(module){
  826. // if (module.moduleName==="subform"){
  827. // module.refreshSubform();
  828. // }
  829. // }.bind(this));
  830. this.designer.saveForm();
  831. //this._getFormData();
  832. //this.designer.actions.saveForm(this.data, function(responseJSON){
  833. // this.form.designer.notice(MWF.APPFD.LP.notice["save_success"], "ok", null, {x: "left", y:"bottom"});
  834. //
  835. // //this.json.id = responseJSON.data;
  836. // if (!this.json.name) this.treeNode.setText("<"+this.json.type+"> "+this.json.id);
  837. // this.treeNode.setTitle(this.json.id);
  838. // this.node.set("id", this.json.id);
  839. //
  840. // if (callback) callback();
  841. // //this.reload(responseJSON.data);
  842. //}.bind(this));
  843. },
  844. explode: function(){
  845. this._getFormData();
  846. MWF.require("MWF.widget.Base64", null, false);
  847. var data = MWF.widget.Base64.encode(JSON.encode(this.data));
  848. MWF.require("MWF.widget.Panel", function(){
  849. var node = new Element("div");
  850. var size = this.designer.formNode.getSize();
  851. var position = this.designer.formNode.getPosition(this.designer.formNode.getOffsetParent());
  852. var textarea = new Element("textarea", {
  853. "styles": {
  854. "border": "1px solid #999",
  855. "width": "770px",
  856. "margin-left": "14px",
  857. "margin-top": "14px",
  858. "height": "580px"
  859. },
  860. "text": JSON.encode(this.data)
  861. }).inject(node);
  862. this.explodePanel = new MWF.widget.Panel(node, {
  863. "style": "form",
  864. "isResize": false,
  865. "isMax": false,
  866. "title": "",
  867. "width": 800,
  868. "height": 660,
  869. "top": position.y,
  870. "left": position.x+3,
  871. "isExpand": false,
  872. "target": this.designer.node
  873. });
  874. this.explodePanel.load();
  875. }.bind(this));
  876. },
  877. implode: function(){
  878. MWF.xDesktop.requireApp("portal.PageDesigner", "Import", function(){
  879. MWF.FormImport.create("O2", this);
  880. }.bind(this));
  881. },
  882. // implodeJsonData: function(str){
  883. // if (str){
  884. // //try{
  885. // debugger;
  886. // var data = JSON.decode(str);
  887. // if (data){
  888. // var json = data.json;
  889. // data.id = this.data.id;
  890. // data.isNewPage = this.data.isNewPage;
  891. // json.id = this.json.id;
  892. // json.name = this.json.name;
  893. // json.application = this.json.application;
  894. // json.applicationName = this.json.applicationName;
  895. //
  896. // this.reload(data);
  897. // this.implodePanel.closePanel();
  898. // }else{
  899. // this.designer.notice(this.designer.lp.implodeError, "error");
  900. // }
  901. // // }catch(e){
  902. // // this.designer.notice(this.designer.lp.implodeError, "error");
  903. // // }
  904. // }else{
  905. // this.designer.notice(this.designer.lp.implodeEmpty, "error");
  906. // }
  907. // },
  908. implodeHTML: function(){
  909. MWF.xDesktop.requireApp("portal.PageDesigner", "Import", function(){
  910. MWF.FormImport.create("html", this, {"type": "process"});
  911. }.bind(this));
  912. },
  913. implodeOffice: function(){
  914. MWF.xDesktop.requireApp("portal.PageDesigner", "Import", function(){
  915. MWF.FormImport.create("office", this);
  916. }.bind(this));
  917. },
  918. deletePropertiesOrStyles: function(name, key){
  919. if (name=="styles"){
  920. try{
  921. if( key && this.json.styles[key] ){
  922. delete this.json.styles[key];
  923. }
  924. this.setCustomStyles();
  925. }catch(e){}
  926. }
  927. if (name=="properties"){
  928. try{
  929. this.node.removeProperty(key);
  930. }catch(e){}
  931. }
  932. },
  933. setPropertiesOrStyles: function(name){
  934. if (name=="styles"){
  935. this.setCustomStyles();
  936. }
  937. if (name=="properties"){
  938. this.node.setProperties(this.json.properties);
  939. }
  940. },
  941. setCustomStyles: function(){
  942. var border = this.node.getStyle("border");
  943. this.node.clearStyles();
  944. this.node.setStyles((this.options.mode==="Mobile") ? this.css.formMobileNode : this.css.formNode);
  945. var y = this.container.getStyle("height");
  946. y = (y) ? y.toInt()-2 : this.container.getSize().y-2;
  947. this.node.setStyle("min-height", ""+y+"px");
  948. if (this.initialStyles) this.node.setStyles(this.initialStyles);
  949. this.node.setStyle("border", border);
  950. Object.each(this.json.styles, function(value, key){
  951. var reg = /^border\w*/ig;
  952. if (!key.test(reg)){
  953. this.node.setStyle(key, value);
  954. }
  955. }.bind(this));
  956. },
  957. _setEditStyle: function(name, obj, oldValue){
  958. if (name=="name"){
  959. var title = this.json.name || this.json.id;
  960. this.treeNode.setText("<"+this.json.type+"> "+title+" ["+this.options.mode+"] ");
  961. }
  962. if (name=="id"){
  963. if (!this.json.name) this.treeNode.setText("<"+this.json.type+"> "+this.json.id+" ["+this.options.mode+"] ");
  964. this.treeNode.setTitle(this.json.id);
  965. this.node.set("id", this.json.id);
  966. }
  967. if (name=="formStyleType"){
  968. var file = (this.stylesList && this.json.formStyleType) ? this.stylesList[this.json.formStyleType].file : null;
  969. var extendFile = (this.stylesList && this.json.formStyleType) ? this.stylesList[this.json.formStyleType].extendFile : null;
  970. this.loadTemplateStyles( file, extendFile, function( templateStyles ){
  971. //this.templateStyles = (this.stylesList && this.json.formStyleType) ? this.stylesList[this.json.formStyleType] : null;
  972. this.templateStyles = templateStyles;
  973. var oldFile, oldExtendFile;
  974. if( oldValue && this.stylesList[oldValue] ){
  975. oldFile = this.stylesList[oldValue].file;
  976. oldExtendFile = this.stylesList[oldValue].extendFile;
  977. }
  978. this.loadTemplateStyles( oldFile, oldExtendFile, function( oldTemplateStyles ){
  979. //if (oldValue) {
  980. // var oldTemplateStyles = this.stylesList[oldValue];
  981. // if (oldTemplateStyles){
  982. // if (oldTemplateStyles["form"]) this.clearTemplateStyles(oldTemplateStyles["form"]);
  983. // }
  984. //}
  985. this.json.styleConfig = (this.stylesList && this.json.formStyleType) ? this.stylesList[this.json.formStyleType] : null;
  986. if (oldTemplateStyles["form"]) this.clearTemplateStyles(oldTemplateStyles["form"]);
  987. if (this.templateStyles["form"]) this.setTemplateStyles(this.templateStyles["form"]);
  988. this.setAllStyles();
  989. this.moduleList.each(function(module){
  990. if (oldTemplateStyles[module.moduleName]){
  991. module.clearTemplateStyles(oldTemplateStyles[module.moduleName]);
  992. }
  993. module.setStyleTemplate();
  994. module.setAllStyles();
  995. }.bind(this));
  996. }.bind(this))
  997. }.bind(this))
  998. }
  999. if (name==="css"){
  1000. this.reloadCss();
  1001. }
  1002. this._setEditStyle_custom(name, obj, oldValue);
  1003. },
  1004. parseCSS: function(css){
  1005. var rex = /(url\(.*\))/g;
  1006. var match;
  1007. while ((match = rex.exec(css)) !== null) {
  1008. var pic = match[0];
  1009. var len = pic.length;
  1010. var s = pic.substring(pic.length-2, pic.length-1);
  1011. var n0 = (s==="'" || s==="\"") ? 5 : 4;
  1012. var n1 = (s==="'" || s==="\"") ? 2 : 1;
  1013. pic = pic.substring(n0, pic.length-n1);
  1014. if ((pic.indexOf("x_processplatform_assemble_surface")!=-1 || pic.indexOf("x_portal_assemble_surface")!=-1)){
  1015. var host1 = MWF.Actions.getHost("x_processplatform_assemble_surface");
  1016. var host2 = MWF.Actions.getHost("x_portal_assemble_surface");
  1017. if (pic.indexOf("/x_processplatform_assemble_surface")!==-1){
  1018. pic = pic.replace("/x_processplatform_assemble_surface", pic+"/x_processplatform_assemble_surface");
  1019. }else if (pic.indexOf("x_processplatform_assemble_surface")!==-1){
  1020. pic = pic.replace("x_processplatform_assemble_surface", pic+"/x_processplatform_assemble_surface");
  1021. }
  1022. if (pic.indexOf("/x_portal_assemble_surface")!==-1){
  1023. pic = pic.replace("/x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  1024. }else if (pic.indexOf("x_portal_assemble_surface")!==-1){
  1025. pic = pic.replace("x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  1026. }
  1027. }
  1028. pic = "url('"+pic+"')";
  1029. var len2 = pic.length;
  1030. css = css.substring(0, match.index) + pic + css.substring(rex.lastIndex, css.length);
  1031. rex.lastIndex = rex.lastIndex + (len2-len);
  1032. }
  1033. return css;
  1034. },
  1035. reloadCss: function(){
  1036. cssText = (this.json.css) ? this.json.css.code : "";
  1037. //var head = (document.head || document.getElementsByTagName("head")[0] || document.documentElement);
  1038. var styleNode = $("style"+this.json.id);
  1039. if (styleNode) styleNode.destroy();
  1040. if (cssText){
  1041. cssText = this.parseCSS(cssText);
  1042. var rex = new RegExp("(.+)(?=\\{)", "g");
  1043. var match;
  1044. var id = this.json.id.replace(/\-/g, "");
  1045. var prefix = ".css" + id + " ";
  1046. while ((match = rex.exec(cssText)) !== null) {
  1047. // var rule = prefix + match[0];
  1048. // cssText = cssText.substring(0, match.index) + rule + cssText.substring(rex.lastIndex, cssText.length);
  1049. // rex.lastIndex = rex.lastIndex + prefix.length;
  1050. var rulesStr = match[0];
  1051. if (rulesStr.indexOf(",")!=-1){
  1052. var rules = rulesStr.split(/\s*,\s*/g);
  1053. rules = rules.map(function(r){
  1054. return prefix + r;
  1055. });
  1056. var rule = rules.join(", ");
  1057. cssText = cssText.substring(0, match.index) + rule + cssText.substring(rex.lastIndex, cssText.length);
  1058. rex.lastIndex = rex.lastIndex + (prefix.length*rules.length);
  1059. }else{
  1060. var rule = prefix + match[0];
  1061. cssText = cssText.substring(0, match.index) + rule + cssText.substring(rex.lastIndex, cssText.length);
  1062. rex.lastIndex = rex.lastIndex + prefix.length;
  1063. }
  1064. }
  1065. var styleNode = document.createElement("style");
  1066. styleNode.setAttribute("type", "text/css");
  1067. styleNode.id="style"+this.json.id;
  1068. styleNode.inject(this.container, "before");
  1069. if(styleNode.styleSheet){
  1070. var setFunc = function(){
  1071. styleNode.styleSheet.cssText = cssText;
  1072. };
  1073. if(styleNode.styleSheet.disabled){
  1074. setTimeout(setFunc, 10);
  1075. }else{
  1076. setFunc();
  1077. }
  1078. }else{
  1079. var cssTextNode = document.createTextNode(cssText);
  1080. styleNode.appendChild(cssTextNode);
  1081. }
  1082. }
  1083. },
  1084. setAllStyles: function(){
  1085. this.setPropertiesOrStyles("styles");
  1086. this.setPropertiesOrStyles("properties");
  1087. this.reloadMaplist();
  1088. },
  1089. reloadMaplist: function(){
  1090. if (this.property) Object.each(this.property.maplists, function(map, name){ map.reload(this.json[name]);}.bind(this));
  1091. },
  1092. _setEditStyle_custom: function(){
  1093. },
  1094. saveAsTemplete: function(){
  1095. },
  1096. isModuleExited : function( id ){
  1097. for( var i=0; i<this.moduleList.length; i++ ){
  1098. if(this.moduleList[i].json.id === id)return true;
  1099. }
  1100. return false;
  1101. },
  1102. checkModuleId: function(id, type, currentSubform){
  1103. var fieldConflict = false;
  1104. var elementConflict = false;
  1105. //if (this.json.moduleList[id]){
  1106. if( this.isModuleExited(id) ){
  1107. elementConflict = true;
  1108. if (this.options.fields.indexOf(type)!=-1 || this.options.fields.indexOf(this.json.moduleList[id].type)!=-1){
  1109. fieldConflict = true;
  1110. }
  1111. return {"fieldConflict": fieldConflict, "elementConflict": elementConflict};
  1112. }
  1113. //if (this.subformList){
  1114. // Object.each(this.subformList, function(subform){
  1115. // if (!currentSubform || currentSubform!=subform.id){
  1116. // if (subform.moduleList[id]){
  1117. // elementConflict = true;
  1118. // if (this.options.fields.indexOf(type)!=-1 || this.options.fields.indexOf(subform.moduleList[id].type)!=-1){
  1119. // fieldConflict = true;
  1120. // }
  1121. // }
  1122. // }
  1123. // }.bind(this));
  1124. //}
  1125. var subformList = this.getAllSubformJsonObject();
  1126. if (subformList){
  1127. Object.each(subformList, function(subform){
  1128. if (!currentSubform || currentSubform!=subform.id){
  1129. if (subform.moduleList[id]){
  1130. elementConflict = true;
  1131. if (this.options.fields.indexOf(type)!=-1 || this.options.fields.indexOf(subform.moduleList[id].type)!=-1){
  1132. fieldConflict = true;
  1133. }
  1134. }
  1135. }
  1136. }.bind(this));
  1137. }
  1138. return {"fieldConflict": fieldConflict, "elementConflict": elementConflict};
  1139. },
  1140. _resetTreeNode: function(){},
  1141. clearSubformList : function( level1subformName ){
  1142. if( !this.level1Subformlist )return;
  1143. if( !this.level1Subformlist[level1subformName] )return;
  1144. delete this.level1Subformlist[level1subformName];
  1145. },
  1146. addSubformList : function( level1subformName, addedSubformId ){
  1147. if( !this.level1Subformlist ){
  1148. this.level1Subformlist = {};
  1149. }
  1150. if( !this.level1Subformlist[level1subformName] ){
  1151. this.level1Subformlist[level1subformName] = [];
  1152. }
  1153. this.level1Subformlist[level1subformName].push( addedSubformId );
  1154. },
  1155. isSubformUnique : function( checkedSubformId, level1subformName, deletedSubformId){
  1156. if( !this.level1Subformlist )return true;
  1157. var level1Subformlist = Object.clone( this.level1Subformlist );
  1158. if( deletedSubformId && level1Subformlist[deletedSubformId] )delete level1Subformlist[deletedSubformId];
  1159. for( var key in level1Subformlist ){
  1160. if( key !== level1subformName ){
  1161. if( level1Subformlist[key].contains( checkedSubformId ) ){
  1162. return false;
  1163. }
  1164. }
  1165. }
  1166. return true;
  1167. },
  1168. getAllSubformTiled : function(){
  1169. var _nestToTiled = function( form , array ){
  1170. if ( form.subformModuleList && form.subformModuleList.length){
  1171. Array.each( form.subformModuleList, function( module ){
  1172. array.push( module );
  1173. if( module.subformModule )_nestToTiled( module.subformModule, array );
  1174. }.bind(this))
  1175. }
  1176. };
  1177. var array = [];
  1178. _nestToTiled( this, array );
  1179. return array;
  1180. },
  1181. getAllSubformJsonObject : function(){
  1182. var list = this.getAllSubformTiled();
  1183. var object = {};
  1184. Array.each( list, function( subform ){
  1185. if( subform && subform.json.subformSelected && subform.subformData && subform.subformData.json){
  1186. object[ subform.json.subformSelected ] = subform.subformData.json;
  1187. }
  1188. }.bind(this));
  1189. return object;
  1190. }
  1191. // getAllFieldModuleNameList: function(){
  1192. // var moduleNameList = [];
  1193. // Object.each(this.json.moduleList, function(o, k){
  1194. // if (this.options.fields.indexOf(o.type))
  1195. // }.bind(this))
  1196. // }
  1197. });