From acefd7c9064d85ee094af56105a77ad5e32311f9 Mon Sep 17 00:00:00 2001 From: Ere Maijala Date: Thu, 19 Dec 2024 20:57:22 +0200 Subject: [PATCH] Fix templates, tweak JS. --- themes/bootstrap3/js/account_ajax.js | 114 +++--------------- .../templates/ajax/account/status-badge.phtml | 2 +- .../templates/myresearch/menu-item.phtml | 2 +- themes/bootstrap5/js/account_ajax.js | 2 +- .../templates/ajax/account/status-badge.phtml | 4 +- .../templates/myresearch/menu-item.phtml | 2 +- 6 files changed, 21 insertions(+), 105 deletions(-) diff --git a/themes/bootstrap3/js/account_ajax.js b/themes/bootstrap3/js/account_ajax.js index 1d5af183fcb..9c85aeadf8b 100644 --- a/themes/bootstrap3/js/account_ajax.js +++ b/themes/bootstrap3/js/account_ajax.js @@ -68,11 +68,24 @@ VuFind.register('account', function Account() { $element.removeClass('hidden'); if (status === LOADING) { $element.html(VuFind.spinner()); - } else { - var moduleStatus = _submodules[sub].render($element, _statuses[sub], ICON_LEVELS); + } else if (Object.prototype.hasOwnProperty.call(_submodules[sub], 'render')) { + // Render using render function: + let moduleStatus = _submodules[sub].render($element, _statuses[sub], ICON_LEVELS); if (moduleStatus > accountStatus) { accountStatus = moduleStatus; } + } else { + // Render with default method: + const subStatus = _statuses[sub]; + if (subStatus.html !== '') { + $element.html(subStatus.html); + } else { + $element.addClass("hidden"); + } + $('[data-toggle="tooltip"],[data-bs-toggle="tooltip"]', $element).tooltip(); + if (subStatus.level > accountStatus) { + accountStatus = subStatus.level; + } } } } @@ -200,25 +213,9 @@ VuFind.register('account', function Account() { }); $(function registerAccountAjax() { - - var renderStatusBadge = (titleKey, count, className = "") => { - return count > 0 - ? ` - ${VuFind.translate(titleKey)}: ${count} , ` - : ""; - }; - VuFind.account.register("fines", { selector: ".fines-status", ajaxMethod: "getUserFines", - render: function render($element, status, ICON_LEVELS) { - if (status.total === 0) { - $element.addClass("hidden"); - return ICON_LEVELS.NONE; - } - $element.html('' + status.display + ''); - return ICON_LEVELS.DANGER; - }, updateNeeded: function updateNeeded(currentStatus, status) { return status.total !== currentStatus.total; } @@ -227,24 +224,6 @@ $(function registerAccountAjax() { VuFind.account.register("checkedOut", { selector: ".checkedout-status", ajaxMethod: "getUserTransactions", - render: function render($element, status, ICON_LEVELS) { - var html = ''; - var level = ICON_LEVELS.NONE; - if (status.ok > 0) { - html += renderStatusBadge('account_normal_checkouts', status.ok, 'account-info'); - } - if (status.warn > 0) { - html += renderStatusBadge('account_checkouts_due', status.warn, 'account-warning'); - level = ICON_LEVELS.WARNING; - } - if (status.overdue > 0) { - html += renderStatusBadge('account_checkouts_overdue', status.overdue, 'account-alert'); - level = ICON_LEVELS.DANGER; - } - $element.html(html); - $('[data-toggle="tooltip"]', $element).tooltip(); - return level; - }, updateNeeded: function updateNeeded(currentStatus, status) { return status.ok !== currentStatus.ok || status.warn !== currentStatus.warn || status.overdue !== currentStatus.overdue; } @@ -253,27 +232,6 @@ $(function registerAccountAjax() { VuFind.account.register("holds", { selector: ".holds-status", ajaxMethod: "getUserHolds", - render: function render($element, status, ICON_LEVELS) { - var html = ''; - var level = ICON_LEVELS.NONE; - if (status.available > 0) { - html += renderStatusBadge('account_requests_available', status.available, 'account-info'); - level = ICON_LEVELS.GOOD; - } - if (status.in_transit > 0) { - html += renderStatusBadge('account_requests_in_transit', status.in_transit, 'account-warning'); - } - if (status.other > 0) { - html += renderStatusBadge('account_requests_other', status.other, 'account-none'); - } - if (html !== '') { - $element.html(html); - } else { - $element.addClass("holds-status hidden"); - } - $('[data-toggle="tooltip"]', $element).tooltip(); - return level; - }, updateNeeded: function updateNeeded(currentStatus, status) { return status.available !== currentStatus.available || status.in_transit !== currentStatus.in_transit || status.other !== currentStatus.other; } @@ -282,27 +240,6 @@ $(function registerAccountAjax() { VuFind.account.register("illRequests", { selector: ".illrequests-status", ajaxMethod: "getUserILLRequests", - render: function render($element, status, ICON_LEVELS) { - var html = ''; - var level = ICON_LEVELS.NONE; - if (status.available > 0) { - html += renderStatusBadge('account_requests_available', status.available, 'account-info'); - level = ICON_LEVELS.GOOD; - } - if (status.in_transit > 0) { - html += renderStatusBadge('account_requests_in_transit', status.in_transit, 'account-warning'); - } - if (status.other > 0) { - html += renderStatusBadge('account_requests_other', status.other, 'account-none'); - } - if (html !== '') { - $element.html(html); - } else { - $element.addClass("holds-status hidden"); - } - $('[data-toggle="tooltip"]', $element).tooltip(); - return level; - }, updateNeeded: function updateNeeded(currentStatus, status) { return status.available !== currentStatus.available || status.in_transit !== currentStatus.in_transit || status.other !== currentStatus.other; } @@ -311,27 +248,6 @@ $(function registerAccountAjax() { VuFind.account.register("storageRetrievalRequests", { selector: ".storageretrievalrequests-status", ajaxMethod: "getUserStorageRetrievalRequests", - render: function render($element, status, ICON_LEVELS) { - var html = ''; - var level = ICON_LEVELS.NONE; - if (status.available > 0) { - html += renderStatusBadge('account_requests_available', status.available, 'account-info'); - level = ICON_LEVELS.GOOD; - } - if (status.in_transit > 0) { - html += renderStatusBadge('account_requests_in_transit', status.in_transit, 'account-warning'); - } - if (status.other > 0) { - html += renderStatusBadge('account_requests_other', status.other, 'account-none'); - } - if (html !== '') { - $element.html(html); - } else { - $element.addClass("holds-status hidden"); - } - $('[data-toggle="tooltip"]', $element).tooltip(); - return level; - }, updateNeeded: function updateNeeded(currentStatus, status) { return status.available !== currentStatus.available || status.in_transit !== currentStatus.in_transit || status.other !== currentStatus.other; } diff --git a/themes/bootstrap3/templates/ajax/account/status-badge.phtml b/themes/bootstrap3/templates/ajax/account/status-badge.phtml index 79192356fb7..895e0772fee 100644 --- a/themes/bootstrap3/templates/ajax/account/status-badge.phtml +++ b/themes/bootstrap3/templates/ajax/account/status-badge.phtml @@ -2,5 +2,5 @@ - transEsc($this->title)?>: escapeHtml($this->count)?> , + transEsc($this->title)?>: escapeHtml($this->count)?> , icon($this->icon, 'icon-link__icon') ?> transEsc($this->label)?> - status ?? false): ?> + status ?? false) && $this->auth()->getManager()->ajaxEnabled()): ?> diff --git a/themes/bootstrap5/js/account_ajax.js b/themes/bootstrap5/js/account_ajax.js index e04f8b9a638..8e995710b3b 100644 --- a/themes/bootstrap5/js/account_ajax.js +++ b/themes/bootstrap5/js/account_ajax.js @@ -82,7 +82,7 @@ VuFind.register('account', function Account() { } else { $element.addClass("hidden"); } - $('[data-toggle="tooltip"],[data-bs-toggle="tooltip"]', $element).tooltip(); + $element[0].querySelectorAll('[data-bs-toggle="tooltip"]').forEach((el) => bootstrap.Tooltip.getOrCreateInstance(el)); if (subStatus.level > accountStatus) { accountStatus = subStatus.level; } diff --git a/themes/bootstrap5/templates/ajax/account/status-badge.phtml b/themes/bootstrap5/templates/ajax/account/status-badge.phtml index 79192356fb7..a1054f93a61 100644 --- a/themes/bootstrap5/templates/ajax/account/status-badge.phtml +++ b/themes/bootstrap5/templates/ajax/account/status-badge.phtml @@ -1,6 +1,6 @@ count > 0): ?> -