OORadioGroup.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. MWF.xDesktop.requireApp('process.Xform', 'Radio', null, false);
  2. MWF.xApplication.process.Xform.OORadioGroup = MWF.APPOORadioGroup = new Class({
  3. Implements: [Events],
  4. Extends: MWF.APPRadio,
  5. options: {
  6. "moduleEvents": ["load", "queryLoad", "postLoad"],
  7. "tag": "oo-radio-group",
  8. "itemTag": "oo-radio"
  9. },
  10. _loadNode: function () {
  11. // if (this.isReadonly() || this.json.showMode==="read"){
  12. // this._loadNodeRead();
  13. // }else{
  14. this._loadNodeEdit();
  15. // }
  16. },
  17. getValue: function(){
  18. if (this.moduleValueAG) return this.moduleValueAG;
  19. var value = this._getBusinessData();
  20. if (!value) value = this._computeValue();
  21. return value || "";
  22. },
  23. _loadNodeEdit: function () {
  24. var node = new Element(this.options.tag, {
  25. 'id': this.json.id,
  26. 'MWFType': this.json.type,
  27. // "label-style": "width:6.2vw; min-width:5em; max-width:9em"
  28. }).inject(this.node, 'before');
  29. this.node.destroy();
  30. this.node = node;
  31. if (this.json.properties) {
  32. this.node.set(this.json.properties);
  33. }
  34. if (this.json.styles) {
  35. this.node.setStyles(this.json.styles);
  36. }
  37. if (this.json.label) {
  38. this.node.setAttribute('label', this.json.label);
  39. }
  40. if (!this.json.countPerline || this.json.countPerline==="0") {
  41. this.node.removeAttribute('col');
  42. }else{
  43. this.node.setAttribute('col', this.json.countPerline);
  44. }
  45. if (!this.isReadonly()){
  46. if (this.json.showMode === 'disabled') {
  47. this.node.setAttribute('disabled', true);
  48. } else if (this.json.showMode === 'read') {
  49. this.node.setAttribute('readmode', true);
  50. if (this.json.readModeEvents!=='yes'){
  51. this.node.setStyle('pointer-events', 'none');
  52. }
  53. } else {
  54. }
  55. }else{
  56. this.node.setAttribute('readmode', true);
  57. if (this.json.readModeEvents!=='yes'){
  58. this.node.setStyle('pointer-events', 'none');
  59. }
  60. }
  61. if (this.json.required){
  62. this.node.setAttribute("required", true);
  63. if (!this.json.validationConfig) this.json.validationConfig = [];
  64. var label = this.json.label ? `“${this.json.label.replace(/ /g, '')}”` : MWF.xApplication.process.Xform.LP.requiredHintField;
  65. this.json.validationConfig.push({
  66. status : "all",
  67. decision : "",
  68. valueType : "value",
  69. operateor : "isnull",
  70. value : "",
  71. prompt : MWF.xApplication.process.Xform.LP.requiredHint.replace('{label}', label),
  72. });
  73. }else{
  74. this.node.removeAttribute("required");
  75. }
  76. this.node.addEvent('change', function () {
  77. var v = this.getInputData('change');
  78. this.validationMode();
  79. if (this.node.value) this.validation();
  80. this._setBusinessData(v);
  81. this.fireEvent('change');
  82. }.bind(this));
  83. this.node.addEventListener('validity', (e) => {
  84. if (this.validationText) {
  85. e.target.setCustomValidity(this.validationText);
  86. }
  87. });
  88. this.setOptions();
  89. },
  90. addModuleEvent: function(key, fun){
  91. if (this.options.moduleEvents.indexOf(key)!==-1){
  92. this.addEvent(key, function(event){
  93. return (fun) ? fun(this, event) : null;
  94. }.bind(this));
  95. }else{
  96. this.node.addEvent(key, function(event){
  97. return (fun) ? fun(this, event) : null;
  98. }.bind(this));
  99. }
  100. },
  101. _loadDomEvents: function(){
  102. Object.each(this.json.events, function(e, key){
  103. if (e.code){
  104. if (this.options.moduleEvents.indexOf(key)===-1){
  105. this.node.addEvent(key, function(event){
  106. return this.form.Macro.fire(e.code, this, event);
  107. }.bind(this));
  108. }
  109. }
  110. }.bind(this));
  111. },
  112. _setOptions: function(optionItems) {
  113. var p = o2.promiseAll(optionItems).then(function (radioValues) {
  114. this.moduleSelectAG = null;
  115. if (!radioValues) radioValues = [];
  116. if (o2.typeOf(radioValues) === "array") {
  117. var flag = (new MWF.widget.UUID).toString();
  118. radioValues.each(function (item, i) {
  119. var tmps = item.split("|");
  120. var text = tmps[0];
  121. var value = tmps[1] || text;
  122. var value = tmps[1] || text;
  123. var radio = new Element(this.options.itemTag, {
  124. "type": "radio",
  125. "name": (this.json.properties && this.json.properties.name) ? this.json.properties.name : flag + this.json.id,
  126. "value": value,
  127. "text": text,
  128. "styles": this.json.buttonStyles
  129. }).inject(this.node);
  130. }.bind(this));
  131. }
  132. }.bind(this), function () {
  133. this.moduleSelectAG = null;
  134. }.bind(this));
  135. this.moduleSelectAG = p;
  136. if (p) p.then(function () {
  137. this.moduleSelectAG = null;
  138. }.bind(this), function () {
  139. this.moduleSelectAG = null;
  140. }.bind(this));
  141. },
  142. __setData: function(data, fireChange){
  143. var old = this.getInputData();
  144. this._setBusinessData(data);
  145. this.node.value = data;
  146. if (fireChange && old!==data) this.fireEvent("change");
  147. this.moduleValueAG = null;
  148. },
  149. __setValue: function(value){
  150. this.moduleValueAG = null;
  151. this._setBusinessData(value);
  152. this.node.value = value;
  153. this.fieldModuleLoaded = true;
  154. },
  155. getTextData: function () {
  156. return {"value": this.node.value , "text": this.node.text};
  157. },
  158. _getInputTextData: function(){
  159. return {"value": this.node.value , "text": this.node.text};
  160. },
  161. getText: function(){
  162. return this.node.text;
  163. },
  164. getInputData: function(){
  165. return this.node.value;
  166. },
  167. getSelectedInput: function(){
  168. var inputs = this.node.getElements(this.options.itemTag);
  169. for (var i of inputs){
  170. if (i.checked) return i;
  171. }
  172. return null;
  173. },
  174. __setData: function(data, fireChange){
  175. this.moduleValueAG = null;
  176. this._setBusinessData(data);
  177. this.node.value = data;
  178. this.validationMode();
  179. this.fieldModuleLoaded = true;
  180. this.fireEvent("setData");
  181. },
  182. //
  183. // createModelNode: function () {
  184. // this.modelNode = new Element('div', {'styles': this.form.css.modelNode}).inject(this.node, 'after');
  185. // new Element('div', {
  186. // 'styles': this.form.css.modelNodeTitle,
  187. // 'text': MWF.xApplication.process.Xform.LP.ANNInput
  188. // }).inject(this.modelNode);
  189. // new Element('div', {
  190. // 'styles': this.form.css.modelNodeContent,
  191. // 'text': MWF.xApplication.process.Xform.LP.ANNInput
  192. // }).inject(this.modelNode);
  193. // },
  194. // __setValue: function (value) {
  195. // this.moduleValueAG = null;
  196. // this._setBusinessData(value);
  197. // this.node.set('value', value || '');
  198. // this.fieldModuleLoaded = true;
  199. // return value;
  200. // },
  201. notValidationMode: function (text) {
  202. this.validationText = text;
  203. this.node.checkValidity();
  204. },
  205. validationMode: function () {
  206. this.validationText = '';
  207. this.node.unInvalidStyle();
  208. }
  209. });