@websy/websy-designs 1.9.14 → 1.10.0

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.
@@ -60,6 +60,10 @@ class APIService {
60
60
  const url = this.buildUrl(entity, id)
61
61
  return this.run('DELETE', url)
62
62
  }
63
+ deleteMany (entity, query) {
64
+ const url = this.buildUrl(entity, null, query)
65
+ return this.run('DELETE', url)
66
+ }
63
67
  get (entity, id, query, offset, limit) {
64
68
  let url = this.buildUrl(entity, id, query)
65
69
  if (offset) {
@@ -70,12 +74,12 @@ class APIService {
70
74
  url += `?offset=${offset}`
71
75
  }
72
76
  }
73
- if (limit) {
77
+ if (limit || this.options.rowLimit) {
74
78
  if (url.indexOf('?') !== -1) {
75
- url += `&limit=${limit}`
79
+ url += `&limit=${limit || this.options.rowLimit}`
76
80
  }
77
81
  else {
78
- url += `?limit=${limit}`
82
+ url += `?limit=${limit || this.options.rowLimit}`
79
83
  }
80
84
  }
81
85
  return this.run('GET', url)
@@ -193,16 +197,51 @@ class ButtonGroup {
193
197
  this.render()
194
198
  }
195
199
  }
200
+ get value () {
201
+ if (this.options.activeItem > -1) {
202
+ return [this.options.items[this.options.activeItem]]
203
+ }
204
+ else if (this.options.multiSelect === true) {
205
+ return this.options.items.filter(d => d.selected)
206
+ }
207
+ return []
208
+ }
209
+ set value (value) {
210
+ let activeIndex = -1
211
+ if (this.options.multiSelect === true) {
212
+ if (Array.isArray(value)) {
213
+ this.options.items.forEach(d => {
214
+ if (value.indexOf(d.value) !== -1) {
215
+ d.selected = true
216
+ }
217
+ else {
218
+ d.selected = false
219
+ }
220
+ })
221
+ }
222
+ }
223
+ else {
224
+ for (let i = 0; i < this.options.items.length; i++) {
225
+ if ((this.options.items[i].value || this.options.items[i].label) === value) {
226
+ activeIndex = i
227
+ }
228
+ }
229
+ this.options.activeItem = activeIndex
230
+ }
231
+ this.render()
232
+ }
196
233
  handleClick (event) {
197
234
  if (event.target.classList.contains('websy-button-group-item')) {
198
235
  const index = +event.target.getAttribute('data-index')
199
236
  if (this.options.multiSelect === true) {
200
237
  if (event.target.classList.contains('active')) {
238
+ this.options.items[index].selected = false
201
239
  this.options.onDeactivate(this.options.items[index], index, event)
202
240
  event.target.classList.remove('active')
203
241
  event.target.classList.add('inactive')
204
242
  }
205
243
  else {
244
+ this.options.items[index].selected = true
206
245
  this.options.onActivate(this.options.items[index], index, event)
207
246
  event.target.classList.add('active')
208
247
  event.target.classList.remove('inactive')
@@ -253,7 +292,10 @@ class ButtonGroup {
253
292
  let activeClass = ''
254
293
  if (this.options.activeItem !== -1) {
255
294
  activeClass = i === this.options.activeItem ? 'active' : 'inactive'
256
- }
295
+ }
296
+ else if (this.options.multiSelect === true) {
297
+ activeClass = t.selected === true ? 'active' : 'inactive'
298
+ }
257
299
  return `
258
300
  <${this.options.tag} ${(t.attributes || []).join(' ')} data-id="${t.id || t.label}" data-index="${i}" class="websy-button-group-item ${(t.classes || []).join(' ')} ${this.options.style}-style ${activeClass}">${t.label}</${this.options.tag}>
259
301
  `
@@ -272,7 +314,12 @@ class WebsyCarousel {
272
314
  showFrameSelector: true,
273
315
  showPrevNext: true,
274
316
  autoPlay: true,
275
- frames: []
317
+ frames: [],
318
+ frameSelectorIcon: `
319
+ <svg xmlns="http://www.w3.org/2000/svg" width="10" height="10" viewBox="0 0 512 512">
320
+ <circle cx="256" cy="256" r="192" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32"/>
321
+ </svg>
322
+ `
276
323
  }
277
324
  this.playTimeoutFn = null
278
325
  this.options = Object.assign({}, DEFAULTS, options)
@@ -383,10 +430,10 @@ class WebsyCarousel {
383
430
  html += `<div class="websy-btn-parent">`
384
431
  this.options.frames.forEach((frame, frameIndex) => {
385
432
  html += `
386
- <svg xmlns="http://www.w3.org/2000/svg" width="10" height="10" viewBox="0 0 512 512" data-index="${frameIndex}" id="${this.elementId}_selector_${frameIndex}"
387
- class="websy-progress-btn ${this.options.currentFrame === frameIndex ? 'websy-progress-btn-active' : ''}">
388
- <title>Ellipse</title><circle cx="256" cy="256" r="192" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32"/>
389
- </svg>
433
+ <div data-index="${frameIndex}" id="${this.elementId}_selector_${frameIndex}"
434
+ class="websy-progress-btn ${this.options.currentFrame === frameIndex ? 'websy-progress-btn-active' : ''}">
435
+ ${this.options.frameSelectorIcon}
436
+ </div>
390
437
  `
391
438
  })
392
439
  html += `</div>`
@@ -1779,6 +1826,7 @@ class WebsyDropdown {
1779
1826
  const contentPos = WebsyUtils.getElementPos(contentEl)
1780
1827
  if (this.options.style === 'plain' && headerPos.width > 0 && headerPos.height > 0) {
1781
1828
  contentEl.style.right = `calc(100vw - ${headerPos.right}px)`
1829
+ contentEl.style.width = `${headerEl.clientWidth}px`
1782
1830
  if (headerPos.bottom + contentPos.height > window.innerHeight) {
1783
1831
  // contentEl.classList.add('on-top')
1784
1832
  contentEl.style.bottom = `calc(100vh - ${headerPos.top}px)`
@@ -1790,6 +1838,7 @@ class WebsyDropdown {
1790
1838
  else if (this.options.style === 'plain' && headerPos.width === 0 && headerPos.height === 0) {
1791
1839
  const targetPos = WebsyUtils.getElementPos(event.target)
1792
1840
  contentEl.style.right = `calc(100vw - ${targetPos.right}px)`
1841
+ contentEl.style.width = `${targetPos.width}px`
1793
1842
  }
1794
1843
  if (this.options.disableSearch !== true) {
1795
1844
  const searchEl = document.getElementById(`${this.elementId}_search`)
@@ -1801,6 +1850,19 @@ class WebsyDropdown {
1801
1850
  this.options.onOpen(this.elementId)
1802
1851
  }
1803
1852
  }
1853
+ set items (items) {
1854
+ this.options.items = [...items]
1855
+ if (this.options.items.length > 0) {
1856
+ this.options.items = this.options.items.map((d, i) => {
1857
+ if (typeof d.index === 'undefined') {
1858
+ d.index = i
1859
+ }
1860
+ return d
1861
+ })
1862
+ }
1863
+ this._originalData = [...this.options.items]
1864
+ this.render()
1865
+ }
1804
1866
  render () {
1805
1867
  if (!this.elementId) {
1806
1868
  console.log('No element Id provided for Websy Dropdown')
@@ -2277,9 +2339,7 @@ class WebsyForm {
2277
2339
  }
2278
2340
  GlobalPubSub.subscribe('recaptchaready', this.recaptchaReady.bind(this))
2279
2341
  this.recaptchaResult = null
2280
- this.options = Object.assign(defaults, {}, {
2281
- // defaults go here
2282
- }, options)
2342
+ this.options = Object.assign({}, defaults, options)
2283
2343
  if (!elementId) {
2284
2344
  console.log('No element Id provided')
2285
2345
  return
@@ -2347,8 +2407,27 @@ class WebsyForm {
2347
2407
  const data = {}
2348
2408
  const temp = new FormData(formEl)
2349
2409
  temp.forEach((value, key) => {
2350
- data[key] = value
2410
+ if (this.fieldMap[key] && this.fieldMap[key].type === 'checkbox') {
2411
+ data[key] = true
2412
+ }
2413
+ if (this.fieldMap[key] && this.fieldMap[key].instance && this.fieldMap[key].instance.value) {
2414
+ data[key] = this.fieldMap[key].instance.value
2415
+ }
2416
+ else {
2417
+ data[key] = value
2418
+ }
2351
2419
  })
2420
+ let keys = Object.keys(data)
2421
+ for (const key in this.fieldMap) {
2422
+ if (keys.indexOf(key) === -1) {
2423
+ if (this.fieldMap[key] && this.fieldMap[key].type === 'checkbox') {
2424
+ data[key] = false
2425
+ }
2426
+ else if (this.fieldMap[key] && this.fieldMap[key].instance && this.fieldMap[key].instance.value) {
2427
+ data[key] = this.fieldMap[key].instance.value
2428
+ }
2429
+ }
2430
+ }
2352
2431
  return data
2353
2432
  }
2354
2433
  set data (d) {
@@ -2406,6 +2485,7 @@ class WebsyForm {
2406
2485
  handleClick (event) {
2407
2486
  if (event.target.classList.contains('submit')) {
2408
2487
  event.preventDefault()
2488
+ event.stopPropagation()
2409
2489
  this.submitForm()
2410
2490
  }
2411
2491
  else if (event.target.classList.contains('cancel')) {
@@ -2578,6 +2658,7 @@ class WebsyForm {
2578
2658
  `
2579
2659
  this.options.fields.forEach((f, i) => {
2580
2660
  this.fieldMap[f.field] = f
2661
+ f.owningElement = this.elementId
2581
2662
  if (f.component) {
2582
2663
  componentsToProcess.push(f)
2583
2664
  html += `
@@ -2664,6 +2745,10 @@ class WebsyForm {
2664
2745
  const el = document.getElementById(`${this.elementId}_input_${field}`)
2665
2746
  if (el) {
2666
2747
  el.value = value
2748
+ el.setAttribute('value', value)
2749
+ if (this.fieldMap[field].type === 'checkbox') {
2750
+ el.checked = value
2751
+ }
2667
2752
  }
2668
2753
  else {
2669
2754
  console.error(`Input for ${field} does not exist in form.`)
@@ -2821,6 +2906,10 @@ class MultiForm {
2821
2906
  }
2822
2907
  this.render()
2823
2908
  }
2909
+ addData (data) {
2910
+ this.formData = this.formData.concat(data)
2911
+ this.render()
2912
+ }
2824
2913
  addEntry () {
2825
2914
  const el = document.getElementById(`${this.elementId}_container`)
2826
2915
  let newId = WebsyDesigns.Utils.createIdentity()
@@ -2838,7 +2927,7 @@ class MultiForm {
2838
2927
  </button>
2839
2928
  `
2840
2929
  el.appendChild(newFormEl)
2841
- let formOptions = Object.assign({}, this.options)
2930
+ let formOptions = Object.assign({}, this.options, { fields: [...this.options.fields.map(f => Object.assign({}, f))] })
2842
2931
  this.forms.push(new WebsyDesigns.Form(`${this.elementId}_${newId}_form`, formOptions))
2843
2932
  }
2844
2933
  clear () {
@@ -2852,14 +2941,20 @@ class MultiForm {
2852
2941
  }
2853
2942
  get data () {
2854
2943
  const d = this.forms.map(f => (f.data))
2855
- // we don't return the last form
2856
- d.pop()
2944
+ console.log('forms data', d)
2945
+ if (this.options.allowAdd !== false) {
2946
+ // we don't return the last form
2947
+ d.pop()
2948
+ }
2857
2949
  return d
2858
2950
  }
2859
2951
  set data (d) {
2860
2952
  this.formData = d
2861
2953
  this.render()
2862
2954
  }
2955
+ get deleted () {
2956
+ return this.formData.filter(d => this.recordsToDelete.includes(`${d.id}`))
2957
+ }
2863
2958
  handleClick (event) {
2864
2959
  if (event.target.classList.contains('websy-multi-form-add')) {
2865
2960
  let id = event.target.getAttribute('data-formid')
@@ -2939,15 +3034,17 @@ class MultiForm {
2939
3034
  `
2940
3035
  }
2941
3036
  el.innerHTML = html
2942
- this.formData.forEach(d => {
2943
- let formOptions = Object.assign({}, this.options)
3037
+ this.forms = new Array(this.formData.length)
3038
+ this.formData.forEach((d, i) => {
3039
+ let formOptions = Object.assign({}, this.options, { fields: [...this.options.fields.map(f => Object.assign({}, f))] })
2944
3040
  let formObject = new WebsyDesigns.Form(`${this.elementId}_${d.formId}_form`, formOptions)
2945
3041
  formObject.data = d
2946
- this.forms.push(formObject)
3042
+ this.forms[i] = formObject
2947
3043
  })
2948
3044
  if (this.options.allowAdd === true) {
2949
- let formOptions = Object.assign({}, this.options)
2950
- this.forms.push(new WebsyDesigns.Form(`${this.elementId}_${id}_form`, formOptions))
3045
+ let formOptions = Object.assign({}, this.options, { fields: [...this.options.fields.map(f => Object.assign({}, f))] })
3046
+ let formObject = new WebsyDesigns.Form(`${this.elementId}_${id}_form`, formOptions)
3047
+ this.forms.push(formObject)
2951
3048
  }
2952
3049
  }
2953
3050
  }
@@ -3957,6 +4054,9 @@ class WebsyPubSub {
3957
4054
  }
3958
4055
  }
3959
4056
  subscribe (id, method, fn) {
4057
+ if (!this.subscriptions) {
4058
+ this.subscriptions = {}
4059
+ }
3960
4060
  if (arguments.length === 3) {
3961
4061
  if (!this.subscriptions[id]) {
3962
4062
  this.subscriptions[id] = {}
@@ -5513,7 +5613,52 @@ class WebsyTemplate {
5513
5613
  return html
5514
5614
  }
5515
5615
  handleClick (event) {
5516
- //
5616
+ if (event.target.classList.contains('clickable')) {
5617
+ this.handleEvent(event, 'clickable', 'click')
5618
+ }
5619
+ }
5620
+ handleEvent (event, eventType, action) {
5621
+ let l = event.target.getAttribute('data-event')
5622
+ if (l) {
5623
+ l = l.split('(')
5624
+ let params = []
5625
+ const id = event.target.getAttribute('data-id')
5626
+ // const locator = event.target.getAttribute('data-locator')
5627
+ // if (l[1]) {
5628
+ // l[1] = l[1].replace(')', '')
5629
+ // params = l[1].split(',')
5630
+ // }
5631
+ // l = l[0]
5632
+ let data = this.options.data
5633
+ // if (locator !== '') {
5634
+ // let locatorItems = locator.split(';')
5635
+ // locatorItems.forEach(loc => {
5636
+ // let locatorParts = loc.split(':')
5637
+ // if (data[locatorParts[0]]) {
5638
+ // data = data[locatorParts[0]]
5639
+ // let parts = locatorParts[1].split('.')
5640
+ // parts.forEach(p => {
5641
+ // data = data[p]
5642
+ // })
5643
+ // }
5644
+ // })
5645
+ // }
5646
+ // params = params.map(p => {
5647
+ // if (typeof p !== 'string' && typeof p !== 'number') {
5648
+ // if (data[+id]) {
5649
+ // p = data[+id][p]
5650
+ // }
5651
+ // }
5652
+ // else if (typeof p === 'string') {
5653
+ // p = p.replace(/"/g, '').replace(/'/g, '')
5654
+ // }
5655
+ // return p
5656
+ // })
5657
+ if (event.target.classList.contains(eventType) && this.options.listeners[action] && this.options.listeners[action][l]) {
5658
+ event.stopPropagation()
5659
+ this.options.listeners[action][l].call(this, event, data[+id], ...params)
5660
+ }
5661
+ }
5517
5662
  }
5518
5663
  render () {
5519
5664
  this.resize()