@websy/websy-designs 1.10.7 → 1.11.1

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.
@@ -6,6 +6,7 @@
6
6
  WebsyPubSub
7
7
  WebsyForm
8
8
  MultiForm
9
+ MediaUpload
9
10
  WebsyDatePicker
10
11
  WebsyDropdown
11
12
  WebsyRouter
@@ -1835,6 +1836,7 @@ class WebsyDropdown {
1835
1836
  const headerPos = WebsyUtils.getElementPos(headerEl)
1836
1837
  const contentPos = WebsyUtils.getElementPos(contentEl)
1837
1838
  if (this.options.style === 'plain' && headerPos.width > 0 && headerPos.height > 0) {
1839
+ contentEl.style.left = 'unset'
1838
1840
  contentEl.style.right = `calc(100vw - ${headerPos.right}px)`
1839
1841
  contentEl.style.width = `${Math.max(this.options.minWidth, headerEl.clientWidth)}px`
1840
1842
  if (headerPos.bottom + contentPos.height > window.innerHeight) {
@@ -1847,6 +1849,7 @@ class WebsyDropdown {
1847
1849
  }
1848
1850
  else if (this.options.style === 'plain' && headerPos.width === 0 && headerPos.height === 0) {
1849
1851
  const targetPos = WebsyUtils.getElementPos(event.target)
1852
+ contentEl.style.left = 'unset'
1850
1853
  contentEl.style.right = `calc(100vw - ${targetPos.right}px)`
1851
1854
  contentEl.style.width = `${Math.max(this.options.minWidth, targetPos.width)}px`
1852
1855
  }
@@ -1932,7 +1935,8 @@ class WebsyDropdown {
1932
1935
  }
1933
1936
  get value () {
1934
1937
  if (this.selectedItems && this.selectedItems.length > 0) {
1935
- return this.selectedItems.map((d, i) => this.options.items[+d])
1938
+ // return this.selectedItems.map((d, i) => this.options.items[+d])
1939
+ return this.selectedItems.map((d, i) => this._originalData[+d])
1936
1940
  }
1937
1941
  return []
1938
1942
  }
@@ -2690,7 +2694,7 @@ class WebsyForm {
2690
2694
  if (f.component) {
2691
2695
  componentsToProcess.push(f)
2692
2696
  html += `
2693
- ${i > 0 ? '-->' : ''}<div id='${this.elementId}_${f.field}_inputContainer' style='${f.style || ''}' class='websy-input-container ${f.classes ? f.classes.join(' ') : ''}'>
2697
+ ${i > 0 ? '-->' : ''}<div id='${this.elementId}_${f.field}_inputContainer' style='${f.style || ''}' class='websy-input-container ${f.classes ? f.classes.join(' ') : ''} ${f.component === 'MediaUpload' ? 'media-upload' : ''}'>
2694
2698
  ${f.label ? `<label for="${f.field}">${f.label}</label>` : ''}${f.required === true ? '<span class="websy-form-required-value">*</span>' : ''}
2695
2699
  <div id='${this.elementId}_input_${f.field}_component' class='form-component'></div>
2696
2700
  <span id='${this.elementId}_${f.field}_error' class='websy-form-validation-error'></span>
@@ -2710,7 +2714,7 @@ class WebsyForm {
2710
2714
  name="${f.field}"
2711
2715
  ${(f.attributes || []).join(' ')}
2712
2716
  class="websy-input websy-textarea"
2713
- ></textarea>
2717
+ >${f.value || ''}</textarea>
2714
2718
  <span id='${this.elementId}_${f.field}_error' class='websy-form-validation-error'></span>
2715
2719
  </div><!--
2716
2720
  `
@@ -2729,7 +2733,7 @@ class WebsyForm {
2729
2733
  ${(f.attributes || []).join(' ')}
2730
2734
  name="${f.field}"
2731
2735
  placeholder="${f.placeholder || ''}"
2732
- value="${f.value || ''}"
2736
+ value="${f.type === 'date' ? '' : f.value || ''}"
2733
2737
  valueAsDate="${f.type === 'date' ? f.value : ''}"
2734
2738
  oninvalidx="this.setCustomValidity('${f.invalidMessage || 'Please fill in this field.'}')"
2735
2739
  />
@@ -2777,6 +2781,9 @@ class WebsyForm {
2777
2781
  if (this.fieldMap[field].type === 'checkbox') {
2778
2782
  el.checked = value
2779
2783
  }
2784
+ if (this.fieldMap[field].type === 'date') {
2785
+ el.valueAsDate = value
2786
+ }
2780
2787
  }
2781
2788
  else {
2782
2789
  console.error(`Input for ${field} does not exist in form.`)
@@ -2921,10 +2928,12 @@ class MultiForm {
2921
2928
  constructor (elementId, options) {
2922
2929
  this.elementId = elementId
2923
2930
  const DEFAULTS = {
2924
- addButton: `<svg xmlns="http://www.w3.org/2000/svg" width="40" height="40" viewBox="0 0 512 512"><line x1="256" y1="112" x2="256" y2="400" style="fill:none;stroke-linecap:round;stroke-linejoin:round;stroke-width:32px"/><line x1="400" y1="256" x2="112" y2="256" style="fill:none;stroke-linecap:round;stroke-linejoin:round;stroke-width:32px"/></svg>`,
2925
- deleteButton: `<svg xmlns="http://www.w3.org/2000/svg" width="40" height="40" viewBox="0 0 512 512"><line x1="368" y1="368" x2="144" y2="144" style="fill:none;stroke-linecap:round;stroke-linejoin:round;stroke-width:32px"/><line x1="368" y1="144" x2="144" y2="368" style="fill:none;stroke-linecap:round;stroke-linejoin:round;stroke-width:32px"/></svg>`,
2931
+ addIcon: `<svg xmlns="http://www.w3.org/2000/svg" width="40" height="40" viewBox="0 0 512 512"><line x1="256" y1="112" x2="256" y2="400" style="fill:none;stroke-linecap:round;stroke-linejoin:round;stroke-width:32px"/><line x1="400" y1="256" x2="112" y2="256" style="fill:none;stroke-linecap:round;stroke-linejoin:round;stroke-width:32px"/></svg>`,
2932
+ deleteIcon: `<svg xmlns="http://www.w3.org/2000/svg" width="40" height="40" viewBox="0 0 512 512"><line x1="368" y1="368" x2="144" y2="144" style="fill:none;stroke-linecap:round;stroke-linejoin:round;stroke-width:32px"/><line x1="368" y1="144" x2="144" y2="368" style="fill:none;stroke-linecap:round;stroke-linejoin:round;stroke-width:32px"/></svg>`,
2926
2933
  allowAdd: true,
2927
- allowDelete: true
2934
+ allowDelete: true,
2935
+ addLabel: '',
2936
+ deleteLabel: ''
2928
2937
  }
2929
2938
  this.options = Object.assign({}, DEFAULTS, options)
2930
2939
  this.formData = []
@@ -2933,7 +2942,12 @@ class MultiForm {
2933
2942
  const el = document.getElementById(elementId)
2934
2943
  if (el) {
2935
2944
  el.addEventListener('click', this.handleClick.bind(this))
2936
- el.innerHTML = `<div id='${elementId}_container' class='websy-multi-form-container'></div>`
2945
+ el.innerHTML = `
2946
+ <div id='${elementId}_container' class='websy-multi-form-container'></div>
2947
+ <button id='${this.elementId}_addButton' class='websy-multi-form-add'>
2948
+ ${this.options.addIcon}${this.options.addLabel}
2949
+ </button>
2950
+ `
2937
2951
  }
2938
2952
  this.render()
2939
2953
  }
@@ -2942,24 +2956,28 @@ class MultiForm {
2942
2956
  this.render()
2943
2957
  }
2944
2958
  addEntry () {
2945
- const el = document.getElementById(`${this.elementId}_container`)
2946
- let newId = WebsyDesigns.Utils.createIdentity()
2947
- const newFormEl = document.createElement('div')
2948
- newFormEl.id = `${this.elementId}_${newId}_formContainer`
2949
- newFormEl.classList.add('websy-multi-form-form-container')
2950
- newFormEl.innerHTML = `
2951
- <div id='${this.elementId}_${newId}_form' class='websy-multi-form-form'>
2952
- </div>
2953
- <button id='${this.elementId}_${newId}_deleteButton' data-formid='${newId}' class='hidden websy-multi-form-delete'>
2954
- ${this.options.deleteButton}
2955
- </button>
2956
- <button id='${this.elementId}_${newId}_addButton' data-formid='${newId}' class='websy-multi-form-add'>
2957
- ${this.options.addButton}
2958
- </button>
2959
- `
2960
- el.appendChild(newFormEl)
2961
- let formOptions = Object.assign({}, this.options, { fields: [...this.options.fields.map(f => Object.assign({}, f))] })
2962
- this.forms.push(new WebsyDesigns.Form(`${this.elementId}_${newId}_form`, formOptions))
2959
+ const addEl = document.getElementById(`${this.elementId}_addButton`)
2960
+ if (typeof this.options.maxRows === 'undefined' || this.forms.length < this.options.maxRows) {
2961
+ const el = document.getElementById(`${this.elementId}_container`)
2962
+ let newId = WebsyDesigns.Utils.createIdentity()
2963
+ const newFormEl = document.createElement('div')
2964
+ newFormEl.id = `${this.elementId}_${newId}_formContainer`
2965
+ newFormEl.classList.add('websy-multi-form-form-container')
2966
+ let html = `
2967
+ <div id='${this.elementId}_${newId}_form' class='websy-multi-form-form'>
2968
+ </div>
2969
+ <button id='${this.elementId}_${newId}_deleteButton' data-formid='${newId}' class='websy-multi-form-delete'>
2970
+ ${this.options.deleteIcon}${this.options.deleteLabel}
2971
+ </button>
2972
+ `
2973
+ newFormEl.innerHTML = html
2974
+ el.appendChild(newFormEl)
2975
+ let formOptions = Object.assign({}, this.options, { fields: [...this.options.fields.map(f => Object.assign({}, f))] })
2976
+ this.forms.push(new WebsyDesigns.Form(`${this.elementId}_${newId}_form`, formOptions))
2977
+ if (addEl) {
2978
+ addEl.style.display = this.forms.length < this.options.maxRows ? 'flex' : 'none'
2979
+ }
2980
+ }
2963
2981
  }
2964
2982
  clear () {
2965
2983
  this.formData = []
@@ -2971,12 +2989,7 @@ class MultiForm {
2971
2989
  }
2972
2990
  }
2973
2991
  get data () {
2974
- const d = this.forms.map(f => (f.data))
2975
- console.log('forms data', d)
2976
- if (this.options.allowAdd !== false) {
2977
- // we don't return the last form
2978
- d.pop()
2979
- }
2992
+ const d = this.forms.map(f => (f.data))
2980
2993
  return d
2981
2994
  }
2982
2995
  set data (d) {
@@ -2988,16 +3001,6 @@ class MultiForm {
2988
3001
  }
2989
3002
  handleClick (event) {
2990
3003
  if (event.target.classList.contains('websy-multi-form-add')) {
2991
- let id = event.target.getAttribute('data-formid')
2992
- // hide add button and show delete button
2993
- const addButtonEl = document.getElementById(`${this.elementId}_${id}_addButton`)
2994
- if (addButtonEl) {
2995
- addButtonEl.classList.add('hidden')
2996
- }
2997
- const deleteButtonEl = document.getElementById(`${this.elementId}_${id}_deleteButton`)
2998
- if (deleteButtonEl) {
2999
- deleteButtonEl.classList.remove('hidden')
3000
- }
3001
3004
  // add new form
3002
3005
  if (this.options.allowAdd === true) {
3003
3006
  this.addEntry()
@@ -3022,6 +3025,10 @@ class MultiForm {
3022
3025
  if (el) {
3023
3026
  el.remove()
3024
3027
  }
3028
+ const addEl = document.getElementById(`${this.elementId}_addButton`)
3029
+ if (addEl) {
3030
+ addEl.style.display = (typeof this.options.maxRows === 'undefined' || this.forms.length < this.options.maxRows) ? 'flex' : 'none'
3031
+ }
3025
3032
  // delete form element based on id
3026
3033
  }
3027
3034
  }
@@ -3041,7 +3048,7 @@ class MultiForm {
3041
3048
  if (this.options.allowDelete === true) {
3042
3049
  html += `
3043
3050
  <button id='${this.elementId}_${d.formId}_deleteButton' data-formid='${d.formId}' data-rowid='${d.id}' class='websy-multi-form-delete'>
3044
- ${this.options.deleteButton}
3051
+ ${this.options.deleteIcon}${this.options.deleteLabel}
3045
3052
  </button>
3046
3053
  `
3047
3054
  }
@@ -3050,20 +3057,6 @@ class MultiForm {
3050
3057
  `
3051
3058
  })
3052
3059
  let id = WebsyDesigns.Utils.createIdentity()
3053
- if (this.options.allowAdd === true) {
3054
- html += `
3055
- <div id='${this.elementId}_${id}_formContainer' class='websy-multi-form-form-container'>
3056
- <div id='${this.elementId}_${id}_form' class='websy-multi-form-form'>
3057
- </div>
3058
- <button id='${this.elementId}_${id}_deleteButton' data-formid='${id}' class='hidden websy-multi-form-delete'>
3059
- ${this.options.deleteButton}
3060
- </button>
3061
- <button id='${this.elementId}_${id}_addButton' data-formid='${id}' class='websy-multi-form-add'>
3062
- ${this.options.addButton}
3063
- </button>
3064
- </div>
3065
- `
3066
- }
3067
3060
  el.innerHTML = html
3068
3061
  this.forms = new Array(this.formData.length)
3069
3062
  this.formData.forEach((d, i) => {
@@ -3072,11 +3065,15 @@ class MultiForm {
3072
3065
  formObject.data = d
3073
3066
  this.forms[i] = formObject
3074
3067
  })
3075
- if (this.options.allowAdd === true) {
3076
- let formOptions = Object.assign({}, this.options, { fields: [...this.options.fields.map(f => Object.assign({}, f))] })
3077
- let formObject = new WebsyDesigns.Form(`${this.elementId}_${id}_form`, formOptions)
3078
- this.forms.push(formObject)
3079
- }
3068
+ const addEl = document.getElementById(`${this.elementId}_addButton`)
3069
+ if (addEl) {
3070
+ if (this.options.allowAdd === true) {
3071
+ addEl.style.display = (typeof this.options.maxRows === 'undefined' || this.forms.length < this.options.maxRows) ? 'flex' : 'none'
3072
+ }
3073
+ else {
3074
+ addEl.style.display = 'none'
3075
+ }
3076
+ }
3080
3077
  }
3081
3078
  }
3082
3079
  validateForm () {
@@ -3714,6 +3711,181 @@ class WebsyNavigationMenu {
3714
3711
  }
3715
3712
  }
3716
3713
 
3714
+ /*
3715
+ global
3716
+ FormData
3717
+ FileReader
3718
+ Image
3719
+ */
3720
+ class MediaUpload {
3721
+ constructor (elementId, options) {
3722
+ const defaults = {
3723
+ allowMultiple: false,
3724
+ createThumbnail: false,
3725
+ thumbSize: 300,
3726
+ supportedTypes: ['image/png', 'image/jpg']
3727
+ }
3728
+ this.media = []
3729
+ this.options = Object.assign({}, defaults, options)
3730
+ this.elementId = elementId
3731
+ if (!elementId) {
3732
+ console.log('No element Id provided')
3733
+ return
3734
+ }
3735
+ const el = document.getElementById(elementId)
3736
+ if (el) {
3737
+ el.addEventListener('change', this.handleChange.bind(this))
3738
+ el.innerHTML = `
3739
+ <div class='websy-upload-form-container'>
3740
+ <span>Drag and drop a file or click to browse.</span>
3741
+ <form id="${this.elementId}_form" enctype="multipart/form-data">
3742
+ <input id="${this.elementId}_file" type="file" name="${this.options.name || 'media'}" accept="${this.options.supportedTypes.join(' ')}" multiple>
3743
+ </form>
3744
+ </div>
3745
+ <div id='${this.elementId}_uploaded' class='websy-uploaded-media'></div>
3746
+ `
3747
+ this.render()
3748
+ }
3749
+ }
3750
+ set data (d = []) {
3751
+ if (Array.isArray(d)) {
3752
+ this.media = d
3753
+ }
3754
+ else {
3755
+ this.media = [d]
3756
+ }
3757
+ this.render()
3758
+ }
3759
+ get data () {
3760
+ return this.media
3761
+ }
3762
+ createHtml (count) {
3763
+ let html = ''
3764
+ for (let i = 0; i < count; i++) {
3765
+ html += `
3766
+ <div>
3767
+ <img id='${this.elementId}_media_${i}'/>
3768
+ </div>
3769
+ `
3770
+ }
3771
+ return html
3772
+ }
3773
+ getForm () {
3774
+ let formFound = false
3775
+ let el = document.getElementById(`${this.elementId}_file`)
3776
+ if (el) {
3777
+ while (formFound === false && el.tagName !== 'BODY') {
3778
+ el = el.parentElement
3779
+ if (el.tagName === 'FORM') {
3780
+ formFound = true
3781
+ return el
3782
+ }
3783
+ }
3784
+ }
3785
+ return null
3786
+ }
3787
+ handleChange (event) {
3788
+ this.fileList = []
3789
+ let uploadForm = document.getElementById(`${this.elementId}_form`)
3790
+ if (!uploadForm) {
3791
+ uploadForm = this.getForm()
3792
+ }
3793
+ if (!uploadForm) {
3794
+ console.error(`The element ${this.elementId}_file does not belong to a form.`)
3795
+ return
3796
+ }
3797
+ const formData = new FormData(uploadForm)
3798
+ const html = this.createHtml(formData.length)
3799
+ formData.forEach((value, key) => {
3800
+ if (key === (this.options.name || 'media')) {
3801
+ this.fileList.push({ name: key, file: value })
3802
+ }
3803
+ })
3804
+ const resultEl = document.getElementById(`${this.elementId}_uploaded`)
3805
+ resultEl.innerHTML = html
3806
+ this.uploadItem(0, this.fileList)
3807
+ }
3808
+ render () {
3809
+ if (this.media.length > 0) {
3810
+ const resultEl = document.getElementById(`${this.elementId}_uploaded`)
3811
+ resultEl.innerHTML = this.createHtml(this.media.length)
3812
+ this.media.forEach((m, i) => {
3813
+ const imgEl = document.getElementById(`${this.elementId}_media_${i}`)
3814
+ imgEl.setAttribute('src', `data:${m.type};base64,` + m.data)
3815
+ })
3816
+ }
3817
+ }
3818
+ uploadItem (index, items, callbackFn) {
3819
+ if (!items[index]) {
3820
+ callbackFn()
3821
+ }
3822
+ else {
3823
+ const r = new FileReader()
3824
+ const mediaData = {
3825
+ type: items[index].file.type,
3826
+ name: items[index].file.name,
3827
+ size: items[index].file.size
3828
+ }
3829
+ r.onloadend = () => {
3830
+ let imgCanvas = document.createElement('canvas')
3831
+ let imgContext = imgCanvas.getContext('2d')
3832
+ let thumbCanvas = document.createElement('canvas')
3833
+ let thumbContext = thumbCanvas.getContext('2d')
3834
+ let img = new Image()
3835
+ img.onload = () => {
3836
+ let width = img.width
3837
+ let height = img.height
3838
+ if (this.options.resize === true && this.options.imgSize) {
3839
+ let ratio = 1
3840
+ if (width > height) {
3841
+ ratio = width / height
3842
+ width = this.options.imgSize
3843
+ height = this.options.imgSize / ratio
3844
+ }
3845
+ else if (height > width) {
3846
+ ratio = height / width
3847
+ width = this.options.imgSize / ratio
3848
+ height = this.options.imgSize
3849
+ }
3850
+ }
3851
+ const fullResEl = document.getElementById(`${this.elementId}_media_${index}_fullres`)
3852
+ if (fullResEl) {
3853
+ fullResEl.innerHTML = `${width} x ${height}`
3854
+ }
3855
+ imgCanvas.width = width
3856
+ imgCanvas.height = height
3857
+ imgContext.drawImage(img, 0, 0, width, height)
3858
+ let ratio = 1
3859
+ if (width > height) {
3860
+ ratio = width / height
3861
+ thumbCanvas.width = this.options.thumbSize
3862
+ thumbCanvas.height = this.options.thumbSize / ratio
3863
+ }
3864
+ else if (height > width) {
3865
+ ratio = height / width
3866
+ thumbCanvas.width = this.options.thumbSize / ratio
3867
+ thumbCanvas.height = this.options.thumbSize
3868
+ }
3869
+ thumbContext.drawImage(img, 0, 0, thumbCanvas.width, thumbCanvas.height)
3870
+ mediaData.name = items[index].name
3871
+ mediaData.fullWidth = imgCanvas.width
3872
+ mediaData.fullHeight = imgCanvas.height
3873
+ mediaData.thumbWidth = thumbCanvas.width
3874
+ mediaData.thumbHeight = thumbCanvas.height
3875
+ mediaData.data = imgCanvas.toDataURL(mediaData.type).replace(/^data:image\/(png|jpg);base64,/, '')
3876
+ mediaData.thumbData = thumbCanvas.toDataURL(mediaData.type).replace(/^data:image\/(png|jpg);base64,/, '')
3877
+ this.media.push(mediaData)
3878
+ const imgEl = document.getElementById(`${this.elementId}_media_${index}`)
3879
+ imgEl.setAttribute('src', imgCanvas.toDataURL(mediaData.type))
3880
+ this.uploadItem(++index, items, callbackFn)
3881
+ }
3882
+ img.src = r.result
3883
+ }
3884
+ r.readAsDataURL(items[index].file)
3885
+ }
3886
+ }
3887
+ }
3888
+
3717
3889
  /* global WebsyDesigns */
3718
3890
  class Pager {
3719
3891
  constructor (elementId, options) {
@@ -3932,7 +4104,7 @@ class WebsyPDFButton {
3932
4104
  else {
3933
4105
  fileName = this.options.fileName || 'Export'
3934
4106
  }
3935
- msg += `download='${fileName}.pdf'`
4107
+ msg += `download="${fileName.replace(/'/g, '')}.pdf"`
3936
4108
  }
3937
4109
  msg += `
3938
4110
  >
@@ -4643,7 +4815,11 @@ class WebsyResultList {
4643
4815
  }
4644
4816
  }
4645
4817
 
4646
- /* global history */
4818
+ /*
4819
+ global
4820
+ history
4821
+ WebsyDesigns
4822
+ */
4647
4823
  class WebsyRouter {
4648
4824
  constructor (options) {
4649
4825
  const defaults = {
@@ -4660,6 +4836,7 @@ class WebsyRouter {
4660
4836
  persistentParameters: false,
4661
4837
  fieldValueSeparator: ':'
4662
4838
  }
4839
+ this.apiService = new WebsyDesigns.APIService('')
4663
4840
  this.triggerIdList = []
4664
4841
  this.viewIdList = []
4665
4842
  this.previousPath = ''
@@ -4692,7 +4869,7 @@ class WebsyRouter {
4692
4869
  }
4693
4870
  addGroup (group) {
4694
4871
  if (!this.groups[group]) {
4695
- const els = document.querySelectorAll(`.websy-view[data-group="${group}"]`)
4872
+ const els = document.querySelectorAll(`.${this.options.viewClass}[data-group="${group}"]`)
4696
4873
  if (els) {
4697
4874
  this.getClosestParent(els[0], parent => {
4698
4875
  this.groups[group] = {
@@ -4811,9 +4988,9 @@ class WebsyRouter {
4811
4988
  if (!this.groups) {
4812
4989
  this.groups = {}
4813
4990
  }
4814
- const parentEl = document.querySelector(`.websy-view[data-view="${parent}"]`)
4991
+ const parentEl = document.querySelector(`.${this.options.viewClass}[data-view="${parent}"]`)
4815
4992
  if (parentEl) {
4816
- const els = parentEl.querySelectorAll(`.websy-view[data-group]`)
4993
+ const els = parentEl.querySelectorAll(`.${this.options.viewClass}[data-group]`)
4817
4994
  for (let i = 0; i < els.length; i++) {
4818
4995
  const g = els[i].getAttribute('data-group')
4819
4996
  const v = els[i].getAttribute('data-view')
@@ -5071,27 +5248,85 @@ class WebsyRouter {
5071
5248
  })
5072
5249
  }
5073
5250
  }
5251
+ preloadView (view, callbackFn) {
5252
+ if (this.options.views[view].load) {
5253
+ this.options.views[view].load(callbackFn)
5254
+ }
5255
+ }
5256
+ initView (view) {
5257
+ return new Promise((resolve, reject) => {
5258
+ if (!this.options.views[view]) {
5259
+ this.options.views[view] = {
5260
+ components: []
5261
+ }
5262
+ }
5263
+ if (this.options.views[view].ready === true) {
5264
+ resolve()
5265
+ }
5266
+ else if (this.options.views[view].template) {
5267
+ this.preloadView(view, (data = {}) => {
5268
+ const viewEl = document.querySelector(`[data-view='${view}'].${this.options.viewClass}`)
5269
+ if (viewEl) {
5270
+ this.options.views[view].templateInstance = new WebsyDesigns.Template(viewEl, {
5271
+ template: this.options.views[view].template,
5272
+ data,
5273
+ readyCallbackFn: () => {
5274
+ this.options.views[view].ready = true
5275
+ resolve()
5276
+ }
5277
+ })
5278
+ }
5279
+ else {
5280
+ console.log(`No view element found for '${view}' to render template`)
5281
+ this.options.views[view].ready = true
5282
+ resolve()
5283
+ }
5284
+ })
5285
+ }
5286
+ else if (this.options.views[view].ready !== true && this.options.views[view].load) {
5287
+ this.preloadView(view, (data = {}) => {
5288
+ this.options.views[view].ready = true
5289
+ resolve()
5290
+ })
5291
+ }
5292
+ else {
5293
+ this.options.views[view].ready = true
5294
+ resolve()
5295
+ }
5296
+ })
5297
+ }
5074
5298
  showView (view, params, group) {
5075
5299
  if (view === '/' || view === '') {
5076
5300
  view = this.options.defaultView || ''
5077
5301
  }
5078
- this.activateItem(view, this.options.triggerClass)
5079
- this.activateItem(view, this.options.viewClass)
5080
- let children = this.getActiveViewsFromParent(view)
5081
- for (let c = 0; c < children.length; c++) {
5082
- this.activateItem(children[c].view, this.options.triggerClass)
5083
- this.activateItem(children[c].view, this.options.viewClass)
5084
- this.showComponents(children[c].view)
5085
- this.publish('show', [children[c].view, null, group])
5086
- }
5087
- if (this.previousView !== this.currentView || group !== 'main') {
5088
- this.showComponents(view)
5089
- this.publish('show', [view, params, group])
5090
- }
5091
- else if (this.previousView === this.currentView && this.previousParams.path !== this.currentParams.path) {
5092
- this.showComponents(view)
5093
- this.publish('show', [view, params, group])
5094
- }
5302
+ this.initView(view).then(() => {
5303
+ this.activateItem(view, this.options.triggerClass)
5304
+ this.activateItem(view, this.options.viewClass)
5305
+ let children = this.getActiveViewsFromParent(view)
5306
+ for (let c = 0; c < children.length; c++) {
5307
+ this.activateItem(children[c].view, this.options.triggerClass)
5308
+ this.activateItem(children[c].view, this.options.viewClass)
5309
+ this.showComponents(children[c].view)
5310
+ if (children[c].show) {
5311
+ children[c].show.call(children[c])
5312
+ }
5313
+ this.publish('show', [children[c].view, null, group])
5314
+ }
5315
+ if (this.previousView !== this.currentView || group !== 'main') {
5316
+ this.showComponents(view)
5317
+ if (this.options.views[view].show) {
5318
+ this.options.views[view].show.call(this.options.views[view])
5319
+ }
5320
+ this.publish('show', [view, params, group])
5321
+ }
5322
+ else if (this.previousView === this.currentView && this.previousParams.path !== this.currentParams.path) {
5323
+ this.showComponents(view)
5324
+ if (this.options.views[view].show) {
5325
+ this.options.views[view].show.call(this.options.views[view])
5326
+ }
5327
+ this.publish('show', [view, params, group])
5328
+ }
5329
+ })
5095
5330
  }
5096
5331
  reloadCurrentView () {
5097
5332
  this.showView(this.currentView, this.currentParams, 'main')
@@ -5828,7 +6063,18 @@ class WebsyTemplate {
5828
6063
  }
5829
6064
  }
5830
6065
  this.options = Object.assign({}, DEFAULTS, options)
5831
- this.elementId = elementId
6066
+ if (typeof elementId === 'object') {
6067
+ if (elementId.id) {
6068
+ this.elementId = elementId.id
6069
+ }
6070
+ else {
6071
+ elementId.id = WebsyDesigns.Utils.createIdentity()
6072
+ this.elementId = elementId.id
6073
+ }
6074
+ }
6075
+ else {
6076
+ this.elementId = elementId
6077
+ }
5832
6078
  this.templateService = new WebsyDesigns.APIService('')
5833
6079
  if (!elementId) {
5834
6080
  console.log('No element Id provided for Websy Template')
@@ -5946,6 +6192,10 @@ class WebsyTemplate {
5946
6192
  }
5947
6193
  return html
5948
6194
  }
6195
+ set data (d) {
6196
+ this.options.data = d
6197
+ this.render()
6198
+ }
5949
6199
  handleClick (event) {
5950
6200
  if (event.target.classList.contains('clickable')) {
5951
6201
  this.handleEvent(event, 'clickable', 'click')
@@ -11113,8 +11363,10 @@ class WebsyKPI {
11113
11363
  }
11114
11364
  html += `
11115
11365
  <div class="websy-kpi-info">
11116
- <div class="websy-kpi-label ${this.options.label.classes.join(' ') || ''}">
11117
- ${(this.options.label || {}).value || ''}
11366
+ <div class="websy-kpi-label-container">
11367
+ <div class="websy-kpi-label ${this.options.label.classes.join(' ') || ''}">
11368
+ ${(this.options.label || {}).value || ''}
11369
+ </div>
11118
11370
  `
11119
11371
  if (this.options.tooltip && this.options.tooltip.value) {
11120
11372
  html += `
@@ -11438,6 +11690,7 @@ const WebsyDesigns = {
11438
11690
  DatePicker: WebsyDatePicker,
11439
11691
  WebsyDropdown,
11440
11692
  Dropdown: WebsyDropdown,
11693
+ MediaUpload: MediaUpload,
11441
11694
  WebsyResultList,
11442
11695
  ResultList: WebsyResultList,
11443
11696
  WebsyTemplate,