@websy/websy-designs 1.6.3 → 1.7.1
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.
- package/dist/server/helpers/v1/authHelper.js +3 -2
- package/dist/websy-designs-es6.debug.js +299 -109
- package/dist/websy-designs-es6.js +632 -378
- package/dist/websy-designs-es6.min.js +1 -1
- package/dist/websy-designs.debug.js +299 -109
- package/dist/websy-designs.js +637 -383
- package/dist/websy-designs.min.css +1 -1
- package/dist/websy-designs.min.js +1 -1
- package/package.json +1 -1
|
@@ -1784,7 +1784,13 @@ class WebsyDropdown {
|
|
|
1784
1784
|
}
|
|
1785
1785
|
this.updateHeader(item)
|
|
1786
1786
|
}
|
|
1787
|
-
|
|
1787
|
+
get value () {
|
|
1788
|
+
if (this.selectedItems && this.selectedItems.length > 0) {
|
|
1789
|
+
return this.selectedItems.map((d, i) => this.options.items[+d])
|
|
1790
|
+
}
|
|
1791
|
+
return []
|
|
1792
|
+
}
|
|
1793
|
+
set value (value) {
|
|
1788
1794
|
this.selectedItems = []
|
|
1789
1795
|
if (Array.isArray(value)) {
|
|
1790
1796
|
this.options.items.forEach(d => {
|
|
@@ -1896,6 +1902,9 @@ class WebsyDropdown {
|
|
|
1896
1902
|
if (item && this.options.onItemSelected) {
|
|
1897
1903
|
this.options.onItemSelected(item, this.selectedItems, dataToUse, this.options)
|
|
1898
1904
|
}
|
|
1905
|
+
if (this.options.onChange) {
|
|
1906
|
+
this.options.onChange(this)
|
|
1907
|
+
}
|
|
1899
1908
|
if (this.options.closeAfterSelection === true) {
|
|
1900
1909
|
this.close()
|
|
1901
1910
|
}
|
|
@@ -2209,7 +2218,9 @@ class WebsyForm {
|
|
|
2209
2218
|
// if (this.options.classes) {
|
|
2210
2219
|
// this.options.classes.forEach(c => el.classList.add(c))
|
|
2211
2220
|
// }
|
|
2221
|
+
el.addEventListener('change', this.handleChange.bind(this))
|
|
2212
2222
|
el.addEventListener('click', this.handleClick.bind(this))
|
|
2223
|
+
el.addEventListener('focusout', this.handleFocusOut.bind(this))
|
|
2213
2224
|
el.addEventListener('keyup', this.handleKeyUp.bind(this))
|
|
2214
2225
|
el.addEventListener('keydown', this.handleKeyDown.bind(this))
|
|
2215
2226
|
this.render()
|
|
@@ -2265,15 +2276,18 @@ class WebsyForm {
|
|
|
2265
2276
|
this.options.fields = []
|
|
2266
2277
|
}
|
|
2267
2278
|
for (let key in d) {
|
|
2268
|
-
this.options.fields.forEach(f => {
|
|
2279
|
+
this.options.fields.forEach(f => {
|
|
2269
2280
|
if (f.field === key) {
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2281
|
+
this.setValue(key, d[key])
|
|
2282
|
+
// f.value = d[key]
|
|
2283
|
+
// const el = document.getElementById(`${this.elementId}_input_${f.field}`)
|
|
2284
|
+
// if (el) {
|
|
2285
|
+
// el.value = f.value
|
|
2286
|
+
// }
|
|
2273
2287
|
}
|
|
2274
2288
|
})
|
|
2275
2289
|
}
|
|
2276
|
-
this.render()
|
|
2290
|
+
// this.render()
|
|
2277
2291
|
}
|
|
2278
2292
|
confirmValidation () {
|
|
2279
2293
|
const el = document.getElementById(`${this.elementId}_validationFail`)
|
|
@@ -2287,6 +2301,20 @@ class WebsyForm {
|
|
|
2287
2301
|
el.innerHTML = msg
|
|
2288
2302
|
}
|
|
2289
2303
|
}
|
|
2304
|
+
handleChange (event) {
|
|
2305
|
+
if (event.target.getAttribute('data-user-type') === 'expiry') {
|
|
2306
|
+
if (event.target.value.length === 7) {
|
|
2307
|
+
let value = event.target.value.split('/')
|
|
2308
|
+
event.target.value = `${value[0]}/${value[1].substring(2, 4)}`
|
|
2309
|
+
}
|
|
2310
|
+
}
|
|
2311
|
+
if (event.target.classList.contains('websy-input')) {
|
|
2312
|
+
let index = event.target.getAttribute('data-index')
|
|
2313
|
+
if (this.options.fields[index] && (this.options.fields[index].required || this.options.fields[index].validate)) {
|
|
2314
|
+
this.validateField(this.options.fields[index], event.target.value)
|
|
2315
|
+
}
|
|
2316
|
+
}
|
|
2317
|
+
}
|
|
2290
2318
|
handleClick (event) {
|
|
2291
2319
|
if (event.target.classList.contains('submit')) {
|
|
2292
2320
|
event.preventDefault()
|
|
@@ -2297,13 +2325,68 @@ class WebsyForm {
|
|
|
2297
2325
|
this.cancelForm()
|
|
2298
2326
|
}
|
|
2299
2327
|
}
|
|
2328
|
+
handleFocusOut (event) {
|
|
2329
|
+
if (event.target.classList.contains('websy-input')) {
|
|
2330
|
+
let index = event.target.getAttribute('data-index')
|
|
2331
|
+
if (this.options.fields[index] && (this.options.fields[index].required || this.options.fields[index].validate)) {
|
|
2332
|
+
this.validateField(this.options.fields[index], event.target.value)
|
|
2333
|
+
}
|
|
2334
|
+
}
|
|
2335
|
+
}
|
|
2300
2336
|
handleKeyDown (event) {
|
|
2301
2337
|
if (event.key === 'enter') {
|
|
2302
2338
|
this.submitForm()
|
|
2303
2339
|
}
|
|
2340
|
+
if (event.target.getAttribute('data-user-type') === 'expiry') {
|
|
2341
|
+
let isNumeric = !isNaN(event.key)
|
|
2342
|
+
let validKey = false
|
|
2343
|
+
if (!validKey) {
|
|
2344
|
+
validKey = ['ArrowLeft', 'ArrowRight', 'Backspace', 'Delete', 'Tab'].indexOf(event.key) !== -1
|
|
2345
|
+
}
|
|
2346
|
+
if ((event.target.value.length === 5 && !validKey) || (!validKey && !isNumeric)) {
|
|
2347
|
+
event.preventDefault()
|
|
2348
|
+
return false
|
|
2349
|
+
}
|
|
2350
|
+
if (event.key === 'Backspace') {
|
|
2351
|
+
if (event.target.value.indexOf('/') === event.target.selectionStart - 1) {
|
|
2352
|
+
let chars = event.target.value.split('')
|
|
2353
|
+
chars.pop()
|
|
2354
|
+
event.target.value = chars.join('')
|
|
2355
|
+
}
|
|
2356
|
+
}
|
|
2357
|
+
}
|
|
2358
|
+
if (event.target.getAttribute('data-user-type') === 'cvv') {
|
|
2359
|
+
let isNumeric = !isNaN(event.key)
|
|
2360
|
+
let validKey = false
|
|
2361
|
+
if (!validKey) {
|
|
2362
|
+
validKey = ['ArrowLeft', 'ArrowRight', 'Backspace', 'Delete', 'Tab'].indexOf(event.key) !== -1
|
|
2363
|
+
}
|
|
2364
|
+
if ((event.target.value.length === 3 && !validKey) || (!validKey && !isNumeric)) {
|
|
2365
|
+
event.preventDefault()
|
|
2366
|
+
return false
|
|
2367
|
+
}
|
|
2368
|
+
}
|
|
2304
2369
|
}
|
|
2305
2370
|
handleKeyUp (event) {
|
|
2306
|
-
|
|
2371
|
+
if (event.target.getAttribute('data-user-type') === 'expiry') {
|
|
2372
|
+
let chars = event.target.value.split('')
|
|
2373
|
+
let isNumeric = !isNaN(event.key)
|
|
2374
|
+
if (event.key === 'Backspace') {
|
|
2375
|
+
if (chars[chars.length - 1] === '/' && chars.length !== 3) {
|
|
2376
|
+
chars.pop()
|
|
2377
|
+
event.target.value = chars.join('')
|
|
2378
|
+
return
|
|
2379
|
+
}
|
|
2380
|
+
}
|
|
2381
|
+
if (event.target.selectionStart === 2) {
|
|
2382
|
+
if (chars[2] && ['ArrowLeft', 'ArrowRight', 'Backspace', 'Delete'].indexOf(event.key) === -1) {
|
|
2383
|
+
event.target.setSelectionRange(3, 3)
|
|
2384
|
+
}
|
|
2385
|
+
else if (isNumeric) {
|
|
2386
|
+
event.target.value += '/'
|
|
2387
|
+
}
|
|
2388
|
+
}
|
|
2389
|
+
}
|
|
2307
2390
|
}
|
|
2308
2391
|
processComponents (components, callbackFn) {
|
|
2309
2392
|
if (components.length === 0) {
|
|
@@ -2312,6 +2395,13 @@ class WebsyForm {
|
|
|
2312
2395
|
else {
|
|
2313
2396
|
components.forEach(c => {
|
|
2314
2397
|
if (typeof WebsyDesigns[c.component] !== 'undefined') {
|
|
2398
|
+
if (!c.options.onChange) {
|
|
2399
|
+
c.options.onChange = () => {
|
|
2400
|
+
if (c.required || c.validate) {
|
|
2401
|
+
this.validateField(c, c.instance.value)
|
|
2402
|
+
}
|
|
2403
|
+
}
|
|
2404
|
+
}
|
|
2315
2405
|
c.instance = new WebsyDesigns[c.component](`${this.elementId}_input_${c.field}_component`, c.options)
|
|
2316
2406
|
}
|
|
2317
2407
|
else {
|
|
@@ -2343,35 +2433,41 @@ class WebsyForm {
|
|
|
2343
2433
|
if (f.component) {
|
|
2344
2434
|
componentsToProcess.push(f)
|
|
2345
2435
|
html += `
|
|
2346
|
-
${i > 0 ? '-->' : ''}<div class='${f.classes
|
|
2347
|
-
${f.label ? `<label for="${f.field}">${f.label}</label>` : ''}
|
|
2436
|
+
${i > 0 ? '-->' : ''}<div id='${this.elementId}_${f.field}_inputContainer' class='websy-input-container ${f.classes ? f.classes.join(' ') : ''}'>
|
|
2437
|
+
${f.label ? `<label for="${f.field}">${f.label}</label>` : ''}${f.required === true ? '<span class="websy-form-required-value">*</span>' : ''}
|
|
2348
2438
|
<div id='${this.elementId}_input_${f.field}_component' class='form-component'></div>
|
|
2439
|
+
<span id='${this.elementId}_${f.field}_error' class='websy-form-validation-error'></span>
|
|
2349
2440
|
</div><!--
|
|
2350
2441
|
`
|
|
2351
2442
|
}
|
|
2352
2443
|
else if (f.type === 'longtext') {
|
|
2353
2444
|
html += `
|
|
2354
|
-
${i > 0 ? '-->' : ''}<div class='${f.classes
|
|
2355
|
-
${f.label ? `<label for="${f.field}">${f.label}</label>` : ''}
|
|
2445
|
+
${i > 0 ? '-->' : ''}<div id='${this.elementId}_${f.field}_inputContainer' class='websy-input-container ${f.classes ? f.classes.join(' ') : ''}'>
|
|
2446
|
+
${f.label ? `<label for="${f.field}">${f.label}</label>` : ''}${f.required === true ? '<span class="websy-form-required-value">*</span>' : ''}
|
|
2356
2447
|
<textarea
|
|
2357
2448
|
id="${this.elementId}_input_${f.field}"
|
|
2358
2449
|
${f.required === true ? 'required' : ''}
|
|
2359
2450
|
placeholder="${f.placeholder || ''}"
|
|
2451
|
+
data-user-type="${f.type}"
|
|
2452
|
+
data-index="${i}"
|
|
2360
2453
|
name="${f.field}"
|
|
2361
2454
|
${(f.attributes || []).join(' ')}
|
|
2362
2455
|
class="websy-input websy-textarea"
|
|
2363
2456
|
></textarea>
|
|
2457
|
+
<span id='${this.elementId}_${f.field}_error' class='websy-form-validation-error'></span>
|
|
2364
2458
|
</div><!--
|
|
2365
2459
|
`
|
|
2366
2460
|
}
|
|
2367
2461
|
else {
|
|
2368
2462
|
html += `
|
|
2369
|
-
${i > 0 ? '-->' : ''}<div class='${f.classes
|
|
2370
|
-
${f.label ? `<label for="${f.field}">${f.label}</label>` : ''}
|
|
2463
|
+
${i > 0 ? '-->' : ''}<div id='${this.elementId}_${f.field}_inputContainer' class='websy-input-container ${f.classes ? f.classes.join(' ') : ''}'>
|
|
2464
|
+
${f.label ? `<label for="${f.field}">${f.label}</label>` : ''}${f.required === true ? '<span class="websy-form-required-value">*</span>' : ''}
|
|
2371
2465
|
<input
|
|
2372
2466
|
id="${this.elementId}_input_${f.field}"
|
|
2373
2467
|
${f.required === true ? 'required' : ''}
|
|
2374
|
-
type="${f.type || 'text'}"
|
|
2468
|
+
type="${(f.type === 'expiry' ? 'text' : f.type === 'cvv' ? 'number' : f.type) || 'text'}"
|
|
2469
|
+
data-user-type="${f.type}"
|
|
2470
|
+
data-index="${i}"
|
|
2375
2471
|
class="websy-input"
|
|
2376
2472
|
${(f.attributes || []).join(' ')}
|
|
2377
2473
|
name="${f.field}"
|
|
@@ -2380,6 +2476,7 @@ class WebsyForm {
|
|
|
2380
2476
|
valueAsDate="${f.type === 'date' ? f.value : ''}"
|
|
2381
2477
|
oninvalidx="this.setCustomValidity('${f.invalidMessage || 'Please fill in this field.'}')"
|
|
2382
2478
|
/>
|
|
2479
|
+
<span id='${this.elementId}_${f.field}_error' class='websy-form-validation-error'></span>
|
|
2383
2480
|
</div><!--
|
|
2384
2481
|
`
|
|
2385
2482
|
}
|
|
@@ -2391,11 +2488,11 @@ class WebsyForm {
|
|
|
2391
2488
|
`
|
|
2392
2489
|
}
|
|
2393
2490
|
html += `
|
|
2394
|
-
--><button class="websy-btn submit ${this.options.submit.classes
|
|
2491
|
+
--><button class="websy-btn submit ${this.options.submit.classes ? this.options.submit.classes.join(' ') : ''}">${this.options.submit.text || 'Save'}</button>${this.options.cancel ? '<!--' : ''}
|
|
2395
2492
|
`
|
|
2396
2493
|
if (this.options.cancel) {
|
|
2397
2494
|
html += `
|
|
2398
|
-
--><button class="websy-btn cancel ${this.options.cancel.classes
|
|
2495
|
+
--><button class="websy-btn cancel ${this.options.cancel.classes ? this.options.cancel.classes.join(' ') : ''}">${this.options.cancel.text || 'Cancel'}</button>
|
|
2399
2496
|
`
|
|
2400
2497
|
}
|
|
2401
2498
|
html += `
|
|
@@ -2413,7 +2510,7 @@ class WebsyForm {
|
|
|
2413
2510
|
setValue (field, value) {
|
|
2414
2511
|
if (this.fieldMap[field]) {
|
|
2415
2512
|
if (this.fieldMap[field].instance) {
|
|
2416
|
-
this.fieldMap[field].instance.
|
|
2513
|
+
this.fieldMap[field].instance.value = value
|
|
2417
2514
|
}
|
|
2418
2515
|
else {
|
|
2419
2516
|
const el = document.getElementById(`${this.elementId}_input_${field}`)
|
|
@@ -2433,7 +2530,10 @@ class WebsyForm {
|
|
|
2433
2530
|
const formEl = document.getElementById(`${this.elementId}Form`)
|
|
2434
2531
|
const buttonEl = formEl.querySelector('button.websy-btn.submit')
|
|
2435
2532
|
const recaptchErrEl = document.getElementById(`${this.elementId}_recaptchaError`)
|
|
2436
|
-
if (
|
|
2533
|
+
if (this.options.preSubmitFn && this.options.preSubmitFn() === false) {
|
|
2534
|
+
return
|
|
2535
|
+
}
|
|
2536
|
+
if (this.validateForm() === true) {
|
|
2437
2537
|
if (buttonEl) {
|
|
2438
2538
|
buttonEl.setAttribute('disabled', true)
|
|
2439
2539
|
}
|
|
@@ -2491,6 +2591,59 @@ class WebsyForm {
|
|
|
2491
2591
|
})
|
|
2492
2592
|
}
|
|
2493
2593
|
}
|
|
2594
|
+
validateForm () {
|
|
2595
|
+
let valid = true
|
|
2596
|
+
let data = this.data
|
|
2597
|
+
for (let i = 0; i < this.options.fields.length; i++) {
|
|
2598
|
+
if (this.options.fields[i].required || this.options.fields[i].validate) {
|
|
2599
|
+
if (this.validateField(this.options.fields[i], data[this.options.fields[i].field]) === false) {
|
|
2600
|
+
valid = false
|
|
2601
|
+
}
|
|
2602
|
+
}
|
|
2603
|
+
}
|
|
2604
|
+
return valid
|
|
2605
|
+
}
|
|
2606
|
+
validateField (field, value) {
|
|
2607
|
+
const inputContainerEl = document.getElementById(`${this.elementId}_${field.field}_inputContainer`)
|
|
2608
|
+
const errorEl = document.getElementById(`${this.elementId}_${field.field}_error`)
|
|
2609
|
+
if (field.required) {
|
|
2610
|
+
let valid = true
|
|
2611
|
+
if (field.component && field.instance && field.instance.value) {
|
|
2612
|
+
valid = field.instance.value.length > 0
|
|
2613
|
+
}
|
|
2614
|
+
else {
|
|
2615
|
+
valid = !(typeof value === 'undefined' || value === '')
|
|
2616
|
+
}
|
|
2617
|
+
if (!valid) {
|
|
2618
|
+
if (errorEl) {
|
|
2619
|
+
errorEl.innerHTML = field.invalidMessage || 'A value is required'
|
|
2620
|
+
}
|
|
2621
|
+
if (inputContainerEl) {
|
|
2622
|
+
inputContainerEl.classList.add('websy-form-input-has-error')
|
|
2623
|
+
}
|
|
2624
|
+
return false
|
|
2625
|
+
}
|
|
2626
|
+
}
|
|
2627
|
+
if (field.validate) {
|
|
2628
|
+
let valid = field.validate(field, value)
|
|
2629
|
+
if (!valid) {
|
|
2630
|
+
if (errorEl) {
|
|
2631
|
+
errorEl.innerHTML = field.invalidMessage || 'A value is required'
|
|
2632
|
+
}
|
|
2633
|
+
if (inputContainerEl) {
|
|
2634
|
+
inputContainerEl.classList.add('websy-form-input-has-error')
|
|
2635
|
+
}
|
|
2636
|
+
return false
|
|
2637
|
+
}
|
|
2638
|
+
}
|
|
2639
|
+
if (errorEl) {
|
|
2640
|
+
errorEl.innerHTML = ''
|
|
2641
|
+
}
|
|
2642
|
+
if (inputContainerEl) {
|
|
2643
|
+
inputContainerEl.classList.remove('websy-form-input-has-error')
|
|
2644
|
+
}
|
|
2645
|
+
return true
|
|
2646
|
+
}
|
|
2494
2647
|
validateRecaptcha (token) {
|
|
2495
2648
|
this.recaptchaValue = token
|
|
2496
2649
|
}
|
|
@@ -2683,24 +2836,26 @@ class WebsyLoadingDialog {
|
|
|
2683
2836
|
return
|
|
2684
2837
|
}
|
|
2685
2838
|
const el = document.getElementById(this.elementId)
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
|
|
2839
|
+
if (el) {
|
|
2840
|
+
let html = `
|
|
2841
|
+
<div class='websy-loading-container ${(this.options.classes || []).join(' ')}'>
|
|
2842
|
+
<div class='websy-ripple'>
|
|
2843
|
+
<div></div>
|
|
2844
|
+
<div></div>
|
|
2845
|
+
</div>
|
|
2846
|
+
<h4>${this.options.title || 'Loading...'}</h4>
|
|
2847
|
+
`
|
|
2848
|
+
if (this.options.messages) {
|
|
2849
|
+
for (let i = 0; i < this.options.messages.length; i++) {
|
|
2850
|
+
html += `<p>${this.options.messages[i]}</p>`
|
|
2851
|
+
}
|
|
2852
|
+
}
|
|
2853
|
+
html += `
|
|
2854
|
+
</div>
|
|
2855
|
+
`
|
|
2856
|
+
el.classList.add('loading')
|
|
2857
|
+
el.innerHTML = html
|
|
2858
|
+
}
|
|
2704
2859
|
}
|
|
2705
2860
|
show (options, override = false) {
|
|
2706
2861
|
if (options) {
|
|
@@ -4115,6 +4270,7 @@ class WebsyRouter {
|
|
|
4115
4270
|
output.items = Object.assign({}, params)
|
|
4116
4271
|
path = this.buildUrlPath(output.items)
|
|
4117
4272
|
}
|
|
4273
|
+
output.path = path
|
|
4118
4274
|
this.currentParams = output
|
|
4119
4275
|
let inputPath = this.currentView
|
|
4120
4276
|
if (this.options.urlPrefix) {
|
|
@@ -4127,13 +4283,13 @@ class WebsyRouter {
|
|
|
4127
4283
|
// this.showView(this.currentView, this.currentParams, 'main')
|
|
4128
4284
|
this.navigate(`${inputPath}?${path}`, 'main', null, noHistory)
|
|
4129
4285
|
}
|
|
4286
|
+
else {
|
|
4287
|
+
this.updateHistory(inputPath, !noHistory, true)
|
|
4288
|
+
}
|
|
4130
4289
|
}
|
|
4131
4290
|
removeUrlParams (params = [], reloadView = false, noHistory = true) {
|
|
4132
4291
|
this.previousParams = Object.assign({}, this.currentParams)
|
|
4133
|
-
|
|
4134
|
-
path: '',
|
|
4135
|
-
items: {}
|
|
4136
|
-
}
|
|
4292
|
+
|
|
4137
4293
|
let path = ''
|
|
4138
4294
|
if (this.currentParams && this.currentParams.items) {
|
|
4139
4295
|
params.forEach(p => {
|
|
@@ -4149,6 +4305,13 @@ class WebsyRouter {
|
|
|
4149
4305
|
// this.showView(this.currentView, this.currentParams, 'main')
|
|
4150
4306
|
this.navigate(`${inputPath}?${path}`, 'main', null, noHistory)
|
|
4151
4307
|
}
|
|
4308
|
+
else if (noHistory === false) {
|
|
4309
|
+
this.currentParams = {
|
|
4310
|
+
items: this.currentParams.items,
|
|
4311
|
+
path
|
|
4312
|
+
}
|
|
4313
|
+
this.updateHistory(inputPath, !noHistory, true)
|
|
4314
|
+
}
|
|
4152
4315
|
}
|
|
4153
4316
|
removeAllUrlParams (reloadView = false, noHistory = true) {
|
|
4154
4317
|
// const output = {
|
|
@@ -4163,14 +4326,12 @@ class WebsyRouter {
|
|
|
4163
4326
|
this.currentParams = {
|
|
4164
4327
|
path: '',
|
|
4165
4328
|
items: {}
|
|
4166
|
-
}
|
|
4329
|
+
}
|
|
4167
4330
|
if (reloadView === true) {
|
|
4168
4331
|
this.navigate(`${inputPath}`, 'main', null, noHistory)
|
|
4169
4332
|
}
|
|
4170
4333
|
else {
|
|
4171
|
-
|
|
4172
|
-
inputPath
|
|
4173
|
-
}, 'unused', inputPath)
|
|
4334
|
+
this.updateHistory(inputPath, !noHistory, true)
|
|
4174
4335
|
}
|
|
4175
4336
|
}
|
|
4176
4337
|
buildUrlPath (params) {
|
|
@@ -4572,28 +4733,7 @@ class WebsyRouter {
|
|
|
4572
4733
|
}
|
|
4573
4734
|
if ((this.currentPath !== inputPath || previousParamsPath !== this.currentParams.path) && group === this.options.defaultGroup) {
|
|
4574
4735
|
let historyUrl = inputPath
|
|
4575
|
-
|
|
4576
|
-
historyUrl = historyUrl === '/' ? '' : `/${historyUrl}`
|
|
4577
|
-
inputPath = inputPath === '/' ? '' : `/${inputPath}`
|
|
4578
|
-
historyUrl = (`/${this.options.urlPrefix}${historyUrl}`).replace(/\/\//g, '/')
|
|
4579
|
-
inputPath = (`/${this.options.urlPrefix}${inputPath}`).replace(/\/\//g, '/')
|
|
4580
|
-
}
|
|
4581
|
-
if (this.currentParams && this.currentParams.path) {
|
|
4582
|
-
historyUrl += `?${this.currentParams.path}`
|
|
4583
|
-
}
|
|
4584
|
-
else if (this.queryParams && this.options.persistentParameters === true) {
|
|
4585
|
-
historyUrl += `?${this.queryParams}`
|
|
4586
|
-
}
|
|
4587
|
-
if (popped === false) {
|
|
4588
|
-
history.pushState({
|
|
4589
|
-
inputPath: historyUrl
|
|
4590
|
-
}, 'unused', historyUrl)
|
|
4591
|
-
}
|
|
4592
|
-
else {
|
|
4593
|
-
history.replaceState({
|
|
4594
|
-
inputPath: historyUrl
|
|
4595
|
-
}, 'unused', historyUrl)
|
|
4596
|
-
}
|
|
4736
|
+
this.updateHistory(historyUrl, popped)
|
|
4597
4737
|
}
|
|
4598
4738
|
if (toggle === false) {
|
|
4599
4739
|
this.showView(newPath.split('?')[0], this.currentParams, group)
|
|
@@ -4628,6 +4768,28 @@ class WebsyRouter {
|
|
|
4628
4768
|
item.apply(null, params)
|
|
4629
4769
|
})
|
|
4630
4770
|
}
|
|
4771
|
+
updateHistory (historyUrl, replaceState = false, overridePersistent = false) {
|
|
4772
|
+
if (this.options.urlPrefix) {
|
|
4773
|
+
historyUrl = historyUrl === '/' ? '' : `/${historyUrl}`
|
|
4774
|
+
historyUrl = (`/${this.options.urlPrefix}${historyUrl}`).replace(/\/\//g, '/')
|
|
4775
|
+
}
|
|
4776
|
+
if ((this.currentParams && this.currentParams.path) || overridePersistent === true) {
|
|
4777
|
+
historyUrl += `?${this.currentParams.path}`
|
|
4778
|
+
}
|
|
4779
|
+
else if (this.queryParams && this.options.persistentParameters === true) {
|
|
4780
|
+
historyUrl += `?${this.queryParams}`
|
|
4781
|
+
}
|
|
4782
|
+
if (replaceState === false) {
|
|
4783
|
+
history.pushState({
|
|
4784
|
+
inputPath: historyUrl
|
|
4785
|
+
}, 'unused', historyUrl)
|
|
4786
|
+
}
|
|
4787
|
+
else {
|
|
4788
|
+
history.replaceState({
|
|
4789
|
+
inputPath: historyUrl
|
|
4790
|
+
}, 'unused', historyUrl)
|
|
4791
|
+
}
|
|
4792
|
+
}
|
|
4631
4793
|
subscribe (event, fn) {
|
|
4632
4794
|
this.options.subscribers[event].push(fn)
|
|
4633
4795
|
}
|
|
@@ -6320,7 +6482,7 @@ class WebsyTable3 {
|
|
|
6320
6482
|
return ''
|
|
6321
6483
|
}
|
|
6322
6484
|
let bodyHtml = ``
|
|
6323
|
-
let sizingColumns = this.options.columns[this.options.columns.length - 1]
|
|
6485
|
+
let sizingColumns = this.options.columns[this.options.columns.length - 1].filter(c => c.show !== false)
|
|
6324
6486
|
if (useWidths === true) {
|
|
6325
6487
|
bodyHtml += '<colgroup>'
|
|
6326
6488
|
bodyHtml += sizingColumns.map(c => `
|
|
@@ -6332,9 +6494,9 @@ class WebsyTable3 {
|
|
|
6332
6494
|
}
|
|
6333
6495
|
data.forEach((row, rowIndex) => {
|
|
6334
6496
|
bodyHtml += `<tr class="websy-table-row">`
|
|
6335
|
-
row.forEach((cell, cellIndex) => {
|
|
6497
|
+
row.forEach((cell, cellIndex) => {
|
|
6336
6498
|
let sizeIndex = cell.level || cellIndex
|
|
6337
|
-
if (typeof sizingColumns[sizeIndex] === 'undefined') {
|
|
6499
|
+
if (typeof sizingColumns[sizeIndex] === 'undefined' || sizingColumns[sizeIndex].show === false) {
|
|
6338
6500
|
return // need to revisit this logic
|
|
6339
6501
|
}
|
|
6340
6502
|
let style = ''
|
|
@@ -6431,7 +6593,7 @@ class WebsyTable3 {
|
|
|
6431
6593
|
return ''
|
|
6432
6594
|
}
|
|
6433
6595
|
let headerHtml = ''
|
|
6434
|
-
let sizingColumns = this.options.columns[this.options.columns.length - 1]
|
|
6596
|
+
let sizingColumns = this.options.columns[this.options.columns.length - 1].filter(c => c.show !== false)
|
|
6435
6597
|
if (useWidths === true) {
|
|
6436
6598
|
headerHtml += '<colgroup>'
|
|
6437
6599
|
headerHtml += sizingColumns.map(c => `
|
|
@@ -6447,7 +6609,10 @@ class WebsyTable3 {
|
|
|
6447
6609
|
return
|
|
6448
6610
|
}
|
|
6449
6611
|
headerHtml += `<tr class="websy-table-row websy-table-header-row">`
|
|
6450
|
-
row.forEach((col, colIndex) => {
|
|
6612
|
+
row.filter(c => c.show !== false).forEach((col, colIndex) => {
|
|
6613
|
+
if (typeof sizingColumns[colIndex] === 'undefined' || sizingColumns[colIndex].show === false) {
|
|
6614
|
+
return // need to revisit this logic
|
|
6615
|
+
}
|
|
6451
6616
|
let style = `width: ${sizingColumns[colIndex].width || sizingColumns[colIndex].actualWidth}px!important; `
|
|
6452
6617
|
let divStyle = style
|
|
6453
6618
|
if (useWidths === true) {
|
|
@@ -6511,8 +6676,12 @@ class WebsyTable3 {
|
|
|
6511
6676
|
if (!this.options.totals) {
|
|
6512
6677
|
return ''
|
|
6513
6678
|
}
|
|
6679
|
+
let sizingColumns = this.options.columns[this.options.columns.length - 1].filter(c => c.show !== false)
|
|
6514
6680
|
let totalHtml = `<tr class="websy-table-row websy-table-total-row">`
|
|
6515
6681
|
this.options.totals.forEach((col, colIndex) => {
|
|
6682
|
+
if (typeof sizingColumns[colIndex] === 'undefined' || sizingColumns[colIndex].show === false) {
|
|
6683
|
+
return // need to revisit this logic
|
|
6684
|
+
}
|
|
6516
6685
|
totalHtml += `<td
|
|
6517
6686
|
class='websy-table-cell ${(col.classes || []).join(' ')}'
|
|
6518
6687
|
colspan='${col.colspan || 1}'
|
|
@@ -6568,36 +6737,37 @@ class WebsyTable3 {
|
|
|
6568
6737
|
let totalWidth = 0
|
|
6569
6738
|
this.sizes.scrollableWidth = this.sizes.outer.width
|
|
6570
6739
|
let firstNonPinnedColumnWidth = 0
|
|
6740
|
+
let columnsForSizing = this.options.columns[this.options.columns.length - 1].filter(c => c.show !== false)
|
|
6571
6741
|
rows.forEach((row, rowIndex) => {
|
|
6572
6742
|
Array.from(row.children).forEach((col, colIndex) => {
|
|
6573
6743
|
let colSize = col.getBoundingClientRect()
|
|
6574
6744
|
this.sizes.cellHeight = colSize.height
|
|
6575
|
-
if (
|
|
6576
|
-
if (!
|
|
6577
|
-
|
|
6745
|
+
if (columnsForSizing[colIndex]) {
|
|
6746
|
+
if (!columnsForSizing[colIndex].actualWidth) {
|
|
6747
|
+
columnsForSizing[colIndex].actualWidth = 0
|
|
6578
6748
|
}
|
|
6579
|
-
|
|
6580
|
-
|
|
6749
|
+
columnsForSizing[colIndex].actualWidth = Math.min(Math.max(columnsForSizing[colIndex].actualWidth, colSize.width), maxWidth)
|
|
6750
|
+
columnsForSizing[colIndex].cellHeight = colSize.height
|
|
6581
6751
|
if (colIndex >= this.pinnedColumns) {
|
|
6582
|
-
firstNonPinnedColumnWidth =
|
|
6752
|
+
firstNonPinnedColumnWidth = columnsForSizing[colIndex].actualWidth
|
|
6583
6753
|
}
|
|
6584
6754
|
}
|
|
6585
6755
|
})
|
|
6586
6756
|
})
|
|
6587
|
-
|
|
6588
|
-
|
|
6589
|
-
|
|
6590
|
-
|
|
6591
|
-
})
|
|
6592
|
-
this.sizes.totalWidth =
|
|
6593
|
-
this.sizes.totalNonPinnedWidth =
|
|
6757
|
+
// columnsForSizing.forEach((col, colIndex) => {
|
|
6758
|
+
// if (colIndex < this.pinnedColumns) {
|
|
6759
|
+
// this.sizes.scrollableWidth -= col.actualWidth
|
|
6760
|
+
// }
|
|
6761
|
+
// })
|
|
6762
|
+
this.sizes.totalWidth = columnsForSizing.reduce((a, b) => a + (b.width || b.actualWidth), 0)
|
|
6763
|
+
this.sizes.totalNonPinnedWidth = columnsForSizing.filter((c, i) => i >= this.pinnedColumns).reduce((a, b) => a + (b.width || b.actualWidth), 0)
|
|
6594
6764
|
this.sizes.pinnedWidth = this.sizes.totalWidth - this.sizes.totalNonPinnedWidth
|
|
6595
6765
|
// const outerSize = outerEl.getBoundingClientRect()
|
|
6596
6766
|
if (this.sizes.totalWidth < this.sizes.outer.width) {
|
|
6597
|
-
let equalWidth = (this.sizes.outer.width - this.sizes.totalWidth) /
|
|
6767
|
+
let equalWidth = (this.sizes.outer.width - this.sizes.totalWidth) / columnsForSizing.length
|
|
6598
6768
|
this.sizes.totalWidth = 0
|
|
6599
6769
|
this.sizes.totalNonPinnedWidth = 0
|
|
6600
|
-
|
|
6770
|
+
columnsForSizing.forEach((c, i) => {
|
|
6601
6771
|
// if (!c.width) {
|
|
6602
6772
|
// if (c.actualWidth < equalWidth) {
|
|
6603
6773
|
// adjust the width
|
|
@@ -6608,7 +6778,7 @@ class WebsyTable3 {
|
|
|
6608
6778
|
// }
|
|
6609
6779
|
// }
|
|
6610
6780
|
this.sizes.totalWidth += c.width || c.actualWidth
|
|
6611
|
-
if (i
|
|
6781
|
+
if (i > this.pinnedColumns) {
|
|
6612
6782
|
this.sizes.totalNonPinnedWidth += c.width || c.actualWidth
|
|
6613
6783
|
}
|
|
6614
6784
|
// equalWidth = (outerSize.width - this.sizes.totalWidth) / (this.options.columns[this.options.columns.length - 1].length - (i + 1))
|
|
@@ -6618,17 +6788,21 @@ class WebsyTable3 {
|
|
|
6618
6788
|
if (this.sizes.pinnedWidth > (this.sizes.outer.width - firstNonPinnedColumnWidth)) {
|
|
6619
6789
|
this.sizes.totalWidth = 0
|
|
6620
6790
|
let diff = this.sizes.pinnedWidth - (this.sizes.outer.width - firstNonPinnedColumnWidth)
|
|
6791
|
+
let oldPinnedWidth = this.sizes.pinnedWidth
|
|
6792
|
+
this.sizes.pinnedWidth = 0
|
|
6621
6793
|
// let colDiff = diff / this.pinnedColumns
|
|
6622
|
-
for (let i = 0; i <
|
|
6794
|
+
for (let i = 0; i < columnsForSizing.length; i++) {
|
|
6623
6795
|
if (i < this.pinnedColumns) {
|
|
6624
|
-
let colDiff = (
|
|
6625
|
-
|
|
6796
|
+
let colDiff = (columnsForSizing[i].actualWidth / oldPinnedWidth) * diff
|
|
6797
|
+
columnsForSizing[i].actualWidth -= colDiff
|
|
6798
|
+
this.sizes.pinnedWidth += columnsForSizing[i].actualWidth
|
|
6626
6799
|
}
|
|
6627
|
-
this.sizes.totalWidth +=
|
|
6800
|
+
this.sizes.totalWidth += columnsForSizing[i].width || columnsForSizing[i].actualWidth
|
|
6628
6801
|
}
|
|
6629
6802
|
}
|
|
6630
6803
|
// take the height of the last cell as the official height for data cells
|
|
6631
6804
|
// this.sizes.dataCellHeight = this.options.columns[this.options.columns.length - 1].cellHeight
|
|
6805
|
+
this.sizes.scrollableWidth = this.sizes.table.width - this.sizes.pinnedWidth
|
|
6632
6806
|
headEl.innerHTML = ''
|
|
6633
6807
|
bodyEl.innerHTML = ''
|
|
6634
6808
|
footerEl.innerHTML = ''
|
|
@@ -6938,18 +7112,21 @@ class WebsyTable3 {
|
|
|
6938
7112
|
this.startCol = 0
|
|
6939
7113
|
this.endCol = 0
|
|
6940
7114
|
for (let i = this.pinnedColumns; i < this.options.allColumns[this.options.allColumns.length - 1].length; i++) {
|
|
6941
|
-
|
|
6942
|
-
|
|
6943
|
-
|
|
6944
|
-
|
|
6945
|
-
|
|
6946
|
-
|
|
7115
|
+
if (this.options.allColumns[this.options.allColumns.length - 1][i].show !== false) {
|
|
7116
|
+
cumulativeWidth += this.options.allColumns[this.options.allColumns.length - 1][i].actualWidth
|
|
7117
|
+
if (actualLeft < cumulativeWidth) {
|
|
7118
|
+
this.startCol = i
|
|
7119
|
+
break
|
|
7120
|
+
}
|
|
7121
|
+
}
|
|
6947
7122
|
}
|
|
6948
7123
|
cumulativeWidth = 0
|
|
6949
7124
|
for (let i = this.startCol; i < this.options.allColumns[this.options.allColumns.length - 1].length; i++) {
|
|
6950
|
-
|
|
6951
|
-
|
|
6952
|
-
this.
|
|
7125
|
+
if (this.options.allColumns[this.options.allColumns.length - 1][i].show !== false) {
|
|
7126
|
+
cumulativeWidth += this.options.allColumns[this.options.allColumns.length - 1][i].actualWidth
|
|
7127
|
+
if (cumulativeWidth < this.sizes.scrollableWidth) {
|
|
7128
|
+
this.endCol = i
|
|
7129
|
+
}
|
|
6953
7130
|
}
|
|
6954
7131
|
}
|
|
6955
7132
|
if (this.endCol < this.options.allColumns[this.options.allColumns.length - 1].length - 1) {
|
|
@@ -7529,6 +7706,9 @@ this.render()
|
|
|
7529
7706
|
/* global d3 options WebsyUtils */
|
|
7530
7707
|
if (typeof options !== 'undefined') {
|
|
7531
7708
|
this.options = Object.assign({}, this.options, options)
|
|
7709
|
+
if (this.options.legendOptions) {
|
|
7710
|
+
this.legend.setOptions(this.options.legendOptions)
|
|
7711
|
+
}
|
|
7532
7712
|
}
|
|
7533
7713
|
if (!this.options.data) {
|
|
7534
7714
|
// tell the user no data has been provided
|
|
@@ -7590,12 +7770,19 @@ else {
|
|
|
7590
7770
|
}
|
|
7591
7771
|
if (this.options.legendPosition === 'top' || this.options.legendPosition === 'bottom') {
|
|
7592
7772
|
this.legendArea.style('width', '100%')
|
|
7773
|
+
if (this.legend.options.maxSize) {
|
|
7774
|
+
this.legendArea.style('height', `${this.legend.options.maxSize}px`)
|
|
7775
|
+
}
|
|
7593
7776
|
this.legend.options.align = 'center'
|
|
7594
7777
|
}
|
|
7595
7778
|
if (this.options.legendPosition === 'left' || this.options.legendPosition === 'right') {
|
|
7779
|
+
let longestLegendValue = legendData.reduce((a, b) => a.length > (b.value || '').length ? a : b.value, '')
|
|
7596
7780
|
this.legend.options.align = 'left'
|
|
7597
7781
|
this.legendArea.style('height', '100%')
|
|
7598
|
-
this.legendArea.style('width', this.legend.testWidth(
|
|
7782
|
+
this.legendArea.style('width', this.legend.testWidth(longestLegendValue) + 'px')
|
|
7783
|
+
if (this.legend.options.maxSize) {
|
|
7784
|
+
this.legendArea.style('width', `${this.legend.options.maxSize}px`)
|
|
7785
|
+
}
|
|
7599
7786
|
}
|
|
7600
7787
|
this.legend.data = legendData
|
|
7601
7788
|
let legendSize = this.legend.getSize()
|
|
@@ -7784,7 +7971,7 @@ else {
|
|
|
7784
7971
|
this.brushBandPadding = this.totalBandPadding / this.options.data.left.data.length
|
|
7785
7972
|
}
|
|
7786
7973
|
plotable = this.plotHeight - this.totalBandPadding
|
|
7787
|
-
noOfPoints = this.options.grouping === 'grouped' ? this.options.data.left.totalValueCount : this.options.data.left.data.length
|
|
7974
|
+
noOfPoints = this.options.grouping === 'grouped' && this.options.allowUnevenBands === true ? this.options.data.left.totalValueCount : this.options.data.left.data.length
|
|
7788
7975
|
noOfGroups = this.options.data.left.data.length
|
|
7789
7976
|
}
|
|
7790
7977
|
else {
|
|
@@ -7801,7 +7988,7 @@ else {
|
|
|
7801
7988
|
this.brushBandPadding = this.totalBandPadding / this.options.data.bottom.data.length
|
|
7802
7989
|
}
|
|
7803
7990
|
plotable = this.plotWidth - this.totalBandPadding
|
|
7804
|
-
noOfPoints = this.options.grouping === 'grouped' ? this.options.data.bottom.totalValueCount : this.options.data.bottom.data.length
|
|
7991
|
+
noOfPoints = this.options.grouping === 'grouped' && this.options.allowUnevenBands === true ? this.options.data.bottom.totalValueCount : this.options.data.bottom.data.length
|
|
7805
7992
|
noOfGroups = this.options.data.bottom.data.length
|
|
7806
7993
|
}
|
|
7807
7994
|
if (plotable / noOfPoints > this.options.maxBandWidth) {
|
|
@@ -7955,7 +8142,7 @@ else {
|
|
|
7955
8142
|
let pos = i * proposedBandWidth
|
|
7956
8143
|
this[`custom${customRangeSide}DetailRange`].push(start + adjustment + pos)
|
|
7957
8144
|
}
|
|
7958
|
-
acc += (this.options.grouping !== 'stacked' ? (d.valueCount || 1) : 1)
|
|
8145
|
+
acc += (this.options.grouping !== 'stacked' && this.options.allowUnevenBands === true ? (d.valueCount || 1) : 1)
|
|
7959
8146
|
let end = (this.widthForCalc / noOfPoints) * acc
|
|
7960
8147
|
// this.customBottomBrushRange.push((end + adjustment) * (this.plotWidth / this.widthForCalc))
|
|
7961
8148
|
return end + adjustment
|
|
@@ -7963,7 +8150,7 @@ else {
|
|
|
7963
8150
|
acc = 0
|
|
7964
8151
|
this[`custom${customRangeSide}BrushRange`] = [0, ...this.options.data[customRangeSideLC].data.map((d, index, arr) => {
|
|
7965
8152
|
let adjustment = (this.brushBandPadding * index) + this.brushBandPadding
|
|
7966
|
-
acc += (this.options.grouping !== 'stacked' ? (d.valueCount || 1) : 1)
|
|
8153
|
+
acc += (this.options.grouping !== 'stacked' && this.options.allowUnevenBands === true ? (d.valueCount || 1) : 1)
|
|
7967
8154
|
return ((this.options.orientation === 'vertical' ? this.plotWidth : this.plotHeight) / noOfPoints) * acc
|
|
7968
8155
|
})]
|
|
7969
8156
|
}
|
|
@@ -8942,8 +9129,8 @@ symbols.exit()
|
|
|
8942
9129
|
symbols
|
|
8943
9130
|
.attr('d', d => drawSymbol(d.y.size || series.symbolSize)(d))
|
|
8944
9131
|
.transition(this.transition)
|
|
8945
|
-
.attr('fill', series.fillSymbols ? series.color : 'white')
|
|
8946
|
-
.attr('stroke', series.color)
|
|
9132
|
+
.attr('fill', d => series.fillSymbols ? d.y.color || series.color : 'white')
|
|
9133
|
+
.attr('stroke', d => d.y.color || series.color)
|
|
8947
9134
|
.attr('transform', d => {
|
|
8948
9135
|
// let adjustment = (this.options.data[xAxis].scale === 'Time' || this.options.data[xAxis].scale === 'Linear') ? 0 : this.options.data[xAxis].bandWidth / 2
|
|
8949
9136
|
// if (this.options.orientation === 'horizontal') {
|
|
@@ -8971,8 +9158,8 @@ symbols.enter()
|
|
|
8971
9158
|
.append('path')
|
|
8972
9159
|
.attr('d', d => drawSymbol(d.y.size || series.symbolSize)(d))
|
|
8973
9160
|
// .transition(this.transition)
|
|
8974
|
-
.attr('fill', series.fillSymbols ? series.color : 'white')
|
|
8975
|
-
.attr('stroke', series.color)
|
|
9161
|
+
.attr('fill', d => series.fillSymbols ? d.y.color || series.color : 'white')
|
|
9162
|
+
.attr('stroke', d => d.y.color || series.color)
|
|
8976
9163
|
.attr('class', d => { return `symbol symbol_${series.key}` })
|
|
8977
9164
|
.attr('transform', d => {
|
|
8978
9165
|
let xIndex = this[xAxis + 'Axis'].domain().indexOf(d.x.value)
|
|
@@ -9213,6 +9400,9 @@ class WebsyLegend {
|
|
|
9213
9400
|
el.innerHTML = html
|
|
9214
9401
|
}
|
|
9215
9402
|
}
|
|
9403
|
+
setOptions (options) {
|
|
9404
|
+
this.options = Object.assign({}, this.options, options)
|
|
9405
|
+
}
|
|
9216
9406
|
testWidth (v) {
|
|
9217
9407
|
let html = this.getLegendItemHTML({value: v})
|
|
9218
9408
|
const el = document.createElement('div')
|