$Component.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. MWF.xApplication.process.FormDesigner.Module = MWF.xApplication.process.FormDesigner.Module || {};
  2. MWF.xDesktop.requireApp("process.FormDesigner", "Module.$Module", null, false);
  3. MWF.xApplication.process.FormDesigner.Module.$Component = MWF.FC$Component = new Class({
  4. Extends: MWF.FC$Module,
  5. Implements: [Options, Events],
  6. _setNodeProperty: function(){
  7. this.node.store("module", this);
  8. if (this.form.moduleList.indexOf(this)==-1) this.form.moduleList.push(this);
  9. if (this.form.moduleNodeList.indexOf(this.node)==-1) this.form.moduleNodeList.push(this.node);
  10. if (this.form.moduleComponentNodeList.indexOf(this.node)==-1) this.form.moduleComponentNodeList.push(this.node);
  11. // this.containers.each(function(container){
  12. // if (this.form.moduleContainerNodeList.indexOf(container.node)==-1) this.form.moduleContainerNodeList.push(container.node);
  13. // container.node.store("module", container);
  14. // }.bind(this));
  15. // this.elements.each(function(element){
  16. // if (this.form.moduleElementNodeList.indexOf(element.node)==-1) this.form.moduleElementNodeList.push(element.node);
  17. // element.node.store("module", element);
  18. // }.bind(this));
  19. },
  20. _initModule: function(){
  21. if (!this.initialized){
  22. if (this.json.initialized!=="yes") this.setStyleTemplate();
  23. this.setPropertiesOrStyles("styles");
  24. this.setPropertiesOrStyles("properties");
  25. this._getContainers();
  26. this._getElements();
  27. this._setNodeProperty();
  28. if (!this.form.isSubform) this._createIconAction();
  29. this._setNodeEvent();
  30. this.initialized = true;
  31. this.json.initialized = "yes";
  32. }
  33. },
  34. _getElements: function(){
  35. // this.elements.push(this);
  36. },
  37. _getContainers: function(){
  38. //this.containers
  39. },
  40. destroy: function(){
  41. this.containers.each(function(module){
  42. //module._deleteModule();
  43. module.destroy();
  44. });
  45. this.elements.each(function(module){
  46. module._deleteModule();
  47. });
  48. this._deleteModule();
  49. },
  50. _deleteModule: function(){
  51. this.form.moduleList.erase(this);
  52. this.form.moduleNodeList.erase(this.node);
  53. this.form.moduleElementNodeList.erase(this.node);
  54. if (this.form.scriptDesigner){
  55. this.form.scriptDesigner.removeModule(this.json);
  56. }
  57. if (this.property) this.property.destroy();
  58. this.node.destroy();
  59. this.actionArea.destroy();
  60. delete this.form.json.moduleList[this.json.id];
  61. this.json = null;
  62. delete this.json;
  63. this.treeNode.destroy();
  64. o2.release(this);
  65. },
  66. _dragIn: function(module){
  67. module.onDragModule = this;
  68. module.inContainer = null;
  69. module.parentContainer = this.parentContainer;
  70. module.nextModule = this;
  71. //this.parentContainer.node.setStyles({"border": "1px solid #ffa200"});
  72. this.node.setStyles({"border": "1px solid #ffa200"});
  73. //this._showInjectAction( module );
  74. if (module.controlMode){
  75. if (module.copyNode) module.copyNode.hide();
  76. }else{
  77. var copyNode = module._getCopyNode(this);
  78. copyNode.show();
  79. copyNode.inject(this.node, "before");
  80. this._positionCopyNode(copyNode);
  81. }
  82. // var copyNode = module._getCopyNode();
  83. // copyNode.inject(this.node, "before");
  84. },
  85. _setControlModeNode: function(){
  86. if (this.controlMode){
  87. if (this.copyNode) this.copyNode.hide();
  88. }else{
  89. if (this.onDragModule) this.onDragModule._dragIn(this);
  90. }
  91. },
  92. _dragOut: function(module){
  93. module.inContainer = null;
  94. module.parentContainer = null;
  95. module.nextModule = null;
  96. //this.parentContainer.node.setStyles(this.parentContainer.css.moduleNode);
  97. //this.parentContainer.node.setStyles(this.parentContainer.json.styles);
  98. this.node.setStyles(this.css.moduleNode);
  99. this.setCustomStyles();
  100. //this._hideInjectAction();
  101. var copyNode = module._getCopyNode();
  102. copyNode.setStyle("display", "none");
  103. },
  104. _dragDrop: function(module, flag){
  105. var f = flag || !(window.event || {}).ctrlKey;
  106. if( f ){
  107. this.node.setStyles(this.css.moduleNode);
  108. this.setCustomStyles();
  109. }
  110. //this.parentContainer.node.setStyles(this.parentContainer.css.moduleNode);
  111. //this.parentContainer.setCustomStyles();
  112. //this._hideInjectAction();
  113. },
  114. copy: function(e){
  115. var newModule = this.copyTo();
  116. newModule.move(e, "copy");
  117. },
  118. copyClearContainer: function(){
  119. var containerTmpNodes = [];
  120. this.containers.each(function(module){
  121. var containerTmpNode = new Element("div");
  122. var subNode = module.node.getFirst();
  123. while (subNode){
  124. var tmpSubNode = subNode.getNext();
  125. subNode.inject(containerTmpNode);
  126. subNode = tmpSubNode;
  127. }
  128. containerTmpNodes.push(containerTmpNode);
  129. }.bind(this));
  130. return containerTmpNodes;
  131. },
  132. copyRecoverContainer: function(containerTmpNodes){
  133. this.containers.each(function(module, idx){
  134. var containerTmpNode = containerTmpNodes[idx];
  135. var subNode = containerTmpNode.getFirst();
  136. while (subNode){
  137. var tmpSubNode = subNode.getNext();
  138. subNode.inject(module.node);
  139. subNode = tmpSubNode;
  140. }
  141. containerTmpNode.destroy();
  142. }.bind(this));
  143. delete containerTmpNodes;
  144. },
  145. copyTo: function(node){
  146. if (!node) node = this.form;
  147. var containerTmpNodes = this.copyClearContainer();
  148. var newNode = this.node.clone(true);
  149. var newModuleJson = Object.clone(this.json);
  150. newNode.inject(node.node);
  151. var className = this.moduleName.capitalize();
  152. var prefix = (this.form.moduleType=="page") ? "PC" : "FC";
  153. if( this.form.designer.options.name.contains("cms.") ){
  154. prefix = "CMSFC";
  155. }
  156. var newTool = new MWF[prefix+className](this.form);
  157. var oldId = newModuleJson.id;
  158. newModuleJson.id = newTool._getNewId();
  159. newNode.set("id", newModuleJson.id);
  160. if( this.form.copyedModule && this.form.copyedModule.checkCopySubModule){
  161. this.form.copyedModule.checkCopySubModule(newModuleJson, oldId);
  162. }
  163. this.form.json.moduleList[newModuleJson.id] = newModuleJson;
  164. if (this.form.scriptDesigner) this.form.scriptDesigner.createModuleScript(newModuleJson);
  165. this.copyComponentJsonData(newNode, newModuleJson.id);
  166. newTool.load(newModuleJson, newNode, node);
  167. this.copyRecoverContainer(containerTmpNodes);
  168. this.containers.each(function(module, idx){
  169. var modules = module._getSubModule();
  170. modules.each(function(subModule){
  171. //module._deleteModule();
  172. if (subModule.moduleType=="container"){
  173. subModule.copySubModule(newTool.containers[idx]);
  174. }
  175. if (subModule.moduleType=="element"){
  176. subModule.copyTo(newTool.containers[idx]);
  177. }
  178. if (subModule.moduleType=="component"){
  179. subModule.copyTo(newTool.containers[idx]);
  180. }
  181. });
  182. });
  183. return newTool;
  184. },
  185. parseModules: function(){}
  186. });