OODatetime.js 6.0 KB

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