@websy/websy-designs 1.0.2 → 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.
@@ -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
  }
@@ -2768,7 +2769,8 @@ const WebsyUtils = {
2768
2769
  class WebsyTable {
2769
2770
  constructor (elementId, options) {
2770
2771
  const DEFAULTS = {
2771
- pageSize: 20
2772
+ pageSize: 20,
2773
+ paging: 'scroll'
2772
2774
  }
2773
2775
  this.elementId = elementId
2774
2776
  this.options = Object.assign({}, DEFAULTS, options)
@@ -2778,8 +2780,8 @@ class WebsyTable {
2778
2780
  this.data = []
2779
2781
  const el = document.getElementById(this.elementId)
2780
2782
  if (el) {
2781
- el.innerHTML = `
2782
- <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' : ''}'>
2783
2785
  <!--<div class="download-button">
2784
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>
2785
2787
  </div>-->
@@ -2790,7 +2792,7 @@ class WebsyTable {
2790
2792
  </tbody>
2791
2793
  <tfoot id="${this.elementId}_foot">
2792
2794
  </tfoot>
2793
- </table>
2795
+ </table>
2794
2796
  <div id="${this.elementId}_errorContainer" class='websy-vis-error-container'>
2795
2797
  <div>
2796
2798
  <div id="${this.elementId}_errorTitle"></div>
@@ -2799,7 +2801,30 @@ class WebsyTable {
2799
2801
  </div>
2800
2802
  <div id="${this.elementId}_loadingContainer"></div>
2801
2803
  </div>
2802
- `
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
+ }
2803
2828
  el.addEventListener('click', this.handleClick.bind(this))
2804
2829
  el.addEventListener('mouseout', this.handleMouseOut.bind(this))
2805
2830
  el.addEventListener('mousemove', this.handleMouseMove.bind(this))
@@ -2943,6 +2968,12 @@ class WebsyTable {
2943
2968
  this.options.onClick(event, this.data[rowIndex][colIndex], this.data[rowIndex], this.options.columns[colIndex])
2944
2969
  }
2945
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
+ }
2946
2977
  }
2947
2978
  handleMouseMove (event) {
2948
2979
  if (this.tooltipTimeoutFn) {
@@ -2962,9 +2993,9 @@ class WebsyTable {
2962
2993
  }
2963
2994
  }
2964
2995
  handleScroll (event) {
2965
- if (this.options.onScroll) {
2996
+ if (this.options.onScroll && this.options.paging === 'scroll') {
2966
2997
  this.options.onScroll(event)
2967
- }
2998
+ }
2968
2999
  }
2969
3000
  hideError () {
2970
3001
  const containerEl = document.getElementById(`${this.elementId}_errorContainer`)
@@ -3053,15 +3084,39 @@ class WebsyTable {
3053
3084
  }).join('') + '</tr>'
3054
3085
  const headEl = document.getElementById(`${this.elementId}_head`)
3055
3086
  headEl.innerHTML = headHTML
3056
- let footHTML = '<tr>' + this.options.columns.map((c, i) => {
3057
- if (c.show !== false) {
3058
- return `
3059
- <th></th>
3060
- `
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('')
3061
3118
  }
3062
- }).join('') + '</tr>'
3063
- const footEl = document.getElementById(`${this.elementId}_foot`)
3064
- footEl.innerHTML = footHTML
3119
+ }
3065
3120
  if (data) {
3066
3121
  // this.data = this.data.concat(data)
3067
3122
  this.appendRows(data)
@@ -4789,3 +4844,5 @@ function usePayPal () {
4789
4844
  pps.src = '//www.paypal.com/sdk/js'
4790
4845
  document.getElementsByTagName('body')[0].appendChild(pps)
4791
4846
  }
4847
+
4848
+ export default WebsyDesigns