|
3 | 3 | constructor(config) {
|
4 | 4 | this.container = config.container;
|
5 | 5 | this.toggler = config.container.querySelector('.ibexa-btn--translations-list-toggler');
|
6 |
| - this.translationsList = config.container.querySelector('.ibexa-translation-selector__list-wrapper'); |
| 6 | + this.extraActionsContainer = config.container.querySelector('.ibexa-extra-actions'); |
| 7 | + this.closeBtn = config.container.querySelector('.ibexa-extra-actions__close-btn'); |
| 8 | + this.confirmBtn = config.container.querySelector('.ibexa-extra-actions__confirm-btn'); |
| 9 | + this.languagesBtns = config.container.querySelectorAll('.ibexa-btn--select-language'); |
7 | 10 | this.backdrop = config.backdrop;
|
8 | 11 |
|
9 | 12 | this.tableNode = null;
|
10 | 13 |
|
11 |
| - this.hideTranslationsList = this.hideTranslationsList.bind(this); |
12 |
| - this.showTranslationsList = this.showTranslationsList.bind(this); |
| 14 | + this.hideExtraActionPanel = this.hideExtraActionPanel.bind(this); |
| 15 | + this.showExtraActionPanel = this.showExtraActionPanel.bind(this); |
| 16 | + this.setActiveLanguage = this.setActiveLanguage.bind(this); |
| 17 | + this.resetLanguageSelector = this.resetLanguageSelector.bind(this); |
| 18 | + |
13 | 19 | this.setPosition = this.setPosition.bind(this);
|
14 | 20 | }
|
15 | 21 |
|
16 | 22 | setPosition() {
|
17 |
| - const topOffset = parseInt(this.translationsList.dataset.topOffset, 10); |
| 23 | + const topOffset = parseInt(this.extraActionsContainer.dataset.topOffset, 10); |
18 | 24 | const topPosition = window.scrollY > topOffset ? 0 : topOffset - window.scrollY;
|
19 | 25 | const height = window.scrollY > topOffset ? window.innerHeight : window.innerHeight + window.scrollY - topOffset;
|
20 | 26 |
|
21 |
| - this.translationsList.style.top = `${topPosition}px`; |
22 |
| - this.translationsList.style.height = `${height}px`; |
| 27 | + this.extraActionsContainer.style.top = `${topPosition}px`; |
| 28 | + this.extraActionsContainer.style.height = `${height}px`; |
23 | 29 | }
|
24 | 30 |
|
25 |
| - hideTranslationsList(event) { |
26 |
| - const closestTranslationSelector = event.target.closest('.ibexa-translation-selector'); |
27 |
| - const clickedOnTranslationsList = closestTranslationSelector && closestTranslationSelector.isSameNode(this.container); |
28 |
| - const clickedOnDraftConflictModal = event.target.closest('.ibexa-modal--version-draft-conflict'); |
29 |
| - |
30 |
| - if (clickedOnTranslationsList || clickedOnDraftConflictModal) { |
31 |
| - return; |
32 |
| - } |
33 |
| - |
| 31 | + hideExtraActionPanel() { |
34 | 32 | if (this.tableNode) {
|
35 | 33 | this.tableNode.classList.add('ibexa-table--last-column-sticky');
|
36 | 34 |
|
37 | 35 | this.tableNode = null;
|
38 | 36 | }
|
39 | 37 |
|
40 | 38 | this.backdrop.hide();
|
41 |
| - this.translationsList.classList.add('ibexa-translation-selector__list-wrapper--hidden'); |
42 |
| - doc.removeEventListener('click', this.hideTranslationsList, false); |
| 39 | + this.extraActionsContainer.classList.add('ibexa-extra-actions--hidden'); |
| 40 | + |
| 41 | + this.closeBtn.removeEventListener('click', this.hideExtraActionPanel, false); |
43 | 42 | }
|
44 | 43 |
|
45 |
| - showTranslationsList({ currentTarget }) { |
46 |
| - this.translationsList.classList.remove('ibexa-translation-selector__list-wrapper--hidden'); |
| 44 | + showExtraActionPanel({ currentTarget }) { |
| 45 | + this.extraActionsContainer.classList.remove('ibexa-extra-actions--hidden'); |
47 | 46 |
|
48 | 47 | this.tableNode = currentTarget.closest('.ibexa-table--last-column-sticky');
|
49 | 48 |
|
|
52 | 51 | }
|
53 | 52 |
|
54 | 53 | this.setPosition();
|
55 |
| - |
56 | 54 | this.backdrop.show();
|
57 |
| - doc.addEventListener('click', this.hideTranslationsList, false); |
| 55 | + this.closeBtn.addEventListener('click', this.hideExtraActionPanel, false); |
| 56 | + |
58 | 57 | ibexa.helpers.tooltips.hideAll();
|
59 | 58 | }
|
60 | 59 |
|
| 60 | + setActiveLanguage(event) { |
| 61 | + const { contentId, languageCode } = event.currentTarget.dataset; |
| 62 | + |
| 63 | + this.confirmBtn.dataset.contentId = contentId; |
| 64 | + this.confirmBtn.dataset.languageCode = languageCode; |
| 65 | + this.confirmBtn.disabled = false; |
| 66 | + |
| 67 | + this.languagesBtns.forEach((btn) => btn.classList.remove('ibexa-btn--active')); |
| 68 | + event.currentTarget.classList.add('ibexa-btn--active'); |
| 69 | + } |
| 70 | + |
| 71 | + resetLanguageSelector() { |
| 72 | + this.confirmBtn.dataset.contentId = null; |
| 73 | + this.confirmBtn.dataset.languageCode = null; |
| 74 | + this.confirmBtn.disabled = true; |
| 75 | + |
| 76 | + this.languagesBtns.forEach((btn) => btn.classList.remove('ibexa-btn--active')); |
| 77 | + } |
| 78 | + |
61 | 79 | init() {
|
62 |
| - this.toggler.addEventListener('click', this.showTranslationsList, false); |
| 80 | + this.toggler.addEventListener('click', this.showExtraActionPanel, false); |
| 81 | + this.languagesBtns.forEach((btn) => { |
| 82 | + btn.addEventListener('click', this.setActiveLanguage, false); |
| 83 | + }); |
| 84 | + |
| 85 | + document.body.addEventListener('ibexa:edit-content-reset-language-selector', this.resetLanguageSelector, false); |
63 | 86 | }
|
64 | 87 | }
|
65 | 88 |
|
|
0 commit comments