@internetarchive/ia-book-actions 0.0.6-7 → 0.0.6-8-04
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/demo/index.html +46 -10
- package/package.json +3 -2
- package/src/components/collapsible-action-group.js +22 -15
- package/src/core/services/actions-handler/actions-handler-service.js +24 -12
- package/src/core/services/actions-handler/actions-handler.js +42 -13
- package/src/core/services/get-lending-actions.js +4 -1
- package/src/ia-book-actions.js +43 -44
- package/test/ia-book-actions.test.js +0 -1
- package/src/components/dialog-alert.js +0 -139
package/demo/index.html
CHANGED
|
@@ -72,14 +72,16 @@
|
|
|
72
72
|
margin: 2px;
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
75
|
+
body.modal-manager-open {
|
|
76
|
+
overflow: hidden;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
modal-manager {
|
|
80
|
+
display: none;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
modal-manager[mode='open'] {
|
|
84
|
+
display: block;
|
|
83
85
|
}
|
|
84
86
|
</style>
|
|
85
87
|
</head>
|
|
@@ -95,6 +97,7 @@
|
|
|
95
97
|
defaultLendingStatus,
|
|
96
98
|
canBrowseAndBorrow,
|
|
97
99
|
} from '../src/assets/data/lending-get-status-service.js';
|
|
100
|
+
import { ModalConfig } from '@internetarchive/modal-manager';
|
|
98
101
|
|
|
99
102
|
const userid = '@neeraj-archive';
|
|
100
103
|
const identifier = 'naturalhistoryof00unse_4111';
|
|
@@ -102,13 +105,20 @@
|
|
|
102
105
|
|
|
103
106
|
let iaBookActions = document.querySelector('ia-book-actions');
|
|
104
107
|
|
|
108
|
+
// render modal-manager
|
|
109
|
+
const modal = document.createElement('modal-manager');
|
|
110
|
+
const modalConfig = new ModalConfig();
|
|
111
|
+
modalConfig.headerColor = '#d9534f';
|
|
112
|
+
document.body.appendChild(modal);
|
|
113
|
+
|
|
105
114
|
// set defaultLendingStatus for unavailable (without borrowables) book
|
|
106
|
-
iaBookActions.userid =
|
|
115
|
+
iaBookActions.userid = userid;
|
|
107
116
|
iaBookActions.identifier = identifier;
|
|
108
117
|
iaBookActions.bookTitle = 'Contemporary Black biography. Volume 39 : profiles from the interContemporary Black biography. Volume 39';
|
|
109
118
|
iaBookActions.lendingStatus = canBrowseAndBorrow;
|
|
110
119
|
iaBookActions.bwbPurchaseUrl = '';
|
|
111
120
|
iaBookActions.barType = '';
|
|
121
|
+
iaBookActions.modalConfig = modalConfig;
|
|
112
122
|
|
|
113
123
|
let lendingStatus1 = iaBookActions.lendingStatus;
|
|
114
124
|
|
|
@@ -122,6 +132,29 @@
|
|
|
122
132
|
});
|
|
123
133
|
});
|
|
124
134
|
|
|
135
|
+
document.querySelectorAll('.errorEnable input[type=checkbox]').forEach((item) => {
|
|
136
|
+
if (window.location.href.indexOf('?error=true') !== -1) {
|
|
137
|
+
item.checked = true;
|
|
138
|
+
}
|
|
139
|
+
item.addEventListener('click', (e) => {
|
|
140
|
+
var searchParams = new URLSearchParams(window.location.search);
|
|
141
|
+
var separate = '';
|
|
142
|
+
if (e.target.checked) {
|
|
143
|
+
separate = '?';
|
|
144
|
+
searchParams.set('error', true);
|
|
145
|
+
} else {
|
|
146
|
+
separate = '';
|
|
147
|
+
searchParams.delete('error');
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (history.pushState) {
|
|
151
|
+
var newurl = window.location.protocol + "//" + window.location.host + window.location.pathname + separate + searchParams;
|
|
152
|
+
window.history.pushState({path:newurl},'',newurl);
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
|
|
125
158
|
document.querySelectorAll('.userState input[type=checkbox]').forEach((item) => {
|
|
126
159
|
item.addEventListener('click', (e) => {
|
|
127
160
|
if (e.target.checked) {
|
|
@@ -156,7 +189,7 @@
|
|
|
156
189
|
if (e.target.value === 'user_has_browsed') {
|
|
157
190
|
lendingStatus1.user_has_browsed = true;
|
|
158
191
|
lendingStatus1.available_to_browse = false;
|
|
159
|
-
lendingStatus1.secondsLeftOnLoan =
|
|
192
|
+
lendingStatus1.secondsLeftOnLoan = 10;
|
|
160
193
|
lendingStatus1.browsingExpired = false;
|
|
161
194
|
} else if(e.target.value === 'browsingExpired') {
|
|
162
195
|
lendingStatus1.user_has_browsed = true;
|
|
@@ -229,6 +262,9 @@
|
|
|
229
262
|
<fieldset>
|
|
230
263
|
<legend>Dev testing for book action bar</legend>
|
|
231
264
|
<table class="initial">
|
|
265
|
+
<tr colspan='5'>
|
|
266
|
+
<td class="errorEnable"><label><input type="checkbox" name="errorEnable" value="errorEnable" />Do you want to see error response?</label></td>
|
|
267
|
+
</tr>
|
|
232
268
|
<tr>
|
|
233
269
|
<td class="userState">
|
|
234
270
|
<label><input type="checkbox" name="user" value="isAdmin" />isAdmin</label>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@internetarchive/ia-book-actions",
|
|
3
|
-
"version": "0.0.6-
|
|
3
|
+
"version": "0.0.6-8-04",
|
|
4
4
|
"description": "Bookreader actions for borrowable book",
|
|
5
5
|
"author": "Internet Archive",
|
|
6
6
|
"license": "AGPL-3.0-only",
|
|
@@ -20,8 +20,9 @@
|
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@internetarchive/ia-icons": "^1.2.2",
|
|
22
22
|
"@internetarchive/icon-bookmark": "^1.1.3",
|
|
23
|
-
"@internetarchive/icon-info": "^1.2.6",
|
|
24
23
|
"@internetarchive/icon-close": "^1.1.3",
|
|
24
|
+
"@internetarchive/icon-info": "^1.2.6",
|
|
25
|
+
"@internetarchive/modal-manager": "^0.2.1",
|
|
25
26
|
"@internetarchive/shared-resize-observer": "^0.0.1",
|
|
26
27
|
"lit-element": "^2.4.0",
|
|
27
28
|
"lit-html": "^1.3.0"
|
|
@@ -27,7 +27,7 @@ export class CollapsibleActionGroup extends ActionsHandler {
|
|
|
27
27
|
hasAdminAccess: { type: Boolean },
|
|
28
28
|
dropdownArrow: { type: String },
|
|
29
29
|
disabled: { type: Boolean },
|
|
30
|
-
|
|
30
|
+
borrowType: { type: String },
|
|
31
31
|
};
|
|
32
32
|
}
|
|
33
33
|
|
|
@@ -46,13 +46,8 @@ export class CollapsibleActionGroup extends ActionsHandler {
|
|
|
46
46
|
this.title = '';
|
|
47
47
|
this.loaderIcon = 'https://archive.org/upload/images/tree/loading.gif';
|
|
48
48
|
this.disabled = false;
|
|
49
|
-
this.
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
firstUpdated() {
|
|
53
|
-
if (this.bookHasBrowsed) {
|
|
54
|
-
this.emitFetchLoanToken();
|
|
55
|
-
}
|
|
49
|
+
this.borrowType = ''; // (browsed|borrowed)
|
|
50
|
+
this.consecutiveLoanCounts = 1; // consecutive loan count
|
|
56
51
|
}
|
|
57
52
|
|
|
58
53
|
updated(changed) {
|
|
@@ -62,19 +57,31 @@ export class CollapsibleActionGroup extends ActionsHandler {
|
|
|
62
57
|
}
|
|
63
58
|
}
|
|
64
59
|
|
|
65
|
-
// this is execute
|
|
66
|
-
if (changed.has('
|
|
67
|
-
this.
|
|
60
|
+
// this is execute to fetch loan token
|
|
61
|
+
if (changed.has('borrowType')) {
|
|
62
|
+
this.emitEnableBookAccess();
|
|
68
63
|
}
|
|
69
64
|
}
|
|
70
65
|
|
|
71
66
|
/* emit custom event to fetch loan token */
|
|
72
|
-
|
|
67
|
+
emitEnableBookAccess() {
|
|
68
|
+
// send consecutiveLoanCounts for browsed books only.
|
|
69
|
+
// for borrowed books, we just send [Counts-1]
|
|
70
|
+
if (this.borrowType === 'browsed') {
|
|
71
|
+
this.consecutiveLoanCounts =
|
|
72
|
+
localStorage.getItem('consecutive-loan-count') ?? 1;
|
|
73
|
+
}
|
|
74
|
+
|
|
73
75
|
this.dispatchEvent(
|
|
74
|
-
new CustomEvent('
|
|
76
|
+
new CustomEvent('enableBookAccess', {
|
|
75
77
|
detail: {
|
|
76
|
-
event: {
|
|
77
|
-
|
|
78
|
+
event: {
|
|
79
|
+
category: `${this.borrowType}BookAccess`, // browsedBookAccess | borrowedBookAccess
|
|
80
|
+
action: `${
|
|
81
|
+
this.borrowType === 'browsed' ? 'BrowseCounts-' : 'Counts-'
|
|
82
|
+
}${this.consecutiveLoanCounts}`, // (BrowseCounts-1|Counts-X)
|
|
83
|
+
},
|
|
84
|
+
borrowType: this.borrowType,
|
|
78
85
|
},
|
|
79
86
|
})
|
|
80
87
|
);
|
|
@@ -8,11 +8,8 @@ export default function ActionsHandlerService(options) {
|
|
|
8
8
|
const option = {
|
|
9
9
|
action: null,
|
|
10
10
|
identifier: '',
|
|
11
|
-
data: {},
|
|
12
11
|
success() {},
|
|
13
12
|
error() {},
|
|
14
|
-
loader: true,
|
|
15
|
-
type: 'POST',
|
|
16
13
|
...options,
|
|
17
14
|
};
|
|
18
15
|
|
|
@@ -32,17 +29,32 @@ export default function ActionsHandlerService(options) {
|
|
|
32
29
|
body: formData,
|
|
33
30
|
})
|
|
34
31
|
.then(response => {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
32
|
+
let shouldReturnError =
|
|
33
|
+
window.location.href.indexOf('?error=true') !== -1;
|
|
34
|
+
const tokenError = 'loan token not found. please try again later.';
|
|
35
|
+
const borrowError =
|
|
36
|
+
'This book is not available to borrow at this time. Please try again later.';
|
|
37
|
+
|
|
38
|
+
// return error reponse if query param has ?error=true param...
|
|
39
|
+
if (option.action == 'create_token' && shouldReturnError) {
|
|
40
|
+
return {
|
|
41
|
+
success: false,
|
|
42
|
+
error: tokenError,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
42
45
|
|
|
46
|
+
if (shouldReturnError) {
|
|
47
|
+
return {
|
|
48
|
+
status: true,
|
|
49
|
+
error: borrowError,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// return success response for /demo/ server...
|
|
54
|
+
if (baseHost == '/demo/1' || baseHost == '/demo/') {
|
|
43
55
|
return {
|
|
44
|
-
|
|
45
|
-
|
|
56
|
+
success: true,
|
|
57
|
+
message: 'operation executed successfully!',
|
|
46
58
|
};
|
|
47
59
|
}
|
|
48
60
|
|
|
@@ -15,24 +15,37 @@ export default class ActionsHandler extends LitElement {
|
|
|
15
15
|
super();
|
|
16
16
|
this.identifier = identifier;
|
|
17
17
|
this.ajaxTimeout = 6000;
|
|
18
|
-
this.loanTokenPollingDelay =
|
|
18
|
+
this.loanTokenPollingDelay =
|
|
19
|
+
window.location.pathname === '/demo/' ? 2000 : 120000; // 120000 ms = 2 min
|
|
19
20
|
this.loanTokenInterval = null;
|
|
20
21
|
this.bindEvents();
|
|
21
22
|
}
|
|
22
23
|
|
|
24
|
+
disconnectedCallback() {
|
|
25
|
+
this.loanTokenInterval = undefined;
|
|
26
|
+
}
|
|
27
|
+
|
|
23
28
|
sendEvent(eventCategory, eventAction) {
|
|
24
29
|
// eslint-disable-next-line no-console
|
|
25
30
|
console?.log('Book action: ', { eventCategory, eventAction });
|
|
26
|
-
window?.archive_analytics?.
|
|
31
|
+
window?.archive_analytics?.send_event_no_sampling(
|
|
27
32
|
eventCategory,
|
|
28
33
|
eventAction,
|
|
29
|
-
|
|
34
|
+
`identifier=${this.identifier}`
|
|
30
35
|
);
|
|
31
36
|
}
|
|
32
37
|
|
|
33
38
|
bindEvents() {
|
|
34
39
|
this.addEventListener('browseBook', ({ detail }) => {
|
|
35
40
|
this.handleBrowseIt();
|
|
41
|
+
this.setConsecutiveLoanCounts();
|
|
42
|
+
const { category, action } = detail.event;
|
|
43
|
+
this.sendEvent(category, action);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
this.addEventListener('browseBookAgain', ({ detail }) => {
|
|
47
|
+
this.handleBrowseIt();
|
|
48
|
+
this.setConsecutiveLoanCounts('browseAgain');
|
|
36
49
|
const { category, action } = detail.event;
|
|
37
50
|
this.sendEvent(category, action);
|
|
38
51
|
});
|
|
@@ -87,16 +100,19 @@ export default class ActionsHandler extends LitElement {
|
|
|
87
100
|
this.sendEvent(category, action);
|
|
88
101
|
});
|
|
89
102
|
|
|
90
|
-
this.addEventListener('
|
|
91
|
-
const
|
|
103
|
+
this.addEventListener('enableBookAccess', ({ detail }) => {
|
|
104
|
+
const borrowType = detail?.borrowType;
|
|
92
105
|
|
|
93
|
-
// fetch loan token and set an interval
|
|
94
|
-
if (
|
|
106
|
+
// fetch loan token for browsed/borrowed book and set an interval
|
|
107
|
+
if (borrowType) {
|
|
95
108
|
console.log('token poll started...');
|
|
96
109
|
|
|
97
110
|
this.loanTokenInterval = setInterval(() => {
|
|
98
111
|
this.handleLoanTokenPoller();
|
|
99
112
|
}, this.loanTokenPollingDelay);
|
|
113
|
+
|
|
114
|
+
const { category, action } = detail?.event;
|
|
115
|
+
this.sendEvent(category, action);
|
|
100
116
|
} else {
|
|
101
117
|
// if book is not browsed, just clear token polling interval
|
|
102
118
|
clearInterval(this.loanTokenInterval);
|
|
@@ -187,22 +203,18 @@ export default class ActionsHandler extends LitElement {
|
|
|
187
203
|
|
|
188
204
|
handleLoanTokenPoller() {
|
|
189
205
|
const context = 'create_token';
|
|
190
|
-
this.ActionError(context);
|
|
191
|
-
|
|
192
206
|
ActionsHandlerService({
|
|
193
207
|
identifier: this.identifier,
|
|
194
208
|
action: context,
|
|
195
|
-
loader: false,
|
|
196
|
-
success: () => {
|
|
197
|
-
this.handleReadItNow();
|
|
198
|
-
},
|
|
199
209
|
error: data => {
|
|
200
210
|
this.ActionError(context, data);
|
|
211
|
+
clearInterval(this.loanTokenInterval); // stop token fetch api
|
|
201
212
|
},
|
|
202
213
|
});
|
|
203
214
|
}
|
|
204
215
|
|
|
205
216
|
ActionError(context, data = {}) {
|
|
217
|
+
console.log(context, data);
|
|
206
218
|
this.dispatchEvent(
|
|
207
219
|
new CustomEvent('lendingActionError', {
|
|
208
220
|
detail: { context, data },
|
|
@@ -242,6 +254,23 @@ export default class ActionsHandler extends LitElement {
|
|
|
242
254
|
}, this.ajaxTimeout);
|
|
243
255
|
}
|
|
244
256
|
|
|
257
|
+
// save consecutive loan count for borrow
|
|
258
|
+
setConsecutiveLoanCounts(action = '') {
|
|
259
|
+
const { localStorage } = window;
|
|
260
|
+
if (localStorage) {
|
|
261
|
+
let newCount = 1;
|
|
262
|
+
const storageKey = `consecutive-loan-count`;
|
|
263
|
+
const existingCount = Number(localStorage.getItem(storageKey));
|
|
264
|
+
|
|
265
|
+
// want to increase browse-count by 1 if,
|
|
266
|
+
// you consecutive reading a book.
|
|
267
|
+
if (action === 'browseAgain') {
|
|
268
|
+
newCount = existingCount ? existingCount + 1 : 1;
|
|
269
|
+
}
|
|
270
|
+
localStorage.setItem(storageKey, newCount);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
245
274
|
deleteLoanCookies() {
|
|
246
275
|
const date = new Date();
|
|
247
276
|
date.setTime(date.getTime() - 24 * 60 * 60 * 1000); // one day ago
|
|
@@ -75,7 +75,9 @@ export default class GetLendingActions {
|
|
|
75
75
|
const disableBorrow = lendingStatus.loanCount >= lendingStatus.maxLoans;
|
|
76
76
|
|
|
77
77
|
let primaryTitleText = '';
|
|
78
|
-
|
|
78
|
+
let isBrowsed =
|
|
79
|
+
lendingStatus.user_has_browsed && !lendingStatus.browsingExpired;
|
|
80
|
+
if (isBrowsed) {
|
|
79
81
|
primaryTitleText = this.getBrowseCountdownTitle();
|
|
80
82
|
} else {
|
|
81
83
|
primaryTitleText = `Your loan of this book has ${lendingStatus.daysLeftOnLoan} days left.`;
|
|
@@ -94,6 +96,7 @@ export default class GetLendingActions {
|
|
|
94
96
|
this.actionsConfig.adminAccessConfig(),
|
|
95
97
|
this.actionsConfig.purchaseConfig(),
|
|
96
98
|
],
|
|
99
|
+
borrowType: isBrowsed ? 'browsed' : 'borrowed',
|
|
97
100
|
};
|
|
98
101
|
}
|
|
99
102
|
|
package/src/ia-book-actions.js
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
import { html, css, LitElement } from 'lit-element';
|
|
3
3
|
|
|
4
4
|
import { SharedResizeObserver } from '@internetarchive/shared-resize-observer';
|
|
5
|
+
import { ModalConfig } from '@internetarchive/modal-manager';
|
|
5
6
|
|
|
6
7
|
import './components/collapsible-action-group.js';
|
|
7
8
|
import './components/book-title-bar.js';
|
|
8
9
|
import './components/text-group.js';
|
|
9
10
|
import './components/info-icon.js';
|
|
10
|
-
import './components/dialog-alert.js';
|
|
11
11
|
|
|
12
12
|
import GetLendingActions from './core/services/get-lending-actions.js';
|
|
13
13
|
import { mobileContainerWidth } from './core/config/constants.js';
|
|
@@ -23,9 +23,8 @@ export default class IABookActions extends LitElement {
|
|
|
23
23
|
bwbPurchaseUrl: { type: String },
|
|
24
24
|
barType: { type: String },
|
|
25
25
|
sharedObserver: { attribute: false },
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
bookHasBrowsed: { type: Boolean },
|
|
26
|
+
disableActionGroup: { type: Boolean },
|
|
27
|
+
modalConfig: { type: Object },
|
|
29
28
|
};
|
|
30
29
|
}
|
|
31
30
|
|
|
@@ -45,8 +44,7 @@ export default class IABookActions extends LitElement {
|
|
|
45
44
|
this.secondaryActions = [];
|
|
46
45
|
this.lendingOptions = {};
|
|
47
46
|
this.disableActionGroup = false;
|
|
48
|
-
this.
|
|
49
|
-
this.bookHasBrowsed = false;
|
|
47
|
+
this.modalConfig = {};
|
|
50
48
|
}
|
|
51
49
|
|
|
52
50
|
disconnectedCallback() {
|
|
@@ -58,6 +56,11 @@ export default class IABookActions extends LitElement {
|
|
|
58
56
|
this.sharedObserver = new SharedResizeObserver();
|
|
59
57
|
this.setupResizeObserver();
|
|
60
58
|
}
|
|
59
|
+
|
|
60
|
+
if (!this.modalConfig) {
|
|
61
|
+
this.modalConfig = new ModalConfig();
|
|
62
|
+
this.modalConfig.headerColor = '#d9534f';
|
|
63
|
+
}
|
|
61
64
|
this.setupLendingToolbarActions();
|
|
62
65
|
}
|
|
63
66
|
|
|
@@ -146,12 +149,10 @@ export default class IABookActions extends LitElement {
|
|
|
146
149
|
return action != null;
|
|
147
150
|
});
|
|
148
151
|
|
|
149
|
-
this.
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
// start timer for 1-hour borrowed book.
|
|
154
|
-
// when 1 hour is completed, we shows browse-again button
|
|
152
|
+
this.borrowType = actions.borrowType;
|
|
153
|
+
if (this.borrowType === 'browsed') {
|
|
154
|
+
// start timer for browsed.
|
|
155
|
+
// when browse is completed, we shows browse-again button
|
|
155
156
|
this.startBrowseTimer();
|
|
156
157
|
}
|
|
157
158
|
}
|
|
@@ -161,21 +162,9 @@ export default class IABookActions extends LitElement {
|
|
|
161
162
|
<section class="lending-wrapper">
|
|
162
163
|
${this.barType === 'title' ? this.bookTitleBar : this.bookActionBar}
|
|
163
164
|
</section>
|
|
164
|
-
|
|
165
|
-
<show-dialog
|
|
166
|
-
.title=${this.dialogTitle}
|
|
167
|
-
.body=${this.dialogBody}
|
|
168
|
-
.actions=${this.dialogActions}
|
|
169
|
-
?opened="${this.dialogVisible}"
|
|
170
|
-
@dialogAlertClose="${() => this.closeDialogAlert()}"
|
|
171
|
-
></show-dialog>
|
|
172
165
|
`;
|
|
173
166
|
}
|
|
174
167
|
|
|
175
|
-
closeDialogAlert() {
|
|
176
|
-
this.dialogVisible = false;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
168
|
get bookTitleBar() {
|
|
180
169
|
return html`<book-title-bar
|
|
181
170
|
.identifier=${this.identifier}
|
|
@@ -192,9 +181,9 @@ export default class IABookActions extends LitElement {
|
|
|
192
181
|
.primaryActions=${this.primaryActions}
|
|
193
182
|
.secondaryActions=${this.secondaryActions}
|
|
194
183
|
.width=${this.width}
|
|
195
|
-
.
|
|
196
|
-
|
|
197
|
-
|
|
184
|
+
.borrowType=${this.borrowType}
|
|
185
|
+
?hasAdminAccess=${this.hasAdminAccess}
|
|
186
|
+
?disabled=${this.disableActionGroup}
|
|
198
187
|
@lendingActionError=${this.handleLendingActionError}
|
|
199
188
|
>
|
|
200
189
|
</collapsible-action-group>
|
|
@@ -209,10 +198,7 @@ export default class IABookActions extends LitElement {
|
|
|
209
198
|
const context = e?.detail?.context;
|
|
210
199
|
const errorMsg = e?.detail?.data?.error;
|
|
211
200
|
|
|
212
|
-
|
|
213
|
-
if (!errorMsg) return;
|
|
214
|
-
|
|
215
|
-
this.initializeDialogAlert(context, errorMsg);
|
|
201
|
+
if (errorMsg) this.showErrorModal(context, errorMsg);
|
|
216
202
|
|
|
217
203
|
// update action bar state if book is not available to browse or borrow.
|
|
218
204
|
if (errorMsg && errorMsg.match(/not available to borrow/gm)) {
|
|
@@ -232,22 +218,35 @@ export default class IABookActions extends LitElement {
|
|
|
232
218
|
}
|
|
233
219
|
}
|
|
234
220
|
|
|
235
|
-
/*
|
|
236
|
-
|
|
237
|
-
this.
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
this.
|
|
221
|
+
/* show error message if something went wrong */
|
|
222
|
+
showErrorModal(context, errorMsg) {
|
|
223
|
+
this.modal = document.querySelector('modal-manager');
|
|
224
|
+
|
|
225
|
+
// fallback if <modal-manager> is not found!
|
|
226
|
+
if (!this.modal) {
|
|
227
|
+
alert(errorMsg);
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
this.disableActionGroup = false;
|
|
232
|
+
this.modalConfig.title = 'Sorry!';
|
|
233
|
+
this.modalConfig.message = errorMsg;
|
|
241
234
|
|
|
242
235
|
if (context === 'create_token') {
|
|
243
|
-
this.
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
href:
|
|
248
|
-
|
|
249
|
-
|
|
236
|
+
this.modalConfig.message = html`<p class="headline">
|
|
237
|
+
Uh oh, something went wrong trying to access this book. Please
|
|
238
|
+
<a href="#">refresh</a> to try again or send us an email to
|
|
239
|
+
<a
|
|
240
|
+
href="mailto:info@archive.org?subject=Help: cannot access my borrowed book: ${this
|
|
241
|
+
.identifier}"
|
|
242
|
+
>info@archive.org</a
|
|
243
|
+
>
|
|
244
|
+
</p>`;
|
|
250
245
|
}
|
|
246
|
+
|
|
247
|
+
this.modal.showModal({
|
|
248
|
+
config: this.modalConfig,
|
|
249
|
+
});
|
|
251
250
|
}
|
|
252
251
|
|
|
253
252
|
get iconClass() {
|
|
@@ -130,7 +130,6 @@ describe('Borrow status actions', () => {
|
|
|
130
130
|
el.dispatchEvent(errorEvent);
|
|
131
131
|
await el.updateComplete;
|
|
132
132
|
|
|
133
|
-
console.log(el.lendingStatus);
|
|
134
133
|
// removed available_to_browse from lending bar
|
|
135
134
|
expect(el.lendingStatus.available_to_browse).to.be.false;
|
|
136
135
|
expect(el.primaryActions[0].text).to.equal('Borrow for 14 days');
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
/* eslint-disable */
|
|
2
|
-
import { LitElement, html, css } from 'lit-element';
|
|
3
|
-
import { classMap } from 'lit-html/directives/class-map';
|
|
4
|
-
|
|
5
|
-
import '@internetarchive/icon-close/icon-close.js';
|
|
6
|
-
import buttonBaseStyle from '../assets/styles/ia-button.js';
|
|
7
|
-
|
|
8
|
-
export class ShowDialog extends LitElement {
|
|
9
|
-
static get properties() {
|
|
10
|
-
return {
|
|
11
|
-
title: { type: String },
|
|
12
|
-
body: { type: String },
|
|
13
|
-
actions: { type: Array },
|
|
14
|
-
opened: { type: Boolean },
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
constructor() {
|
|
19
|
-
super();
|
|
20
|
-
this.title = 'Error';
|
|
21
|
-
this.body =
|
|
22
|
-
'Unexpected error: loan does not exist. Please try deleting your archive.org cookie.';
|
|
23
|
-
this.actions = [];
|
|
24
|
-
this.opened = false;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
updated(changed) {
|
|
28
|
-
if (changed.get('opened') === false) {
|
|
29
|
-
this.addOverlay();
|
|
30
|
-
} else {
|
|
31
|
-
this.removeOverlay();
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
render() {
|
|
36
|
-
return html`
|
|
37
|
-
<div
|
|
38
|
-
class="${classMap({
|
|
39
|
-
dialog: true,
|
|
40
|
-
opened: this.opened,
|
|
41
|
-
closed: !this.opened,
|
|
42
|
-
})}"
|
|
43
|
-
>
|
|
44
|
-
<div class="dialog-head">
|
|
45
|
-
${this.title}
|
|
46
|
-
<ia-icon-close
|
|
47
|
-
@click="${() =>
|
|
48
|
-
this.dispatchEvent(new CustomEvent('dialogAlertClose'))}"
|
|
49
|
-
></ia-icon-close>
|
|
50
|
-
</div>
|
|
51
|
-
<div class="dialog-body">${this.body}</div>
|
|
52
|
-
<div class="dialog-foot">${this.renderActionButton}</div>
|
|
53
|
-
</div>
|
|
54
|
-
`;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/* exceptional case to use dom element */
|
|
58
|
-
addOverlay() {
|
|
59
|
-
if (this.opened && !document.getElementById('ui-overlay')) {
|
|
60
|
-
const overlayElement = document.createElement('div');
|
|
61
|
-
overlayElement.id = 'ui-overlay';
|
|
62
|
-
document.getElementsByTagName('body')[0].appendChild(overlayElement);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/* exceptional case to use dom element */
|
|
67
|
-
removeOverlay() {
|
|
68
|
-
const overlayElement = document.getElementById('ui-overlay');
|
|
69
|
-
if (overlayElement) overlayElement.remove();
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
get renderActionButton() {
|
|
73
|
-
if (!this.actions) return;
|
|
74
|
-
|
|
75
|
-
return this.actions.map(
|
|
76
|
-
action =>
|
|
77
|
-
html`<a class=${action.className} href=${action.href}>
|
|
78
|
-
${action.text}
|
|
79
|
-
</button>`
|
|
80
|
-
);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
static get styles() {
|
|
84
|
-
const dialogStyle = css`
|
|
85
|
-
:host {
|
|
86
|
-
color: #343434;
|
|
87
|
-
font-size: 1.6rem;
|
|
88
|
-
}
|
|
89
|
-
.dialog {
|
|
90
|
-
position: absolute;
|
|
91
|
-
background: #fff;
|
|
92
|
-
border-radius: 1.2rem;
|
|
93
|
-
z-index: 3000;
|
|
94
|
-
flex-direction: column;
|
|
95
|
-
min-width: 300px;
|
|
96
|
-
max-width: 400px;
|
|
97
|
-
left: 50%;
|
|
98
|
-
transform: translateX(-50%);
|
|
99
|
-
|
|
100
|
-
border: 2px solid #ccc;
|
|
101
|
-
border-radius: 12px;
|
|
102
|
-
box-shadow: 0px 0px 27px 6px rgb(66 66 66 / 80%);
|
|
103
|
-
}
|
|
104
|
-
.dialog-head,
|
|
105
|
-
.dialog-body,
|
|
106
|
-
.dialog-foot {
|
|
107
|
-
padding: 1rem;
|
|
108
|
-
user-select: none;
|
|
109
|
-
text-align: left;
|
|
110
|
-
}
|
|
111
|
-
.dialog-body {
|
|
112
|
-
border: 1px solid #d8d8d8;
|
|
113
|
-
}
|
|
114
|
-
ia-icon-close {
|
|
115
|
-
position: absolute;
|
|
116
|
-
right: 0.5rem;
|
|
117
|
-
top: 0.5rem;
|
|
118
|
-
width: 2.5rem;
|
|
119
|
-
height: 2.5rem;
|
|
120
|
-
vertical-align: middle;
|
|
121
|
-
--iconFillColor: #333;
|
|
122
|
-
cursor: pointer;
|
|
123
|
-
}
|
|
124
|
-
.opened {
|
|
125
|
-
display: flex;
|
|
126
|
-
}
|
|
127
|
-
.closed {
|
|
128
|
-
display: none;
|
|
129
|
-
}
|
|
130
|
-
a {
|
|
131
|
-
text-decoration: none;
|
|
132
|
-
}
|
|
133
|
-
`;
|
|
134
|
-
|
|
135
|
-
return [buttonBaseStyle, dialogStyle];
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
customElements.define('show-dialog', ShowDialog);
|