@recras/online-booking-js 2.0.2 → 2.0.4
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/.github/workflows/npmpublish.yml +6 -6
- package/README.md +1 -1
- package/changelog.md +6 -0
- package/dist/onlinebooking.js +36 -12
- package/dist/onlinebooking.min.js +1 -1
- package/error_messages.patch +2409 -0
- package/package.json +13 -13
- package/src/booking.js +3 -2
- package/src/contactForm.js +17 -8
- package/src/dateHelper.js +8 -0
- package/src/vouchers.js +1 -1
- package/test/js-unit/recrasBookingSpec.js +0 -10
- package/test/js-unit/recrasDateHelperSpec.js +9 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@recras/online-booking-js",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.4",
|
|
4
4
|
"description": "JS library for easy integration of Recras online booking and voucher sales",
|
|
5
5
|
"main": "dist/onlinebooking.js",
|
|
6
6
|
"scripts": {
|
|
@@ -31,22 +31,22 @@
|
|
|
31
31
|
},
|
|
32
32
|
"homepage": "https://github.com/Recras/online-booking-js#readme",
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@babel/cli": "7.
|
|
35
|
-
"@babel/core": "7.
|
|
36
|
-
"@babel/plugin-proposal-class-properties": "7.
|
|
37
|
-
"@babel/plugin-transform-arrow-functions": "7.
|
|
38
|
-
"@babel/plugin-transform-for-of": "7.
|
|
39
|
-
"@babel/plugin-transform-object-assign": "7.
|
|
40
|
-
"@babel/preset-env": "7.
|
|
34
|
+
"@babel/cli": "7.18.9",
|
|
35
|
+
"@babel/core": "7.18.9",
|
|
36
|
+
"@babel/plugin-proposal-class-properties": "7.18.6",
|
|
37
|
+
"@babel/plugin-transform-arrow-functions": "7.18.6",
|
|
38
|
+
"@babel/plugin-transform-for-of": "7.18.8",
|
|
39
|
+
"@babel/plugin-transform-object-assign": "7.18.6",
|
|
40
|
+
"@babel/preset-env": "7.18.9",
|
|
41
41
|
"babel-plugin-transform-es2017-object-entries": "0.0.5",
|
|
42
|
-
"jasmine-core": "4.0
|
|
42
|
+
"jasmine-core": "4.3.0",
|
|
43
43
|
"jasmine-spec-reporter": "7.0.0",
|
|
44
|
-
"jshint": "2.13.
|
|
45
|
-
"karma": "6.
|
|
44
|
+
"jshint": "2.13.5",
|
|
45
|
+
"karma": "6.4.0",
|
|
46
46
|
"karma-chrome-launcher": "3.1.0",
|
|
47
47
|
"karma-firefox-launcher": "2.1.2",
|
|
48
|
-
"karma-jasmine": "
|
|
48
|
+
"karma-jasmine": "5.1.0",
|
|
49
49
|
"karma-spec-reporter": "0.0.34",
|
|
50
|
-
"uglify-js": "3.
|
|
50
|
+
"uglify-js": "3.16.3"
|
|
51
51
|
}
|
|
52
52
|
}
|
package/src/booking.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*******************************
|
|
2
2
|
* Recras integration library *
|
|
3
|
-
* v 2.0.
|
|
3
|
+
* v 2.0.4 *
|
|
4
4
|
*******************************/
|
|
5
5
|
|
|
6
6
|
class RecrasBooking {
|
|
@@ -1194,7 +1194,7 @@ class RecrasBooking {
|
|
|
1194
1194
|
<label for="recras-onlinebooking-date">
|
|
1195
1195
|
${ this.languageHelper.translate('DATE') }
|
|
1196
1196
|
</label>
|
|
1197
|
-
<input type="text" id="recras-onlinebooking-date" class="recras-onlinebooking-date" min="${ today }" disabled
|
|
1197
|
+
<input type="text" id="recras-onlinebooking-date" class="recras-onlinebooking-date" min="${ today }" disabled autocomplete="off">
|
|
1198
1198
|
<label for="recras-onlinebooking-time">
|
|
1199
1199
|
${ this.languageHelper.translate('TIME') }
|
|
1200
1200
|
</label>
|
|
@@ -1238,6 +1238,7 @@ class RecrasBooking {
|
|
|
1238
1238
|
i18n: RecrasCalendarHelper.i18n(this.languageHelper),
|
|
1239
1239
|
onDraw: (pika) => this.calendarOnDraw(pika, pack.id),
|
|
1240
1240
|
onSelect: (date) => this.calendarOnDateSelect(date, pack.id),
|
|
1241
|
+
parse: RecrasDateHelper.parseMDY,
|
|
1241
1242
|
}
|
|
1242
1243
|
);
|
|
1243
1244
|
|
package/src/contactForm.js
CHANGED
|
@@ -424,6 +424,7 @@ class RecrasContactForm {
|
|
|
424
424
|
field: this.findElement('[data-identifier="boeking.datum"]'),
|
|
425
425
|
i18n: RecrasCalendarHelper.i18n(this.languageHelper),
|
|
426
426
|
numberOfMonths: 1,
|
|
427
|
+
parse: RecrasDateHelper.parseMDY,
|
|
427
428
|
}
|
|
428
429
|
);
|
|
429
430
|
new Pikaday(pikadayOptions);
|
|
@@ -456,24 +457,32 @@ class RecrasContactForm {
|
|
|
456
457
|
);
|
|
457
458
|
}
|
|
458
459
|
|
|
459
|
-
|
|
460
|
+
showErrors() {
|
|
461
|
+
let errors = [];
|
|
460
462
|
for (let el of this.getEmptyRequiredFields()) {
|
|
461
463
|
const labelEl = el.parentNode.querySelector('label');
|
|
462
464
|
const requiredText = this.languageHelper.translate('CONTACT_FORM_FIELD_REQUIRED', {
|
|
463
465
|
FIELD_NAME: labelEl.innerText,
|
|
464
466
|
});
|
|
465
|
-
|
|
466
|
-
'afterend',
|
|
467
|
-
`<div class="booking-error">${ requiredText }</div>`
|
|
468
|
-
);
|
|
467
|
+
errors.push(requiredText);
|
|
469
468
|
}
|
|
470
469
|
for (let el of this.getInvalidFields()) {
|
|
471
|
-
|
|
470
|
+
let parentEl = el.closest('div');
|
|
471
|
+
if (parentEl.classList.contains('radioGroup')) {
|
|
472
|
+
parentEl = parentEl.parentNode.closest('div');
|
|
473
|
+
}
|
|
474
|
+
const labelEl = parentEl.querySelector('label');
|
|
475
|
+
console.log(labelEl, parentEl.querySelectorAll('label'));
|
|
472
476
|
const invalidText = this.languageHelper.translate('CONTACT_FORM_FIELD_INVALID', {
|
|
473
477
|
FIELD_NAME: labelEl.innerText,
|
|
474
478
|
});
|
|
475
|
-
|
|
479
|
+
errors.push(invalidText);
|
|
476
480
|
}
|
|
481
|
+
errors = [...new Set(errors)]; // Only unique text
|
|
482
|
+
this.findElement('button[type="submit"]').insertAdjacentHTML(
|
|
483
|
+
'afterend',
|
|
484
|
+
`<div class="booking-error"><ul><li>${ errors.join('<li>') }</ul></div>`
|
|
485
|
+
);
|
|
477
486
|
}
|
|
478
487
|
|
|
479
488
|
showLabel(field, idx) {
|
|
@@ -501,7 +510,7 @@ class RecrasContactForm {
|
|
|
501
510
|
);
|
|
502
511
|
return false;
|
|
503
512
|
} else if (this.hasEmptyRequiredFields() || !this.isValid()) {
|
|
504
|
-
this.
|
|
513
|
+
this.showErrors();
|
|
505
514
|
return false;
|
|
506
515
|
}
|
|
507
516
|
|
package/src/dateHelper.js
CHANGED
|
@@ -20,6 +20,14 @@ class RecrasDateHelper {
|
|
|
20
20
|
return date;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
static parseMDY(dateStr) {
|
|
24
|
+
const parts = dateStr.split('-');
|
|
25
|
+
const day = parseInt(parts[0], 10);
|
|
26
|
+
const month = parseInt(parts[1], 10) - 1;
|
|
27
|
+
const year = parseInt(parts[2], 10);
|
|
28
|
+
return new Date(year, month, day);
|
|
29
|
+
}
|
|
30
|
+
|
|
23
31
|
static setTimeForDate(date, timeStr) {
|
|
24
32
|
date.setHours(timeStr.substr(0, 2), timeStr.substr(3, 2));
|
|
25
33
|
return date;
|
package/src/vouchers.js
CHANGED
|
@@ -184,7 +184,7 @@ class RecrasVoucher {
|
|
|
184
184
|
let shouldDisable = false;
|
|
185
185
|
this.contactForm.removeErrors();
|
|
186
186
|
if (this.contactForm.hasEmptyRequiredFields() || !this.contactForm.isValid() || !this.contactForm.checkRequiredCheckboxes()) {
|
|
187
|
-
this.contactForm.
|
|
187
|
+
this.contactForm.showErrors();
|
|
188
188
|
shouldDisable = true;
|
|
189
189
|
}
|
|
190
190
|
|
|
@@ -511,16 +511,6 @@ describe('RecrasBooking', () => {
|
|
|
511
511
|
expect(rb.setMinMaxAmountWarning).toHaveBeenCalledWith('packageline0', 5, 'minimum');
|
|
512
512
|
});
|
|
513
513
|
|
|
514
|
-
it('gives error if amount is less than the line minimum', async () => {
|
|
515
|
-
await rb.promise;
|
|
516
|
-
|
|
517
|
-
let el = document.getElementById('packageline2');
|
|
518
|
-
el.value = '1';
|
|
519
|
-
el.dispatchEvent(new Event('input'));
|
|
520
|
-
|
|
521
|
-
expect(rb.setMinMaxAmountWarning).toHaveBeenCalledWith('packageline2', 10, 'minimum');
|
|
522
|
-
});
|
|
523
|
-
|
|
524
514
|
it('gives error if amount is more than the maximum', async () => {
|
|
525
515
|
await rb.promise;
|
|
526
516
|
|
|
@@ -21,6 +21,15 @@ describe('RecrasDateHelper', () => {
|
|
|
21
21
|
});
|
|
22
22
|
});
|
|
23
23
|
|
|
24
|
+
describe('parseMDY', () => {
|
|
25
|
+
it('correctly parses entered date', () => {
|
|
26
|
+
const dateStr = '11-09-2022';
|
|
27
|
+
const date = RecrasDateHelper.parseMDY(dateStr);
|
|
28
|
+
expect(date.getMonth()).toEqual(8); // months are 0-indexed
|
|
29
|
+
expect(date.getDate()).toEqual(11);
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
|
|
24
33
|
describe('setTimeForDate', () => {
|
|
25
34
|
it('Correctly sets the time', () => {
|
|
26
35
|
let date = new Date(2018, 3, 20);
|