@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.
@@ -2014,7 +2014,12 @@ class WebsyDropdown {
2014
2014
  labelEl.innerHTML = item.label
2015
2015
  labelEl.setAttribute('data-info', item.label)
2016
2016
  inputEl.value = item.value
2017
- }
2017
+ }
2018
+ else if (this.selectedItems[0]) {
2019
+ labelEl.innerHTML = dataToUse[this.selectedItems[0]].label
2020
+ labelEl.setAttribute('data-info', dataToUse[this.selectedItems[0]].label)
2021
+ inputEl.value = dataToUse[this.selectedItems[0]].value
2022
+ }
2018
2023
  }
2019
2024
  else if (this.selectedItems.length > 1) {
2020
2025
  if (this.options.showCompleteSelectedList === true) {
@@ -2043,10 +2048,12 @@ class WebsyDropdown {
2043
2048
  if (this.options.onSearch) {
2044
2049
  dataToUse = this.options.items
2045
2050
  }
2051
+ let item
2046
2052
  if (typeof index !== 'undefined' && index !== null) {
2047
2053
  let pos = this.selectedItems.indexOf(index)
2048
2054
  if (this.options.multiSelect === false) {
2049
2055
  this.selectedItems = [index]
2056
+ item = dataToUse[index]
2050
2057
  }
2051
2058
  else {
2052
2059
  if (pos !== -1) {
@@ -2054,11 +2061,10 @@ class WebsyDropdown {
2054
2061
  }
2055
2062
  else {
2056
2063
  this.selectedItems.push(index)
2064
+ item = dataToUse[index]
2057
2065
  }
2058
2066
  }
2059
- }
2060
- // const item = this.options.items[index]
2061
- const item = dataToUse[index]
2067
+ }
2062
2068
  this.updateHeader(item)
2063
2069
  if (item && this.options.onItemSelected) {
2064
2070
  this.options.onItemSelected(item, this.selectedItems, dataToUse, this.options)
@@ -2360,6 +2366,7 @@ class WebsyForm {
2360
2366
  clearAfterSave: false,
2361
2367
  fields: [],
2362
2368
  mode: 'add',
2369
+ useLoader: false,
2363
2370
  onSuccess: function (data) {},
2364
2371
  onError: function (err) { console.log('Error submitting form data:', err) }
2365
2372
  }
@@ -2394,6 +2401,7 @@ class WebsyForm {
2394
2401
  if (this.options.cancelFn) {
2395
2402
  this.options.cancelFn(this.elementId)
2396
2403
  }
2404
+ this.loader.hide()
2397
2405
  }
2398
2406
  checkRecaptcha () {
2399
2407
  return new Promise((resolve, reject) => {
@@ -2444,6 +2452,7 @@ class WebsyForm {
2444
2452
  clear () {
2445
2453
  const formEl = document.getElementById(`${this.elementId}Form`)
2446
2454
  formEl.reset()
2455
+ this.loader.hide()
2447
2456
  }
2448
2457
  get data () {
2449
2458
  const formEl = document.getElementById(`${this.elementId}Form`)
@@ -2466,6 +2475,9 @@ class WebsyForm {
2466
2475
  if (this.fieldMap[key] && this.fieldMap[key].type === 'checkbox') {
2467
2476
  data[key] = false
2468
2477
  }
2478
+ else if (this.fieldMap[key] && (this.fieldMap[key].component === 'Switch' || this.fieldMap[key].component === 'WebsySwitch')) {
2479
+ data[key] = this.fieldMap[key].instance.options.enabled
2480
+ }
2469
2481
  else if (this.fieldMap[key] && this.fieldMap[key].instance && this.fieldMap[key].instance.value) {
2470
2482
  data[key] = this.fieldMap[key].instance.value
2471
2483
  }
@@ -2702,6 +2714,7 @@ class WebsyForm {
2702
2714
  this.options.fields.forEach((f, i) => {
2703
2715
  this.fieldMap[f.field] = f
2704
2716
  f.owningElement = this.elementId
2717
+ let inputValue = typeof f.value === 'function' ? f.value() : f.value
2705
2718
  if (f.disabled || f.readOnly || this.options.readOnly) {
2706
2719
  if (!f.options) {
2707
2720
  f.options = {}
@@ -2745,7 +2758,7 @@ class WebsyForm {
2745
2758
  ${f.disabled || f.readOnly || this.options.readOnly ? 'disabled' : ''}
2746
2759
  ${(f.attributes || []).join(' ')}
2747
2760
  class="websy-input websy-textarea ${f.readOnly || this.options.readOnly ? 'websy-input-readonly' : ''}"
2748
- >${f.value || ''}</textarea>
2761
+ >${inputValue || ''}</textarea>
2749
2762
  <span id='${this.elementId}_${f.field}_error' class='websy-form-validation-error'></span>
2750
2763
  </div><!--
2751
2764
  `
@@ -2764,8 +2777,8 @@ class WebsyForm {
2764
2777
  ${(f.attributes || []).join(' ')}
2765
2778
  name="${f.field}"
2766
2779
  placeholder="${f.placeholder || ''}"
2767
- value="${f.type === 'date' ? '' : f.value || ''}"
2768
- valueAsDate="${f.type === 'date' ? f.value : ''}"
2780
+ value="${f.type === 'date' ? '' : inputValue || ''}"
2781
+ valueAsDate="${f.type === 'date' ? inputValue : ''}"
2769
2782
  ${f.disabled || f.readOnly || this.options.readOnly ? 'disabled' : ''}
2770
2783
  oninvalidx="this.setCustomValidity('${f.invalidMessage || 'Please fill in this field.'}')"
2771
2784
  />
@@ -2796,8 +2809,12 @@ class WebsyForm {
2796
2809
  html += `
2797
2810
  </form>
2798
2811
  <div id="${this.elementId}_validationFail" class="websy-validation-failure"></div>
2812
+ <div id="${this.elementId}_loader" class=""></div>
2799
2813
  `
2800
2814
  el.innerHTML = html
2815
+ if (!this.loader) {
2816
+ this.loader = new WebsyDesigns.LoadingDialog(`${this.elementId}_loader`, { title: '&nbsp;' })
2817
+ }
2801
2818
  this.processComponents(componentsToProcess, () => {
2802
2819
  if ((this.options.useRecaptcha === true || this.options.useRecaptchaV3 === true) && typeof grecaptcha !== 'undefined') {
2803
2820
  this.recaptchaReady()
@@ -2850,6 +2867,9 @@ class WebsyForm {
2850
2867
  if (recaptchErrEl) {
2851
2868
  recaptchErrEl.classList.add('websy-hidden')
2852
2869
  }
2870
+ if (this.options.useLoader) {
2871
+ this.loader.show()
2872
+ }
2853
2873
  const formData = new FormData(formEl)
2854
2874
  const data = {}
2855
2875
  const temp = new FormData(formEl)
@@ -2878,10 +2898,13 @@ class WebsyForm {
2878
2898
  }
2879
2899
  else if (this.options.submitFn) {
2880
2900
  this.options.submitFn(data, () => {
2901
+ this.loader.hide()
2881
2902
  if (this.options.clearAfterSave === true) {
2882
2903
  // this.render()
2883
2904
  formEl.reset()
2884
2905
  }
2906
+ }, () => {
2907
+ this.loader.hide()
2885
2908
  })
2886
2909
  }
2887
2910
  }
@@ -5381,6 +5404,10 @@ class WebsyRouter {
5381
5404
  this.showView(this.currentView, this.currentParams, 'main')
5382
5405
  }
5383
5406
  navigate (inputPath, group = 'main', event, popped) {
5407
+ if (inputPath.indexOf('http') === 0) {
5408
+ window.open(inputPath, '_blank')
5409
+ return
5410
+ }
5384
5411
  if (typeof popped === 'undefined') {
5385
5412
  popped = false
5386
5413
  }
@@ -6052,6 +6079,12 @@ class Switch {
6052
6079
  this.render()
6053
6080
  }
6054
6081
  }
6082
+ get data () {
6083
+ return this.options.enabled
6084
+ }
6085
+ set data (d) {
6086
+ this.options.enabled = d
6087
+ }
6055
6088
  disable () {
6056
6089
  this.options.enabled = false
6057
6090
  let method = this.options.enabled === true ? 'add' : 'remove'
@@ -1964,6 +1964,10 @@ var WebsyDropdown = /*#__PURE__*/function () {
1964
1964
  labelEl.innerHTML = item.label;
1965
1965
  labelEl.setAttribute('data-info', item.label);
1966
1966
  inputEl.value = item.value;
1967
+ } else if (this.selectedItems[0]) {
1968
+ labelEl.innerHTML = dataToUse[this.selectedItems[0]].label;
1969
+ labelEl.setAttribute('data-info', dataToUse[this.selectedItems[0]].label);
1970
+ inputEl.value = dataToUse[this.selectedItems[0]].value;
1967
1971
  }
1968
1972
  } else if (this.selectedItems.length > 1) {
1969
1973
  if (this.options.showCompleteSelectedList === true) {
@@ -1998,20 +2002,21 @@ var WebsyDropdown = /*#__PURE__*/function () {
1998
2002
  if (this.options.onSearch) {
1999
2003
  dataToUse = this.options.items;
2000
2004
  }
2005
+ var item;
2001
2006
  if (typeof index !== 'undefined' && index !== null) {
2002
2007
  var pos = this.selectedItems.indexOf(index);
2003
2008
  if (this.options.multiSelect === false) {
2004
2009
  this.selectedItems = [index];
2010
+ item = dataToUse[index];
2005
2011
  } else {
2006
2012
  if (pos !== -1) {
2007
2013
  this.selectedItems.splice(pos, 1);
2008
2014
  } else {
2009
2015
  this.selectedItems.push(index);
2016
+ item = dataToUse[index];
2010
2017
  }
2011
2018
  }
2012
2019
  }
2013
- // const item = this.options.items[index]
2014
- var item = dataToUse[index];
2015
2020
  this.updateHeader(item);
2016
2021
  if (item && this.options.onItemSelected) {
2017
2022
  this.options.onItemSelected(item, this.selectedItems, dataToUse, this.options);
@@ -2324,6 +2329,7 @@ var WebsyForm = /*#__PURE__*/function () {
2324
2329
  clearAfterSave: false,
2325
2330
  fields: [],
2326
2331
  mode: 'add',
2332
+ useLoader: false,
2327
2333
  onSuccess: function onSuccess(data) {},
2328
2334
  onError: function onError(err) {
2329
2335
  console.log('Error submitting form data:', err);
@@ -2362,6 +2368,7 @@ var WebsyForm = /*#__PURE__*/function () {
2362
2368
  if (this.options.cancelFn) {
2363
2369
  this.options.cancelFn(this.elementId);
2364
2370
  }
2371
+ this.loader.hide();
2365
2372
  }
2366
2373
  }, {
2367
2374
  key: "checkRecaptcha",
@@ -2422,6 +2429,7 @@ var WebsyForm = /*#__PURE__*/function () {
2422
2429
  value: function clear() {
2423
2430
  var formEl = document.getElementById("".concat(this.elementId, "Form"));
2424
2431
  formEl.reset();
2432
+ this.loader.hide();
2425
2433
  }
2426
2434
  }, {
2427
2435
  key: "data",
@@ -2445,6 +2453,8 @@ var WebsyForm = /*#__PURE__*/function () {
2445
2453
  if (keys.indexOf(key) === -1) {
2446
2454
  if (this.fieldMap[key] && this.fieldMap[key].type === 'checkbox') {
2447
2455
  data[key] = false;
2456
+ } else if (this.fieldMap[key] && (this.fieldMap[key].component === 'Switch' || this.fieldMap[key].component === 'WebsySwitch')) {
2457
+ data[key] = this.fieldMap[key].instance.options.enabled;
2448
2458
  } else if (this.fieldMap[key] && this.fieldMap[key].instance && this.fieldMap[key].instance.value) {
2449
2459
  data[key] = this.fieldMap[key].instance.value;
2450
2460
  }
@@ -2706,6 +2716,7 @@ var WebsyForm = /*#__PURE__*/function () {
2706
2716
  this.options.fields.forEach(function (f, i) {
2707
2717
  _this20.fieldMap[f.field] = f;
2708
2718
  f.owningElement = _this20.elementId;
2719
+ var inputValue = typeof f.value === 'function' ? f.value() : f.value;
2709
2720
  if (f.disabled || f.readOnly || _this20.options.readOnly) {
2710
2721
  if (!f.options) {
2711
2722
  f.options = {};
@@ -2729,9 +2740,9 @@ var WebsyForm = /*#__PURE__*/function () {
2729
2740
  componentsToProcess.push(f);
2730
2741
  html += "\n ".concat(i > 0 ? '-->' : '', "<div id='").concat(_this20.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(_this20.elementId, "_input_").concat(f.field, "_component' class='form-component'></div>\n <span id='").concat(_this20.elementId, "_").concat(f.field, "_error' class='websy-form-validation-error'></span>\n </div><!--\n ");
2731
2742
  } else if (f.type === 'longtext') {
2732
- html += "\n ".concat(i > 0 ? '-->' : '', "<div id='").concat(_this20.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(_this20.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 || _this20.options.readOnly ? 'disabled' : '', "\n ").concat((f.attributes || []).join(' '), "\n class=\"websy-input websy-textarea ").concat(f.readOnly || _this20.options.readOnly ? 'websy-input-readonly' : '', "\"\n >").concat(f.value || '', "</textarea>\n <span id='").concat(_this20.elementId, "_").concat(f.field, "_error' class='websy-form-validation-error'></span>\n </div><!--\n ");
2743
+ html += "\n ".concat(i > 0 ? '-->' : '', "<div id='").concat(_this20.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(_this20.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 || _this20.options.readOnly ? 'disabled' : '', "\n ").concat((f.attributes || []).join(' '), "\n class=\"websy-input websy-textarea ").concat(f.readOnly || _this20.options.readOnly ? 'websy-input-readonly' : '', "\"\n >").concat(inputValue || '', "</textarea>\n <span id='").concat(_this20.elementId, "_").concat(f.field, "_error' class='websy-form-validation-error'></span>\n </div><!--\n ");
2733
2744
  } else {
2734
- html += "\n ".concat(i > 0 ? '-->' : '', "<div id='").concat(_this20.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(_this20.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 || _this20.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 || _this20.options.readOnly ? 'disabled' : '', "\n oninvalidx=\"this.setCustomValidity('").concat(f.invalidMessage || 'Please fill in this field.', "')\"\n />\n <span id='").concat(_this20.elementId, "_").concat(f.field, "_error' class='websy-form-validation-error'></span>\n </div><!--\n ");
2745
+ html += "\n ".concat(i > 0 ? '-->' : '', "<div id='").concat(_this20.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(_this20.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 || _this20.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 || _this20.options.readOnly ? 'disabled' : '', "\n oninvalidx=\"this.setCustomValidity('").concat(f.invalidMessage || 'Please fill in this field.', "')\"\n />\n <span id='").concat(_this20.elementId, "_").concat(f.field, "_error' class='websy-form-validation-error'></span>\n </div><!--\n ");
2735
2746
  }
2736
2747
  });
2737
2748
  if (this.options.useRecaptcha === true) {
@@ -2745,8 +2756,13 @@ var WebsyForm = /*#__PURE__*/function () {
2745
2756
  if (this.options.cancel) {
2746
2757
  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 ");
2747
2758
  }
2748
- html += " \n </form>\n <div id=\"".concat(this.elementId, "_validationFail\" class=\"websy-validation-failure\"></div>\n ");
2759
+ 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 ");
2749
2760
  el.innerHTML = html;
2761
+ if (!this.loader) {
2762
+ this.loader = new WebsyDesigns.LoadingDialog("".concat(this.elementId, "_loader"), {
2763
+ title: '&nbsp;'
2764
+ });
2765
+ }
2750
2766
  this.processComponents(componentsToProcess, function () {
2751
2767
  if ((_this20.options.useRecaptcha === true || _this20.options.useRecaptchaV3 === true) && typeof grecaptcha !== 'undefined') {
2752
2768
  _this20.recaptchaReady();
@@ -2801,6 +2817,9 @@ var WebsyForm = /*#__PURE__*/function () {
2801
2817
  if (recaptchErrEl) {
2802
2818
  recaptchErrEl.classList.add('websy-hidden');
2803
2819
  }
2820
+ if (_this21.options.useLoader) {
2821
+ _this21.loader.show();
2822
+ }
2804
2823
  var formData = new FormData(formEl);
2805
2824
  var data = {};
2806
2825
  var temp = new FormData(formEl);
@@ -2827,10 +2846,13 @@ var WebsyForm = /*#__PURE__*/function () {
2827
2846
  });
2828
2847
  } else if (_this21.options.submitFn) {
2829
2848
  _this21.options.submitFn(data, function () {
2849
+ _this21.loader.hide();
2830
2850
  if (_this21.options.clearAfterSave === true) {
2831
2851
  // this.render()
2832
2852
  formEl.reset();
2833
2853
  }
2854
+ }, function () {
2855
+ _this21.loader.hide();
2834
2856
  });
2835
2857
  }
2836
2858
  } else {
@@ -5198,6 +5220,10 @@ var WebsyRouter = /*#__PURE__*/function () {
5198
5220
  var group = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'main';
5199
5221
  var event = arguments.length > 2 ? arguments[2] : undefined;
5200
5222
  var popped = arguments.length > 3 ? arguments[3] : undefined;
5223
+ if (inputPath.indexOf('http') === 0) {
5224
+ window.open(inputPath, '_blank');
5225
+ return;
5226
+ }
5201
5227
  if (typeof popped === 'undefined') {
5202
5228
  popped = false;
5203
5229
  }
@@ -5895,6 +5921,14 @@ var Switch = /*#__PURE__*/function () {
5895
5921
  }
5896
5922
  }
5897
5923
  _createClass(Switch, [{
5924
+ key: "data",
5925
+ get: function get() {
5926
+ return this.options.enabled;
5927
+ },
5928
+ set: function set(d) {
5929
+ this.options.enabled = d;
5930
+ }
5931
+ }, {
5898
5932
  key: "disable",
5899
5933
  value: function disable() {
5900
5934
  this.options.enabled = false;