From 8a375b8e7b68578d42f62f3dad4ecc25cbeeb41d Mon Sep 17 00:00:00 2001
From: Demian Katz <demian.katz@villanova.edu>
Date: Wed, 25 Oct 2017 13:04:27 -0400
Subject: [PATCH] Send back a response, even if empty, for all requested
 statuses. - Resolves VUFIND-1253.

---
 module/VuFind/src/VuFind/Controller/AjaxController.php | 2 +-
 themes/bootstrap3/js/check_save_statuses.js            | 7 ++++++-
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/module/VuFind/src/VuFind/Controller/AjaxController.php b/module/VuFind/src/VuFind/Controller/AjaxController.php
index 2e7a6bdee09..cae11df5b66 100644
--- a/module/VuFind/src/VuFind/Controller/AjaxController.php
+++ b/module/VuFind/src/VuFind/Controller/AjaxController.php
@@ -566,8 +566,8 @@ class AjaxController extends AbstractBase
             $checked[$selector] = true;
 
             $data = $user->getSavedData($id, null, $source);
+            $result[$selector] = [];
             if ($data && count($data) > 0) {
-                $result[$selector] = [];
                 // if this item was saved, add it to the list of saved items.
                 foreach ($data as $list) {
                     $result[$selector][] = [
diff --git a/themes/bootstrap3/js/check_save_statuses.js b/themes/bootstrap3/js/check_save_statuses.js
index 3a75ae5d084..7e41a81748e 100644
--- a/themes/bootstrap3/js/check_save_statuses.js
+++ b/themes/bootstrap3/js/check_save_statuses.js
@@ -3,13 +3,18 @@
 
 function displaySaveStatus(itemLists, $item) {
   if (itemLists.length > 0) {
+    // If we got lists back, display them!
     var html = '<ul>' + itemLists.map(function convertToLi(l) {
       return '<li><a href="' + l.list_url + '">' + htmlEncode(l.list_title) + '</a></li>';
     }).join('') + '</ul>';
-    $item.removeClass('js-save-pending');
     $item.find('.savedLists').addClass('loaded');
     $item.find('.js-load').replaceWith(html);
+  } else {
+    // If we got nothing back, remove the pending status:
+    $item.find('.js-load').remove();
   }
+  // No matter what, clear the flag that we have a pending save:
+  $item.removeClass('js-save-pending');
 }
 
 function saveStatusFail(response, textStatus) {
-- 
GitLab