OOInput.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. MWF.xDesktop.requireApp('process.Xform', '$Input', null, false);
  2. MWF.xApplication.process.Xform.OOInput = MWF.APPOOInput = new Class({
  3. Implements: [Events],
  4. Extends: MWF.APP$Input,
  5. iconStyle: 'textFieldIcon',
  6. options: {
  7. "moduleEvents": ["load", "queryLoad", "postLoad"]
  8. },
  9. _loadNode: function () {
  10. // if (this.isReadonly() || this.json.showMode==="read"){
  11. // this._loadNodeRead();
  12. // }else{
  13. this._loadNodeEdit();
  14. // }
  15. },
  16. loadDescription: function () {
  17. this.node.setAttribute('placeholder', this.json.description || '');
  18. },
  19. _loadDomEvents: function(){
  20. Object.each(this.json.events, function(e, key){
  21. if (e.code){
  22. if (this.options.moduleEvents.indexOf(key)===-1){
  23. this.node.addEvent(key, function(event){
  24. return this.form.Macro.fire(e.code, this, event);
  25. }.bind(this));
  26. }
  27. }
  28. }.bind(this));
  29. },
  30. _loadNodeEdit: function () {
  31. this.node.set({
  32. 'id': this.json.id,
  33. 'MWFType': this.json.type,
  34. 'validity-blur': 'true',
  35. // "label-style": "width:6.2vw; min-width:5em; max-width:9em"
  36. });
  37. if (this.json.properties) {
  38. this.node.set(this.json.properties);
  39. }
  40. if (this.json.styles) {
  41. this.node.setStyles(this.json.styles);
  42. }
  43. if (this.json.label) {
  44. this.node.setAttribute('label', this.json.label);
  45. }
  46. if (this.json.showIcon != 'no' && !this.form.json.hideModuleIcon) {
  47. this.node.setAttribute('right-icon', 'edit');
  48. } else if (this.form.json.nodeStyleWithhideModuleIcon) {
  49. this.node.setAttribute('right-icon', '');
  50. }
  51. this.node.setAttribute('readonly', false);
  52. this.node.setAttribute('readmode', false);
  53. this.node.setAttribute('disabled', false);
  54. if (!this.isReadonly()){
  55. if (this.json.showMode === 'readonlyMode') {
  56. this.node.setAttribute('readonly', true);
  57. } else if (this.json.showMode === 'disabled') {
  58. this.node.setAttribute('disabled', true);
  59. } else if (this.json.showMode === 'read') {
  60. this.node.setAttribute('readmode', true);
  61. if (this.json.readModeEvents!=='yes'){
  62. this.node.setStyle('pointer-events', 'none');
  63. }
  64. } else {
  65. }
  66. }else{
  67. this.node.setAttribute('readmode', true);
  68. if (this.json.readModeEvents!=='yes'){
  69. this.node.setStyle('pointer-events', 'none');
  70. }
  71. }
  72. if (this.json.required){
  73. this.node.setAttribute("required", true);
  74. if (!this.json.validationConfig) this.json.validationConfig = [];
  75. var label = this.json.label ? `“${this.json.label.replace(/ /g, '')}”` : MWF.xApplication.process.Xform.LP.requiredHintField;
  76. this.json.validationConfig.push({
  77. status : "all",
  78. decision : "",
  79. valueType : "value",
  80. operateor : "isnull",
  81. value : "",
  82. prompt : MWF.xApplication.process.Xform.LP.requiredHint.replace('{label}', label),
  83. });
  84. }else{
  85. this.node.removeAttribute("required");
  86. }
  87. if (this.json.dataType){
  88. this.node.setAttribute("type", this.json.dataType);
  89. }
  90. this.node.addEvent('change', function () {
  91. var v = this.getInputData('change');
  92. this.validationMode();
  93. this.validation()
  94. this._setBusinessData(v);
  95. this.fireEvent('change');
  96. }.bind(this));
  97. var inputNode = this.node;
  98. if (inputNode) inputNode.addEvent('input', function (e) {
  99. var v = e.target.get('value');
  100. this._setBusinessData(v);
  101. }.bind(this));
  102. this.node.addEvent('blur', function () {
  103. this.validationMode();
  104. this.validation();
  105. }.bind(this));
  106. this.node.addEvent('keyup', function () {
  107. this.validationMode();
  108. }.bind(this));
  109. this.node.addEventListener('validity', (e) => {
  110. if (this.validationText) {
  111. e.target.setCustomValidity(this.validationText);
  112. }
  113. });
  114. },
  115. createModelNode: function () {
  116. // this.modelNode = new Element('div', {'styles': this.form.css.modelNode}).inject(this.node, 'after');
  117. // new Element('div', {
  118. // 'styles': this.form.css.modelNodeTitle,
  119. // 'text': MWF.xApplication.process.Xform.LP.ANNInput
  120. // }).inject(this.modelNode);
  121. // new Element('div', {
  122. // 'styles': this.form.css.modelNodeContent,
  123. // 'text': MWF.xApplication.process.Xform.LP.ANNInput
  124. // }).inject(this.modelNode);
  125. },
  126. __setData: function(data, fireChange){
  127. var old = this.getInputData();
  128. this.validationMode();
  129. this._setBusinessData(data);
  130. this.node.value = data;
  131. if (fireChange && old!==data) this.fireEvent("change");
  132. this.moduleValueAG = null;
  133. },
  134. __setValue: function (value) {
  135. this.moduleValueAG = null;
  136. this.validationMode();
  137. this._setBusinessData(value);
  138. // this.node.set('value', value || '');
  139. this.node.value = value;
  140. this.fieldModuleLoaded = true;
  141. return value;
  142. },
  143. getInputData: function () {
  144. return this.node.value;
  145. },
  146. notValidationMode: function (text) {
  147. this.validationText = text;
  148. this.node.checkValidity();
  149. },
  150. validationMode: function () {
  151. this.validationText = '';
  152. this.node.unInvalidStyle();
  153. }
  154. });