@websy/websy-designs 1.11.10 → 1.11.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2087,7 +2087,12 @@ class WebsyDropdown {
2087
2087
  labelEl.innerHTML = item.label
2088
2088
  labelEl.setAttribute('data-info', item.label)
2089
2089
  inputEl.value = item.value
2090
- }
2090
+ }
2091
+ else if (this.selectedItems[0]) {
2092
+ labelEl.innerHTML = dataToUse[this.selectedItems[0]].label
2093
+ labelEl.setAttribute('data-info', dataToUse[this.selectedItems[0]].label)
2094
+ inputEl.value = dataToUse[this.selectedItems[0]].value
2095
+ }
2091
2096
  }
2092
2097
  else if (this.selectedItems.length > 1) {
2093
2098
  if (this.options.showCompleteSelectedList === true) {
@@ -2116,10 +2121,12 @@ class WebsyDropdown {
2116
2121
  if (this.options.onSearch) {
2117
2122
  dataToUse = this.options.items
2118
2123
  }
2124
+ let item
2119
2125
  if (typeof index !== 'undefined' && index !== null) {
2120
2126
  let pos = this.selectedItems.indexOf(index)
2121
2127
  if (this.options.multiSelect === false) {
2122
2128
  this.selectedItems = [index]
2129
+ item = dataToUse[index]
2123
2130
  }
2124
2131
  else {
2125
2132
  if (pos !== -1) {
@@ -2127,11 +2134,10 @@ class WebsyDropdown {
2127
2134
  }
2128
2135
  else {
2129
2136
  this.selectedItems.push(index)
2137
+ item = dataToUse[index]
2130
2138
  }
2131
2139
  }
2132
- }
2133
- // const item = this.options.items[index]
2134
- const item = dataToUse[index]
2140
+ }
2135
2141
  this.updateHeader(item)
2136
2142
  if (item && this.options.onItemSelected) {
2137
2143
  this.options.onItemSelected(item, this.selectedItems, dataToUse, this.options)
@@ -2155,6 +2161,7 @@ class WebsyForm {
2155
2161
  clearAfterSave: false,
2156
2162
  fields: [],
2157
2163
  mode: 'add',
2164
+ useLoader: false,
2158
2165
  onSuccess: function (data) {},
2159
2166
  onError: function (err) { console.log('Error submitting form data:', err) }
2160
2167
  }
@@ -2189,6 +2196,7 @@ class WebsyForm {
2189
2196
  if (this.options.cancelFn) {
2190
2197
  this.options.cancelFn(this.elementId)
2191
2198
  }
2199
+ this.loader.hide()
2192
2200
  }
2193
2201
  checkRecaptcha () {
2194
2202
  return new Promise((resolve, reject) => {
@@ -2239,6 +2247,7 @@ class WebsyForm {
2239
2247
  clear () {
2240
2248
  const formEl = document.getElementById(`${this.elementId}Form`)
2241
2249
  formEl.reset()
2250
+ this.loader.hide()
2242
2251
  }
2243
2252
  get data () {
2244
2253
  const formEl = document.getElementById(`${this.elementId}Form`)
@@ -2261,6 +2270,9 @@ class WebsyForm {
2261
2270
  if (this.fieldMap[key] && this.fieldMap[key].type === 'checkbox') {
2262
2271
  data[key] = false
2263
2272
  }
2273
+ else if (this.fieldMap[key] && (this.fieldMap[key].component === 'Switch' || this.fieldMap[key].component === 'WebsySwitch')) {
2274
+ data[key] = this.fieldMap[key].instance.options.enabled
2275
+ }
2264
2276
  else if (this.fieldMap[key] && this.fieldMap[key].instance && this.fieldMap[key].instance.value) {
2265
2277
  data[key] = this.fieldMap[key].instance.value
2266
2278
  }
@@ -2497,6 +2509,7 @@ class WebsyForm {
2497
2509
  this.options.fields.forEach((f, i) => {
2498
2510
  this.fieldMap[f.field] = f
2499
2511
  f.owningElement = this.elementId
2512
+ let inputValue = typeof f.value === 'function' ? f.value() : f.value
2500
2513
  if (f.disabled || f.readOnly || this.options.readOnly) {
2501
2514
  if (!f.options) {
2502
2515
  f.options = {}
@@ -2540,7 +2553,7 @@ class WebsyForm {
2540
2553
  ${f.disabled || f.readOnly || this.options.readOnly ? 'disabled' : ''}
2541
2554
  ${(f.attributes || []).join(' ')}
2542
2555
  class="websy-input websy-textarea ${f.readOnly || this.options.readOnly ? 'websy-input-readonly' : ''}"
2543
- >${f.value || ''}</textarea>
2556
+ >${inputValue || ''}</textarea>
2544
2557
  <span id='${this.elementId}_${f.field}_error' class='websy-form-validation-error'></span>
2545
2558
  </div><!--
2546
2559
  `
@@ -2559,8 +2572,8 @@ class WebsyForm {
2559
2572
  ${(f.attributes || []).join(' ')}
2560
2573
  name="${f.field}"
2561
2574
  placeholder="${f.placeholder || ''}"
2562
- value="${f.type === 'date' ? '' : f.value || ''}"
2563
- valueAsDate="${f.type === 'date' ? f.value : ''}"
2575
+ value="${f.type === 'date' ? '' : inputValue || ''}"
2576
+ valueAsDate="${f.type === 'date' ? inputValue : ''}"
2564
2577
  ${f.disabled || f.readOnly || this.options.readOnly ? 'disabled' : ''}
2565
2578
  oninvalidx="this.setCustomValidity('${f.invalidMessage || 'Please fill in this field.'}')"
2566
2579
  />
@@ -2591,8 +2604,12 @@ class WebsyForm {
2591
2604
  html += `
2592
2605
  </form>
2593
2606
  <div id="${this.elementId}_validationFail" class="websy-validation-failure"></div>
2607
+ <div id="${this.elementId}_loader" class=""></div>
2594
2608
  `
2595
2609
  el.innerHTML = html
2610
+ if (!this.loader) {
2611
+ this.loader = new WebsyDesigns.LoadingDialog(`${this.elementId}_loader`, { title: '&nbsp;' })
2612
+ }
2596
2613
  this.processComponents(componentsToProcess, () => {
2597
2614
  if ((this.options.useRecaptcha === true || this.options.useRecaptchaV3 === true) && typeof grecaptcha !== 'undefined') {
2598
2615
  this.recaptchaReady()
@@ -2645,6 +2662,9 @@ class WebsyForm {
2645
2662
  if (recaptchErrEl) {
2646
2663
  recaptchErrEl.classList.add('websy-hidden')
2647
2664
  }
2665
+ if (this.options.useLoader) {
2666
+ this.loader.show()
2667
+ }
2648
2668
  const formData = new FormData(formEl)
2649
2669
  const data = {}
2650
2670
  const temp = new FormData(formEl)
@@ -2673,10 +2693,13 @@ class WebsyForm {
2673
2693
  }
2674
2694
  else if (this.options.submitFn) {
2675
2695
  this.options.submitFn(data, () => {
2696
+ this.loader.hide()
2676
2697
  if (this.options.clearAfterSave === true) {
2677
2698
  // this.render()
2678
2699
  formEl.reset()
2679
2700
  }
2701
+ }, () => {
2702
+ this.loader.hide()
2680
2703
  })
2681
2704
  }
2682
2705
  }
@@ -4937,6 +4960,10 @@ class WebsyRouter {
4937
4960
  this.showView(this.currentView, this.currentParams, 'main')
4938
4961
  }
4939
4962
  navigate (inputPath, group = 'main', event, popped) {
4963
+ if (inputPath.indexOf('http') === 0) {
4964
+ window.open(inputPath, '_blank')
4965
+ return
4966
+ }
4940
4967
  if (typeof popped === 'undefined') {
4941
4968
  popped = false
4942
4969
  }
@@ -5162,6 +5189,12 @@ class Switch {
5162
5189
  this.render()
5163
5190
  }
5164
5191
  }
5192
+ get data () {
5193
+ return this.options.enabled
5194
+ }
5195
+ set data (d) {
5196
+ this.options.enabled = d
5197
+ }
5165
5198
  disable () {
5166
5199
  this.options.enabled = false
5167
5200
  let method = this.options.enabled === true ? 'add' : 'remove'
@@ -2069,6 +2069,10 @@ var WebsyDropdown = /*#__PURE__*/function () {
2069
2069
  labelEl.innerHTML = item.label;
2070
2070
  labelEl.setAttribute('data-info', item.label);
2071
2071
  inputEl.value = item.value;
2072
+ } else if (this.selectedItems[0]) {
2073
+ labelEl.innerHTML = dataToUse[this.selectedItems[0]].label;
2074
+ labelEl.setAttribute('data-info', dataToUse[this.selectedItems[0]].label);
2075
+ inputEl.value = dataToUse[this.selectedItems[0]].value;
2072
2076
  }
2073
2077
  } else if (this.selectedItems.length > 1) {
2074
2078
  if (this.options.showCompleteSelectedList === true) {
@@ -2103,20 +2107,21 @@ var WebsyDropdown = /*#__PURE__*/function () {
2103
2107
  if (this.options.onSearch) {
2104
2108
  dataToUse = this.options.items;
2105
2109
  }
2110
+ var item;
2106
2111
  if (typeof index !== 'undefined' && index !== null) {
2107
2112
  var pos = this.selectedItems.indexOf(index);
2108
2113
  if (this.options.multiSelect === false) {
2109
2114
  this.selectedItems = [index];
2115
+ item = dataToUse[index];
2110
2116
  } else {
2111
2117
  if (pos !== -1) {
2112
2118
  this.selectedItems.splice(pos, 1);
2113
2119
  } else {
2114
2120
  this.selectedItems.push(index);
2121
+ item = dataToUse[index];
2115
2122
  }
2116
2123
  }
2117
2124
  }
2118
- // const item = this.options.items[index]
2119
- var item = dataToUse[index];
2120
2125
  this.updateHeader(item);
2121
2126
  if (item && this.options.onItemSelected) {
2122
2127
  this.options.onItemSelected(item, this.selectedItems, dataToUse, this.options);
@@ -2145,6 +2150,7 @@ var WebsyForm = /*#__PURE__*/function () {
2145
2150
  clearAfterSave: false,
2146
2151
  fields: [],
2147
2152
  mode: 'add',
2153
+ useLoader: false,
2148
2154
  onSuccess: function onSuccess(data) {},
2149
2155
  onError: function onError(err) {
2150
2156
  console.log('Error submitting form data:', err);
@@ -2183,6 +2189,7 @@ var WebsyForm = /*#__PURE__*/function () {
2183
2189
  if (this.options.cancelFn) {
2184
2190
  this.options.cancelFn(this.elementId);
2185
2191
  }
2192
+ this.loader.hide();
2186
2193
  }
2187
2194
  }, {
2188
2195
  key: "checkRecaptcha",
@@ -2243,6 +2250,7 @@ var WebsyForm = /*#__PURE__*/function () {
2243
2250
  value: function clear() {
2244
2251
  var formEl = document.getElementById("".concat(this.elementId, "Form"));
2245
2252
  formEl.reset();
2253
+ this.loader.hide();
2246
2254
  }
2247
2255
  }, {
2248
2256
  key: "data",
@@ -2266,6 +2274,8 @@ var WebsyForm = /*#__PURE__*/function () {
2266
2274
  if (keys.indexOf(key) === -1) {
2267
2275
  if (this.fieldMap[key] && this.fieldMap[key].type === 'checkbox') {
2268
2276
  data[key] = false;
2277
+ } else if (this.fieldMap[key] && (this.fieldMap[key].component === 'Switch' || this.fieldMap[key].component === 'WebsySwitch')) {
2278
+ data[key] = this.fieldMap[key].instance.options.enabled;
2269
2279
  } else if (this.fieldMap[key] && this.fieldMap[key].instance && this.fieldMap[key].instance.value) {
2270
2280
  data[key] = this.fieldMap[key].instance.value;
2271
2281
  }
@@ -2527,6 +2537,7 @@ var WebsyForm = /*#__PURE__*/function () {
2527
2537
  this.options.fields.forEach(function (f, i) {
2528
2538
  _this18.fieldMap[f.field] = f;
2529
2539
  f.owningElement = _this18.elementId;
2540
+ var inputValue = typeof f.value === 'function' ? f.value() : f.value;
2530
2541
  if (f.disabled || f.readOnly || _this18.options.readOnly) {
2531
2542
  if (!f.options) {
2532
2543
  f.options = {};
@@ -2550,9 +2561,9 @@ var WebsyForm = /*#__PURE__*/function () {
2550
2561
  componentsToProcess.push(f);
2551
2562
  html += "\n ".concat(i > 0 ? '-->' : '', "<div id='").concat(_this18.elementId, "_").concat(f.field, "_inputContainer' style='").concat(f.style || '', "' class='websy-input-container ").concat(f.classes ? f.classes.join(' ') : '', " ").concat(f.component === 'MediaUpload' ? 'media-upload' : '', "'>\n ").concat(f.label ? "<label for=\"".concat(f.field, "\">").concat(f.label, "</label>") : '').concat(f.required === true ? '<span class="websy-form-required-value">*</span>' : '', "\n <div id='").concat(_this18.elementId, "_input_").concat(f.field, "_component' class='form-component'></div>\n <span id='").concat(_this18.elementId, "_").concat(f.field, "_error' class='websy-form-validation-error'></span>\n </div><!--\n ");
2552
2563
  } else if (f.type === 'longtext') {
2553
- html += "\n ".concat(i > 0 ? '-->' : '', "<div id='").concat(_this18.elementId, "_").concat(f.field, "_inputContainer' style='").concat(f.style || '', "' class='websy-input-container ").concat(f.classes ? f.classes.join(' ') : '', "'>\n ").concat(f.label ? "<label for=\"".concat(f.field, "\">").concat(f.label, "</label>") : '').concat(f.required === true ? '<span class="websy-form-required-value">*</span>' : '', "\n <textarea\n id=\"").concat(_this18.elementId, "_input_").concat(f.field, "\"\n ").concat(f.required === true ? 'required' : '', " \n placeholder=\"").concat(f.placeholder || '', "\"\n data-user-type=\"").concat(f.type, "\"\n data-index=\"").concat(i, "\"\n name=\"").concat(f.field, "\" \n ").concat(f.disabled || f.readOnly || _this18.options.readOnly ? 'disabled' : '', "\n ").concat((f.attributes || []).join(' '), "\n class=\"websy-input websy-textarea ").concat(f.readOnly || _this18.options.readOnly ? 'websy-input-readonly' : '', "\"\n >").concat(f.value || '', "</textarea>\n <span id='").concat(_this18.elementId, "_").concat(f.field, "_error' class='websy-form-validation-error'></span>\n </div><!--\n ");
2564
+ html += "\n ".concat(i > 0 ? '-->' : '', "<div id='").concat(_this18.elementId, "_").concat(f.field, "_inputContainer' style='").concat(f.style || '', "' class='websy-input-container ").concat(f.classes ? f.classes.join(' ') : '', "'>\n ").concat(f.label ? "<label for=\"".concat(f.field, "\">").concat(f.label, "</label>") : '').concat(f.required === true ? '<span class="websy-form-required-value">*</span>' : '', "\n <textarea\n id=\"").concat(_this18.elementId, "_input_").concat(f.field, "\"\n ").concat(f.required === true ? 'required' : '', " \n placeholder=\"").concat(f.placeholder || '', "\"\n data-user-type=\"").concat(f.type, "\"\n data-index=\"").concat(i, "\"\n name=\"").concat(f.field, "\" \n ").concat(f.disabled || f.readOnly || _this18.options.readOnly ? 'disabled' : '', "\n ").concat((f.attributes || []).join(' '), "\n class=\"websy-input websy-textarea ").concat(f.readOnly || _this18.options.readOnly ? 'websy-input-readonly' : '', "\"\n >").concat(inputValue || '', "</textarea>\n <span id='").concat(_this18.elementId, "_").concat(f.field, "_error' class='websy-form-validation-error'></span>\n </div><!--\n ");
2554
2565
  } else {
2555
- html += "\n ".concat(i > 0 ? '-->' : '', "<div id='").concat(_this18.elementId, "_").concat(f.field, "_inputContainer' style='").concat(f.style || '', "' class='websy-input-container ").concat(f.classes ? f.classes.join(' ') : '', "'>\n ").concat(f.label ? "<label for=\"".concat(f.field, "\">").concat(f.label, "</label>") : '').concat(f.required === true ? '<span class="websy-form-required-value">*</span>' : '', "\n <input \n id=\"").concat(_this18.elementId, "_input_").concat(f.field, "\"\n ").concat(f.required === true ? 'required' : '', " \n type=\"").concat((f.type === 'expiry' ? 'text' : f.type === 'cvv' ? 'number' : f.type) || 'text', "\" \n data-user-type=\"").concat(f.type, "\"\n data-index=\"").concat(i, "\"\n class=\"websy-input ").concat(f.readOnly || _this18.options.readOnly ? 'websy-input-readonly' : '', "\" \n ").concat((f.attributes || []).join(' '), "\n name=\"").concat(f.field, "\" \n placeholder=\"").concat(f.placeholder || '', "\"\n value=\"").concat(f.type === 'date' ? '' : f.value || '', "\"\n valueAsDate=\"").concat(f.type === 'date' ? f.value : '', "\"\n ").concat(f.disabled || f.readOnly || _this18.options.readOnly ? 'disabled' : '', "\n oninvalidx=\"this.setCustomValidity('").concat(f.invalidMessage || 'Please fill in this field.', "')\"\n />\n <span id='").concat(_this18.elementId, "_").concat(f.field, "_error' class='websy-form-validation-error'></span>\n </div><!--\n ");
2566
+ html += "\n ".concat(i > 0 ? '-->' : '', "<div id='").concat(_this18.elementId, "_").concat(f.field, "_inputContainer' style='").concat(f.style || '', "' class='websy-input-container ").concat(f.classes ? f.classes.join(' ') : '', "'>\n ").concat(f.label ? "<label for=\"".concat(f.field, "\">").concat(f.label, "</label>") : '').concat(f.required === true ? '<span class="websy-form-required-value">*</span>' : '', "\n <input \n id=\"").concat(_this18.elementId, "_input_").concat(f.field, "\"\n ").concat(f.required === true ? 'required' : '', " \n type=\"").concat((f.type === 'expiry' ? 'text' : f.type === 'cvv' ? 'number' : f.type) || 'text', "\" \n data-user-type=\"").concat(f.type, "\"\n data-index=\"").concat(i, "\"\n class=\"websy-input ").concat(f.readOnly || _this18.options.readOnly ? 'websy-input-readonly' : '', "\" \n ").concat((f.attributes || []).join(' '), "\n name=\"").concat(f.field, "\" \n placeholder=\"").concat(f.placeholder || '', "\"\n value=\"").concat(f.type === 'date' ? '' : inputValue || '', "\"\n valueAsDate=\"").concat(f.type === 'date' ? inputValue : '', "\"\n ").concat(f.disabled || f.readOnly || _this18.options.readOnly ? 'disabled' : '', "\n oninvalidx=\"this.setCustomValidity('").concat(f.invalidMessage || 'Please fill in this field.', "')\"\n />\n <span id='").concat(_this18.elementId, "_").concat(f.field, "_error' class='websy-form-validation-error'></span>\n </div><!--\n ");
2556
2567
  }
2557
2568
  });
2558
2569
  if (this.options.useRecaptcha === true) {
@@ -2566,8 +2577,13 @@ var WebsyForm = /*#__PURE__*/function () {
2566
2577
  if (this.options.cancel) {
2567
2578
  html += "\n --><button class=\"websy-btn cancel ".concat(this.options.cancel.classes ? this.options.cancel.classes.join(' ') : '', "\">").concat(this.options.cancel.text || 'Cancel', "</button>\n ");
2568
2579
  }
2569
- html += " \n </form>\n <div id=\"".concat(this.elementId, "_validationFail\" class=\"websy-validation-failure\"></div>\n ");
2580
+ html += " \n </form>\n <div id=\"".concat(this.elementId, "_validationFail\" class=\"websy-validation-failure\"></div>\n <div id=\"").concat(this.elementId, "_loader\" class=\"\"></div>\n ");
2570
2581
  el.innerHTML = html;
2582
+ if (!this.loader) {
2583
+ this.loader = new WebsyDesigns.LoadingDialog("".concat(this.elementId, "_loader"), {
2584
+ title: '&nbsp;'
2585
+ });
2586
+ }
2571
2587
  this.processComponents(componentsToProcess, function () {
2572
2588
  if ((_this18.options.useRecaptcha === true || _this18.options.useRecaptchaV3 === true) && typeof grecaptcha !== 'undefined') {
2573
2589
  _this18.recaptchaReady();
@@ -2622,6 +2638,9 @@ var WebsyForm = /*#__PURE__*/function () {
2622
2638
  if (recaptchErrEl) {
2623
2639
  recaptchErrEl.classList.add('websy-hidden');
2624
2640
  }
2641
+ if (_this19.options.useLoader) {
2642
+ _this19.loader.show();
2643
+ }
2625
2644
  var formData = new FormData(formEl);
2626
2645
  var data = {};
2627
2646
  var temp = new FormData(formEl);
@@ -2648,10 +2667,13 @@ var WebsyForm = /*#__PURE__*/function () {
2648
2667
  });
2649
2668
  } else if (_this19.options.submitFn) {
2650
2669
  _this19.options.submitFn(data, function () {
2670
+ _this19.loader.hide();
2651
2671
  if (_this19.options.clearAfterSave === true) {
2652
2672
  // this.render()
2653
2673
  formEl.reset();
2654
2674
  }
2675
+ }, function () {
2676
+ _this19.loader.hide();
2655
2677
  });
2656
2678
  }
2657
2679
  } else {
@@ -4776,6 +4798,10 @@ var WebsyRouter = /*#__PURE__*/function () {
4776
4798
  var group = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'main';
4777
4799
  var event = arguments.length > 2 ? arguments[2] : undefined;
4778
4800
  var popped = arguments.length > 3 ? arguments[3] : undefined;
4801
+ if (inputPath.indexOf('http') === 0) {
4802
+ window.open(inputPath, '_blank');
4803
+ return;
4804
+ }
4779
4805
  if (typeof popped === 'undefined') {
4780
4806
  popped = false;
4781
4807
  }
@@ -5017,6 +5043,14 @@ var Switch = /*#__PURE__*/function () {
5017
5043
  }
5018
5044
  }
5019
5045
  _createClass(Switch, [{
5046
+ key: "data",
5047
+ get: function get() {
5048
+ return this.options.enabled;
5049
+ },
5050
+ set: function set(d) {
5051
+ this.options.enabled = d;
5052
+ }
5053
+ }, {
5020
5054
  key: "disable",
5021
5055
  value: function disable() {
5022
5056
  this.options.enabled = false;