$Elinput.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. o2.xDesktop.requireApp("process.Xform", "$ElModule", null, false);
  2. o2.xDesktop.requireApp("process.Xform", "$Input", null, false);
  3. o2.xApplication.process.Xform.$Elinput = o2.APP$Elinput = new Class({
  4. Implements: [Events],
  5. Extends: MWF.APP$ElModule,
  6. });
  7. Object.assign(o2.APP$Elinput.prototype, o2.APP$Input.prototype);
  8. Object.assign(o2.APP$Elinput.prototype, {
  9. isReadonly : function(){
  10. return !!(this.readonly || this.json.isReadonly || this.form.json.isReadonly || this.isSectionMergeRead() );
  11. },
  12. reload: function(){
  13. if (this.vm) {
  14. var node = this.vm.$el;
  15. this.vm.$destroy();
  16. node.empty();
  17. }
  18. this.vm = null;
  19. this.vueApp = null;
  20. this._loadUserInterface();
  21. },
  22. __setValue: function(value){
  23. this.moduleValueAG = null;
  24. this._setBusinessData(value);
  25. this.json[this.json.$id] = value;
  26. this.__setReadonly(value);
  27. this.fieldModuleLoaded = true;
  28. return value;
  29. },
  30. __setData: function(data){
  31. var old = this.getInputData();
  32. this._setBusinessData(data);
  33. this.json[this.json.$id] = data;
  34. this.__setReadonly(data);
  35. if (old!==data) this.fireEvent("change");
  36. this.moduleValueAG = null;
  37. this.validationMode();
  38. },
  39. __setReadonly: function(data){
  40. if (this.isReadonly()) {
  41. this.node.set("text", data);
  42. if( this.json.elProperties ){
  43. this.node.set(this.json.elProperties );
  44. }
  45. if (this.json.elStyles){
  46. this.node.setStyles( this._parseStyles(this.json.elStyles) );
  47. }
  48. if( !this.eventLoaded ){
  49. this._loadDomEvents();
  50. this.eventLoaded = true;
  51. }
  52. this.fireEvent("postLoad");
  53. if( this.moduleSelectAG && typeOf(this.moduleSelectAG.then) === "function" ){
  54. this.moduleSelectAG.then(function () {
  55. this.fireEvent("load");
  56. this.isLoaded = true;
  57. }.bind(this));
  58. }else{
  59. this.fireEvent("load");
  60. this.isLoaded = true;
  61. }
  62. }
  63. },
  64. getInputData: function(){
  65. return this.json[this.json.$id];
  66. },
  67. // _getVueModelBindId: function(){
  68. // if (this.json.id.indexOf("..")!==-1){
  69. // this.json["$id"] ="__"+this.json.id.replace(/\.\./g, "_")
  70. // }else{
  71. // this.json["$id"] = this.json.id;
  72. // }
  73. // },
  74. _loadNodeEdit: function(){
  75. var id = (this.json.id.indexOf("..")!==-1) ? this.json.id.replace(/\.\./g, "_") : this.json.id;
  76. this.json["$id"] = (id.indexOf("-")!==-1) ? id.replace(/-/g, "_") : id;
  77. this.node.appendHTML(this._createElementHtml(), "before");
  78. var input = this.node.getPrevious();
  79. this.node.destroy();
  80. this.node = input;
  81. this.node.set({
  82. "id": this.json.id,
  83. "MWFType": this.json.type
  84. });
  85. this.node.addClass("o2_vue");
  86. this._createVueApp();
  87. },
  88. _loadDomEvents: function(){
  89. Object.each(this.json.events, function(e, key){
  90. if (e.code){
  91. if (this.options.moduleEvents.indexOf(key)===-1 && this.options.elEvents.indexOf(key)===-1){
  92. this.node.addEvent(key, function(event){
  93. return this.form.Macro.fire(e.code, this, event);
  94. }.bind(this));
  95. }
  96. }
  97. }.bind(this));
  98. },
  99. addModuleEvent: function(key, fun){
  100. if (this.options.moduleEvents.indexOf(key)!==-1 || this.options.elEvents.indexOf(key)!==-1 ){
  101. this.addEvent(key, function(event){
  102. return (fun) ? fun(this, event) : null;
  103. }.bind(this));
  104. }else{
  105. this.node.addEvent(key, function(event){
  106. return (fun) ? fun(this, event) : null;
  107. }.bind(this));
  108. }
  109. },
  110. getValue: function(){
  111. if (this.moduleValueAG) return this.moduleValueAG;
  112. var value = this._getBusinessData();
  113. if (value || value===false || value===0){
  114. return value;
  115. }else{
  116. value = this._computeValue();
  117. return (o2.typeOf(value)!=="null") ? value : "";
  118. }
  119. // if (!value) value = this._computeValue();
  120. // return (o2.typeOf(value)!=="null") ? value : "";
  121. //return value || "";
  122. },
  123. _afterLoaded: function(){}
  124. })