From 28c8bc9e6593f5b3ac4f111bf1e9b4ecf05edd10 Mon Sep 17 00:00:00 2001
From: Ere Maijala <ere.maijala@helsinki.fi>
Date: Tue, 10 Mar 2020 18:29:28 +0200
Subject: [PATCH] Standardise use of data-clear-account-cache attribute.
 (#1576)

- Removes the special case for library card selection and adds support for clearing all caches with an empty attribute also with links and select fields.
---
 themes/bootstrap3/js/account_ajax.js                  | 11 +++++++----
 .../templates/librarycards/selectcard.phtml           |  2 +-
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/themes/bootstrap3/js/account_ajax.js b/themes/bootstrap3/js/account_ajax.js
index 4d74f156819..4327ae25020 100644
--- a/themes/bootstrap3/js/account_ajax.js
+++ b/themes/bootstrap3/js/account_ajax.js
@@ -31,7 +31,7 @@ VuFind.register('account', function Account() {
 
   // Clearing save forces AJAX update next page load
   var clearCache = function clearCache(name) {
-    if (typeof name === "undefined") {
+    if (typeof name === "undefined" || name === '') {
       for (var sub in _submodules) {
         if (Object.prototype.hasOwnProperty.call(_submodules, sub)) {
           clearCache(sub);
@@ -122,11 +122,14 @@ VuFind.register('account', function Account() {
 
   var init = function init() {
     // Update information when certain actions are performed
-    $("[data-clear-account-cache]").submit(function dataClearCache() {
+    $("form[data-clear-account-cache]").submit(function dataClearCacheForm() {
       clearCache($(this).attr("data-clear-account-cache"));
     });
-    $("#library_card").change(function clearChangeLibraryCard() {
-      clearCache(/* all */);
+    $("a[data-clear-account-cache]").click(function dataClearCacheLink() {
+      clearCache($(this).attr("data-clear-account-cache"));
+    });
+    $("select[data-clear-account-cache]").change(function dataClearCacheSelect() {
+      clearCache($(this).attr("data-clear-account-cache"));
     });
   };
 
diff --git a/themes/bootstrap3/templates/librarycards/selectcard.phtml b/themes/bootstrap3/templates/librarycards/selectcard.phtml
index b2fa24eca4d..361049d5c87 100644
--- a/themes/bootstrap3/templates/librarycards/selectcard.phtml
+++ b/themes/bootstrap3/templates/librarycards/selectcard.phtml
@@ -1,6 +1,6 @@
 <?php if ($this->user): ?>
   <?php $cards = $this->user->getLibraryCards(); if ($cards->count() > 1): ?>
-    <form class="form-inline" action="<?=$this->url('librarycards-selectcard')?>" method="get">
+    <form class="form-inline" action="<?=$this->url('librarycards-selectcard')?>" method="get" data-clear-account-cache>
       <label for="library_card"><?=$this->transEsc('Library Card')?></label>
       <select id="library_card" name="cardID" class="jumpMenu form-control">
         <?php if (null === $this->user->cat_username): ?>
-- 
GitLab