profile-pane 3.1.2-85b34f39 → 3.1.2-87f8a2f3

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.
@@ -1,721 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.createAddressBookUriSelectorDialog = void 0;
7
- exports.getButtonContainer = getButtonContainer;
8
- var _contactsHelpers = require("./contactsHelpers");
9
- var _buttonsHelper = require("./buttonsHelper");
10
- var _texts = require("./texts");
11
- var _contactsErrors = require("./contactsErrors");
12
- const CONTACTS_POPUP_OVERLAY_ID = 'contacts-popup-overlay';
13
- const CONTACTS_OVERLAY_ACTIVE_CLASS = 'contactsOverlayActive';
14
- const createAddressBookUriSelectorDialog = (context, contactsModule, contactData, addressBooksData) => {
15
- const addressBookUriSelectorDialog = context.dom.createElement('dialog');
16
- addressBookUriSelectorDialog.setAttribute('role', 'dialog');
17
- addressBookUriSelectorDialog.setAttribute('aria-live', 'polite');
18
- addressBookUriSelectorDialog.setAttribute('aria-label', 'Contact address book selection dialog');
19
- addressBookUriSelectorDialog.setAttribute('aria-describedby', 'addressbook-contacts-selection');
20
- addressBookUriSelectorDialog.classList.add('contactsAddressBookSelector');
21
- addressBookUriSelectorDialog.setAttribute('id', 'contacts-selector-dialog');
22
- const button = context.dom.getElementById('add-to-contacts-button');
23
- button.setAttribute('disabled', '');
24
- const closeButton = createCloseButton(context, addressBookUriSelectorDialog, 'contactsCloseButton');
25
- const addressBookCreationDiv = context.dom.createElement('div');
26
- addressBookCreationDiv.setAttribute('id', 'addressbook-creation-div');
27
- addressBookCreationDiv.setAttribute('role', 'addressBookCreation');
28
- addressBookCreationDiv.setAttribute('aria-live', 'polite');
29
- addressBookCreationDiv.setAttribute('tabindex', '0');
30
- addressBookCreationDiv.setAttribute('aria-label', 'Address book creation section');
31
- addressBookCreationDiv.setAttribute('aria-describedby', 'addressbook-details-section');
32
- addressBookCreationDiv.classList.add('contactsAddressBookCreationDiv');
33
- const addressBookContactSubmitButton = createNewContactCreationButton(context, contactsModule, addressBooksData, contactData);
34
- const addressBookDetailsSection = createAddressBookDetailsSection(context);
35
- const errorDisplaySection = createErrorDisplaySection(context);
36
- const addressBookListDiv = createAddressBookListDiv(context, contactsModule, contactData, addressBooksData, addressBookDetailsSection);
37
- addressBookDetailsSection.appendChild(addressBookListDiv);
38
- addressBookCreationDiv.appendChild(addressBookDetailsSection);
39
- addressBookCreationDiv.appendChild(addressBookContactSubmitButton);
40
- addressBookUriSelectorDialog.appendChild(closeButton);
41
- addressBookUriSelectorDialog.appendChild(addressBookCreationDiv);
42
- addressBookUriSelectorDialog.appendChild(errorDisplaySection);
43
- return addressBookUriSelectorDialog;
44
- };
45
- exports.createAddressBookUriSelectorDialog = createAddressBookUriSelectorDialog;
46
- const createAddressBookDetailsSection = context => {
47
- const addressBookDetailsSection = context.dom.createElement('section');
48
- addressBookDetailsSection.setAttribute('id', 'addressbook-details-section');
49
- addressBookDetailsSection.setAttribute('role', 'addressBookDetails');
50
- addressBookDetailsSection.setAttribute('aria-live', 'polite');
51
- addressBookDetailsSection.setAttribute('tabindex', '0');
52
- addressBookDetailsSection.classList.add('contactsAddressBookDetails');
53
- return addressBookDetailsSection;
54
- };
55
- const createAddressBookCreationButton = (context, contactsModule, addressBooksData, contactData) => {
56
- const setButtonOnClickHandler = async event => {
57
- event.preventDefault();
58
- const newAddressBookForm = createNewAddressBookForm(context, addressBooksData, contactsModule, contactData);
59
- const addressBookDialog = context.dom.getElementById('contacts-selector-dialog');
60
- showPopupOverlay(context);
61
- addressBookDialog.appendChild(newAddressBookForm);
62
- };
63
- const addressBookCreationButton = context.dom.createElement('button');
64
- addressBookCreationButton.setAttribute('id', 'contacts-create-addressbook-button');
65
- addressBookCreationButton.setAttribute('type', 'button');
66
- addressBookCreationButton.setAttribute('role', 'button');
67
- addressBookCreationButton.setAttribute('aria-label', 'Create a new address book');
68
- addressBookCreationButton.setAttribute('tabindex', '0');
69
- addressBookCreationButton.textContent = 'Create Address Book';
70
- addressBookCreationButton.classList.add('contactsActionButton', 'contactsAddressBookCreationButton');
71
- addressBookCreationButton.addEventListener('click', setButtonOnClickHandler);
72
- return addressBookCreationButton;
73
- };
74
- const createAddressBookUriEntryButton = (context, contactsModule, addressBooksData, contactData) => {
75
- const setButtonOnClickHandler = async event => {
76
- event.preventDefault();
77
- const addressBookUriSelectorDialog = context.dom.getElementById('contacts-selector-dialog');
78
- const addressBookUriEntryDiv = createAddressBookUriEntryDiv(context, contactsModule, addressBooksData, contactData);
79
- showPopupOverlay(context);
80
- addressBookUriSelectorDialog.appendChild(addressBookUriEntryDiv);
81
- };
82
- const addressBookCreationButton = context.dom.createElement('button');
83
- addressBookCreationButton.setAttribute('id', 'contacts-addressbook-uri-entry-button');
84
- addressBookCreationButton.setAttribute('type', 'button');
85
- addressBookCreationButton.setAttribute('role', 'button');
86
- addressBookCreationButton.setAttribute('aria-label', 'Enter an address book URI to add the contact to a specific address book');
87
- addressBookCreationButton.setAttribute('tabindex', '0');
88
- addressBookCreationButton.textContent = 'Enter Address Book URI';
89
- addressBookCreationButton.classList.add('contactsActionButton', 'contactsAddressBookUriEntryButton');
90
- addressBookCreationButton.addEventListener('click', setButtonOnClickHandler);
91
- return addressBookCreationButton;
92
- };
93
- const createAddressBookUriEntryDiv = (context, contactsModule, addressBooksData, contactData) => {
94
- const addressBookUriEntryDiv = context.dom.createElement('div');
95
- addressBookUriEntryDiv.setAttribute('role', 'addressBookUriEntry');
96
- addressBookUriEntryDiv.setAttribute('aria-live', 'polite');
97
- addressBookUriEntryDiv.setAttribute('tabindex', '0');
98
- addressBookUriEntryDiv.setAttribute('aria-label', 'Address book URI entry div');
99
- addressBookUriEntryDiv.setAttribute('aria-describedby', 'addressbook-uri-entry-div');
100
- addressBookUriEntryDiv.setAttribute('id', 'contacts-addressbook-uri-entry');
101
- addressBookUriEntryDiv.classList.add('contactsPopupMessage', 'contactsAddressBookUriEntry');
102
- const closeButton = createCloseButton(context, addressBookUriEntryDiv, 'contactsAddressBookUriEntryCloseButton');
103
- addressBookUriEntryDiv.appendChild(closeButton);
104
- addressBookUriEntryDiv.appendChild(createAddressBookUriEntryForm(context, contactsModule, addressBooksData, contactData));
105
- return addressBookUriEntryDiv;
106
- };
107
- const createAddressBookUriEntryForm = (context, contactsModule, addressBooksData, contactData) => {
108
- const setButtonOnSubmitHandler = async event => {
109
- event.preventDefault();
110
- const addressBookUriField = context.dom.querySelector('#addressBookUriInput');
111
-
112
- // @ts-ignore
113
- const enteredAddressBookUri = addressBookUriField.value;
114
- if (!enteredAddressBookUri) {
115
- (0, _contactsErrors.addErrorToErrorDisplay)(context, _texts.errorNotExistsAddressBookUri);
116
- return;
117
- } else {
118
- const uriCheck = enteredAddressBookUri.substring(enteredAddressBookUri.length - 5, enteredAddressBookUri.length);
119
- const normalizedUri = uriCheck === '#this' ? enteredAddressBookUri : enteredAddressBookUri + '#this';
120
- const books = await (0, _contactsHelpers.addANewAddressBookUriToAddressBooks)(context, contactsModule, addressBooksData, normalizedUri);
121
- const addressBookListDiv = context.dom.querySelector('#addressbook-list');
122
- if (addressBookListDiv) {
123
- const addressBookUriEntry = context.dom.getElementById('contacts-addressbook-uri-entry');
124
- addressBookUriEntry.remove();
125
- removePopupOverlayIfNoPopup(context);
126
- const addressBookCreationButton = context.dom.getElementById('contacts-create-addressbook-button');
127
- const addressBookUriEntryButton = context.dom.getElementById('contacts-addressbook-uri-entry-button');
128
- addressBookCreationButton.remove();
129
- addressBookUriEntryButton.remove();
130
- addressBookListDiv.appendChild(createAddressBookButton(context, contactsModule, books.addressBooksData, books.addressBook, enteredAddressBookUri, contactData));
131
- addressBookListDiv.appendChild(createAddressBookCreationButton(context, contactsModule, books.addressBooksData, contactData));
132
- addressBookListDiv.appendChild(createAddressBookUriEntryButton(context, contactsModule, books.addressBooksData, contactData));
133
- }
134
- }
135
- };
136
- const inputAddressUriEventListener = () => {
137
- checkAndRemoveErrorDisplay(context);
138
- };
139
- const addressBookUriEntryForm = context.dom.createElement('form');
140
- addressBookUriEntryForm.setAttribute('id', 'contacts-address-uri-entry-form');
141
- addressBookUriEntryForm.classList.add('contactsAddressBookUriEntryForm');
142
- addressBookUriEntryForm.method = 'post';
143
- addressBookUriEntryForm.addEventListener('submit', setButtonOnSubmitHandler);
144
- const addressBookUriEntryLabel = context.dom.createElement('label');
145
- addressBookUriEntryLabel.classList.add('label');
146
- addressBookUriEntryLabel.setAttribute('for', 'addressBookUriInput');
147
- const addressBookNameInputBox = context.dom.createElement('input');
148
- addressBookNameInputBox.type = 'text';
149
- addressBookNameInputBox.name = 'addressBookUri';
150
- addressBookNameInputBox.id = 'addressBookUriInput';
151
- addressBookNameInputBox.placeholder = 'Enter address book URI to find your address book';
152
- addressBookNameInputBox.classList.add('input', 'contactsAddressBookUriInput');
153
- addressBookNameInputBox.addEventListener('click', inputAddressUriEventListener);
154
- addressBookUriEntryForm.appendChild(addressBookUriEntryLabel);
155
- addressBookUriEntryForm.appendChild(addressBookNameInputBox);
156
- addressBookUriEntryForm.appendChild(createAddressBookUriEntryAddButton(context));
157
- return addressBookUriEntryForm;
158
- };
159
- const createAddressBookUriEntryAddButton = context => {
160
- const setButtonOnClickHandler = async event => {
161
- event.preventDefault();
162
- const addressBookUriEntryForm = context.dom.querySelector('#contacts-address-uri-entry-form');
163
- // @ts-ignore
164
- if (addressBookUriEntryForm) addressBookUriEntryForm.requestSubmit();
165
- };
166
- const entryButton = context.dom.createElement('button');
167
- entryButton.setAttribute('id', 'contacts-addressbook-entry-button');
168
- entryButton.setAttribute('role', 'button');
169
- entryButton.setAttribute('aria-label', 'Create Address Book from entered URI');
170
- entryButton.setAttribute('tabindex', '0');
171
- entryButton.classList.add('contactsActionButton', 'contactsAddressBookUriEntryAddButton');
172
- entryButton.setAttribute('type', 'submit');
173
- entryButton.addEventListener('click', setButtonOnClickHandler);
174
- entryButton.innerHTML = 'Add';
175
- return entryButton;
176
- };
177
- const createAddressBookListDiv = (context, contactsModule, contactData, addressBooksData, addressBookDetailsSection) => {
178
- const addressBookListDiv = context.dom.createElement('div');
179
- addressBookListDiv.setAttribute('class', 'contactsAddressBookList');
180
- addressBookListDiv.setAttribute('role', 'addressBooksList');
181
- addressBookListDiv.setAttribute('aria-live', 'polite');
182
- addressBookListDiv.setAttribute('tabindex', '0');
183
- addressBookListDiv.setAttribute('aria-label', 'Address book list to select which address book to add the contact to');
184
- addressBookListDiv.setAttribute('aria-describedby', 'addressbook-list');
185
- addressBookListDiv.setAttribute('id', 'addressbook-list');
186
- addressBookListDiv.innerHTML = 'Address Books';
187
- addressBooksData.public.forEach((addressBook, addressBookUri) => {
188
- addressBookListDiv.appendChild(createAddressBookButton(context, contactsModule, addressBooksData, addressBook, addressBookUri, contactData));
189
- });
190
- addressBooksData.private.forEach((addressBook, addressBookUri) => {
191
- addressBookListDiv.appendChild(createAddressBookButton(context, contactsModule, addressBooksData, addressBook, addressBookUri, contactData));
192
- });
193
- const addressBookCreationButton = createAddressBookCreationButton(context, contactsModule, addressBooksData, contactData);
194
- const addressBookUriEntryButton = createAddressBookUriEntryButton(context, contactsModule, addressBooksData, contactData);
195
- addressBookListDiv.appendChild(addressBookCreationButton);
196
- addressBookListDiv.appendChild(addressBookUriEntryButton);
197
- return addressBookListDiv;
198
- };
199
- const createAddressBookGroupCreationButton = (context, contactsModule, addressBooksData, contactData) => {
200
- const setButtonOnClickHandler = async event => {
201
- event.preventDefault();
202
- const addressBookDialog = context.dom.getElementById('contacts-selector-dialog');
203
- const groupNameForm = context.dom.getElementById('new-group-form');
204
- if (!groupNameForm) {
205
- showPopupOverlay(context);
206
- addressBookDialog.appendChild(createGroupNameForm(context, contactsModule, addressBooksData, contactData));
207
- }
208
- };
209
- const groupCreationButton = context.dom.createElement('button');
210
- groupCreationButton.setAttribute('id', 'contacts-create-group-button');
211
- groupCreationButton.setAttribute('type', 'button');
212
- groupCreationButton.setAttribute('role', 'button');
213
- groupCreationButton.setAttribute('aria-label', 'Create a new group in the selected address book');
214
- groupCreationButton.setAttribute('tabindex', '0');
215
- groupCreationButton.textContent = 'Create Group';
216
- groupCreationButton.classList.add('contactsActionButton', 'contactsCreateGroupCreationButton');
217
- groupCreationButton.addEventListener('click', setButtonOnClickHandler);
218
- return groupCreationButton;
219
- };
220
- const createGroupListDiv = (context, contactsModule, addressBooksData, addressBook, contactData) => {
221
- const groupListDiv = context.dom.createElement('div');
222
- groupListDiv.setAttribute('class', 'contactsGroupList');
223
- groupListDiv.setAttribute('role', 'groupList');
224
- groupListDiv.setAttribute('aria-live', 'polite');
225
- groupListDiv.setAttribute('tabindex', '0');
226
- groupListDiv.setAttribute('aria-label', 'Group list to select which groups in the address book to add the contact to');
227
- groupListDiv.setAttribute('aria-describedby', 'group-list');
228
- groupListDiv.setAttribute('id', 'group-list');
229
- groupListDiv.innerHTML = 'Groups';
230
- if (addressBook) {
231
- addressBook.groups.map(group => {
232
- groupListDiv.appendChild(createGroupButton(context, group));
233
- });
234
- }
235
- groupListDiv.appendChild(createAddressBookGroupCreationButton(context, contactsModule, addressBooksData, contactData));
236
- return groupListDiv;
237
- };
238
- const createErrorDisplaySection = context => {
239
- const setButtonOnClickHandler = event => {
240
- event.preventDefault();
241
- errorDisplaySection.classList.remove('contactsShowErrors');
242
- };
243
- const errorDisplaySection = context.dom.createElement('section');
244
- errorDisplaySection.setAttribute('role', 'errorDisplay');
245
- errorDisplaySection.setAttribute('aria-live', 'assertive');
246
- errorDisplaySection.setAttribute('tabindex', '0');
247
- errorDisplaySection.setAttribute('aria-label', 'Section to display error messages related to contact creation');
248
- errorDisplaySection.setAttribute('id', 'error-display-section');
249
- errorDisplaySection.classList.add('contactsErrorDisplay');
250
- const closeButton = context.dom.createElement('button');
251
- closeButton.setAttribute('type', 'button');
252
- closeButton.setAttribute('aria-label', 'Close error message display');
253
- closeButton.setAttribute('tabindex', '0');
254
- closeButton.setAttribute('role', 'button');
255
- closeButton.classList.add('contactsCloseErrorDisplayButton');
256
- closeButton.textContent = 'x';
257
- closeButton.addEventListener('click', setButtonOnClickHandler);
258
- errorDisplaySection.appendChild(closeButton);
259
- return errorDisplaySection;
260
- };
261
- const checkAndRemoveErrorDisplay = context => {
262
- const errorDisplaySection = context.dom.getElementById('error-display-section');
263
- if (errorDisplaySection.classList.contains('contactsShowErrors')) {
264
- errorDisplaySection.classList.remove('contactsShowErrors');
265
- errorDisplaySection.innerHTML = '';
266
- }
267
- };
268
- const createNewContactCreationButton = (context, contactsModule, addressBooksData, contactData) => {
269
- const setButtonOnClickHandler = async event => {
270
- event.preventDefault();
271
- const contactExistsByWebID = (0, _contactsHelpers.checkIfContactExistsByWebID)(addressBooksData, contactData.webID);
272
- const contactExistsByName = (0, _contactsHelpers.checkIfContactExistsByName)(addressBooksData, contactData.name);
273
- const contactExistsHandled = handleContactExists(context, contactsModule, addressBooksData, contactData, contactExistsByWebID, contactExistsByName);
274
- if (contactExistsHandled) return;
275
- let selectedAddressBookUri = null;
276
- let selectedGroupUris = [];
277
- const selectedAddressBookElement = context.dom.querySelectorAll('.selectedAddressBook');
278
- selectedAddressBookElement.forEach(addressBookButton => {
279
- selectedAddressBookUri = addressBookButton.getAttribute('id');
280
- });
281
- const selectedGroupElements = context.dom.querySelectorAll('.selectedGroup');
282
- selectedGroupElements.forEach(groupButtons => {
283
- selectedGroupUris.push(groupButtons.getAttribute('id'));
284
- });
285
- if (selectedGroupUris.length) {
286
- const selectedAddressBookUris = {
287
- addressBookUri: selectedAddressBookUri,
288
- groupUris: selectedGroupUris
289
- };
290
- try {
291
- const contactUri = await (0, _contactsHelpers.createContactInAddressBook)(context, contactsModule, addressBooksData, contactData, selectedAddressBookUris);
292
- finalizeContactEntry(context, addressBooksData, contactData, contactUri);
293
- } catch (error) {
294
- (0, _contactsErrors.addErrorToErrorDisplay)(context, `${_texts.errorContactCreation}\n${error}`);
295
- }
296
- } else {
297
- (0, _contactsErrors.addErrorToErrorDisplay)(context, _texts.groupIsRequired);
298
- }
299
- };
300
- const button = context.dom.createElement('button');
301
- button.setAttribute('type', 'submit');
302
- button.setAttribute('id', 'add-contact');
303
- button.setAttribute('role', 'button');
304
- button.setAttribute('aria-label', 'Add contact to selected address book');
305
- button.setAttribute('tabindex', '0');
306
- button.classList.add('contactsActionButton', 'contactsNewContactCreationButton');
307
- button.addEventListener('click', setButtonOnClickHandler);
308
- button.textContent = 'Add Contact';
309
- return button;
310
- };
311
- const createAddressBookButton = (context, contactsModule, addressBooksData, addressBook, addressBookUri, contactData) => {
312
- const setButtonOnClickHandler = event => {
313
- event.preventDefault();
314
- const selectedAddressBookButton = event.target;
315
- const previouslySelected = selectedAddressBookButton.classList.contains('contactsSelectedButton');
316
- const addressBookDetailsSection = context.dom.getElementById('addressbook-details-section');
317
- let addressBook = null;
318
- // remove the previous groups
319
- const groupDivToRemove = context.dom.getElementById('group-list');
320
- if (groupDivToRemove) groupDivToRemove.remove();
321
-
322
- // remove presious address book selection bc you can only have one
323
- const selectedAddressBookElements = context.dom.querySelectorAll('.selectedAddressBook');
324
- selectedAddressBookElements.forEach(addressBookButton => {
325
- addressBookButton.classList.remove('contactsSelectedButton', 'selectedAddressBook');
326
- });
327
- if (previouslySelected) {
328
- selectedAddressBookButton.classList.remove('contactsSelectedButton', 'selectedAddressBook');
329
- const groupForm = context.dom.getElementById('new-group-form');
330
- if (groupForm) {
331
- groupForm.remove();
332
- removePopupOverlayIfNoPopup(context);
333
- }
334
- } else {
335
- const addressForm = context.dom.getElementById('new-addressbook-form');
336
- if (addressForm) {
337
- addressForm.remove();
338
- removePopupOverlayIfNoPopup(context);
339
- }
340
- selectedAddressBookButton.classList.add('contactsSelectedButton', 'selectedAddressBook');
341
- // selected address book code
342
- const selectedAddressBookUri = event.target.id;
343
- // can check for the class on private
344
- addressBook = addressBooksData.public.get(selectedAddressBookUri);
345
- if (!addressBook) addressBook = addressBooksData.private.get(selectedAddressBookUri);
346
-
347
- // remove the previous groups
348
- const groupDivToRemove = context.dom.getElementById('group-list');
349
- if (groupDivToRemove) groupDivToRemove.remove();
350
- // add groups for addressbook
351
- const groupListDiv = createGroupListDiv(context, contactsModule, addressBooksData, addressBook, contactData);
352
- addressBookDetailsSection.appendChild(groupListDiv);
353
- }
354
- };
355
- const button = context.dom.createElement('button');
356
- button.setAttribute('value', addressBook.name);
357
- button.setAttribute('id', addressBookUri);
358
- button.setAttribute('role', 'button');
359
- button.setAttribute('type', 'submit');
360
- button.setAttribute('aria-label', 'Select address book ' + addressBook.name);
361
- button.setAttribute('tabindex', '0');
362
- button.classList.add('contactsButton');
363
- button.addEventListener('click', setButtonOnClickHandler);
364
- button.innerHTML = addressBook.name;
365
- return button;
366
- };
367
- const createNewAddressBookForm = (context, addressBooksData, contactsModule, contactData) => {
368
- const newAddressBookEventListener = async event => {
369
- event.preventDefault();
370
- let enteredAddressBookUri = null;
371
- let newGroupUri = null;
372
- const addressNameField = context.dom.querySelector('#addressBookNameInput');
373
-
374
- // @ts-ignore
375
- const enteredAddressName = addressNameField.value;
376
- const addressContainerField = context.dom.querySelector('#addressBookContainerInput');
377
-
378
- // @ts-ignore
379
- const enteredAddressContainer = addressContainerField.value;
380
- const groupNameField = context.dom.querySelector('#groupNameInput');
381
- // @ts-ignore
382
- const enteredGroupName = groupNameField.value;
383
- if (enteredAddressName) {
384
- // add addressbook first
385
- try {
386
- enteredAddressBookUri = await (0, _contactsHelpers.handleAddressBookCreation)(context, enteredAddressContainer, enteredAddressName);
387
- const books = await (0, _contactsHelpers.addANewAddressBookUriToAddressBooks)(context, contactsModule, addressBooksData, enteredAddressBookUri);
388
- if (enteredGroupName) {
389
- newGroupUri = await contactsModule.createNewGroup({
390
- addressBookUri: enteredAddressBookUri,
391
- groupName: enteredGroupName
392
- });
393
- const groupAdded = await (0, _contactsHelpers.addGroupToAddressBookData)(addressBooksData, enteredAddressBookUri, {
394
- name: enteredGroupName,
395
- uri: newGroupUri
396
- });
397
- if (!groupAdded) {
398
- (0, _contactsErrors.addErrorToErrorDisplay)(context, _texts.errorGroupCreation);
399
- return;
400
- }
401
- }
402
- const addressBookListDiv = context.dom.querySelector('#addressbook-list');
403
- const groupListDiv = context.dom.querySelector('#group-list');
404
- if (addressBookListDiv) {
405
- newAddressBookForm.remove();
406
- removePopupOverlayIfNoPopup(context);
407
- const addressBookCreationButton = context.dom.getElementById('contacts-create-addressbook-button');
408
- const addressBookUriEntryButton = context.dom.getElementById('contacts-addressbook-uri-entry-button');
409
- addressBookCreationButton.remove();
410
- addressBookUriEntryButton.remove();
411
- addressBookListDiv.appendChild(createAddressBookButton(context, contactsModule, addressBooksData, books.addressBook, enteredAddressBookUri, contactData));
412
- addressBookListDiv.appendChild(addressBookCreationButton);
413
- addressBookListDiv.appendChild(addressBookUriEntryButton);
414
- }
415
- if (groupListDiv) {
416
- const groupCreationButton = context.dom.getElementById('contacts-create-group-button');
417
- groupCreationButton.remove();
418
- groupListDiv.appendChild(createGroupButton(context, {
419
- uri: newGroupUri,
420
- name: enteredGroupName
421
- }));
422
- groupListDiv.appendChild(groupCreationButton);
423
- }
424
- } catch (error) {
425
- (0, _contactsErrors.addErrorToErrorDisplay)(context, error);
426
- }
427
- }
428
- };
429
- const submitFormEventListener = event => {
430
- event.preventDefault();
431
- newAddressBookForm.requestSubmit();
432
- };
433
- const newAddressBookForm = context.dom.createElement('form');
434
- newAddressBookForm.method = 'post';
435
- newAddressBookForm.innerHTML = 'Create a new address book';
436
- newAddressBookForm.setAttribute('id', 'new-addressbook-form');
437
- newAddressBookForm.classList.add('contactsPopupMessage', 'contactsNewAddressForm');
438
- const addressBookNameLabel = context.dom.createElement('label');
439
- addressBookNameLabel.classList.add('label');
440
- addressBookNameLabel.setAttribute('for', 'addressBookNameInput');
441
- const addressBookNameInputBox = context.dom.createElement('input');
442
- addressBookNameInputBox.type = 'text';
443
- addressBookNameInputBox.name = 'addressBookName';
444
- addressBookNameInputBox.id = 'addressBookNameInput';
445
- addressBookNameInputBox.placeholder = 'New address book name';
446
- addressBookNameInputBox.classList.add('input', 'contactsAddressBookInput');
447
- addressBookNameInputBox.required = true;
448
- const addressBookContainerLabel = context.dom.createElement('label');
449
- addressBookContainerLabel.classList.add('label');
450
- addressBookContainerLabel.setAttribute('for', 'addressBookContainerInput');
451
- const addressBookContainerInputBox = context.dom.createElement('input');
452
- addressBookContainerInputBox.type = 'text';
453
- addressBookContainerInputBox.name = 'addressBookContainer';
454
- addressBookContainerInputBox.id = 'addressBookContainerInput';
455
- addressBookContainerInputBox.placeholder = 'Address book container';
456
- addressBookContainerInputBox.classList.add('input', 'contactsAddressBookInput');
457
- addressBookContainerInputBox.required = true;
458
- const groupNameLabel = context.dom.createElement('label');
459
- groupNameLabel.classList.add('label');
460
- groupNameLabel.setAttribute('for', 'groupNameInput');
461
- const groupNameInputBox = context.dom.createElement('input');
462
- groupNameInputBox.type = 'text';
463
- groupNameInputBox.name = 'groupName';
464
- groupNameInputBox.id = 'groupNameInput';
465
- groupNameInputBox.placeholder = 'New group name';
466
- groupNameInputBox.classList.add('input', 'contactsGroupInput');
467
- groupNameInputBox.required = true;
468
- const submitButton = context.dom.createElement('button');
469
- submitButton.setAttribute('id', 'submit-addressbook');
470
- submitButton.setAttribute('role', 'button');
471
- submitButton.setAttribute('type', 'submit');
472
- submitButton.setAttribute('aria-label', 'Create a new address book with the entered name, container, type and group');
473
- submitButton.setAttribute('tabindex', '0');
474
- submitButton.classList.add('contactsActionButton', 'contactsAddressBookCreationSubmitButton');
475
- submitButton.addEventListener('click', submitFormEventListener);
476
- submitButton.innerHTML = 'Create Address Book';
477
- const closeButton = createCloseButton(context, newAddressBookForm, 'contactsAddressBookCreationCloseButton');
478
- newAddressBookForm.appendChild(closeButton);
479
- newAddressBookForm.appendChild(addressBookNameLabel);
480
- newAddressBookForm.appendChild(addressBookNameInputBox);
481
- newAddressBookForm.appendChild(addressBookContainerLabel);
482
- newAddressBookForm.appendChild(addressBookContainerInputBox);
483
- newAddressBookForm.appendChild(groupNameLabel);
484
- newAddressBookForm.appendChild(groupNameInputBox);
485
- newAddressBookForm.appendChild(submitButton);
486
- newAddressBookForm.addEventListener('submit', newAddressBookEventListener);
487
- return newAddressBookForm;
488
- };
489
- const createCloseButton = (context, element, specialClass) => {
490
- const setButtonOnClickHandler = event => {
491
- event.preventDefault();
492
- if (element) {
493
- element.remove();
494
- removePopupOverlayIfNoPopup(context);
495
- }
496
- if (specialClass === 'contactsCloseButton') {
497
- const button = context.dom.getElementById('add-to-contacts-button');
498
- if (button) button.removeAttribute('disabled');
499
- }
500
- };
501
- const closeButton = context.dom.createElement('button');
502
- closeButton.setAttribute('id', 'close-addressbook');
503
- closeButton.setAttribute('role', 'button');
504
- closeButton.setAttribute('type', 'button');
505
- const ariaLabel = specialClass === 'contactsCloseButton' ? 'Close contacts dialog' : 'Close dialog';
506
- closeButton.setAttribute('aria-label', ariaLabel);
507
- closeButton.setAttribute('tabindex', '0');
508
- closeButton.classList.add('contactsCloseButton', specialClass);
509
- closeButton.addEventListener('click', setButtonOnClickHandler);
510
- closeButton.innerHTML = 'x';
511
- return closeButton;
512
- };
513
- const createGroupNameForm = (context, contactsModule, addressBooksData, contactData) => {
514
- const addGroupEventListener = async event => {
515
- event.preventDefault();
516
- let selectedAddressBookUri = null;
517
- const selectedAddressBookElement = context.dom.querySelectorAll('.selectedAddressBook');
518
- selectedAddressBookElement.forEach(addressBookButton => {
519
- selectedAddressBookUri = addressBookButton.getAttribute('id');
520
- });
521
- const groupNameField = context.dom.querySelector('#groupNameInput');
522
- // @ts-ignore
523
- const enteredGroupName = groupNameField.value;
524
- if (!selectedAddressBookUri) {
525
- (0, _contactsErrors.addErrorToErrorDisplay)(context, _texts.errorNotExistsAddressBookUri);
526
- return;
527
- }
528
- if (enteredGroupName) {
529
- // add group first
530
- try {
531
- const newGroupUri = await contactsModule.createNewGroup({
532
- addressBookUri: selectedAddressBookUri,
533
- groupName: enteredGroupName
534
- });
535
- const newGroup = {
536
- name: enteredGroupName,
537
- uri: newGroupUri
538
- };
539
- const wasUpdated = (0, _contactsHelpers.addGroupToAddressBookData)(addressBooksData, selectedAddressBookUri, newGroup);
540
- if (!wasUpdated) {
541
- (0, _contactsErrors.addErrorToErrorDisplay)(context, _texts.errorNotExistsAddressBookUri);
542
- return;
543
- }
544
- const removeGroupAddButton = context.dom.getElementById('contacts-create-group-button');
545
- if (removeGroupAddButton) removeGroupAddButton.remove();
546
- const groupListDiv = context.dom.querySelector('#group-list');
547
- if (groupListDiv) {
548
- groupListDiv.appendChild(createGroupButton(context, newGroup));
549
- groupListDiv.appendChild(createAddressBookGroupCreationButton(context, contactsModule, addressBooksData, contactData));
550
- }
551
- newGroupForm.remove();
552
- removePopupOverlayIfNoPopup(context);
553
- } catch (error) {
554
- (0, _contactsErrors.addErrorToErrorDisplay)(context, `${_texts.errorGroupCreation}\n${error}`);
555
- }
556
- }
557
- };
558
- const newGroupForm = context.dom.createElement('form');
559
- newGroupForm.addEventListener('submit', addGroupEventListener);
560
- newGroupForm.innerHTML = 'Create a new group';
561
- newGroupForm.setAttribute('id', 'new-group-form');
562
- newGroupForm.classList.add('contactsPopupMessage', 'contactsNewGroupForm');
563
- const groupNameLabel = context.dom.createElement('label');
564
- groupNameLabel.classList.add('label');
565
- groupNameLabel.setAttribute('for', 'groupNameInput');
566
- const groupNameInputBox = context.dom.createElement('input');
567
- groupNameInputBox.type = 'text';
568
- groupNameInputBox.name = 'groupName';
569
- groupNameInputBox.id = 'groupNameInput';
570
- groupNameInputBox.placeholder = 'New group name';
571
- groupNameInputBox.classList.add('input', 'contactsGroupInput');
572
- const submitButton = createAddGroupButton(context, newGroupForm);
573
- const closeButton = createCloseButton(context, newGroupForm, 'contactsGroupCreationCloseButton');
574
- newGroupForm.appendChild(groupNameLabel);
575
- newGroupForm.appendChild(groupNameInputBox);
576
- newGroupForm.appendChild(submitButton);
577
- newGroupForm.appendChild(closeButton);
578
- return newGroupForm;
579
- };
580
- const createAddGroupButton = (context, form) => {
581
- const setButtonOnClickHandler = async event => {
582
- event.preventDefault();
583
- form.requestSubmit();
584
- };
585
- const button = context.dom.createElement('button');
586
- button.setAttribute('id', 'contacts-create-group-button');
587
- button.setAttribute('type', 'button');
588
- button.setAttribute('role', 'button');
589
- button.setAttribute('aria-label', 'Create a new group in the selected address book');
590
- button.setAttribute('tabindex', '0');
591
- button.textContent = 'Create Group';
592
- button.classList.add('contactsActionButton', 'contactsCreateGroupCreationButton');
593
- button.addEventListener('click', setButtonOnClickHandler);
594
- return button;
595
- };
596
- const handleContactExists = (context, contactsModule, addressBooksData, contactData, contactExistsByWebID, contactExistsByName) => {
597
- if (contactExistsByWebID) {
598
- (0, _contactsErrors.addErrorToErrorDisplay)(context, _texts.contactExistsMessage);
599
- return true;
600
- } else if (contactExistsByName) {
601
- // need to disable and possibly grey out the dialog
602
- const selectorDialog = context.dom.getElementById('contacts-selector-dialog');
603
- const contactExistsDiv = context.dom.createElement('div');
604
- contactExistsDiv.setAttribute('role', 'alert');
605
- contactExistsDiv.setAttribute('aria-live', 'assertive');
606
- contactExistsDiv.setAttribute('tabindex', '0');
607
- contactExistsDiv.setAttribute('aria-label', 'Alert message indicating that the contact already exists');
608
- contactExistsDiv.setAttribute('id', 'contacts-contact-exists');
609
- contactExistsDiv.classList.add('contactsContactExistsAlert');
610
- contactExistsDiv.innerHTML = `${contactData.name} already exists. \n Do you want to add their WebID?`;
611
- const confirmButton = context.dom.createElement('button');
612
- confirmButton.setAttribute('id', 'contacts-confirm-add-webid-button');
613
- confirmButton.setAttribute('role', 'button');
614
- confirmButton.setAttribute('type', 'button');
615
- confirmButton.setAttribute('aria-label', 'Confirm adding the contact webID to the existing contact');
616
- confirmButton.setAttribute('tabindex', '0');
617
- confirmButton.classList.add('contactsConfirmButton');
618
- confirmButton.innerHTML = 'Yes';
619
- confirmButton.addEventListener('click', async event => {
620
- event.preventDefault();
621
- await (0, _contactsHelpers.addWebIDToExistingContact)(context, contactsModule, addressBooksData, contactData.webID, contactExistsByName);
622
- finalizeContactEntry(context, addressBooksData, contactData, addressBooksData.contactWebIDs.get(contactData.webID));
623
- (0, _contactsHelpers.refreshButton)(context, addressBooksData, contactData);
624
- });
625
- const cancelButton = context.dom.createElement('button');
626
- cancelButton.setAttribute('id', 'contacts-cancel-add-webid-button');
627
- cancelButton.setAttribute('role', 'button');
628
- cancelButton.setAttribute('type', 'button');
629
- cancelButton.setAttribute('aria-label', 'Cancel adding the contact webID to the existing contact');
630
- cancelButton.setAttribute('tabindex', '0');
631
- cancelButton.classList.add('contactsCancelButton');
632
- cancelButton.innerHTML = 'No';
633
- cancelButton.addEventListener('click', event => {
634
- event.preventDefault();
635
- selectorDialog.remove();
636
- (0, _buttonsHelper.complain)(getButtonContainer(context), context, 'Contact was not added');
637
- setTimeout(() => {
638
- (0, _buttonsHelper.clearPreviousMessage)(getButtonContainer(context));
639
- }, 2000);
640
- (0, _contactsHelpers.refreshButton)(context, addressBooksData, contactData);
641
- });
642
- const actionsDiv = context.dom.createElement('div');
643
- actionsDiv.setAttribute('id', 'contacts-contact-exists-actions');
644
- actionsDiv.setAttribute('role', 'group');
645
- actionsDiv.setAttribute('aria-label', 'Actions for existing contact alert');
646
- actionsDiv.setAttribute('tabindex', '0');
647
- actionsDiv.classList.add('contactsContactExistsActions');
648
- actionsDiv.appendChild(confirmButton);
649
- actionsDiv.appendChild(cancelButton);
650
- contactExistsDiv.appendChild(actionsDiv);
651
- showPopupOverlay(context);
652
- selectorDialog.appendChild(contactExistsDiv);
653
- return true;
654
- }
655
- return false;
656
- };
657
- const finalizeContactEntry = (context, addressBooksData, contactData, contactUri) => {
658
- addressBooksData.contactWebIDs.set(contactData.webID, contactUri);
659
- const selectorDialog = context.dom.getElementById('contacts-selector-dialog');
660
- selectorDialog.remove();
661
- const buttonContainer = getButtonContainer(context);
662
- (0, _buttonsHelper.mention)(buttonContainer, _texts.contactWasAddedSuccesMessage);
663
- const button = context.dom.getElementById('add-to-contacts-button');
664
- button.removeAttribute('disabled');
665
- setTimeout(() => {
666
- (0, _buttonsHelper.clearPreviousMessage)(buttonContainer);
667
- }, 2000);
668
- (0, _contactsHelpers.refreshButton)(context, addressBooksData, contactData);
669
- };
670
- const createGroupButton = (context, group) => {
671
- const setButtonOnClickHandler = async event => {
672
- event.preventDefault();
673
- const selectedGroupButton = event.target;
674
- const previouslySelected = selectedGroupButton.classList.contains('contactsSelectedButton');
675
- if (previouslySelected) {
676
- selectedGroupButton.classList.remove('contactsSelectedButton', 'selectedGroup');
677
- (0, _contactsErrors.checkAndAddErrorDisplay)(context, _texts.groupIsRequired);
678
- } else {
679
- selectedGroupButton.classList.add('contactsSelectedButton', 'selectedGroup');
680
- checkAndRemoveErrorDisplay(context);
681
- }
682
- };
683
- const button = context.dom.createElement('button');
684
- button.setAttribute('value', group.name);
685
- button.setAttribute('id', group.uri);
686
- button.setAttribute('type', 'button');
687
- button.setAttribute('role', 'button');
688
- button.setAttribute('aria-label', 'Select group ' + group.name);
689
- button.setAttribute('tabindex', '0');
690
- button.classList.add('contactsButton');
691
- button.addEventListener('click', setButtonOnClickHandler);
692
- button.innerHTML = group.name;
693
- return button;
694
- };
695
- function getButtonContainer(context) {
696
- const buttonContainer = context.dom.getElementById('add-to-contacts-button-container');
697
- return buttonContainer;
698
- }
699
- const showPopupOverlay = context => {
700
- const selectorDialog = context.dom.getElementById('contacts-selector-dialog');
701
- if (!selectorDialog) return;
702
- selectorDialog.classList.add(CONTACTS_OVERLAY_ACTIVE_CLASS);
703
- const existingOverlay = selectorDialog.querySelector(`#${CONTACTS_POPUP_OVERLAY_ID}`);
704
- if (existingOverlay) return;
705
- const overlay = context.dom.createElement('div');
706
- overlay.setAttribute('role', 'popupOverlay');
707
- overlay.setAttribute('aria-label', 'Overlay to focus on the active popup message and disable interaction with the rest of the dialog');
708
- overlay.setAttribute('tabindex', '0');
709
- overlay.setAttribute('id', CONTACTS_POPUP_OVERLAY_ID);
710
- overlay.classList.add('contactsPopupOverlay');
711
- selectorDialog.appendChild(overlay);
712
- };
713
- const removePopupOverlayIfNoPopup = context => {
714
- const selectorDialog = context.dom.getElementById('contacts-selector-dialog');
715
- if (!selectorDialog) return;
716
- const activePopup = selectorDialog.querySelector('.contactsPopupMessage, .contactsContactExistsAlert');
717
- if (activePopup) return;
718
- const overlay = selectorDialog.querySelector(`#${CONTACTS_POPUP_OVERLAY_ID}`);
719
- if (overlay) overlay.remove();
720
- selectorDialog.classList.remove(CONTACTS_OVERLAY_ACTIVE_CLASS);
721
- };