From 2b5e672efc2dd3d99038256cdc36bb6e6f8d6d0c Mon Sep 17 00:00:00 2001
From: Chris Hallberg <crhallberg@gmail.com>
Date: Tue, 23 Feb 2016 11:20:52 -0500
Subject: [PATCH] Fixes to saved list refactor, now works based on record ids
 and sources rather than location and index.

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

diff --git a/module/VuFind/src/VuFind/Controller/AjaxController.php b/module/VuFind/src/VuFind/Controller/AjaxController.php
index edcfa676c88..181f6c52f4a 100644
--- a/module/VuFind/src/VuFind/Controller/AjaxController.php
+++ b/module/VuFind/src/VuFind/Controller/AjaxController.php
@@ -501,11 +501,15 @@ class AjaxController extends AbstractBase
             $source = isset($sources[$i]) ? $sources[$i] : DEFAULT_SEARCH_BACKEND;
             $data = $user->getSavedData($id, null, $source);
             if ($data && count($data) > 0) {
-                $result[$i] = [];
+                $selector = $source . '|' . $id;
+                $result[$selector] = [];
                 // if this item was saved, add it to the list of saved items.
                 foreach ($data as $list) {
-                    $result[$i][] = [
-                        'list_id' => $list->list_id,
+                    $result[$selector][] = [
+                        'list_url' => $this->url()->fromRoute(
+                            'userList',
+                            ['id' => $list->list_id]
+                        ),
                         'list_title' => $list->list_title
                     ];
                 }
diff --git a/themes/bootstrap3/js/check_save_statuses.js b/themes/bootstrap3/js/check_save_statuses.js
index 66556d4d88c..1cf43788fd6 100644
--- a/themes/bootstrap3/js/check_save_statuses.js
+++ b/themes/bootstrap3/js/check_save_statuses.js
@@ -1,11 +1,14 @@
 /*global VuFind */
 
 function checkSaveStatuses() {
+  var elements = {}
   var data = $.map($('.result,.record'), function(record) {
     if($(record).find('.hiddenId').length == 0 || $(record).find('.hiddenSource').length == 0) {
       return false;
     }
-    return {'id':$(record).find('.hiddenId').val(), 'source':$(record).find('.hiddenSource')[0].value};
+    var datum = {'id':$(record).find('.hiddenId').val(), 'source':$(record).find('.hiddenSource')[0].value};
+    elements[datum.source+"|"+datum.id] = $(record).find('.savedLists');
+    return datum;
   });
   if (data.length) {
     var ids = [];
@@ -21,15 +24,15 @@ function checkSaveStatuses() {
       data: {id:ids, 'source':srcs}
     })
     .done(function(response) {
-      for (var rn in response.data) {
-        var list = $('#result'+rn).find('.savedLists');
-        if (list.length == 0) {
+      for (var sel in response.data) {
+        var list = elements[sel];
+        if (!list) {
           list = $('.savedLists');
         }
         var html = list.find('strong')[0].outerHTML+'<ul>';
-        for (var i=0; i<response.data[rn].length; i++) {
-          html += '<li><a href="' + VuFind.getPath() + '/MyResearch/MyList/' + response.data[rn][i].list_id + '">'
-                   + response.data[rn][i].list_title + '</a></li>';
+        for (var i=0; i<response.data[sel].length; i++) {
+          html += '<li><a href="' + response.data[sel][i].list_url + '">'
+                   + response.data[sel][i].list_title + '</a></li>';
         }
         html += '</ul>';
         list.html(html).removeClass('hidden');
-- 
GitLab