Subform.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  1. MWF.xApplication.process.FormDesigner.Module = MWF.xApplication.process.FormDesigner.Module || {};
  2. MWF.xDesktop.requireApp("process.FormDesigner", "Module.$Element", null, false);
  3. MWF.xApplication.process.FormDesigner.Module.Subform = MWF.FCSubform = new Class({
  4. Extends: MWF.FC$Element,
  5. Implements: [Options, Events],
  6. options: {
  7. "style": "default",
  8. "propertyPath": "/x_component_process_FormDesigner/Module/Subform/subform.html",
  9. "actions": [
  10. {
  11. "name": "move",
  12. "icon": "move1.png",
  13. "event": "mousedown",
  14. "action": "move",
  15. "title": MWF.APPFD.LP.formAction.move
  16. },
  17. {
  18. "name": "delete",
  19. "icon": "delete1.png",
  20. "event": "click",
  21. "action": "delete",
  22. "title": MWF.APPFD.LP.formAction["delete"]
  23. }
  24. // {
  25. // "name": "styleBrush",
  26. // "icon": "styleBrush.png",
  27. // "event": "click",
  28. // "action": "styleBrush",
  29. // "title": MWF.APPFD.LP.formAction["styleBrush"]
  30. // }
  31. ],
  32. },
  33. initialize: function(form, options){
  34. this.setOptions(options);
  35. this.path = "/x_component_process_FormDesigner/Module/Subform/";
  36. this.cssPath = "/x_component_process_FormDesigner/Module/Subform/"+this.options.style+"/css.wcss";
  37. this._loadCss();
  38. this.moduleType = "element";
  39. this.moduleName = "subform";
  40. this.form = form;
  41. this.container = null;
  42. this.containerNode = null;
  43. },
  44. load : function(json, node, parent){
  45. this.json = json;
  46. this.node= node;
  47. this.node.store("module", this);
  48. //this.node.empty();
  49. this.node.setStyles(this.css.moduleNode);
  50. //this._loadNodeStyles();
  51. this._initModule();
  52. if (this.json.subformSelected && this.json.subformSelected!=="none" && this.json.subformType!=="script"){
  53. this.redoSelectedSubform(this.json.subformSelected, null, "");
  54. }else{
  55. this.node.empty();
  56. this.loadIcon();
  57. }
  58. this._loadTreeNode(parent);
  59. this.setCustomStyles();
  60. this.parentContainer = this.treeNode.parentNode.module;
  61. this._setEditStyle_custom("id");
  62. this.parseModules();
  63. this.json.moduleName = this.moduleName;
  64. this.node.addEvent("click", function(){
  65. this.refreshSubform();
  66. }.bind(this));
  67. this.node.addEvent("dblclick", function(e){
  68. this.openSubform(e);
  69. }.bind(this));
  70. },
  71. _initModule: function(){
  72. if (!this.json.isSaved) this.setStyleTemplate();
  73. this.setPropertiesOrStyles("styles");
  74. this.setPropertiesOrStyles("inputStyles");
  75. this.setPropertiesOrStyles("properties");
  76. this._setNodeProperty();
  77. if (!this.form.isSubform) this._createIconAction();
  78. this._setNodeEvent();
  79. this.json.isSaved = true;
  80. this.queryGetFormDataFun = this.queryGetFormData.bind(this);
  81. this.postGetFormDataFun = this.postGetFormData.bind(this);
  82. this.form.addEvent("queryGetFormData", this.queryGetFormDataFun);
  83. this.form.addEvent("postGetFormData", this.postGetFormDataFun);
  84. },
  85. openSubform: function(e){
  86. if (this.json.subformSelected && this.json.subformSelected!=="none" && this.json.subformType!=="script"){
  87. layout.desktop.openApplication(e, "process.FormDesigner", {"id": this.json.subformSelected, "appId": "FormDesigner"+this.json.subformSelected});
  88. }
  89. },
  90. _createMoveNode: function(){
  91. this.moveNode = new Element("div", {
  92. "MWFType": "subform",
  93. "id": this.json.id,
  94. "styles": this.css.moduleNodeMove,
  95. "events": {
  96. "selectstart": function(){
  97. return false;
  98. }
  99. }
  100. }).inject(this.form.container);
  101. },
  102. _createNode: function(){
  103. this.node = this.moveNode.clone(true, true);
  104. this.node.setStyles(this.css.moduleNode);
  105. this.node.set("id", this.json.id);
  106. this.node.addEvent("selectstart", function(){
  107. return false;
  108. });
  109. // debugger;
  110. // if (this.json.subformSelected && this.json.subformSelected!="none" && this.json.subformType!=="script"){
  111. // this.redoSelectedSubform(this.json.subformSelected, $(this.property.data.pid+"selectSubform").getElement("select"), "");
  112. // }else{
  113. this.loadIcon();
  114. // }
  115. this.node.addEvent("click", function(){
  116. this.refreshSubform();
  117. }.bind(this));
  118. },
  119. postGetFormData: function(node){
  120. if (!node || node.contains(this.node)) this.show();
  121. },
  122. queryGetFormData: function(node){
  123. if (!node || node.contains(this.node)) this.hide();
  124. },
  125. hide: function(){
  126. this.node.empty();
  127. },
  128. show: function(){
  129. if (this.subformData){
  130. this.subformModule = new MWF.FCSubform.Form(this.form, this.node);
  131. this.subformModule.load(this.subformData);
  132. }else{
  133. this.node.empty();
  134. this.loadIcon();
  135. }
  136. },
  137. "delete": function(e){
  138. var module = this;
  139. this.form.designer.shortcut = false;
  140. this.form.designer.confirm("warn", module.node, MWF.APPFD.LP.notice.deleteElementTitle, MWF.APPFD.LP.notice.deleteElement, 300, 120, function(){
  141. if (this.queryGetFormDataFun) module.form.removeEvent("queryGetFormData", this.queryGetFormDataFun);
  142. if (this.postGetFormDataFun) module.form.removeEvent("postGetFormData", this.postGetFormDataFun);
  143. module.destroy();
  144. module.form.selected();
  145. module.form.designer.shortcut = true;
  146. this.close();
  147. }, function(){
  148. module.form.designer.shortcut = true;
  149. this.close();
  150. }, null);
  151. },
  152. refreshSubform: function(){
  153. if (this.json.subformSelected && this.json.subformSelected!=="none" && this.json.subformType!=="script"){
  154. MWF.Actions.get("x_processplatform_assemble_designer").getForm(this.json.subformSelected, function(json){
  155. if (this.subformData.updateTime!==json.data.updateTime){
  156. var select = null;
  157. if (this.property){
  158. select = $(this.property.data.pid+"selectSubform").getElement("select");
  159. }
  160. this.clearSubformList(this.json.subformSelected);
  161. this.reloadSubform(json.data, select, "");
  162. }
  163. }.bind(this));
  164. }
  165. },
  166. loadIcon: function(){
  167. this.iconNode = new Element("div", {
  168. "styles": this.css.iconNode
  169. }).inject(this.node);
  170. new Element("div", {
  171. "styles": this.css.iconNodeIcon
  172. }).inject(this.iconNode);
  173. new Element("div", {
  174. "styles": this.css.iconNodeText,
  175. "text": "Subform"
  176. }).inject(this.iconNode);
  177. },
  178. _loadNodeStyles: function(){
  179. this.iconNode = this.node.getElement("div").setStyles(this.css.iconNode);
  180. this.iconNode.getFirst("div").setStyles(this.css.iconNodeIcon);
  181. this.iconNode.getLast("div").setStyles(this.css.iconNodeText);
  182. },
  183. _setEditStyle: function(name, input, oldValue){
  184. if (name==="subformSelected"){
  185. if (this.json.subformSelected!==oldValue){
  186. this.redoSelectedSubform(name, input, oldValue);
  187. }
  188. }
  189. if (name==="subformType"){
  190. if (this.json.subformType!==oldValue){
  191. if (this.json.subformType !== "script"){
  192. this.redoSelectedSubform(name, $(this.property.data.pid+"selectSubform").getElement("select"), "");
  193. }
  194. if (this.json.subformType === "script"){
  195. this.subformData = null;
  196. this.clearSubformList(this.json.subformSelected);
  197. this.node.empty();
  198. this.loadIcon();
  199. }
  200. }
  201. }
  202. },
  203. redoSelectedSubform: function(name, input, oldValue){
  204. if (this.json.subformSelected==="none") this.json.subformSelected="";
  205. if (this.json.subformSelected && this.json.subformSelected!=="none"){
  206. if (this.form.subformList && this.form.subformList[this.json.subformSelected]){
  207. //var p = (input) ? input.getPosition() : this.node.getPosition();
  208. var p = this.node.getPosition(document.bosy);
  209. this.form.designer.alert("error", {
  210. "event": {
  211. "x": p.x+150,
  212. "y": p.y+80
  213. }
  214. }, this.form.designer.lp.subformConflictTitle, this.form.designer.lp.subformConflictInfor, 400, 120);
  215. this.json.subformSelected = oldValue;
  216. if (input){
  217. for (var i=0; i<input.options.length; i++){
  218. if (input.options[i].value===oldValue){
  219. input.options[i].set("selected", true);
  220. break;
  221. }
  222. }
  223. }
  224. this.node.empty();
  225. this.loadIcon();
  226. }else{
  227. MWF.Actions.get("x_processplatform_assemble_designer").getForm(this.json.subformSelected, function(json){
  228. this.reloadSubform(json.data, input, oldValue);
  229. }.bind(this));
  230. }
  231. }else{
  232. this.subformData = null;
  233. this.clearSubformList(oldValue);
  234. this.node.empty();
  235. this.loadIcon();
  236. }
  237. },
  238. clearSubformList: function(formName){
  239. if (!this.form.subformList) this.form.subformList = {};
  240. if (formName) if (this.form.subformList[formName]) delete this.form.subformList[formName];
  241. },
  242. addSubformList: function(){
  243. if (!this.form.subformList) this.form.subformList = {};
  244. this.form.subformList[this.json.subformSelected] = Object.clone(this.subformData.json);
  245. },
  246. getSubformData: function(data){
  247. var subformDataStr = null;
  248. if (this.form.options.mode !== "Mobile"){
  249. subformDataStr = data.data;
  250. }else{
  251. subformDataStr = data.mobileData;
  252. }
  253. this.subformData = null;
  254. if (subformDataStr){
  255. this.subformData = JSON.decode(MWF.decodeJsonString(subformDataStr));
  256. this.subformData.updateTime = data.updateTime;
  257. }
  258. },
  259. reloadSubform: function(data, input, oldValue){
  260. this.getSubformData(data);
  261. if (this.subformData){
  262. var oldSubformData = (this.form.subformList && oldValue) ? this.form.subformList[oldValue] : null;
  263. this.clearSubformList(oldValue);
  264. if (this.checkSubform(data, input)){
  265. this.node.empty();
  266. this.loadSubform();
  267. this.addSubformList();
  268. }else{
  269. if (oldSubformData){
  270. if (!this.form.subformList) this.form.subformList = {};
  271. this.form.subformList[oldValue] = oldSubformData;
  272. }else{
  273. this.clearSubformList(oldValue);
  274. this.node.empty();
  275. this.loadIcon();
  276. }
  277. this.json.subformSelected = oldValue;
  278. if (!oldValue){
  279. if (input) input.options[0].set("selected", true);
  280. }else{
  281. if (input){
  282. for (var i=0; i<input.options.length; i++){
  283. if (input.options[i].value===oldValue){
  284. input.options[i].set("selected", true);
  285. break;
  286. }
  287. }
  288. }
  289. }
  290. }
  291. }else{
  292. this.json.subformSelected = oldValue;
  293. if (input){
  294. if (!oldValue){
  295. input.options[0].set("selected", true);
  296. }else{
  297. for (var i=0; i<input.options.length; i++){
  298. if (input.options[i].value===oldValue){
  299. input.options[i].set("selected", true);
  300. break;
  301. }
  302. }
  303. }
  304. }
  305. }
  306. },
  307. regetSubformData: function(){
  308. var flag = false;
  309. if (this.json.subformSelected && this.json.subformSelected!=="none" && this.json.subformType!=="script"){
  310. MWF.Actions.get("x_processplatform_assemble_designer").getForm(this.json.subformSelected, function(json){
  311. if (!this.subformData || this.subformData.updateTime!==json.data.updateTime){
  312. this.getSubformData(json.data);
  313. flag = true;
  314. }
  315. }.bind(this), null, false);
  316. }
  317. return flag;
  318. },
  319. getConflictFields: function(){
  320. var moduleNames = [];
  321. if (this.subformData){
  322. Object.each(this.subformData.json.moduleList, function(o, key){
  323. var check = this.form.checkModuleId(key, o.type, this.subformData.json.id);
  324. if (check.fieldConflict){
  325. moduleNames.push(key)
  326. }else if (check.elementConflict){
  327. o.changeId = this.json.id+"_"+key;
  328. }
  329. }.bind(this));
  330. }
  331. return moduleNames;
  332. },
  333. checkSubform: function(data, input){
  334. var moduleNames = this.getConflictFields();
  335. // Object.each(this.subformData.json.moduleList, function(o, key){
  336. // var check = this.form.checkModuleId(key, o.type, this.subformData.json.id);
  337. // if (check.fieldConflict){
  338. // moduleNames.push(key)
  339. // }else if (check.elementConflict){
  340. // o.changeId = this.json.id+"_"+key;
  341. // }
  342. // }.bind(this));
  343. if (moduleNames.length){
  344. var txt = this.form.designer.lp.subformNameConflictInfor;
  345. txt = txt.replace("{name}", moduleNames.join(", "));
  346. //var p = (input) ? input.getPosition() : this.node.getPosition();
  347. // var p = this.node.getPosition(document.body);
  348. // this.form.designer.alert("error", {
  349. // "event": {
  350. // "x": p.x+150,
  351. // "y": p.y+80
  352. // }
  353. // }, this.form.designer.lp.subformNameConflictTitle, txt, 400, 200);
  354. this.form.designer.notice(txt, "error", this.node);
  355. return false;
  356. }
  357. return true;
  358. },
  359. loadSubform: function(data) {
  360. this.subformData.json.style = this.form.json.style;
  361. this.subformData.json.properties = this.form.json.properties;
  362. this.subformData.json.jsheader = {"code": "", "html": ""};
  363. this.subformData.json.events = {};
  364. this.subformData.json.formStyleType = this.form.json.formStyleType;
  365. //this.subformData.json.id = this.json.id;
  366. this.subformModule = new MWF.FCSubform.Form(this.form, this.node);
  367. this.subformModule.load(this.subformData);
  368. //this.createRefreshNode();
  369. },
  370. destroy: function(){
  371. this.form.moduleList.erase(this);
  372. this.form.moduleNodeList.erase(this.node);
  373. this.form.moduleElementNodeList.erase(this.node);
  374. this.clearSubformList(this.json.subformSelected);
  375. this.node.destroy();
  376. this.actionArea.destroy();
  377. delete this.form.json.moduleList[this.json.id];
  378. this.json = null;
  379. delete this.json;
  380. this.treeNode.destroy();
  381. }
  382. });
  383. MWF.xApplication.process.FormDesigner.Module.Subform.Form = new Class({
  384. Extends: MWF.FCForm,
  385. initialize: function(form, container, options){
  386. this.parentform = form
  387. this.css = this.parentform.css;
  388. this.container = container;
  389. this.form = this;
  390. this.isSubform = true;
  391. this.moduleType = "subform";
  392. this.moduleList = [];
  393. this.moduleNodeList = [];
  394. this.moduleContainerNodeList = [];
  395. this.moduleElementNodeList = [];
  396. this.moduleComponentNodeList = [];
  397. // this.moduleContainerList = [];
  398. this.dataTemplate = {};
  399. this.designer = this.parentform.designer;
  400. this.selectedModules = [];
  401. },
  402. load : function(data){
  403. this.data = data;
  404. this.json = data.json;
  405. this.html = data.html;
  406. this.json.mode = this.options.mode;
  407. this.container.set("html", this.html);
  408. this.loadDomModules();
  409. //this.setCustomStyles();
  410. //this.node.setProperties(this.json.properties);
  411. //this.setNodeEvents();
  412. if (this.options.mode==="Mobile"){
  413. if (oldStyleValue) this._setEditStyle("formStyleType", null, oldStyleValue);
  414. }
  415. },
  416. loadDomModules: function(){
  417. this.node = this.container.getFirst();
  418. this.node.set("id", this.json.id);
  419. this.node.setStyles((this.options.mode==="Mobile") ? this.css.formMobileNode : this.css.formNode);
  420. this.node.store("module", this);
  421. this.loadDomTree();
  422. },
  423. loadDomTree: function(){
  424. this.createFormTreeNode();
  425. this.parseModules(this, this.node);
  426. },
  427. createFormTreeNode: function(){
  428. this.treeNode = {
  429. "insertChild": function(){return this;},
  430. "appendChild": function(){return this;},
  431. "selectNode": function(){},
  432. "node": null,
  433. "parentNode": {}
  434. };
  435. this.treeNode.module = this;
  436. }
  437. });