$ElComponent.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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.$ElComponent = MWF.FC$ElComponent = new Class({
  4. Extends: MWF.FC$Component,
  5. Implements: [Options, Events],
  6. _initModuleType: function(){
  7. this.className = "ElComponent"
  8. this.moduleType = "component";
  9. this.moduleName = "elComponent";
  10. },
  11. initialize: function(form, options){
  12. this.setOptions(options);
  13. this._initModuleType();
  14. this.path = "../x_component_process_FormDesigner/Module/"+this.className+"/";
  15. this.cssPath = "../x_component_process_FormDesigner/Module/"+this.className+"/"+this.options.style+"/css.wcss";
  16. this._loadCss();
  17. this.form = form;
  18. this.container = null;
  19. this.containerNode = null;
  20. this.isPropertyLoaded = false;
  21. },
  22. showProperty: function(callback){
  23. if (!this.property){
  24. this.property = new MWF.xApplication.process.FormDesigner.Property(this, this.form.designer.propertyContentArea, this.form.designer, {
  25. "path": this.options.propertyPath,
  26. "onPostLoad": function(){
  27. this.property.show();
  28. this.isPropertyLoaded = true;
  29. if (callback) callback();
  30. }.bind(this)
  31. });
  32. this.property.load();
  33. }else{
  34. this.property.show();
  35. if (callback) callback();
  36. }
  37. },
  38. _createMoveNode: function(){
  39. this.moveNode = new Element("div", {
  40. "MWFType": this.moduleName,
  41. "id": this.json.id,
  42. "styles": this.css.moduleNodeMove,
  43. "text": this.json.name || this.json.id,
  44. "events": {
  45. "selectstart": function(){
  46. return false;
  47. }
  48. }
  49. }).inject(this.form.container);
  50. },
  51. _createNode: function(){
  52. this.node = new Element("div", {
  53. "MWFType": this.moduleName,
  54. "id": this.json.id,
  55. "styles": this.css.moduleNode,
  56. "events": {
  57. "selectstart": function(){
  58. return false;
  59. }
  60. }
  61. });
  62. },
  63. _initModule: function(){
  64. if (!this.initialized){
  65. if (this.json.initialized!=="yes") this.setStyleTemplate();
  66. this._resetModuleDomNode();
  67. }
  68. },
  69. _loadVue: function(callback){
  70. if (!window.Vue){
  71. o2.load(["vue", "elementui"], { "sequence": true }, callback);
  72. }else{
  73. if (callback) callback();
  74. }
  75. },
  76. _createElementHtml: function(){
  77. return "";
  78. },
  79. _resetModuleDomNode: function(){
  80. if (!this.vm){
  81. this.node.set("html", this._createElementHtml());
  82. this._loadVue(this._mountVueApp.bind(this));
  83. }
  84. },
  85. _mountVueApp: function(){
  86. if (!this.vueApp) this.vueApp = this._createVueExtend();
  87. try{
  88. this.vm = new Vue(this.vueApp);
  89. this.vm.$o2module = this;
  90. this.vm.$o2callback = callback;
  91. this.vm.$mount(this.node);
  92. }catch(e){
  93. this.node.store("module", this);
  94. this._loadVueCss();
  95. if (callback) callback();
  96. }
  97. },
  98. _createVueData: function(){
  99. return {};
  100. },
  101. _createVueExtend: function(){
  102. var _self = this;
  103. return {
  104. data: this._createVueData(),
  105. mounted: function(){
  106. _self._afterMounted(this.$el);
  107. }
  108. };
  109. },
  110. _afterMounted: function(el){
  111. this.node = el;
  112. this.node.store("module", this);
  113. this._getContainers();
  114. this._getElements();
  115. this._setNodeProperty();
  116. if (!this.form.isSubform) this._createIconAction();
  117. this._setNodeEvent();
  118. this.initialized = true;
  119. this.json.initialized = "yes";
  120. this.selected(true);
  121. },
  122. _setOtherNodeEvent: function(){},
  123. _setEditStyle_custom: function(name){
  124. switch (name){
  125. case "name": this.setPropertyName(); break;
  126. case "id": this.setPropertyId(); break;
  127. default: if (this.isPropertyLoaded) if (this.vm) this.resetElement();
  128. }
  129. },
  130. setPropertyName: function(){},
  131. setPropertyId: function(){},
  132. resetElement: function(){
  133. this._createNode();
  134. this.node.inject(this.vm.$el,"before");
  135. var node = this.vm.$el;
  136. this.vm.$destroy();
  137. node.destroy();
  138. this.vm = null;
  139. this.isSetEvents = false;
  140. this._resetModuleDomNode();
  141. }
  142. });