@websy/websy-designs 0.0.125 → 0.0.129

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.
@@ -42,19 +42,22 @@ class WebsyPopupDialog {
42
42
  handleClick (event) {
43
43
  if (event.target.classList.contains('websy-btn')) {
44
44
  const buttonIndex = event.target.getAttribute('data-index')
45
- const buttonInfo = this.options.buttons[buttonIndex]
46
- if (buttonInfo && buttonInfo.preventClose !== true) {
47
- this.hide()
48
- }
45
+ const buttonInfo = this.options.buttons[buttonIndex]
49
46
  if (buttonInfo && buttonInfo.fn) {
50
- if (this.options.collectData === true) {
47
+ if (typeof this.options.collectData !== 'undefined') {
51
48
  const collectEl = document.getElementById(`${this.elementId}_collect`)
52
49
  if (collectEl) {
53
50
  buttonInfo.collectedData = collectEl.value
54
51
  }
55
52
  }
53
+ if (buttonInfo.preventClose !== true) {
54
+ this.hide()
55
+ }
56
56
  buttonInfo.fn(buttonInfo)
57
- }
57
+ }
58
+ else if (buttonInfo && buttonInfo.preventClose !== true) {
59
+ this.hide()
60
+ }
58
61
  }
59
62
  else if (this.closeOnOutsideClick === true) {
60
63
  this.hide()
@@ -80,10 +83,10 @@ class WebsyPopupDialog {
80
83
  if (this.options.message) {
81
84
  html += `<p>${this.options.message}</p>`
82
85
  }
83
- if (this.options.collectData === true) {
86
+ if (typeof this.options.collectData !== 'undefined') {
84
87
  html += `
85
88
  <div>
86
- <input id="${this.elementId}_collect" class="websy-input" placeholder="${this.options.collectPlaceholder || ''}">
89
+ <input id="${this.elementId}_collect" class="websy-input" value="${typeof this.options.collectData === 'boolean' ? '' : this.options.collectData}" placeholder="${this.options.collectPlaceholder || ''}">
87
90
  </div>
88
91
  `
89
92
  }
@@ -168,40 +171,72 @@ class WebsyLoadingDialog {
168
171
  }
169
172
  }
170
173
 
174
+ /* global */
171
175
  class WebsyNavigationMenu {
172
176
  constructor (elementId, options) {
173
177
  this.options = Object.assign({}, {
174
- collapsable: false,
178
+ collapsible: false,
175
179
  orientation: 'horizontal',
176
180
  parentMap: {},
177
- childIndentation: 10
181
+ childIndentation: 10,
182
+ activeSymbol: 'none'
178
183
  }, options)
179
184
  if (!elementId) {
180
185
  console.log('No element Id provided for Websy Menu')
181
186
  return
182
- }
187
+ }
183
188
  const el = document.getElementById(elementId)
184
189
  if (el) {
185
190
  this.elementId = elementId
191
+ this.lowestLevel = 0
192
+ this.flatItems = []
193
+ this.itemMap = {}
194
+ this.flattenItems(0, this.options.items)
195
+ console.log(this.flatItems)
186
196
  el.classList.add(`websy-${this.options.orientation}-list-container`)
187
197
  el.classList.add('websy-menu')
198
+ if (this.options.align) {
199
+ el.classList.add(`${this.options.align}-align`)
200
+ }
201
+ if (Array.isArray(this.options.classes)) {
202
+ this.options.classes = this.options.classes.join(' ')
203
+ }
188
204
  if (this.options.classes) {
189
- this.options.classes.forEach(c => el.classList.add(c))
205
+ this.options.classes.split(' ').forEach(c => el.classList.add(c))
190
206
  }
191
207
  el.addEventListener('click', this.handleClick.bind(this))
192
208
  this.render()
193
209
  }
194
210
  }
211
+ flattenItems (index, items, level = 0) {
212
+ if (items[index]) {
213
+ this.lowestLevel = Math.max(level, this.lowestLevel)
214
+ items[index].id = items[index].id || `${this.elementId}_${this.normaliseString(items[index].text)}`
215
+ this.itemMap[items[index].id] = items[index]
216
+ items[index].level = level
217
+ this.flatItems.push(items[index])
218
+ if (items[index].items) {
219
+ this.flattenItems(0, items[index].items, level + 1)
220
+ }
221
+ this.flattenItems(++index, items, level)
222
+ }
223
+ }
195
224
  handleClick (event) {
196
225
  if (event.target.classList.contains('websy-menu-icon') ||
197
226
  event.target.nodeName === 'svg' ||
198
227
  event.target.nodeName === 'rect') {
199
228
  this.toggleMobileMenu()
200
229
  }
201
- if (event.target.classList.contains('trigger-item') &&
202
- event.target.classList.contains('websy-menu-header')) {
203
- this.toggleMobileMenu('remove')
204
- }
230
+ if (event.target.classList.contains('websy-menu-header')) {
231
+ let item = this.itemMap[event.target.id]
232
+ if (event.target.classList.contains('trigger-item') && item.level === this.lowestLevel) {
233
+ this.toggleMobileMenu('remove')
234
+ }
235
+ if (item.items) {
236
+ event.target.classList.toggle('menu-open')
237
+ this.toggleMenu(item.id)
238
+ }
239
+ }
205
240
  if (event.target.classList.contains('websy-menu-mask')) {
206
241
  this.toggleMobileMenu()
207
242
  }
@@ -213,7 +248,7 @@ class WebsyNavigationMenu {
213
248
  const el = document.getElementById(this.elementId)
214
249
  if (el) {
215
250
  let html = ``
216
- if (this.options.collapsable === true) {
251
+ if (this.options.collapsible === true) {
217
252
  html += `
218
253
  <div id='${this.elementId}_menuIcon' class='websy-menu-icon'>
219
254
  <svg viewbox="0 0 40 40" width="30" height="40">
@@ -225,9 +260,12 @@ class WebsyNavigationMenu {
225
260
  `
226
261
  }
227
262
  if (this.options.logo) {
263
+ if (Array.isArray(this.options.logo.classes)) {
264
+ this.options.logo.classes = this.options.logo.classes.join(' ')
265
+ }
228
266
  html += `
229
267
  <div
230
- class='logo ${(this.options.logo.classes && this.options.logo.classes.join(' ')) || ''}'
268
+ class='logo ${this.options.logo.classes || ''}'
231
269
  ${this.options.logo.attributes && this.options.logo.attributes.join(' ')}
232
270
  >
233
271
  <img src='${this.options.logo.url}'></img>
@@ -236,7 +274,7 @@ class WebsyNavigationMenu {
236
274
  <div id="${this.elementId}_menuContainer" class="websy-menu-block-container">
237
275
  `
238
276
  }
239
- html += this.renderBlock(this.options.items, 'main', 1)
277
+ html += this.renderBlock(this.options.items, 'main', 0)
240
278
  html += `</div>`
241
279
  el.innerHTML = html
242
280
  if (this.options.navigator) {
@@ -244,9 +282,9 @@ class WebsyNavigationMenu {
244
282
  }
245
283
  }
246
284
  }
247
- renderBlock (items, block, level) {
285
+ renderBlock (items, block, level = 0) {
248
286
  let html = `
249
- <ul class='websy-${this.options.orientation}-list ${(block !== 'main' ? 'websy-menu-collapsed' : '')}' id='${this.elementId}_${block}_list'
287
+ <ul class='websy-${this.options.orientation}-list ${level > 0 ? 'websy-child-list' : ''} ${(block !== 'main' ? 'websy-menu-collapsed' : '')}' id='${this.elementId}_${block}_list'
250
288
  `
251
289
  if (block !== 'main') {
252
290
  html += ` data-collapsed='${(block !== 'main' ? 'true' : 'false')}'`
@@ -257,25 +295,36 @@ class WebsyNavigationMenu {
257
295
  let selected = '' // items[i].default === true ? 'selected' : ''
258
296
  let active = items[i].default === true ? 'active' : ''
259
297
  let currentBlock = this.normaliseString(items[i].text)
260
- let blockId = items[i].id || `${this.elementId}_${currentBlock}_label`
298
+ let blockId = items[i].id // || `${this.elementId}_${currentBlock}_label`
299
+ if (Array.isArray(items[i].classes)) {
300
+ items[i].classes = items[i].classes.join(' ')
301
+ }
261
302
  html += `
262
303
  <li class='websy-${this.options.orientation}-list-item'>
263
- <div class='websy-menu-header ${items[i].classes && items[i].classes.join(' ')} ${selected} ${active}'
304
+ <div class='websy-menu-header ${items[i].classes || ''} ${selected} ${active}'
264
305
  id='${blockId}'
265
306
  data-id='${currentBlock}'
266
307
  data-menu-id='${this.elementId}_${currentBlock}_list'
267
308
  data-popout-id='${level > 1 ? block : currentBlock}'
268
309
  data-text='${items[i].text}'
269
310
  style='padding-left: ${level * this.options.childIndentation}px'
270
- ${items[i].attributes && items[i].attributes.join(' ')}
311
+ ${(items[i].attributes && items[i].attributes.join(' ')) || ''}
271
312
  >
272
313
  `
273
314
  if (this.options.orientation === 'horizontal') {
274
315
  html += items[i].text
275
316
  }
276
- html += `
317
+ if (this.options.activeSymbol === 'line') {
318
+ html += `
277
319
  <span class='selected-bar'></span>
320
+ `
321
+ }
322
+ if (this.options.activeSymbol === 'triangle') {
323
+ html += `
278
324
  <span class='active-square'></span>
325
+ `
326
+ }
327
+ html += `
279
328
  <span class='${items[i].items && items[i].items.length > 0 ? 'menu-carat' : ''}'></span>
280
329
  `
281
330
  if (this.options.orientation === 'vertical') {
@@ -287,7 +336,7 @@ class WebsyNavigationMenu {
287
336
  </div>
288
337
  `
289
338
  if (items[i].items) {
290
- html += this.renderBlock(items[i].items, currentBlock, level + 1)
339
+ html += this.renderBlock(items[i].items, currentBlock, items[i].level + 1)
291
340
  }
292
341
  // map the item to it's parent
293
342
  if (block && block !== 'main') {
@@ -301,9 +350,12 @@ class WebsyNavigationMenu {
301
350
  }
302
351
  html += `</ul>`
303
352
  return html
304
- }
305
- toggleOpen () {
306
-
353
+ }
354
+ toggleMenu (id) {
355
+ const el = document.getElementById(`${id}_list`)
356
+ if (el) {
357
+ el.classList.toggle('websy-menu-collapsed')
358
+ }
307
359
  }
308
360
  toggleMobileMenu (method) {
309
361
  if (typeof method === 'undefined') {
@@ -1625,9 +1677,9 @@ class WebsyPubSub {
1625
1677
  class WebsyRouter {
1626
1678
  constructor (options) {
1627
1679
  const defaults = {
1628
- triggerClass: 'trigger-item',
1629
- triggerToggleClass: 'trigger-toggle',
1630
- viewClass: 'view',
1680
+ triggerClass: 'websy-trigger',
1681
+ triggerToggleClass: 'websy-trigger-toggle',
1682
+ viewClass: 'websy-view',
1631
1683
  activeClass: 'active',
1632
1684
  viewAttribute: 'data-view',
1633
1685
  groupAttribute: 'data-group',
@@ -1650,19 +1702,7 @@ class WebsyRouter {
1650
1702
  window.addEventListener('keyup', this.handleKeyUp.bind(this))
1651
1703
  window.addEventListener('focus', this.handleFocus.bind(this))
1652
1704
  window.addEventListener('click', this.handleClick.bind(this))
1653
- this.options = Object.assign({}, defaults, options)
1654
- // add any necessary CSS if the viewClass has been changed
1655
- if (this.options.viewClass !== defaults.viewClass || this.options.activeClass !== defaults.activeClass) {
1656
- let style = `
1657
- <style>
1658
- .${this.options.viewClass}{ display: none; }
1659
- .${this.options.viewClass}.${this.options.activeClass}{ display: initial; }
1660
- .${this.options.triggerClass}{cursor: pointer;}
1661
- </style>
1662
- `
1663
- document.querySelector('head').innerHTML += style
1664
- }
1665
- // this.navigate(this.currentPath, this.options.defaultGroup)
1705
+ this.options = Object.assign({}, defaults, options)
1666
1706
  }
1667
1707
  addGroup (group) {
1668
1708
  if (!this.groups[group]) {
@@ -1750,7 +1790,7 @@ class WebsyRouter {
1750
1790
  }
1751
1791
  }
1752
1792
  init () {
1753
- this.registerElements(document)
1793
+ // this.registerElements(document)
1754
1794
  let view = ''
1755
1795
  let params = this.formatParams(this.queryParams)
1756
1796
  let url
@@ -2003,6 +2043,9 @@ class WebsyRouter {
2003
2043
  }
2004
2044
  }
2005
2045
  }
2046
+ on (event, fn) {
2047
+ this.options.subscribers[event].push(fn)
2048
+ }
2006
2049
  onPopState (event) {
2007
2050
  if (event.state) {
2008
2051
  let url
@@ -2028,7 +2071,7 @@ class WebsyRouter {
2028
2071
  }
2029
2072
  subscribe (event, fn) {
2030
2073
  this.options.subscribers[event].push(fn)
2031
- }
2074
+ }
2032
2075
  get currentPath () {
2033
2076
  let path = window.location.pathname.split('/').pop()
2034
2077
  if (path.indexOf('.htm') !== -1) {
@@ -2080,8 +2123,9 @@ class WebsyRouter {
2080
2123
 
2081
2124
  /* global XMLHttpRequest fetch ENV */
2082
2125
  class APIService {
2083
- constructor (baseUrl) {
2126
+ constructor (baseUrl = '', options = {}) {
2084
2127
  this.baseUrl = baseUrl
2128
+ this.options = Object.assign({}, options)
2085
2129
  }
2086
2130
  add (entity, data, options = {}) {
2087
2131
  const url = this.buildUrl(entity)
@@ -2203,7 +2247,8 @@ class WebsyPDFButton {
2203
2247
  const DEFAULTS = {
2204
2248
  classes: [],
2205
2249
  wait: 0,
2206
- buttonText: 'Download'
2250
+ buttonText: 'Download',
2251
+ directDownload: false
2207
2252
  }
2208
2253
  this.elementId = elementId
2209
2254
  this.options = Object.assign({}, DEFAULTS, options)
@@ -2311,15 +2356,22 @@ class WebsyPDFButton {
2311
2356
  this.service.add('', pdfData, {responseType: 'blob'}).then(response => {
2312
2357
  this.loader.hide()
2313
2358
  const blob = new Blob([response], {type: 'application/pdf'})
2359
+ let msg = `
2360
+ <div class='text-center websy-pdf-download'>
2361
+ <div>Your file is ready to download</div>
2362
+ <a href='${URL.createObjectURL(blob)}' target='_blank'
2363
+ `
2364
+ if (this.options.directDownload === true) {
2365
+ msg += `download='${this.options.fileName || 'Export'}.pdf'`
2366
+ }
2367
+ msg += `
2368
+ >
2369
+ <button class='websy-btn download-pdf'>${this.options.buttonText}</button>
2370
+ </a>
2371
+ </div>
2372
+ `
2314
2373
  this.popup.show({
2315
- message: `
2316
- <div class='text-center websy-pdf-download'>
2317
- <div>Your file is ready to download</div>
2318
- <a href='${URL.createObjectURL(blob)}' target='_blank'>
2319
- <button class='websy-btn download-pdf'>${this.options.buttonText}</button>
2320
- </a>
2321
- </div>
2322
- `,
2374
+ message: msg,
2323
2375
  mask: true
2324
2376
  })
2325
2377
  }, err => {
@@ -3872,24 +3924,40 @@ const WebsyUtils = {
3872
3924
 
3873
3925
  const WebsyDesigns = {
3874
3926
  WebsyPopupDialog,
3927
+ PopupDialog: WebsyPopupDialog,
3875
3928
  WebsyLoadingDialog,
3929
+ LoadingDialog: WebsyLoadingDialog,
3876
3930
  WebsyNavigationMenu,
3931
+ NavigationMenu: WebsyNavigationMenu,
3877
3932
  WebsyForm,
3933
+ Form: WebsyForm,
3878
3934
  WebsyDatePicker,
3935
+ DatePicker: WebsyDatePicker,
3879
3936
  WebsyDropdown,
3937
+ Dropdown: WebsyDropdown,
3880
3938
  WebsyResultList,
3939
+ ResultList: WebsyResultList,
3881
3940
  WebsyTemplate,
3941
+ Template: WebsyTemplate,
3882
3942
  WebsyPubSub,
3943
+ PubSub: WebsyPubSub,
3883
3944
  WebsyRouter,
3945
+ Router: WebsyRouter,
3884
3946
  WebsyTable,
3947
+ Table: WebsyTable,
3885
3948
  WebsyChart,
3949
+ Chart: WebsyChart,
3886
3950
  WebsyChartTooltip,
3951
+ ChartTooltip: WebsyChartTooltip,
3887
3952
  WebsyMap,
3953
+ Map: WebsyMap,
3888
3954
  WebsyKPI,
3889
- WebsyPDFButton,
3955
+ KPI: WebsyKPI,
3956
+ WebsyPDFButton,
3890
3957
  PDFButton: WebsyPDFButton,
3891
3958
  APIService,
3892
- WebsyUtils
3959
+ WebsyUtils,
3960
+ Utils: WebsyUtils
3893
3961
  }
3894
3962
 
3895
3963
  const GlobalPubSub = new WebsyPubSub('empty', {})