@websy/websy-designs 1.0.0 → 1.0.3

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.
@@ -172,7 +172,17 @@ function ShopRoutes (dbHelper, engine, app) {
172
172
  dbHelper.execute(sql).then(result => {
173
173
  if (result.rows.length > 0) {
174
174
  let basket = result.rows[0]
175
- basket.items = JSON.parse(basket.items)
175
+ try {
176
+ basket.items = JSON.parse(JSONSafeRead(basket.items))
177
+ }
178
+ catch (error) {
179
+ if (basket.items) {
180
+ basket.items = JSON.parse(basket.items)
181
+ }
182
+ else {
183
+ basket.items = []
184
+ }
185
+ }
176
186
  try {
177
187
  basket.meta = JSON.parse(JSONSafeRead(basket.meta))
178
188
  }
@@ -230,10 +240,10 @@ function ShopRoutes (dbHelper, engine, app) {
230
240
  }
231
241
 
232
242
  function JSONSafeWrite (v) {
233
- return v.replace(/'/g, '\'\'').replace(/\\(?=[bfnrtv0'"])/g, '\\\\').replace(/\t/)
243
+ return v.replace(/'/g, '\'\'').replace(/\\(?=[bfnrtv0'"])/g, '\\\\').replace(/\t/g, '')
234
244
  }
235
245
  function JSONSafeRead (v) {
236
- return v.replace(/''/g, '\'').replace(/\\(?=[^bfnrtv0'"])/g, '\\\\')
246
+ return v.replace(/''/g, '\'').replace(/\\(?=[^bfnrtv0'"])/g, '\\\\').replace(/\t/g, '')
237
247
  }
238
248
 
239
249
  function readyCallback () {
@@ -3,7 +3,6 @@ const bodyParser = require('body-parser')
3
3
  // const cookie = require('cookie')
4
4
  const cookieParser = require('cookie-parser')
5
5
  const expressSession = require('express-session')
6
- const { log } = require('grunt')
7
6
  // const sessionHelper = require('./helpers/v1/sessionHelper')
8
7
  // const DBSession = require(process.env.EXPRESS_SESSION_CONNECT)(expressSession)
9
8
 
@@ -967,12 +967,13 @@ class WebsyForm {
967
967
  el.innerHTML = msg
968
968
  }
969
969
  }
970
- handleClick (event) {
971
- event.preventDefault()
970
+ handleClick (event) {
972
971
  if (event.target.classList.contains('submit')) {
972
+ event.preventDefault()
973
973
  this.submitForm()
974
974
  }
975
975
  else if (event.target.classList.contains('cancel')) {
976
+ event.preventDefault()
976
977
  this.cancelForm()
977
978
  }
978
979
  }
@@ -2260,18 +2261,7 @@ class WebsyRouter {
2260
2261
  groupActiveView = this.groups[group].activeView
2261
2262
  }
2262
2263
  this.previousPath = this.groups[group].activeView
2263
- }
2264
- if (toggle === true) {
2265
- if (this.previousPath !== '') {
2266
- this.hideView(this.previousPath, group)
2267
- }
2268
- }
2269
- else {
2270
- this.hideView(this.previousView, group)
2271
2264
  }
2272
- if (toggle === true && newPath === groupActiveView) {
2273
- return
2274
- }
2275
2265
  if (group && this.groups[group] && group !== this.options.defaultGroup) {
2276
2266
  this.groups[group].activeView = newPath
2277
2267
  }
@@ -2287,6 +2277,17 @@ class WebsyRouter {
2287
2277
  if (this.currentViewMain === '/') {
2288
2278
  this.currentViewMain = this.options.defaultView
2289
2279
  }
2280
+ if (toggle === true) {
2281
+ if (this.previousPath !== '') {
2282
+ this.hideView(this.previousPath, group)
2283
+ }
2284
+ }
2285
+ else {
2286
+ this.hideView(this.previousView, group)
2287
+ }
2288
+ if (toggle === true && newPath === groupActiveView) {
2289
+ return
2290
+ }
2290
2291
  if (toggle === false) {
2291
2292
  this.showView(this.currentView, this.currentParams)
2292
2293
  }
@@ -2764,10 +2765,12 @@ const WebsyUtils = {
2764
2765
  }
2765
2766
  }
2766
2767
 
2768
+ /* global WebsyDesigns */
2767
2769
  class WebsyTable {
2768
2770
  constructor (elementId, options) {
2769
2771
  const DEFAULTS = {
2770
- pageSize: 20
2772
+ pageSize: 20,
2773
+ paging: 'scroll'
2771
2774
  }
2772
2775
  this.elementId = elementId
2773
2776
  this.options = Object.assign({}, DEFAULTS, options)
@@ -2777,8 +2780,8 @@ class WebsyTable {
2777
2780
  this.data = []
2778
2781
  const el = document.getElementById(this.elementId)
2779
2782
  if (el) {
2780
- el.innerHTML = `
2781
- <div id='${this.elementId}_tableContainer' class='websy-vis-table'>
2783
+ let html = `
2784
+ <div id='${this.elementId}_tableContainer' class='websy-vis-table ${this.options.paging === 'pages' ? 'with-paging' : ''}'>
2782
2785
  <!--<div class="download-button">
2783
2786
  <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M16 11h5l-9 10-9-10h5v-11h8v11zm1 11h-10v2h10v-2z"/></svg>
2784
2787
  </div>-->
@@ -2789,14 +2792,45 @@ class WebsyTable {
2789
2792
  </tbody>
2790
2793
  <tfoot id="${this.elementId}_foot">
2791
2794
  </tfoot>
2792
- </table>
2795
+ </table>
2796
+ <div id="${this.elementId}_errorContainer" class='websy-vis-error-container'>
2797
+ <div>
2798
+ <div id="${this.elementId}_errorTitle"></div>
2799
+ <div id="${this.elementId}_errorMessage"></div>
2800
+ </div>
2801
+ </div>
2802
+ <div id="${this.elementId}_loadingContainer"></div>
2793
2803
  </div>
2794
- `
2804
+ `
2805
+ if (this.options.paging === 'pages') {
2806
+ html += `
2807
+ <div class="websy-table-paging-container">
2808
+ Show <div id="${this.elementId}_pageSizeSelector" class="websy-vis-page-selector"></div> rows
2809
+ <ul id="${this.elementId}_pageList" class="websy-vis-page-list"></ul>
2810
+ </div>
2811
+ `
2812
+ }
2813
+ let pageOptions = [10, 20, 50, 100, 200]
2814
+ el.innerHTML = html
2815
+ if (this.options.paging === 'pages') {
2816
+ this.pageSizeSelector = new WebsyDesigns.Dropdown(`${this.elementId}_pageSizeSelector`, {
2817
+ selectedItems: [pageOptions.indexOf(this.options.pageSize)],
2818
+ items: pageOptions.map(p => ({ label: p.toString(), value: p })),
2819
+ allowClear: false,
2820
+ disableSearch: true,
2821
+ onItemSelected: (selectedItem) => {
2822
+ if (this.options.onChangePageSize) {
2823
+ this.options.onChangePageSize(selectedItem.value)
2824
+ }
2825
+ }
2826
+ })
2827
+ }
2795
2828
  el.addEventListener('click', this.handleClick.bind(this))
2796
2829
  el.addEventListener('mouseout', this.handleMouseOut.bind(this))
2797
2830
  el.addEventListener('mousemove', this.handleMouseMove.bind(this))
2798
2831
  const scrollEl = document.getElementById(`${this.elementId}_tableContainer`)
2799
2832
  scrollEl.addEventListener('scroll', this.handleScroll.bind(this))
2833
+ this.loadingDialog = new WebsyDesigns.LoadingDialog(`${this.elementId}_loadingContainer`)
2800
2834
  this.render()
2801
2835
  }
2802
2836
  else {
@@ -2804,6 +2838,7 @@ class WebsyTable {
2804
2838
  }
2805
2839
  }
2806
2840
  appendRows (data) {
2841
+ this.hideError()
2807
2842
  let bodyHTML = ''
2808
2843
  if (data) {
2809
2844
  bodyHTML += data.map((r, rowIndex) => {
@@ -2830,12 +2865,13 @@ class WebsyTable {
2830
2865
  class='${this.options.columns[i].classes || ''}'
2831
2866
  style='${style}'
2832
2867
  colspan='${c.colspan || 1}'
2868
+ rowspan='${c.rowspan || 1}'
2833
2869
  >
2834
2870
  <a href='${c.value}' target='${this.options.columns[i].openInNewTab === true ? '_blank' : '_self'}'>${c.displayText || this.options.columns[i].linkText || c.value}</a>
2835
2871
  </td>
2836
2872
  `
2837
2873
  }
2838
- else if (this.options.columns[i].showAsNavigatorLink === true && c.value.trim() !== '') {
2874
+ else if ((this.options.columns[i].showAsNavigatorLink === true || this.options.columns[i].showAsRouterLink === true) && c.value.trim() !== '') {
2839
2875
  return `
2840
2876
  <td
2841
2877
  data-view='${c.value}'
@@ -2844,6 +2880,7 @@ class WebsyTable {
2844
2880
  class='trigger-item ${this.options.columns[i].clickable === true ? 'clickable' : ''} ${this.options.columns[i].classes || ''}'
2845
2881
  style='${style}'
2846
2882
  colspan='${c.colspan || 1}'
2883
+ rowspan='${c.rowspan || 1}'
2847
2884
  >${c.displayText || this.options.columns[i].linkText || c.value}</td>
2848
2885
  `
2849
2886
  }
@@ -2862,6 +2899,7 @@ class WebsyTable {
2862
2899
  class='${this.options.columns[i].classes || ''}'
2863
2900
  style='${style}'
2864
2901
  colspan='${c.colspan || 1}'
2902
+ rowspan='${c.rowspan || 1}'
2865
2903
  >${c.value}</td>
2866
2904
  `
2867
2905
  }
@@ -2930,6 +2968,12 @@ class WebsyTable {
2930
2968
  this.options.onClick(event, this.data[rowIndex][colIndex], this.data[rowIndex], this.options.columns[colIndex])
2931
2969
  }
2932
2970
  }
2971
+ else if (event.target.classList.contains('websy-page-num')) {
2972
+ const pageNum = +event.target.getAttribute('data-page')
2973
+ if (this.options.onSetPage) {
2974
+ this.options.onSetPage(pageNum)
2975
+ }
2976
+ }
2933
2977
  }
2934
2978
  handleMouseMove (event) {
2935
2979
  if (this.tooltipTimeoutFn) {
@@ -2949,10 +2993,19 @@ class WebsyTable {
2949
2993
  }
2950
2994
  }
2951
2995
  handleScroll (event) {
2952
- if (this.options.onScroll) {
2996
+ if (this.options.onScroll && this.options.paging === 'scroll') {
2953
2997
  this.options.onScroll(event)
2954
- }
2998
+ }
2955
2999
  }
3000
+ hideError () {
3001
+ const containerEl = document.getElementById(`${this.elementId}_errorContainer`)
3002
+ if (containerEl) {
3003
+ containerEl.classList.remove('active')
3004
+ }
3005
+ }
3006
+ hideLoading () {
3007
+ this.loadingDialog.hide()
3008
+ }
2956
3009
  internalSort (column, colIndex) {
2957
3010
  this.options.columns.forEach((c, i) => {
2958
3011
  c.activeSort = i === colIndex
@@ -2993,11 +3046,13 @@ class WebsyTable {
2993
3046
  if (!this.options.columns) {
2994
3047
  return
2995
3048
  }
3049
+ this.hideError()
2996
3050
  this.data = []
2997
3051
  this.rowCount = 0
2998
3052
  const bodyEl = document.getElementById(`${this.elementId}_body`)
2999
3053
  bodyEl.innerHTML = ''
3000
3054
  if (this.options.allowDownload === true) {
3055
+ // doesn't do anything yet
3001
3056
  const el = document.getElementById(this.elementId)
3002
3057
  if (el) {
3003
3058
  el.classList.add('allow-download')
@@ -3029,20 +3084,65 @@ class WebsyTable {
3029
3084
  }).join('') + '</tr>'
3030
3085
  const headEl = document.getElementById(`${this.elementId}_head`)
3031
3086
  headEl.innerHTML = headHTML
3032
- let footHTML = '<tr>' + this.options.columns.map((c, i) => {
3033
- if (c.show !== false) {
3034
- return `
3035
- <th></th>
3036
- `
3087
+ // let footHTML = '<tr>' + this.options.columns.map((c, i) => {
3088
+ // if (c.show !== false) {
3089
+ // return `
3090
+ // <th></th>
3091
+ // `
3092
+ // }
3093
+ // }).join('') + '</tr>'
3094
+ // const footEl = document.getElementById(`${this.elementId}_foot`)
3095
+ // footEl.innerHTML = footHTML
3096
+ if (this.options.paging === 'pages') {
3097
+ const pagingEl = document.getElementById(`${this.elementId}_pageList`)
3098
+ if (pagingEl) {
3099
+ let pages = (new Array(this.options.pageCount)).fill('').map((item, index) => {
3100
+ return `<li data-page="${index}" class="websy-page-num ${(this.options.pageNum === index) ? 'active' : ''}">${index + 1}</li>`
3101
+ })
3102
+ let startIndex = 0
3103
+ if (this.options.pageCount > 8) {
3104
+ startIndex = Math.max(0, this.options.pageNum - 4)
3105
+ pages = pages.splice(startIndex, 10)
3106
+ if (startIndex > 0) {
3107
+ pages.splice(0, 0, `<li>Page&nbsp;</li><li data-page="0" class="websy-page-num">First</li><li>...</li>`)
3108
+ }
3109
+ else {
3110
+ pages.splice(0, 0, '<li>Page&nbsp;</li>')
3111
+ }
3112
+ if (this.options.pageNum < this.options.pageCount - 1) {
3113
+ pages.push('<li>...</li>')
3114
+ pages.push(`<li data-page="${this.options.pageCount - 1}" class="websy-page-num">Last</li>`)
3115
+ }
3116
+ }
3117
+ pagingEl.innerHTML = pages.join('')
3037
3118
  }
3038
- }).join('') + '</tr>'
3039
- const footEl = document.getElementById(`${this.elementId}_foot`)
3040
- footEl.innerHTML = footHTML
3119
+ }
3041
3120
  if (data) {
3042
3121
  // this.data = this.data.concat(data)
3043
3122
  this.appendRows(data)
3044
3123
  }
3045
- }
3124
+ }
3125
+ showError (options) {
3126
+ const containerEl = document.getElementById(`${this.elementId}_errorContainer`)
3127
+ if (containerEl) {
3128
+ containerEl.classList.add('active')
3129
+ }
3130
+ if (options.title) {
3131
+ const titleEl = document.getElementById(`${this.elementId}_errorTitle`)
3132
+ if (titleEl) {
3133
+ titleEl.innerHTML = options.title
3134
+ }
3135
+ }
3136
+ if (options.message) {
3137
+ const messageEl = document.getElementById(`${this.elementId}_errorTitle`)
3138
+ if (messageEl) {
3139
+ messageEl.innerHTML = options.message
3140
+ }
3141
+ }
3142
+ }
3143
+ showLoading (options) {
3144
+ this.loadingDialog.show(options)
3145
+ }
3046
3146
  }
3047
3147
 
3048
3148
  /* global d3 include WebsyDesigns */
@@ -4744,3 +4844,5 @@ function usePayPal () {
4744
4844
  pps.src = '//www.paypal.com/sdk/js'
4745
4845
  document.getElementsByTagName('body')[0].appendChild(pps)
4746
4846
  }
4847
+
4848
+ export default WebsyDesigns