Skip to content
Snippets Groups Projects
Commit 2b5e672e authored by Chris Hallberg's avatar Chris Hallberg
Browse files

Fixes to saved list refactor, now works based on record ids and sources rather...

Fixes to saved list refactor, now works based on record ids and sources rather than location and index.
parent 07c0db71
No related merge requests found
...@@ -501,11 +501,15 @@ class AjaxController extends AbstractBase ...@@ -501,11 +501,15 @@ class AjaxController extends AbstractBase
$source = isset($sources[$i]) ? $sources[$i] : DEFAULT_SEARCH_BACKEND; $source = isset($sources[$i]) ? $sources[$i] : DEFAULT_SEARCH_BACKEND;
$data = $user->getSavedData($id, null, $source); $data = $user->getSavedData($id, null, $source);
if ($data && count($data) > 0) { 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. // if this item was saved, add it to the list of saved items.
foreach ($data as $list) { foreach ($data as $list) {
$result[$i][] = [ $result[$selector][] = [
'list_id' => $list->list_id, 'list_url' => $this->url()->fromRoute(
'userList',
['id' => $list->list_id]
),
'list_title' => $list->list_title 'list_title' => $list->list_title
]; ];
} }
......
/*global VuFind */ /*global VuFind */
function checkSaveStatuses() { function checkSaveStatuses() {
var elements = {}
var data = $.map($('.result,.record'), function(record) { var data = $.map($('.result,.record'), function(record) {
if($(record).find('.hiddenId').length == 0 || $(record).find('.hiddenSource').length == 0) { if($(record).find('.hiddenId').length == 0 || $(record).find('.hiddenSource').length == 0) {
return false; 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) { if (data.length) {
var ids = []; var ids = [];
...@@ -21,15 +24,15 @@ function checkSaveStatuses() { ...@@ -21,15 +24,15 @@ function checkSaveStatuses() {
data: {id:ids, 'source':srcs} data: {id:ids, 'source':srcs}
}) })
.done(function(response) { .done(function(response) {
for (var rn in response.data) { for (var sel in response.data) {
var list = $('#result'+rn).find('.savedLists'); var list = elements[sel];
if (list.length == 0) { if (!list) {
list = $('.savedLists'); list = $('.savedLists');
} }
var html = list.find('strong')[0].outerHTML+'<ul>'; var html = list.find('strong')[0].outerHTML+'<ul>';
for (var i=0; i<response.data[rn].length; i++) { for (var i=0; i<response.data[sel].length; i++) {
html += '<li><a href="' + VuFind.getPath() + '/MyResearch/MyList/' + response.data[rn][i].list_id + '">' html += '<li><a href="' + response.data[sel][i].list_url + '">'
+ response.data[rn][i].list_title + '</a></li>'; + response.data[sel][i].list_title + '</a></li>';
} }
html += '</ul>'; html += '</ul>';
list.html(html).removeClass('hidden'); list.html(html).removeClass('hidden');
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment