@websy/websy-designs 1.9.7 → 1.9.9

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.
@@ -5,6 +5,7 @@
5
5
  WebsyNavigationMenu
6
6
  WebsyPubSub
7
7
  WebsyForm
8
+ MultiForm
8
9
  WebsyDatePicker
9
10
  WebsyDropdown
10
11
  WebsyRouter
@@ -2368,7 +2369,15 @@ class WebsyForm {
2368
2369
  let index = event.target.getAttribute('data-index')
2369
2370
  if (this.options.fields[index] && (this.options.fields[index].required || this.options.fields[index].validate)) {
2370
2371
  this.validateField(this.options.fields[index], event.target.value)
2371
- }
2372
+ }
2373
+ if (this.options.fields[index].onChange) {
2374
+ this.options.fields[index].onChange({
2375
+ value: event.target.value,
2376
+ field: this.options.fields[index],
2377
+ form: this,
2378
+ index
2379
+ })
2380
+ }
2372
2381
  }
2373
2382
  }
2374
2383
  handleClick (event) {
@@ -2387,6 +2396,14 @@ class WebsyForm {
2387
2396
  if (this.options.fields[index] && (this.options.fields[index].required || this.options.fields[index].validate)) {
2388
2397
  this.validateField(this.options.fields[index], event.target.value)
2389
2398
  }
2399
+ if (this.options.fields[index].onLeave) {
2400
+ this.options.fields[index].onLeave({
2401
+ value: event.target.value,
2402
+ field: this.options.fields[index],
2403
+ form: this,
2404
+ index
2405
+ })
2406
+ }
2390
2407
  }
2391
2408
  }
2392
2409
  handleKeyDown (event) {
@@ -2541,7 +2558,7 @@ class WebsyForm {
2541
2558
  if (f.component) {
2542
2559
  componentsToProcess.push(f)
2543
2560
  html += `
2544
- ${i > 0 ? '-->' : ''}<div id='${this.elementId}_${f.field}_inputContainer' class='websy-input-container ${f.classes ? f.classes.join(' ') : ''}'>
2561
+ ${i > 0 ? '-->' : ''}<div id='${this.elementId}_${f.field}_inputContainer' style='${f.style || ''}' class='websy-input-container ${f.classes ? f.classes.join(' ') : ''}'>
2545
2562
  ${f.label ? `<label for="${f.field}">${f.label}</label>` : ''}${f.required === true ? '<span class="websy-form-required-value">*</span>' : ''}
2546
2563
  <div id='${this.elementId}_input_${f.field}_component' class='form-component'></div>
2547
2564
  <span id='${this.elementId}_${f.field}_error' class='websy-form-validation-error'></span>
@@ -2550,7 +2567,7 @@ class WebsyForm {
2550
2567
  }
2551
2568
  else if (f.type === 'longtext') {
2552
2569
  html += `
2553
- ${i > 0 ? '-->' : ''}<div id='${this.elementId}_${f.field}_inputContainer' class='websy-input-container ${f.classes ? f.classes.join(' ') : ''}'>
2570
+ ${i > 0 ? '-->' : ''}<div id='${this.elementId}_${f.field}_inputContainer' style='${f.style || ''}' class='websy-input-container ${f.classes ? f.classes.join(' ') : ''}'>
2554
2571
  ${f.label ? `<label for="${f.field}">${f.label}</label>` : ''}${f.required === true ? '<span class="websy-form-required-value">*</span>' : ''}
2555
2572
  <textarea
2556
2573
  id="${this.elementId}_input_${f.field}"
@@ -2568,7 +2585,7 @@ class WebsyForm {
2568
2585
  }
2569
2586
  else {
2570
2587
  html += `
2571
- ${i > 0 ? '-->' : ''}<div id='${this.elementId}_${f.field}_inputContainer' class='websy-input-container ${f.classes ? f.classes.join(' ') : ''}'>
2588
+ ${i > 0 ? '-->' : ''}<div id='${this.elementId}_${f.field}_inputContainer' style='${f.style || ''}' class='websy-input-container ${f.classes ? f.classes.join(' ') : ''}'>
2572
2589
  ${f.label ? `<label for="${f.field}">${f.label}</label>` : ''}${f.required === true ? '<span class="websy-form-required-value">*</span>' : ''}
2573
2590
  <input
2574
2591
  id="${this.elementId}_input_${f.field}"
@@ -2757,6 +2774,158 @@ class WebsyForm {
2757
2774
  }
2758
2775
  }
2759
2776
 
2777
+ /*
2778
+ global
2779
+ WebsyDesigns
2780
+ */
2781
+ class MultiForm {
2782
+ constructor (elementId, options) {
2783
+ this.elementId = elementId
2784
+ const DEFAULTS = {
2785
+ 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>`,
2786
+ 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>`
2787
+ }
2788
+ this.options = Object.assign({}, DEFAULTS, options)
2789
+ this.formData = []
2790
+ this.forms = []
2791
+ this.recordsToDelete = []
2792
+ const el = document.getElementById(elementId)
2793
+ if (el) {
2794
+ el.addEventListener('click', this.handleClick.bind(this))
2795
+ el.innerHTML = `<div id='${elementId}_container' class='websy-multi-form-container'></div>`
2796
+ }
2797
+ this.render()
2798
+ }
2799
+ addEntry () {
2800
+ const el = document.getElementById(`${this.elementId}_container`)
2801
+ let newId = WebsyDesigns.Utils.createIdentity()
2802
+ const newFormEl = document.createElement('div')
2803
+ newFormEl.id = `${this.elementId}_${newId}_formContainer`
2804
+ newFormEl.classList.add('websy-multi-form-form-container')
2805
+ newFormEl.innerHTML = `
2806
+ <div id='${this.elementId}_${newId}_form' class='websy-multi-form-form'>
2807
+ </div>
2808
+ <button id='${this.elementId}_${newId}_deleteButton' data-formid='${newId}' class='hidden websy-multi-form-delete'>
2809
+ ${this.options.deleteButton}
2810
+ </button>
2811
+ <button id='${this.elementId}_${newId}_addButton' data-formid='${newId}' class='websy-multi-form-add'>
2812
+ ${this.options.addButton}
2813
+ </button>
2814
+ `
2815
+ el.appendChild(newFormEl)
2816
+ let formOptions = Object.assign({}, this.options)
2817
+ this.forms.push(new WebsyDesigns.Form(`${this.elementId}_${newId}_form`, formOptions))
2818
+ }
2819
+ clear () {
2820
+ this.formData = []
2821
+ this.forms = []
2822
+ this.recordsToDelete = []
2823
+ const el = document.getElementById(`${this.elementId}_container`)
2824
+ if (el) {
2825
+ el.innerHTML = ''
2826
+ }
2827
+ }
2828
+ get data () {
2829
+ const d = this.forms.map(f => (f.data))
2830
+ // we don't return the last form
2831
+ d.pop()
2832
+ return d
2833
+ }
2834
+ set data (d) {
2835
+ this.formData = d
2836
+ this.render()
2837
+ }
2838
+ handleClick (event) {
2839
+ if (event.target.classList.contains('websy-multi-form-add')) {
2840
+ let id = event.target.getAttribute('data-formid')
2841
+ // hide add button and show delete button
2842
+ const addButtonEl = document.getElementById(`${this.elementId}_${id}_addButton`)
2843
+ if (addButtonEl) {
2844
+ addButtonEl.classList.add('hidden')
2845
+ }
2846
+ const deleteButtonEl = document.getElementById(`${this.elementId}_${id}_deleteButton`)
2847
+ if (deleteButtonEl) {
2848
+ deleteButtonEl.classList.remove('hidden')
2849
+ }
2850
+ // add new form
2851
+ this.addEntry()
2852
+ }
2853
+ if (event.target.classList.contains('websy-multi-form-delete')) {
2854
+ // delete form based on index
2855
+ let id = event.target.getAttribute('data-formid')
2856
+ let rowId = event.target.getAttribute('data-rowid')
2857
+ this.recordsToDelete.push(rowId)
2858
+ let indexToDelete = -1
2859
+ for (let i = 0; i < this.forms.length; i++) {
2860
+ if (this.forms[i].elementId === `${this.elementId}_${id}_form`) {
2861
+ indexToDelete = i
2862
+ break
2863
+ }
2864
+ }
2865
+ if (indexToDelete !== -1) {
2866
+ this.forms.splice(indexToDelete, 1)
2867
+ }
2868
+ const el = document.getElementById(`${this.elementId}_${id}_formContainer`)
2869
+ if (el) {
2870
+ el.remove()
2871
+ }
2872
+ // delete form element based on id
2873
+ }
2874
+ }
2875
+ render () {
2876
+ this.forms = []
2877
+ this.recordsToDelete = []
2878
+ const el = document.getElementById(`${this.elementId}_container`)
2879
+ if (el) {
2880
+ let html = ''
2881
+ this.formData.forEach(d => {
2882
+ d.formId = WebsyDesigns.Utils.createIdentity()
2883
+ html += `
2884
+ <div id='${this.elementId}_${d.formId}_formContainer' class='websy-multi-form-form-container'>
2885
+ <div id='${this.elementId}_${d.formId}_form' class='websy-multi-form-form'>
2886
+ </div>
2887
+ <button id='${this.elementId}_${d.formId}_deleteButton' data-formid='${d.formId}' data-rowid='${d.id}' class='websy-multi-form-delete'>
2888
+ ${this.options.deleteButton}
2889
+ </button>
2890
+ </div>
2891
+ `
2892
+ })
2893
+ let id = WebsyDesigns.Utils.createIdentity()
2894
+ html += `
2895
+ <div id='${this.elementId}_${id}_formContainer' class='websy-multi-form-form-container'>
2896
+ <div id='${this.elementId}_${id}_form' class='websy-multi-form-form'>
2897
+ </div>
2898
+ <button id='${this.elementId}_${id}_deleteButton' data-formid='${id}' class='hidden websy-multi-form-delete'>
2899
+ ${this.options.deleteButton}
2900
+ </button>
2901
+ <button id='${this.elementId}_${id}_addButton' data-formid='${id}' class='websy-multi-form-add'>
2902
+ ${this.options.addButton}
2903
+ </button>
2904
+ </div>
2905
+ `
2906
+ el.innerHTML = html
2907
+ this.formData.forEach(d => {
2908
+ let formOptions = Object.assign({}, this.options)
2909
+ let formObject = new WebsyDesigns.Form(`${this.elementId}_${d.formId}_form`, formOptions)
2910
+ formObject.data = d
2911
+ this.forms.push(formObject)
2912
+ })
2913
+ let formOptions = Object.assign({}, this.options)
2914
+ this.forms.push(new WebsyDesigns.Form(`${this.elementId}_${id}_form`, formOptions))
2915
+ }
2916
+ }
2917
+ validateForm () {
2918
+ // we don't validate the last form
2919
+ for (let i = 0; i < this.forms.length - 1; i++) {
2920
+ let valid = this.forms[i].validateForm()
2921
+ if (!valid) {
2922
+ return false
2923
+ }
2924
+ }
2925
+ return true
2926
+ }
2927
+ }
2928
+
2760
2929
  /* global include */
2761
2930
  const WebsyIcons = {
2762
2931
  'search-icon': `
@@ -4276,7 +4445,11 @@ class WebsyResultList {
4276
4445
  }
4277
4446
  render () {
4278
4447
  if (this.options.entity) {
4279
- this.apiService.get(this.options.entity).then(results => {
4448
+ let url = this.options.entity
4449
+ if (this.options.sortField) {
4450
+ url += (url.indexOf('?') === -1 ? '?' : '&') + `by=${this.options.sortField}&order=${this.options.sortOrder || 'ASC'}`
4451
+ }
4452
+ this.apiService.get(url).then(results => {
4280
4453
  this.rows = results.rows
4281
4454
  this.resize()
4282
4455
  })
@@ -6557,7 +6730,7 @@ class WebsyTable3 {
6557
6730
  <div id="${this.elementId}_errorMessage"></div>
6558
6731
  </div>
6559
6732
  </div>
6560
- <div id="${this.elementId}_dropdownContainer" class="table-dropdown-container"></div>
6733
+ <div id="${this.elementId}_dropdownContainerx" class="table-dropdown-container"></div>
6561
6734
  <div id="${this.elementId}_loadingContainer"></div>
6562
6735
  </div>
6563
6736
  <div id="${this.elementId}_vScrollContainer" class="websy-v-scroll-container" style="width: ${this.options.isTouchDevice ? this.options.touchScrollWidth : this.options.scrollWidth}px;">
@@ -6576,6 +6749,16 @@ class WebsyTable3 {
6576
6749
  `
6577
6750
  }
6578
6751
  el.innerHTML = html
6752
+ const dropdownContainerEl = document.getElementById(`${this.elementId}_dropdownContainer`)
6753
+ if (dropdownContainerEl) {
6754
+ dropdownContainerEl.innerHTML = ''
6755
+ }
6756
+ else {
6757
+ const div = document.createElement('div')
6758
+ div.id = `${this.elementId}_dropdownContainer`
6759
+ div.classList.add('table-dropdown-container')
6760
+ document.body.appendChild(div)
6761
+ }
6579
6762
  el.addEventListener('click', this.handleClick.bind(this))
6580
6763
  el.addEventListener('mousedown', this.handleMouseDown.bind(this))
6581
6764
  el.addEventListener('touchstart', this.handleTouchStart.bind(this))
@@ -6675,7 +6858,7 @@ class WebsyTable3 {
6675
6858
  bodyHtml += `<td
6676
6859
  class='websy-table-cell ${sizeIndex < this.pinnedColumns ? 'pinned' : 'unpinned'} ${(cell.classes || []).join(' ')} ${(sizingColumns[sizeIndex].classes || []).join(' ')}'
6677
6860
  style='${style}'
6678
- data-info='${cell.value.replace(/'/g, '`')}'
6861
+ data-info='${cell.value.replace ? cell.value.replace(/'/g, '`') : cell.value}'
6679
6862
  colspan='${cell.colspan || 1}'
6680
6863
  rowspan='${cell.rowspan || 1}'
6681
6864
  data-row-index='${rowIndex}'
@@ -7474,6 +7657,10 @@ class WebsyTable3 {
7474
7657
  if (this.endCol === this.options.allColumns[this.options.allColumns.length - 1].length - 1 && cumulativeWidth > this.sizes.scrollableWidth && actualLeft > 0) {
7475
7658
  this.startCol += 1
7476
7659
  }
7660
+ if (scrollHandleEl.offsetWidth + scrollHandleEl.offsetLeft >= scrollContainerEl.offsetWidth) {
7661
+ this.startCol += 1
7662
+ this.endCol += 1
7663
+ }
7477
7664
  this.endCol = Math.max(this.startCol, this.endCol)
7478
7665
  this.options.onScroll('y', this.startRow, this.endRow, this.startCol - this.pinnedColumns, this.endCol - this.pinnedColumns)
7479
7666
  }
@@ -7563,6 +7750,7 @@ class WebsyChart {
7563
7750
  minBandWidth: 30,
7564
7751
  maxBandWidth: 100,
7565
7752
  allowUnevenBands: true,
7753
+ allowBrushing: true,
7566
7754
  balancedMinMax: false
7567
7755
  }
7568
7756
  this.elementId = elementId
@@ -8324,7 +8512,7 @@ else {
8324
8512
  maxBandWidthFits = true
8325
8513
  proposedBandWidth = this.options.maxBandWidth
8326
8514
  }
8327
- if (!maxBandWidthFits) {
8515
+ if (!maxBandWidthFits && this.options.allowBrushing === true) {
8328
8516
  // Check to see if all bars at the min allowed width will fit
8329
8517
  if (plotable / noOfPoints < this.options.minBandWidth) {
8330
8518
  this.brushNeeded = true
@@ -8527,6 +8715,9 @@ else {
8527
8715
  else {
8528
8716
  leftRange = [(this.widthForCalc + this.totalBandPadding), 0]
8529
8717
  }
8718
+ if (this.options.allowBrushing !== true) {
8719
+ bottomRange = bottomBrushRange
8720
+ }
8530
8721
  this.bottomAxis = d3[`scale${this.options.data.bottom.scale || 'Ordinal'}`]()
8531
8722
  .domain(bottomDomain)
8532
8723
  .range(bottomRange)
@@ -10628,6 +10819,7 @@ const WebsyDesigns = {
10628
10819
  NavigationMenu: WebsyNavigationMenu,
10629
10820
  WebsyForm,
10630
10821
  Form: WebsyForm,
10822
+ MultiForm,
10631
10823
  WebsyDatePicker,
10632
10824
  DatePicker: WebsyDatePicker,
10633
10825
  WebsyDropdown,