OOSelect.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. MWF.xDesktop.requireApp("process.Xform", "$Selector", null, false);
  2. MWF.xApplication.process.Xform.OOSelect = MWF.APPOOSelect = new Class({
  3. Implements: [Events],
  4. Extends: MWF.APP$Selector,
  5. iconStyle: "selectIcon",
  6. options: {
  7. "moduleEvents": ["load", "queryLoad", "postLoad"]
  8. },
  9. initialize: function(node, json, form, options){
  10. this.node = $(node);
  11. this.node.store("module", this);
  12. this.json = json;
  13. this.form = form;
  14. this.field = true;
  15. this.fieldModuleLoaded = false;
  16. this.nodeHtml = this.node.get("html");
  17. },
  18. reload: function(){
  19. if (this.areaNode){
  20. this.node = this.areaNode;
  21. this.areaNode.empty();
  22. this.areaNode = null;
  23. }
  24. this._beforeReloaded();
  25. this._loadUserInterface();
  26. this._loadStyles();
  27. this._afterLoaded();
  28. this._afterReloaded();
  29. this.fireEvent("postLoad");
  30. },
  31. loadDescription: function () {
  32. this.node.setAttribute('placeholder', this.json.description || '');
  33. },
  34. _loadNode: function(){
  35. this._loadNodeEdit();
  36. },
  37. _loadMergeReadContentNode: function( contentNode, data ){
  38. // this._showValue(contentNode, data.data);
  39. },
  40. _loadDomEvents: function(){
  41. Object.each(this.json.events, function(e, key){
  42. if (e.code){
  43. if (this.options.moduleEvents.indexOf(key)===-1){
  44. this.node.addEvent(key, function(event){
  45. return this.form.Macro.fire(e.code, this, event);
  46. }.bind(this));
  47. }
  48. }
  49. }.bind(this));
  50. },
  51. __showValue: function(node, value, optionItems){
  52. // if (value){
  53. // if (typeOf(value)!=="array") value = [value];
  54. // var texts = [];
  55. // optionItems.each(function(item){
  56. // var tmps = item.split("|");
  57. // var t = tmps[0];
  58. // var v = tmps[1] || t;
  59. //
  60. // if (v){
  61. //
  62. // if (value.indexOf(v)!=-1){
  63. // texts.push(t);
  64. // }
  65. // }
  66. //
  67. // });
  68. // node.set("text", texts.join(", "));
  69. // }
  70. },
  71. _loadStyles: function(){
  72. if (this.json.styles) this.node.setStyles(this.json.styles);
  73. },
  74. _resetNodeEdit: function(){
  75. // var node = new Element('oo-select', {
  76. // 'id': this.json.id,
  77. // 'MWFType': this.json.type
  78. // }).inject(this.node, 'before');
  79. // this.node.destroy();
  80. // this.node = node;
  81. this.node.set({
  82. 'id': this.json.id,
  83. 'MWFType': this.json.type,
  84. // "label-style": "width:6.2vw; min-width:5em; max-width:9em"
  85. });
  86. },
  87. _loadNodeEdit: function(){
  88. this._resetNodeEdit();
  89. this.node.removeAttribute("placeholder");
  90. if (this.json.properties) {
  91. this.node.set(this.json.properties);
  92. }
  93. if (this.json.styles) {
  94. this.node.setStyles(this.json.styles);
  95. }
  96. if (this.json.label) {
  97. this.node.setAttribute('label', this.json.label);
  98. }
  99. this.node.setAttribute('readonly', false);
  100. this.node.setAttribute('readmode', false);
  101. this.node.setAttribute('disabled', false);
  102. if (!this.isReadonly()){
  103. if (this.json.showMode === 'readonlyMode') {
  104. this.node.setAttribute('readonly', true);
  105. } else if (this.json.showMode === 'disabled') {
  106. this.node.setAttribute('disabled', true);
  107. } else if (this.json.showMode === 'read') {
  108. this.node.setAttribute('readmode', true);
  109. if (this.json.readModeEvents!=='yes'){
  110. this.node.setStyle('pointer-events', 'none');
  111. }
  112. } else {
  113. }
  114. }else{
  115. this.node.setAttribute('readmode', true);
  116. if (this.json.readModeEvents!=='yes'){
  117. this.node.setStyle('pointer-events', 'none');
  118. }
  119. }
  120. if (this.json.required){
  121. this.node.setAttribute("required", true);
  122. if (!this.json.validationConfig) this.json.validationConfig = [];
  123. var label = this.json.label ? `“${this.json.label.replace(/ /g, '')}”` : MWF.xApplication.process.Xform.LP.requiredHintField;
  124. this.json.validationConfig.push({
  125. status : "all",
  126. decision : "",
  127. valueType : "value",
  128. operateor : "isnull",
  129. value : "",
  130. prompt : MWF.xApplication.process.Xform.LP.requiredHint.replace('{label}', label),
  131. });
  132. }else{
  133. this.node.removeAttribute("required");
  134. }
  135. this.node.addEvent("change", function( ev ){
  136. var v = this.getInputData("change");
  137. this._setBusinessData(v);
  138. this.validationMode();
  139. this.validation();
  140. this.fireEvent("change", [this._getSelectedOption()]);
  141. }.bind(this));
  142. var inputNode = this.node;
  143. if (inputNode) inputNode.addEvent('input', function (e) {
  144. var v = e.target.get('value');
  145. this._setBusinessData(v);
  146. }.bind(this));
  147. this.node.addEvent('blur', function () {
  148. this.validation();
  149. }.bind(this));
  150. this.node.addEvent('keyup', function () {
  151. this.validationMode();
  152. }.bind(this));
  153. this.node.addEventListener('validity', (e) => {
  154. if (this.validationText) {
  155. e.target.setCustomValidity(this.validationText);
  156. }
  157. });
  158. this.setOptions();
  159. },
  160. _setOptions: function(optionItems){
  161. var p = o2.promiseAll(optionItems).then(function(options){
  162. this.moduleSelectAG = null;
  163. if (!options) options = [];
  164. if (o2.typeOf(options)==="array"){
  165. options.each(function(item){
  166. var tmps = item.split("|");
  167. var text = tmps[0];
  168. var value = tmps[1] || text;
  169. var option = new Element("oo-option", {
  170. "value": value
  171. });
  172. option.setAttribute('text', text);
  173. option.inject(this.node);
  174. }.bind(this));
  175. this.fireEvent("setOptions", [options])
  176. }
  177. }.bind(this), function(){
  178. this.moduleSelectAG = null;
  179. }.bind(this));
  180. this.moduleSelectAG = p;
  181. if (p) p.then(function(){
  182. this.moduleSelectAG = null;
  183. }.bind(this), function(){
  184. this.moduleSelectAG = null;
  185. }.bind(this));
  186. },
  187. addOption: function(text, value){
  188. var option = new Element("oo-option", {
  189. "value": value || text,
  190. "text": text
  191. }).inject(this.node);
  192. this.fireEvent("addOption", [text, value])
  193. },
  194. // _setValue: function(value, m, fireChange){
  195. // var mothed = m || "__setValue";
  196. // if (!!value){
  197. // var p = o2.promiseAll(value).then(function(v){
  198. // if (o2.typeOf(v)=="array") v = v[0];
  199. // if (this.moduleSelectAG){
  200. // this.moduleValueAG = this.moduleSelectAG;
  201. // this.moduleSelectAG.then(function(){
  202. // this[mothed](v, fireChange);
  203. // return v;
  204. // }.bind(this), function(){});
  205. // }else{
  206. // this[mothed](v, fireChange)
  207. // }
  208. // return v;
  209. // }.bind(this), function(){});
  210. //
  211. // this.moduleValueAG = p;
  212. // if (this.moduleValueAG) this.moduleValueAG.then(function(){
  213. // this.moduleValueAG = null;
  214. // }.bind(this), function(){
  215. // this.moduleValueAG = null;
  216. // }.bind(this));
  217. // }else{
  218. // this[mothed](value, fireChange);
  219. // }
  220. // },
  221. __setValue: function(value){
  222. this._setBusinessData(value);
  223. this.node.value = value;
  224. this.fieldModuleLoaded = true;
  225. this.moduleValueAG = null;
  226. },
  227. _getSelectedOption: function(){
  228. var ops = this.node.getElements("oo-option");
  229. for( var i=0; i<ops.length; i++ ){
  230. if( ops[i].selected )return ops[i];
  231. }
  232. return null;
  233. },
  234. _getInputTextData: function(){
  235. return {"value": this.node.value , "text": this.node.text};
  236. },
  237. getText: function(){
  238. return this.node.text;
  239. },
  240. getInputData: function(){
  241. return this.node.value;
  242. },
  243. resetData: function(){
  244. this.setData(this.getValue());
  245. },
  246. setData: function(data, fireChange){
  247. return this._setValue(data, "__setData", fireChange);
  248. },
  249. __setData: function(data, fireChange){
  250. var old = this.getInputData();
  251. this.moduleValueAG = null;
  252. this._setBusinessData(data);
  253. this.node.set('value', data || '');
  254. this.fieldModuleLoaded = true;
  255. if (fireChange && old!==data) this.fireEvent("change");
  256. return value;
  257. },
  258. notValidationMode: function (text) {
  259. this.validationText = text;
  260. this.node.checkValidity();
  261. },
  262. validationMode: function () {
  263. this.validationText = '';
  264. this.node.unInvalidStyle();
  265. }
  266. });