OOCheckGroup.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. MWF.xDesktop.requireApp('process.Xform', 'OORadioGroup', null, false);
  2. MWF.xApplication.process.Xform.OOCheckGroup = MWF.APPOOCheckGroup = new Class({
  3. Implements: [Events],
  4. Extends: MWF.APPOORadioGroup,
  5. options: {
  6. "moduleEvents": ["load", "queryLoad", "postLoad"],
  7. "tag": "oo-checkbox-group",
  8. "itemTag": "oo-checkbox"
  9. },
  10. // _loadNode: function () {
  11. // // if (this.isReadonly() || this.json.showMode==="read"){
  12. // // this._loadNodeRead();
  13. // // }else{
  14. // this._loadNodeEdit();
  15. // // }
  16. // },
  17. //
  18. //
  19. _loadNodeEdit: function () {
  20. var node = new Element(this.options.tag, {
  21. 'id': this.json.id,
  22. 'MWFType': this.json.type,
  23. // "label-style": "width:6.2vw; min-width:4.3em; max-width:9em"
  24. }).inject(this.node, 'before');
  25. this.node.destroy();
  26. this.node = node;
  27. if (this.json.properties) {
  28. this.node.set(this.json.properties);
  29. }
  30. if (this.json.styles) {
  31. this.node.setStyles(this.json.styles);
  32. }
  33. if (this.json.label) {
  34. this.node.setAttribute('label', this.json.label);
  35. }
  36. if (!this.json.countPerline || this.json.countPerline==="0") {
  37. this.node.removeAttribute('col');
  38. }else{
  39. this.node.setAttribute('col', this.json.countPerline);
  40. }
  41. if (this.json.canSelectCount){
  42. this.node.setAttribute('count', this.json.canSelectCount);
  43. }
  44. if (!this.isReadonly()){
  45. if (this.json.showMode === 'disabled') {
  46. this.node.setAttribute('disabled', true);
  47. } else if (this.json.showMode === 'read') {
  48. this.node.setAttribute('readmode', true);
  49. if (this.json.readModeEvents!=='yes'){
  50. this.node.setStyle('pointer-events', 'none');
  51. }
  52. } else {
  53. }
  54. }else{
  55. this.node.setAttribute('readmode', true);
  56. if (this.json.readModeEvents!=='yes'){
  57. this.node.setStyle('pointer-events', 'none');
  58. }
  59. }
  60. if (this.json.required){
  61. this.node.setAttribute("required", true);
  62. if (!this.json.validationConfig) this.json.validationConfig = [];
  63. var label = this.json.label ? `“${this.json.label.replace(/ /g, '')}”` : MWF.xApplication.process.Xform.LP.requiredHintField;
  64. this.json.validationConfig.push({
  65. status : "all",
  66. decision : "",
  67. valueType : "value",
  68. operateor : "isnull",
  69. value : "",
  70. prompt : MWF.xApplication.process.Xform.LP.requiredHint.replace('{label}', label),
  71. });
  72. }else{
  73. this.node.removeAttribute("required");
  74. }
  75. this.node.addEvent('change', function () {
  76. var v = this.getInputData('change');
  77. this.validationMode();
  78. // if (this.node.value.length) this.validation();
  79. this._setBusinessData(v);
  80. this.fireEvent('change');
  81. }.bind(this));
  82. this.node.addEventListener('validity', (e) => {
  83. if (this.validationText) {
  84. e.target.setCustomValidity(this.validationText);
  85. }
  86. });
  87. this.setOptions();
  88. },
  89. _setValue: function(value, m, fireChange){
  90. var mothed = m || "__setValue";
  91. if (!!value){
  92. var p = o2.promiseAll(value).then(function(v){
  93. //if (o2.typeOf(v)=="array") v = v[0];
  94. if (this.moduleSelectAG){
  95. this.moduleValueAG = this.moduleSelectAG;
  96. this.moduleSelectAG.then(function(){
  97. this[mothed](v, fireChange);
  98. return v;
  99. }.bind(this), function(){});
  100. }else{
  101. this[mothed](v, fireChange)
  102. }
  103. return v;
  104. }.bind(this), function(){});
  105. this.moduleValueAG = p;
  106. if (this.moduleValueAG) this.moduleValueAG.then(function(){
  107. this.moduleValueAG = null;
  108. }.bind(this), function(){
  109. this.moduleValueAG = null;
  110. }.bind(this));
  111. }else{
  112. this[mothed](value, fireChange);
  113. }
  114. },
  115. __setData: function(data, fireChange){
  116. var old = this.getInputData();
  117. this._setBusinessData(data);
  118. this.node.value = data;
  119. if (fireChange && old!==data) this.fireEvent("change");
  120. this.moduleValueAG = null;
  121. },
  122. __setValue: function(value){
  123. this.moduleValueAG = null;
  124. this._setBusinessData(value);
  125. this.node.value = value;
  126. this.fieldModuleLoaded = true;
  127. },
  128. getSelectedInput: function(){
  129. var inputs = this.node.getElements(this.options.itemTag);
  130. var items = [];
  131. for (var i of inputs){
  132. if (i.checked) items.push(i);
  133. }
  134. return items;
  135. },
  136. // __setData: function(data, fireChange){
  137. // this.moduleValueAG = null;
  138. // this._setBusinessData(data);
  139. // this.node.value = data;
  140. // this.validationMode();
  141. // this.fieldModuleLoaded = true;
  142. // this.fireEvent("setData");
  143. // },
  144. //
  145. // notValidationMode: function (text) {
  146. // this.validationText = text;
  147. // this.node.checkValidity();
  148. // },
  149. // validationMode: function () {
  150. // this.validationText = '';
  151. // }
  152. });