Skip to content

Commit

Permalink
Fix templates, tweak JS.
Browse files Browse the repository at this point in the history
  • Loading branch information
EreMaijala committed Dec 19, 2024
1 parent 715f108 commit acefd7c
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 105 deletions.
114 changes: 15 additions & 99 deletions themes/bootstrap3/js/account_ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
}
Expand Down Expand Up @@ -200,25 +213,9 @@ VuFind.register('account', function Account() {
});

$(function registerAccountAjax() {

var renderStatusBadge = (titleKey, count, className = "") => {
return count > 0
? `<span aria-hidden="true" class="badge ${className}" data-toggle="tooltip" title="${VuFind.translate(titleKey)}">${count}</span>
<span class="sr-only">${VuFind.translate(titleKey)}: ${count} , </span>`
: "";
};

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('<span class="badge account-alert">' + status.display + '</span>');
return ICON_LEVELS.DANGER;
},
updateNeeded: function updateNeeded(currentStatus, status) {
return status.total !== currentStatus.total;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
<span aria-hidden="true" class="badge <?=$this->class?>" data-toggle="tooltip" title="<?=$this->transEscAttr($this->title)?>">
<?=$this->escapeHtml($this->count)?>
</span>
<span class="visually-hidden"><?=$this->transEsc($this->title)?>: <?=$this->escapeHtml($this->count)?> , </span>
<span class="sr-only"><?=$this->transEsc($this->title)?>: <?=$this->escapeHtml($this->count)?> , </span>
<?php endif;
2 changes: 1 addition & 1 deletion themes/bootstrap3/templates/myresearch/menu-item.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<?=$this->icon($this->icon, 'icon-link__icon') ?>
<?php endif; ?>
<span class="icon-link__label"><?=$this->transEsc($this->label)?></span>
<?php if ($this->status ?? false): ?>
<?php if (($this->status ?? false) && $this->auth()->getManager()->ajaxEnabled()): ?>
<span class="<?=strtolower($this->name)?>-status status hidden"><?=$this->icon('spinner') ?></span>
<?php endif; ?>
</a>
Expand Down
2 changes: 1 addition & 1 deletion themes/bootstrap5/js/account_ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions themes/bootstrap5/templates/ajax/account/status-badge.phtml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php if ($this->count > 0): ?>
<span aria-hidden="true" class="badge <?=$this->class?>" data-toggle="tooltip" title="<?=$this->transEscAttr($this->title)?>">
<span aria-hidden="true" class="badge <?=$this->class?>" data-bs-toggle="tooltip" title="<?=$this->transEscAttr($this->title)?>">
<?=$this->escapeHtml($this->count)?>
</span>
<span class="visually-hidden"><?=$this->transEsc($this->title)?>: <?=$this->escapeHtml($this->count)?> , </span>
<span class="sr-only"><?=$this->transEsc($this->title)?>: <?=$this->escapeHtml($this->count)?> , </span>
<?php endif;
2 changes: 1 addition & 1 deletion themes/bootstrap5/templates/myresearch/menu-item.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<?=$this->icon($this->icon, 'icon-link__icon') ?>
<?php endif; ?>
<span class="icon-link__label"><?=$this->transEsc($this->label)?></span>
<?php if ($this->status ?? false): ?>
<?php if (($this->status ?? false) && $this->auth()->getManager()->ajaxEnabled()): ?>
<span class="<?=strtolower($this->name)?>-status status hidden"><?=$this->icon('spinner') ?></span>
<?php endif; ?>
</a>
Expand Down

0 comments on commit acefd7c

Please sign in to comment.