@internetarchive/ia-book-actions 1.3.0 → 1.4.1-alpha1
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/index.html +3 -3
- package/package.json +1 -1
- package/src/components/collapsible-action-group.js +3 -1
- package/src/core/config/analytics-event-and-category.js +8 -2
- package/src/core/services/actions-handler/actions-handler.js +37 -1
- package/src/core/services/loan-analytics.js +17 -3
- package/src/core/services/loan-renew-helper.js +16 -6
- package/src/ia-book-actions.js +7 -6
- package/demo/index.html +0 -454
package/index.html
CHANGED
|
@@ -134,12 +134,12 @@
|
|
|
134
134
|
iaBookActions.bwbPurchaseUrl = '';
|
|
135
135
|
iaBookActions.modalConfig = modalConfig;
|
|
136
136
|
iaBookActions.lendingBarPostInit = lendingBarPostInit;
|
|
137
|
-
iaBookActions.tokenDelay =
|
|
138
|
-
iaBookActions.timerExecutionSeconds =
|
|
137
|
+
iaBookActions.tokenDelay = 2; // 2 seconds
|
|
138
|
+
iaBookActions.timerExecutionSeconds = 2 // 4 seconds
|
|
139
139
|
iaBookActions.returnUrl = '';
|
|
140
140
|
iaBookActions.localCache = localCache;
|
|
141
141
|
|
|
142
|
-
let loanTotalTime2Min = { loanTotalTime:
|
|
142
|
+
let loanTotalTime2Min = { loanTotalTime: 60, loanRenewAtLast: 55, pageChangedInLast: 5 };
|
|
143
143
|
let loanTotalTime5Min = { loanTotalTime: 300, loanRenewAtLast: 240, pageChangedInLast: 60 };
|
|
144
144
|
let loanTotalTime10Min = { loanTotalTime: 600, loanRenewAtLast: 480, pageChangedInLast: 120 };
|
|
145
145
|
let loanTotalTime30Min = { loanTotalTime: 1800, loanRenewAtLast: 1500, pageChangedInLast: 600 };
|
package/package.json
CHANGED
|
@@ -29,6 +29,7 @@ export class CollapsibleActionGroup extends ActionsHandler {
|
|
|
29
29
|
disabled: { type: Boolean },
|
|
30
30
|
returnUrl: { type: String },
|
|
31
31
|
autoRenew: { type: Boolean },
|
|
32
|
+
loanRenewType: { type: String },
|
|
32
33
|
autoReturn: { type: Boolean },
|
|
33
34
|
returnNow: { type: Boolean },
|
|
34
35
|
};
|
|
@@ -51,6 +52,7 @@ export class CollapsibleActionGroup extends ActionsHandler {
|
|
|
51
52
|
this.disabled = false;
|
|
52
53
|
this.returnUrl = '';
|
|
53
54
|
this.autoRenew = false;
|
|
55
|
+
this.loanRenewType = '';
|
|
54
56
|
this.autoReturn = false;
|
|
55
57
|
this.returnNow = false;
|
|
56
58
|
}
|
|
@@ -64,7 +66,7 @@ export class CollapsibleActionGroup extends ActionsHandler {
|
|
|
64
66
|
}
|
|
65
67
|
|
|
66
68
|
if (changed.has('autoRenew') && this.autoRenew) {
|
|
67
|
-
this.dispatchLoanEvent('autoRenew');
|
|
69
|
+
this.dispatchLoanEvent('autoRenew', { renewType: this.loanRenewType });
|
|
68
70
|
}
|
|
69
71
|
|
|
70
72
|
const requestingAutoreturn = changed.has('autoReturn') && this.autoReturn;
|
|
@@ -13,8 +13,7 @@ export const analyticsCategories = {
|
|
|
13
13
|
export const analyticsActions = {
|
|
14
14
|
browse: 'Borrow-1Hour',
|
|
15
15
|
browseAgain: 'Borrow-Again',
|
|
16
|
-
|
|
17
|
-
browseAutoReturn: 'AutoReturnBook',
|
|
16
|
+
browseRenew: 'BookRenew',
|
|
18
17
|
borrow: 'Borrow-14Days',
|
|
19
18
|
waitlistJoin: 'JoinWaitlist',
|
|
20
19
|
waitlistLeave: 'LeaveWaitlist',
|
|
@@ -25,3 +24,10 @@ export const analyticsActions = {
|
|
|
25
24
|
printDisability: 'Print-Disability',
|
|
26
25
|
titleBar: 'Book-Title-Bar',
|
|
27
26
|
};
|
|
27
|
+
|
|
28
|
+
export const analyticsLabels = {
|
|
29
|
+
browseAutoRenew: 'BookAutoRenew',
|
|
30
|
+
browseAutoReturn: 'BookAutoReturn',
|
|
31
|
+
browseManualRenew: 'BookManualRenew',
|
|
32
|
+
browseManualReturn: 'BookManualReturn',
|
|
33
|
+
};
|
|
@@ -6,6 +6,7 @@ import log from '../log.js';
|
|
|
6
6
|
|
|
7
7
|
import ActionsHandlerService from './actions-handler-service.js';
|
|
8
8
|
import LoanAnanlytics from '../loan-analytics.js';
|
|
9
|
+
import { analyticsCategories, analyticsActions, analyticsLabels } from '../../config/analytics-event-and-category.js';
|
|
9
10
|
import * as Cookies from '../doc-cookies.js';
|
|
10
11
|
|
|
11
12
|
/**
|
|
@@ -52,12 +53,19 @@ export default class ActionsHandler extends LitElement {
|
|
|
52
53
|
);
|
|
53
54
|
});
|
|
54
55
|
|
|
55
|
-
this.addEventListener('autoRenew', async () => {
|
|
56
|
+
this.addEventListener('autoRenew', async ({ detail }) => {
|
|
56
57
|
this.handleLoanRenewNow();
|
|
57
58
|
await this.loanAnanlytics?.storeLoanStatsCount(
|
|
58
59
|
this.identifier,
|
|
59
60
|
'autorenew'
|
|
60
61
|
);
|
|
62
|
+
|
|
63
|
+
const analyticsLabel = detail?.renewType === 'auto' ? analyticsLabels.browseAutoRenew : analyticsLabels.browseManualRenew;
|
|
64
|
+
this.loanAnanlytics?.sendEvent(
|
|
65
|
+
analyticsCategories.browse,
|
|
66
|
+
analyticsActions.browseRenew,
|
|
67
|
+
analyticsLabel
|
|
68
|
+
);
|
|
61
69
|
});
|
|
62
70
|
|
|
63
71
|
this.addEventListener('autoReturn', async () => {
|
|
@@ -66,12 +74,24 @@ export default class ActionsHandler extends LitElement {
|
|
|
66
74
|
this.identifier,
|
|
67
75
|
'autoreturn'
|
|
68
76
|
);
|
|
77
|
+
|
|
78
|
+
this.loanAnanlytics?.sendEvent(
|
|
79
|
+
analyticsCategories.browse,
|
|
80
|
+
analyticsActions.browseAutoReturn,
|
|
81
|
+
this.identifier
|
|
82
|
+
);
|
|
69
83
|
});
|
|
70
84
|
|
|
71
85
|
this.addEventListener('returnNow', ({ detail }) => {
|
|
72
86
|
// use loan stats count when 1-hour borrow is active
|
|
73
87
|
if (detail?.borrowType === 'browse') {
|
|
74
88
|
this.loanAnanlytics?.storeLoanStatsCount(this.identifier, 'return');
|
|
89
|
+
|
|
90
|
+
this.loanAnanlytics?.sendEvent(
|
|
91
|
+
analyticsCategories.browse,
|
|
92
|
+
analyticsActions.browseManualReturn,
|
|
93
|
+
this.identifier
|
|
94
|
+
);
|
|
75
95
|
}
|
|
76
96
|
|
|
77
97
|
this.handleReturnIt('returnNow');
|
|
@@ -116,6 +136,8 @@ export default class ActionsHandler extends LitElement {
|
|
|
116
136
|
const { category, action } = detail.event;
|
|
117
137
|
this.loanAnanlytics?.sendEvent(category, action, this.identifier);
|
|
118
138
|
|
|
139
|
+
this.setStickyAdminAccess(true);
|
|
140
|
+
|
|
119
141
|
// keep existing params and add new one
|
|
120
142
|
const url = new URL(window.location.href);
|
|
121
143
|
url.searchParams.append('admin', 1);
|
|
@@ -125,6 +147,8 @@ export default class ActionsHandler extends LitElement {
|
|
|
125
147
|
this.addEventListener('exitAdminAccess', ({ detail }) => {
|
|
126
148
|
const { category, action } = detail.event;
|
|
127
149
|
this.loanAnanlytics?.sendEvent(category, action, this.identifier);
|
|
150
|
+
|
|
151
|
+
this.setStickyAdminAccess(false);
|
|
128
152
|
});
|
|
129
153
|
|
|
130
154
|
this.addEventListener('bookTitleBar', ({ detail }) => {
|
|
@@ -372,4 +396,16 @@ export default class ActionsHandler extends LitElement {
|
|
|
372
396
|
'.archive.org'
|
|
373
397
|
);
|
|
374
398
|
}
|
|
399
|
+
|
|
400
|
+
/**
|
|
401
|
+
* Set sticky admin access on or off.
|
|
402
|
+
* @see WEBDEV-6835
|
|
403
|
+
*
|
|
404
|
+
* @param {boolean} value - Whether to enable or disable sticky admin access.
|
|
405
|
+
* @returns {void}
|
|
406
|
+
*/
|
|
407
|
+
setStickyAdminAccess(value) {
|
|
408
|
+
const domain = window.location.hostname === 'localhost' ? 'localhost' : '.archive.org';
|
|
409
|
+
Cookies.setItem('sticky-admin-access', value, '', '/', domain);
|
|
410
|
+
}
|
|
375
411
|
}
|
|
@@ -35,6 +35,8 @@ export default class LoanAnanlytics {
|
|
|
35
35
|
try {
|
|
36
36
|
await this.getLoanStatsCount(action);
|
|
37
37
|
|
|
38
|
+
this.sendMatrixStatsEvents(action);
|
|
39
|
+
|
|
38
40
|
const date = new Date();
|
|
39
41
|
date.setHours(date.getHours() + 2); // 2 hours
|
|
40
42
|
|
|
@@ -101,14 +103,26 @@ export default class LoanAnanlytics {
|
|
|
101
103
|
|
|
102
104
|
// store these counts in cookies
|
|
103
105
|
this.lendingEventCounts = { browse, renew, expire };
|
|
106
|
+
}
|
|
104
107
|
|
|
108
|
+
/**
|
|
109
|
+
* Send auto-renew Matrix stats events to GA
|
|
110
|
+
* eg
|
|
111
|
+
* - browse001-autorenew000:browse
|
|
112
|
+
* - browse001-autorenew001:autorenew
|
|
113
|
+
* - and so on...
|
|
114
|
+
*
|
|
115
|
+
* @param {action} action
|
|
116
|
+
* @memberof LoanAnanlytics
|
|
117
|
+
*/
|
|
118
|
+
sendMatrixStatsEvents(action) {
|
|
105
119
|
// obtain GA category, event
|
|
106
120
|
const category = analyticsCategories.browse;
|
|
107
121
|
const event = `browse${this.paddedNumber(
|
|
108
122
|
this.gaStats?.browse
|
|
109
123
|
)}-autorenew${this.paddedNumber(this.gaStats?.renew)}:${action}`;
|
|
110
124
|
|
|
111
|
-
// send
|
|
125
|
+
// send events
|
|
112
126
|
this.sendEvent(category, event, this.identifier);
|
|
113
127
|
}
|
|
114
128
|
|
|
@@ -148,9 +162,9 @@ export default class LoanAnanlytics {
|
|
|
148
162
|
// log(
|
|
149
163
|
// 'eventCategory:-',
|
|
150
164
|
// eventCategory,
|
|
151
|
-
// '
|
|
165
|
+
// '||\teventAction:-',
|
|
152
166
|
// eventAction,
|
|
153
|
-
// '
|
|
167
|
+
// '||\tlabel:-',
|
|
154
168
|
// label
|
|
155
169
|
// );
|
|
156
170
|
|
|
@@ -23,6 +23,7 @@ export class LoanRenewHelper {
|
|
|
23
23
|
this.result = {
|
|
24
24
|
texts: null,
|
|
25
25
|
renewNow: false,
|
|
26
|
+
renewType: '',
|
|
26
27
|
};
|
|
27
28
|
}
|
|
28
29
|
|
|
@@ -57,8 +58,11 @@ export class LoanRenewHelper {
|
|
|
57
58
|
|
|
58
59
|
// if user viewed new page in last 10 minutes, renew immediately
|
|
59
60
|
if (lastTimeFrame !== null && currentTime >= lastTimeFrame) {
|
|
60
|
-
this.result
|
|
61
|
-
|
|
61
|
+
this.result = {
|
|
62
|
+
texts: this.loanRenewMessage,
|
|
63
|
+
renewNow: true,
|
|
64
|
+
renewType: 'auto',
|
|
65
|
+
};
|
|
62
66
|
}
|
|
63
67
|
|
|
64
68
|
this.setPageChangedTime();
|
|
@@ -88,11 +92,17 @@ export class LoanRenewHelper {
|
|
|
88
92
|
pageChangedTime === undefined ||
|
|
89
93
|
pageChangedTime <= pageChangeTimeFrame
|
|
90
94
|
) {
|
|
91
|
-
this.result
|
|
92
|
-
|
|
95
|
+
this.result = {
|
|
96
|
+
texts: this.loanReturnWarning,
|
|
97
|
+
renewNow: false, // not viewed
|
|
98
|
+
renewType: '',
|
|
99
|
+
};
|
|
93
100
|
} else if (pageChangedTime >= pageChangeTimeFrame) {
|
|
94
|
-
this.result
|
|
95
|
-
|
|
101
|
+
this.result = {
|
|
102
|
+
texts: '',
|
|
103
|
+
renewNow: true, // viewed in last time frame
|
|
104
|
+
renewType: 'auto',
|
|
105
|
+
};
|
|
96
106
|
}
|
|
97
107
|
|
|
98
108
|
return this.result;
|
package/src/ia-book-actions.js
CHANGED
|
@@ -101,10 +101,10 @@ export default class IABookActions extends LitElement {
|
|
|
101
101
|
/**
|
|
102
102
|
* contains one hour auto-loan-renew time configuration
|
|
103
103
|
* defaults to 1 hour config
|
|
104
|
-
* @type {
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
104
|
+
* @type {object} loanRenewTimeConfig
|
|
105
|
+
* @property {number} loanTotalTime - total seconds a loan does have
|
|
106
|
+
* @property {number} loanRenewAtLast - check for loan renew at last
|
|
107
|
+
* @property {number} pageChangedInLast - consider loan renew eligible if viewed new page
|
|
108
108
|
*/
|
|
109
109
|
this.loanRenewTimeConfig = {
|
|
110
110
|
loanTotalTime: 3600, // 1 hour
|
|
@@ -120,7 +120,7 @@ export default class IABookActions extends LitElement {
|
|
|
120
120
|
* @property {boolean} renewNow - key to determine if need to renew now
|
|
121
121
|
* @property {number} secondsLeft - seconds left in active loan
|
|
122
122
|
*/
|
|
123
|
-
this.loanRenewResult = { texts: '', renewNow: false, secondsLeft: 0 };
|
|
123
|
+
this.loanRenewResult = { texts: '', renewNow: false, secondsLeft: 0, renewType: '' };
|
|
124
124
|
}
|
|
125
125
|
|
|
126
126
|
disconnectedCallback() {
|
|
@@ -468,7 +468,7 @@ export default class IABookActions extends LitElement {
|
|
|
468
468
|
/** Handles Renew action in warning modal */
|
|
469
469
|
async patronWantsToRenewBook() {
|
|
470
470
|
this.showWarningDisabledModal();
|
|
471
|
-
this.loanRenewResult = { texts: '', renewNow: true };
|
|
471
|
+
this.loanRenewResult = { texts: '', renewNow: true, renewType: 'manual' };
|
|
472
472
|
}
|
|
473
473
|
|
|
474
474
|
async patronWantsToReturnBook() {
|
|
@@ -595,6 +595,7 @@ export default class IABookActions extends LitElement {
|
|
|
595
595
|
.returnUrl=${this.returnUrl}
|
|
596
596
|
.localCache=${this.localCache}
|
|
597
597
|
.loanTotalTime=${this.loanRenewTimeConfig.loanTotalTime}
|
|
598
|
+
.loanRenewType=${this.loanRenewResult.renewType}
|
|
598
599
|
?hasAdminAccess=${this.hasAdminAccess}
|
|
599
600
|
?disabled=${this.disableActionGroup}
|
|
600
601
|
?autoRenew=${this.loanRenewResult.renewNow}
|
package/demo/index.html
DELETED
|
@@ -1,454 +0,0 @@
|
|
|
1
|
-
<!doctype html>
|
|
2
|
-
<html lang="en-GB">
|
|
3
|
-
|
|
4
|
-
<head>
|
|
5
|
-
<meta charset="utf-8">
|
|
6
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
|
|
7
|
-
<style>
|
|
8
|
-
html {
|
|
9
|
-
font-size: 10px;
|
|
10
|
-
/* This is to match petabox's base font size */
|
|
11
|
-
}
|
|
12
|
-
body {
|
|
13
|
-
margin: 0;
|
|
14
|
-
text-align: center;
|
|
15
|
-
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
|
|
16
|
-
}
|
|
17
|
-
#demo {
|
|
18
|
-
height: 100px;
|
|
19
|
-
}
|
|
20
|
-
ia-book-actions {
|
|
21
|
-
--white: #fff;
|
|
22
|
-
--black: #000;
|
|
23
|
-
--primaryBGColor: var(--black);
|
|
24
|
-
--secondaryBGColor: #222;
|
|
25
|
-
--tertiaryBGColor: #333;
|
|
26
|
-
--primaryTextColor: var(--white);
|
|
27
|
-
--primaryCTAFill: #194880;
|
|
28
|
-
--primaryCTABorder: #c5d1df;
|
|
29
|
-
--secondaryCTAFill: #333;
|
|
30
|
-
--secondaryCTABorder: #999;
|
|
31
|
-
--secondaryCTAFillRGB: 51, 51, 51;
|
|
32
|
-
--primaryErrorCTAFill: #e51c26;
|
|
33
|
-
--primaryErrorCTABorder: #f8c6c8;
|
|
34
|
-
--primaryCTAFillRGB: 25, 72, 128;
|
|
35
|
-
--primaryErrorCTAFillRGB: 229, 28, 38;
|
|
36
|
-
--primaryDisableCTAFill: #767676;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
fieldset {
|
|
40
|
-
width: fit-content;
|
|
41
|
-
margin-top: 50px;
|
|
42
|
-
}
|
|
43
|
-
fieldset legend {
|
|
44
|
-
text-align: left;
|
|
45
|
-
font-size: 12px;
|
|
46
|
-
}
|
|
47
|
-
td {
|
|
48
|
-
color: white;
|
|
49
|
-
font-size: 14px;
|
|
50
|
-
border-radius: 5%;
|
|
51
|
-
display: table-cell;
|
|
52
|
-
text-align: initial;
|
|
53
|
-
margin: 5px 0;
|
|
54
|
-
width: max-content;
|
|
55
|
-
display: block;
|
|
56
|
-
}
|
|
57
|
-
label {
|
|
58
|
-
padding: 10px;
|
|
59
|
-
display: block;
|
|
60
|
-
cursor: pointer;
|
|
61
|
-
margin: 2px;
|
|
62
|
-
background: #4e545a;
|
|
63
|
-
border-radius: 10px;
|
|
64
|
-
}
|
|
65
|
-
input[type="radio"], input[type="checkbox"] {
|
|
66
|
-
margin-top: 0;
|
|
67
|
-
vertical-align: middle;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
.initial td {
|
|
71
|
-
float: left;
|
|
72
|
-
margin: 2px;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
fieldset {
|
|
76
|
-
display: inline-grid;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
.action-button button {
|
|
80
|
-
padding: 6px;
|
|
81
|
-
cursor: pointer;
|
|
82
|
-
border: 2px solid #194880;
|
|
83
|
-
border-radius: 10px;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
body.modal-manager-open {
|
|
87
|
-
overflow: hidden;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
modal-manager[mode='closed'] {
|
|
91
|
-
display: none;
|
|
92
|
-
}
|
|
93
|
-
</style>
|
|
94
|
-
</head>
|
|
95
|
-
|
|
96
|
-
<body>
|
|
97
|
-
<ia-book-actions></ia-book-actions>
|
|
98
|
-
|
|
99
|
-
<script type="module">
|
|
100
|
-
/* eslint-disable */
|
|
101
|
-
|
|
102
|
-
import '../src/ia-book-actions.js';
|
|
103
|
-
import {
|
|
104
|
-
defaultLendingStatus,
|
|
105
|
-
canBrowseAndBorrow,
|
|
106
|
-
} from '../src/assets/data/lending-get-status-service.js';
|
|
107
|
-
import { ModalConfig } from '@internetarchive/modal-manager';
|
|
108
|
-
import { LocalCache } from '@internetarchive/local-cache';
|
|
109
|
-
|
|
110
|
-
const localCache = new LocalCache({
|
|
111
|
-
namespace: 'loanRenew',
|
|
112
|
-
defaultTTL: 1 * 60, // 1 minute
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
const userid = '@neeraj-archive';
|
|
116
|
-
const identifier = 'naturalhistoryof00unse_4111';
|
|
117
|
-
let bwbPurchaseUrl = 'https://www.betterworldbooks.com/product/detail/cambridge-ancient-hist-v04-0521044863';
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
const modalConfig = new ModalConfig();
|
|
121
|
-
modalConfig.headerColor = '#d9534f';
|
|
122
|
-
|
|
123
|
-
let lendingBarPostInit = function lendingBarPostInit() {
|
|
124
|
-
setTimeout(function() {}, 100);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
// set defaultLendingStatus for unavailable (without borrowables) book
|
|
128
|
-
let iaBookActions = document.querySelector('ia-book-actions');
|
|
129
|
-
|
|
130
|
-
iaBookActions.userid = userid;
|
|
131
|
-
iaBookActions.identifier = identifier;
|
|
132
|
-
iaBookActions.bookTitle = 'Contemporary Black biography. Volume 39 : profiles from the interContemporary Black biography. Volume 39';
|
|
133
|
-
iaBookActions.lendingStatus = canBrowseAndBorrow;
|
|
134
|
-
iaBookActions.bwbPurchaseUrl = '';
|
|
135
|
-
iaBookActions.modalConfig = modalConfig;
|
|
136
|
-
iaBookActions.lendingBarPostInit = lendingBarPostInit;
|
|
137
|
-
iaBookActions.tokenDelay = 2; // 2 seconds
|
|
138
|
-
iaBookActions.timerExecutionSeconds = 4 // 4 seconds
|
|
139
|
-
iaBookActions.returnUrl = '';
|
|
140
|
-
iaBookActions.localCache = localCache;
|
|
141
|
-
|
|
142
|
-
let loanTotalTime2Min = { loanTotalTime: 120, loanRenewAtLast: 80, pageChangedInLast: 15 };
|
|
143
|
-
let loanTotalTime5Min = { loanTotalTime: 300, loanRenewAtLast: 180, pageChangedInLast: 15 };
|
|
144
|
-
let loanTotalTime1Hour = { loanTotalTime: 3600, loanRenewAtLast: 660, pageChangedInLast: 900 };
|
|
145
|
-
|
|
146
|
-
iaBookActions.loanRenewTimeConfig = loanTotalTime2Min;
|
|
147
|
-
|
|
148
|
-
let lendingStatus1 = iaBookActions.lendingStatus;
|
|
149
|
-
let secondsLeftOnLoan = iaBookActions.loanRenewTimeConfig.loanTotalTime;
|
|
150
|
-
|
|
151
|
-
document.querySelectorAll('.titleBar input[type=checkbox]').forEach((item) => {
|
|
152
|
-
item.addEventListener('click', (e) => {
|
|
153
|
-
if (e.target.checked) {
|
|
154
|
-
iaBookActions.barType = 'title';
|
|
155
|
-
} else {
|
|
156
|
-
iaBookActions.barType = 'action';
|
|
157
|
-
}
|
|
158
|
-
});
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
document.querySelectorAll('.searchParam input[type=checkbox]').forEach((item) => {
|
|
162
|
-
item.addEventListener('click', (e) => {
|
|
163
|
-
var searchParams = new URLSearchParams(window.location.search);
|
|
164
|
-
var separate = '';
|
|
165
|
-
if (e.target.checked) {
|
|
166
|
-
separate = '?';
|
|
167
|
-
searchParams.set('q', 'test');
|
|
168
|
-
} else {
|
|
169
|
-
separate = '';
|
|
170
|
-
searchParams.delete('q');
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
if (history.pushState) {
|
|
174
|
-
var newurl = window.location.protocol + "//" + window.location.host + window.location.pathname + separate + searchParams;
|
|
175
|
-
window.history.pushState({path:newurl},'',newurl);
|
|
176
|
-
}
|
|
177
|
-
});
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
document.querySelectorAll('.errorEnable input[type=checkbox]').forEach((item) => {
|
|
181
|
-
if (window.location.href.indexOf('?error=true') !== -1) {
|
|
182
|
-
item.checked = true;
|
|
183
|
-
}
|
|
184
|
-
item.addEventListener('click', (e) => {
|
|
185
|
-
var searchParams = new URLSearchParams(window.location.search);
|
|
186
|
-
var separate = '';
|
|
187
|
-
if (e.target.checked) {
|
|
188
|
-
separate = '?';
|
|
189
|
-
searchParams.set('error', true);
|
|
190
|
-
} else {
|
|
191
|
-
separate = '';
|
|
192
|
-
searchParams.delete('error');
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
if (history.pushState) {
|
|
196
|
-
var newurl = window.location.protocol + "//" + window.location.host + window.location.pathname + separate + searchParams;
|
|
197
|
-
window.history.pushState({path:newurl},'',newurl);
|
|
198
|
-
}
|
|
199
|
-
});
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
document.querySelectorAll('.userState input[type=checkbox]').forEach((item) => {
|
|
204
|
-
item.addEventListener('click', (e) => {
|
|
205
|
-
if (e.target.checked) {
|
|
206
|
-
if (e.target.value === 'isAdmin') lendingStatus1.isAdmin = true;
|
|
207
|
-
if (e.target.value === 'isLoggedIn') iaBookActions.userid = '@neeraj';
|
|
208
|
-
} else {
|
|
209
|
-
if (e.target.value === 'isAdmin') lendingStatus1.isAdmin = false;
|
|
210
|
-
if (e.target.value === 'isLoggedIn') iaBookActions.userid = '';
|
|
211
|
-
}
|
|
212
|
-
let lending = {...defaultLendingStatus, ...lendingStatus1};
|
|
213
|
-
iaBookActions.lendingStatus = lending;
|
|
214
|
-
});
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
document.querySelectorAll('.printDisabled input[type=checkbox]').forEach((item) => {
|
|
218
|
-
item.addEventListener('click', (e) => {
|
|
219
|
-
if (e.target.checked) {
|
|
220
|
-
if (e.target.value === 'is_printdisabled') lendingStatus1.is_printdisabled = true;
|
|
221
|
-
if (e.target.value === 'user_is_printdisabled') lendingStatus1.user_is_printdisabled = true;
|
|
222
|
-
} else {
|
|
223
|
-
if (e.target.value === 'is_printdisabled') lendingStatus1.is_printdisabled = false;
|
|
224
|
-
if (e.target.value === 'user_is_printdisabled') lendingStatus1.user_is_printdisabled = false;
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
let lending = {...defaultLendingStatus, ...lendingStatus1};
|
|
228
|
-
iaBookActions.lendingStatus = lending;
|
|
229
|
-
});
|
|
230
|
-
});
|
|
231
|
-
|
|
232
|
-
document.querySelectorAll('.availableToBrowse input[type=radio]').forEach((item) => {
|
|
233
|
-
item.addEventListener('click', async (e) => {
|
|
234
|
-
if (e.target.value === 'user_has_browsed') {
|
|
235
|
-
lendingStatus1.user_has_browsed = true;
|
|
236
|
-
lendingStatus1.available_to_browse = false;
|
|
237
|
-
lendingStatus1.secondsLeftOnLoan = secondsLeftOnLoan;
|
|
238
|
-
lendingStatus1.browsingExpired = false;
|
|
239
|
-
|
|
240
|
-
const expireDate = new Date(
|
|
241
|
-
new Date().getTime() + iaBookActions.loanRenewTimeConfig.loanTotalTime * 1000
|
|
242
|
-
);
|
|
243
|
-
try {
|
|
244
|
-
// set a value
|
|
245
|
-
await localCache.set({
|
|
246
|
-
key: `${identifier}-loanTime`,
|
|
247
|
-
value: expireDate,
|
|
248
|
-
ttl: Number(iaBookActions.loanRenewTimeConfig.loanTotalTime),
|
|
249
|
-
});
|
|
250
|
-
|
|
251
|
-
await localCache.delete(`${identifier}-pageChangedTime`);
|
|
252
|
-
} catch (error) {}
|
|
253
|
-
|
|
254
|
-
} else if(e.target.value === 'browsingExpired') {
|
|
255
|
-
lendingStatus1.user_has_browsed = true;
|
|
256
|
-
lendingStatus1.available_to_browse = false;
|
|
257
|
-
lendingStatus1.secondsLeftOnLoan = 0;
|
|
258
|
-
lendingStatus1.browsingExpired = true;
|
|
259
|
-
} else if (e.target.value === 'available_to_browse') {
|
|
260
|
-
lendingStatus1.available_to_browse = true;
|
|
261
|
-
lendingStatus1.user_has_browsed = false;
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
// wait for a while
|
|
265
|
-
setTimeout(() => {
|
|
266
|
-
let lending = {...defaultLendingStatus, ...lendingStatus1};
|
|
267
|
-
iaBookActions.lendingStatus = lending;
|
|
268
|
-
}, 10);
|
|
269
|
-
});
|
|
270
|
-
});
|
|
271
|
-
|
|
272
|
-
document.querySelector('#show_warning_modal').addEventListener('click', async () => {
|
|
273
|
-
if (!iaBookActions.lendingStatus.user_has_browsed) {
|
|
274
|
-
const newLendingStatus = { ...iaBookActions.lendingStatus, user_has_browsed: true };
|
|
275
|
-
iaBookActions.lendingStatus = newLendingStatus;
|
|
276
|
-
await iaBookActions.updateComplete;
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
iaBookActions.showWarningModal();
|
|
280
|
-
|
|
281
|
-
if (iaBookActions.lendingStatus.user_has_browsed) {
|
|
282
|
-
iaBookActions.showWarningModal();
|
|
283
|
-
}
|
|
284
|
-
});
|
|
285
|
-
|
|
286
|
-
document.querySelector('#show_expired_modal').addEventListener('click', async () => {
|
|
287
|
-
if (!iaBookActions.lendingStatus.user_has_browsed) {
|
|
288
|
-
const newLendingStatus = { ...iaBookActions.lendingStatus, user_has_browsed: true };
|
|
289
|
-
iaBookActions.lendingStatus = newLendingStatus;
|
|
290
|
-
await iaBookActions.updateComplete;
|
|
291
|
-
}
|
|
292
|
-
await new Promise(resolve => setTimeout(resolve, 5000));
|
|
293
|
-
|
|
294
|
-
iaBookActions.browseHasExpired();
|
|
295
|
-
});
|
|
296
|
-
|
|
297
|
-
document.querySelector('#resync_timer').addEventListener('click', async (e) => {
|
|
298
|
-
if (iaBookActions.lendingStatus.user_has_browsed) {
|
|
299
|
-
document.querySelector('ia-book-actions').dispatchEvent(
|
|
300
|
-
new Event('visibilitychange', {
|
|
301
|
-
detail: {},
|
|
302
|
-
bubbles: true,
|
|
303
|
-
composed: true,
|
|
304
|
-
})
|
|
305
|
-
);
|
|
306
|
-
}
|
|
307
|
-
await new Promise(resolve => setTimeout(resolve, 5000));
|
|
308
|
-
});
|
|
309
|
-
|
|
310
|
-
document.querySelectorAll('.availableToBorrow input[type=radio]').forEach((item) => {
|
|
311
|
-
item.addEventListener('click', (e) => {
|
|
312
|
-
if (e.target.value === 'available_to_borrow') {
|
|
313
|
-
lendingStatus1.available_to_borrow = true;
|
|
314
|
-
lendingStatus1.user_on_waitlist = false;
|
|
315
|
-
lendingStatus1.available_to_waitlist = false;
|
|
316
|
-
lendingStatus1.user_has_borrowed = false;
|
|
317
|
-
} else if (e.target.value === 'user_can_claim_waitlist') {
|
|
318
|
-
lendingStatus1.available_to_borrow = true;
|
|
319
|
-
lendingStatus1.user_on_waitlist = true;
|
|
320
|
-
lendingStatus1.user_can_claim_waitlist = true;
|
|
321
|
-
lendingStatus1.user_has_borrowed = false;
|
|
322
|
-
lendingStatus1.available_to_waitlist = false;
|
|
323
|
-
} else if (e.target.value === 'user_on_waitlist') {
|
|
324
|
-
lendingStatus1.available_to_borrow = false;
|
|
325
|
-
lendingStatus1.user_on_waitlist = true;
|
|
326
|
-
lendingStatus1.available_to_waitlist = false;
|
|
327
|
-
lendingStatus1.user_has_borrowed = false;
|
|
328
|
-
} else if (e.target.value === 'available_to_waitlist') {
|
|
329
|
-
lendingStatus1.available_to_borrow = false;
|
|
330
|
-
lendingStatus1.user_on_waitlist = false;
|
|
331
|
-
lendingStatus1.available_to_waitlist = true;
|
|
332
|
-
lendingStatus1.user_has_borrowed = false;
|
|
333
|
-
} else if (e.target.value === 'user_has_borrowed') {
|
|
334
|
-
lendingStatus1.available_to_borrow = false;
|
|
335
|
-
lendingStatus1.user_on_waitlist = false;
|
|
336
|
-
lendingStatus1.available_to_waitlist = false;
|
|
337
|
-
lendingStatus1.user_has_borrowed = true;
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
let lending = {...defaultLendingStatus, ...lendingStatus1};
|
|
341
|
-
iaBookActions.lendingStatus = lending;
|
|
342
|
-
});
|
|
343
|
-
});
|
|
344
|
-
|
|
345
|
-
document.querySelectorAll('.purchase input[type=checkbox]').forEach((item) => {
|
|
346
|
-
item.addEventListener('click', (e) => {
|
|
347
|
-
if (e.target.checked) {
|
|
348
|
-
bwbPurchaseUrl = 'https://www.google.com';
|
|
349
|
-
} else {
|
|
350
|
-
bwbPurchaseUrl = ''
|
|
351
|
-
}
|
|
352
|
-
iaBookActions.bwbPurchaseUrl = bwbPurchaseUrl;
|
|
353
|
-
})
|
|
354
|
-
});
|
|
355
|
-
|
|
356
|
-
document.querySelector('.pageChangedEvent').addEventListener('click', () => {
|
|
357
|
-
// dispatch event to say book page has flipped
|
|
358
|
-
document.querySelector('ia-book-actions').dispatchEvent(
|
|
359
|
-
new CustomEvent('BookReader:userAction', {
|
|
360
|
-
detail: {},
|
|
361
|
-
bubbles: true,
|
|
362
|
-
composed: true,
|
|
363
|
-
})
|
|
364
|
-
);
|
|
365
|
-
})
|
|
366
|
-
|
|
367
|
-
// listen for IABookReader:BrowsingHasExpired
|
|
368
|
-
window.addEventListener('IABookReader:BrowsingHasExpired', () => {
|
|
369
|
-
console.log('IABookReader:BrowsingHasExpired EVENT FIRED');
|
|
370
|
-
});
|
|
371
|
-
</script>
|
|
372
|
-
|
|
373
|
-
<div>
|
|
374
|
-
<fieldset>
|
|
375
|
-
<legend>Dev testing for book title bar</legend>
|
|
376
|
-
<table class="initial">
|
|
377
|
-
<tr>
|
|
378
|
-
<td class="titleBar">
|
|
379
|
-
<label><input type="checkbox" name="title" value="title" />Title Bar</label>
|
|
380
|
-
</td>
|
|
381
|
-
<td class="searchParam">
|
|
382
|
-
<label><input type="checkbox" name="search" value="Search Param" />Search Param</label>
|
|
383
|
-
</td>
|
|
384
|
-
<td>
|
|
385
|
-
<label class="ia-button"><button class="pageChangedEvent">Page Change Event</button></label>
|
|
386
|
-
</td>
|
|
387
|
-
</tr>
|
|
388
|
-
</table>
|
|
389
|
-
</fieldset>
|
|
390
|
-
|
|
391
|
-
<fieldset>
|
|
392
|
-
<legend>Dev testing for book action bar</legend>
|
|
393
|
-
<table class="initial">
|
|
394
|
-
<tr colspan='5'>
|
|
395
|
-
<td class="errorEnable"><label><input type="checkbox" name="errorEnable" value="errorEnable" />Do you want to see error response?</label></td>
|
|
396
|
-
</tr>
|
|
397
|
-
<tr>
|
|
398
|
-
<td class="userState">
|
|
399
|
-
<label><input type="checkbox" name="user" value="isAdmin" />isAdmin</label>
|
|
400
|
-
<label><input type="checkbox" name="user" value="isLoggedIn" />isLoggedIn</label>
|
|
401
|
-
</td>
|
|
402
|
-
<td class="printDisabled">
|
|
403
|
-
<label><input type="checkbox" name="is_printdisabled" value="is_printdisabled" />is_printdisabled</label>
|
|
404
|
-
<label><input type="checkbox" name="user_is_printdisabled" value="user_is_printdisabled" />user_is_printdisabled</label>
|
|
405
|
-
</td>
|
|
406
|
-
<td class="availableToBrowse">
|
|
407
|
-
<label><input type="radio" name="browse" value="available_to_browse" />available_to_browse</label>
|
|
408
|
-
<label><input type="radio" name="browse" value="user_has_browsed" />user_has_browsed</label>
|
|
409
|
-
<label><input type="radio" name="browse" value="browsingExpired" />browsingExpired</label>
|
|
410
|
-
</td>
|
|
411
|
-
<td class="availableToBorrow">
|
|
412
|
-
<label><input type="radio" name="borrow" value="available_to_borrow" />available_to_borrow</label>
|
|
413
|
-
<label><input type="radio" name="borrow" value="user_on_waitlist" />user_on_waitlist</label>
|
|
414
|
-
<label><input type="radio" name="borrow" value="user_can_claim_waitlist" />user_can_claim_waitlist</label>
|
|
415
|
-
<label><input type="radio" name="borrow" value="available_to_waitlist" />available_to_waitlist</label>
|
|
416
|
-
<label><input type="radio" name="borrow" value="user_has_borrowed" />user_has_borrowed</label>
|
|
417
|
-
</td>
|
|
418
|
-
<td class="purchase">
|
|
419
|
-
<label><input type="checkbox" name="purchase" value="purchase" />purchase</label>
|
|
420
|
-
</td>
|
|
421
|
-
|
|
422
|
-
<td class="reflect">
|
|
423
|
-
<input type="button" style="padding: 10px;
|
|
424
|
-
background: #194880;
|
|
425
|
-
color: white;
|
|
426
|
-
font-weight: bold; display: none" name="purchase" value="Reflect" />
|
|
427
|
-
</td>
|
|
428
|
-
</tr>
|
|
429
|
-
<tr>
|
|
430
|
-
<td>
|
|
431
|
-
<fieldset style="margin-top: 10px;">
|
|
432
|
-
<legend style="color: black;">controls for browsed book</legend>
|
|
433
|
-
<table aria-hidden="true">
|
|
434
|
-
<tbody><tr>
|
|
435
|
-
<td class="action-button">
|
|
436
|
-
<button id="show_warning_modal">When Browsing (`user_has_browsed`),<br> show Warning Modal</button>
|
|
437
|
-
</td>
|
|
438
|
-
<td class="action-button">
|
|
439
|
-
<button id="show_expired_modal">While Browsing (`user_has_browsed`),<br> Expire book & show its modal</button>
|
|
440
|
-
</td>
|
|
441
|
-
<td class="action-button">
|
|
442
|
-
<button id="resync_timer">While Browsing (`user_has_browsed`),<br> resync timer</button>
|
|
443
|
-
</td>
|
|
444
|
-
</tr>
|
|
445
|
-
</tbody></table>
|
|
446
|
-
</fieldset>
|
|
447
|
-
</td>
|
|
448
|
-
</tr>
|
|
449
|
-
</table>
|
|
450
|
-
</fieldset>
|
|
451
|
-
</div>
|
|
452
|
-
<modal-manager></modal-manager>
|
|
453
|
-
</body>
|
|
454
|
-
</html>
|