Subform.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. MWF.xApplication.cms.FormDesigner.Module = MWF.xApplication.cms.FormDesigner.Module || {};
  2. MWF.xDesktop.requireApp("process.FormDesigner", "Module.Subform", null, false);
  3. MWF.xApplication.cms.FormDesigner.Module.Subform = MWF.CMSFCSubform = new Class({
  4. Extends: MWF.FCSubform,
  5. Implements : [MWF.CMSFCMI],
  6. openSubform: function(e){
  7. if (this.json.subformSelected && this.json.subformSelected!=="none" && this.json.subformType!=="script"){
  8. layout.desktop.openApplication(e, "cms.FormDesigner", {"id": this.json.subformSelected, "appId": "FormDesigner"+this.json.subformSelected});
  9. }
  10. },
  11. refreshSubform: function(){
  12. if (this.json.subformSelected && this.json.subformSelected!=="none" && this.json.subformType!=="script"){
  13. MWF.Actions.get("x_cms_assemble_control").getForm(this.json.subformSelected, function(json){
  14. if (this.subformData.updateTime!==json.data.updateTime){
  15. var select = null;
  16. if (this.property){
  17. select = $(this.property.data.pid+"selectSubform").getElement("select");
  18. }
  19. this.clearSubformList(this.json.subformSelected);
  20. this.reloadSubform(json.data, select, "");
  21. }
  22. }.bind(this));
  23. }
  24. },
  25. redoSelectedSubform: function(name, input, oldValue){
  26. if (this.json.subformSelected==="none") this.json.subformSelected="";
  27. if (this.json.subformSelected && this.json.subformSelected!=="none"){
  28. if (this.form.subformList && this.form.subformList[this.json.subformSelected]){
  29. //var p = (input) ? input.getPosition() : this.node.getPosition();
  30. var p = this.node.getPosition(document.bosy);
  31. this.form.designer.alert("error", {
  32. "event": {
  33. "x": p.x+150,
  34. "y": p.y+80
  35. }
  36. }, this.form.designer.lp.subformConflictTitle, this.form.designer.lp.subformConflictInfor, 400, 120);
  37. this.json.subformSelected = oldValue;
  38. if (input){
  39. for (var i=0; i<input.options.length; i++){
  40. if (input.options[i].value===oldValue){
  41. input.options[i].set("selected", true);
  42. break;
  43. }
  44. }
  45. }
  46. this.node.empty();
  47. this.loadIcon();
  48. }else{
  49. MWF.Actions.get("x_cms_assemble_control").getForm(this.json.subformSelected, function(json){
  50. this.reloadSubform(json.data, input, oldValue);
  51. }.bind(this));
  52. }
  53. }else{
  54. this.subformData = null;
  55. this.clearSubformList(oldValue);
  56. this.node.empty();
  57. this.loadIcon();
  58. }
  59. },
  60. regetSubformData: function(){
  61. var flag = false;
  62. if (this.json.subformSelected && this.json.subformSelected!=="none" && this.json.subformType!=="script"){
  63. MWF.Actions.get("x_cms_assemble_control").getForm(this.json.subformSelected, function(json){
  64. if (!this.subformData || this.subformData.updateTime!==json.data.updateTime){
  65. this.getSubformData(json.data);
  66. flag = true;
  67. }
  68. }.bind(this), null, false);
  69. }
  70. return flag;
  71. },
  72. checkSubform: function(data, input){
  73. var moduleNames = this.getConflictFields();
  74. if (moduleNames.length){
  75. var txt = this.form.designer.lp.subformNameConflictInfor;
  76. txt = txt.replace("{name}", moduleNames.join(", "));
  77. this.form.designer.notice(txt, "error", this.node);
  78. return false;
  79. }
  80. return true;
  81. },
  82. loadSubform: function(data) {
  83. this.subformData.json.style = this.form.json.style;
  84. this.subformData.json.properties = this.form.json.properties;
  85. this.subformData.json.jsheader = {"code": "", "html": ""};
  86. this.subformData.json.events = {};
  87. this.subformData.json.formStyleType = this.form.json.formStyleType;
  88. //this.subformData.json.id = this.json.id;
  89. this.subformModule = new MWF.CMSFCSubform.Form(this.form, this.node);
  90. this.subformModule.load(this.subformData);
  91. //this.createRefreshNode();
  92. }
  93. });
  94. MWF.xApplication.cms.FormDesigner.Module.Subform.Form = new Class({
  95. Extends: MWF.CMSFCForm,
  96. initialize: function(form, container, options){
  97. this.parentform = form;
  98. this.css = this.parentform.css;
  99. this.container = container;
  100. this.form = this;
  101. this.isSubform = true;
  102. this.moduleType = "subform";
  103. this.moduleList = [];
  104. this.moduleNodeList = [];
  105. this.moduleContainerNodeList = [];
  106. this.moduleElementNodeList = [];
  107. this.moduleComponentNodeList = [];
  108. // this.moduleContainerList = [];
  109. this.dataTemplate = {};
  110. this.designer = this.parentform.designer;
  111. this.selectedModules = [];
  112. },
  113. load : function(data){
  114. this.data = data;
  115. this.json = data.json;
  116. this.html = data.html;
  117. this.json.mode = this.options.mode;
  118. this.container.set("html", this.html);
  119. this.loadDomModules();
  120. //this.setCustomStyles();
  121. //this.node.setProperties(this.json.properties);
  122. //this.setNodeEvents();
  123. if (this.options.mode==="Mobile"){
  124. if (oldStyleValue) this._setEditStyle("formStyleType", null, oldStyleValue);
  125. }
  126. },
  127. loadDomModules: function(){
  128. this.node = this.container.getFirst();
  129. this.node.set("id", this.json.id);
  130. this.node.setStyles((this.options.mode==="Mobile") ? this.css.formMobileNode : this.css.formNode);
  131. this.node.store("module", this);
  132. this.loadDomTree();
  133. },
  134. loadDomTree: function(){
  135. this.createFormTreeNode();
  136. this.parseModules(this, this.node);
  137. },
  138. createFormTreeNode: function(){
  139. this.treeNode = {
  140. "insertChild": function(){return this;},
  141. "appendChild": function(){return this;},
  142. "selectNode": function(){},
  143. "node": null,
  144. "parentNode": {}
  145. };
  146. this.treeNode.module = this;
  147. }
  148. });