# Retrieve the users cached records AKA 'My List'
# Returns an empty list if there are no cached records
sub fetch_mylist {
- my ($self, $with_marc_xml) = @_;
+ my ($self, $with_marc_xml, $skip_sort) = @_;
my $list = [];
my $cache_key = $self->cgi->cookie((ref $self)->COOKIE_ANON_CACHE);
# Leverage QueryParser to sort the items by values of config.metabib_fields
# from the items' marc records.
- if (@$list) {
+ if (@$list && !$skip_sort) {
my ($sorter, $modifier) = $self->_get_bookbag_sort_params("anonsort");
my $query = $self->_prepare_anonlist_sorting_query($list, $sorter, $modifier);
my $args = {
# Adds a record (by id) to My List, creating a new anon cache + list if necessary.
sub load_mylist_add {
my $self = shift;
- my $rec_id = $self->cgi->param('record');
- my ($cache_key, $list) = $self->fetch_mylist;
- push(@$list, $rec_id);
-
- $cache_key = $U->simplereq(
- 'open-ils.actor',
- 'open-ils.actor.anon_cache.set_value',
- $cache_key, (ref $self)->ANON_CACHE_MYLIST, $list);
+ my ($cache_key, $list) = $self->_do_mylist_add();
# Check if we need to warn patron about adding to a "temporary"
# list:
return $self->mylist_action_redirect($cache_key);
}
-sub load_mylist_delete {
+sub load_api_mylist_add {
my $self = shift;
- my $rec_id = $self->cgi->param('record');
- my ($cache_key, $list) = $self->fetch_mylist;
- $list = [ grep { $_ ne $rec_id } @$list ];
+ my ($cache_key, $list) = $self->_do_mylist_add();
+
+ $self->ctx->{json_response} = {
+ mylist => [ map { 0 + $_ } @$list ], # force integers
+ };
+ $self->ctx->{json_reponse_cookie} =
+ $self->cgi->cookie(
+ -name => (ref $self)->COOKIE_ANON_CACHE,
+ -path => '/',
+ -value => ($cache_key) ? $cache_key : '',
+ -expires => ($cache_key) ? undef : '-1h'
+ );
+
+ return Apache2::Const::OK;
+}
+
+sub _do_mylist_add {
+ my $self = shift;
+ my @rec_ids = $self->cgi->param('record');
+
+ my ($cache_key, $list) = $self->fetch_mylist(0, 1);
+ push(@$list, @rec_ids);
$cache_key = $U->simplereq(
'open-ils.actor',
'open-ils.actor.anon_cache.set_value',
$cache_key, (ref $self)->ANON_CACHE_MYLIST, $list);
+ return ($cache_key, $list);
+}
+
+sub load_mylist_delete {
+ my $self = shift;
+
+ my ($cache_key, $list) = $self->_do_mylist_delete;
+
return $self->mylist_action_redirect($cache_key);
}
+sub load_api_mylist_delete {
+ my $self = shift;
+
+ my ($cache_key, $list) = $self->_do_mylist_delete();
+
+ $self->ctx->{json_response} = {
+ mylist => [ map { 0 + $_ } @$list ], # force integers
+ };
+ $self->ctx->{json_reponse_cookie} =
+ $self->cgi->cookie(
+ -name => (ref $self)->COOKIE_ANON_CACHE,
+ -path => '/',
+ -value => ($cache_key) ? $cache_key : '',
+ -expires => ($cache_key) ? undef : '-1h'
+ );
+
+ return Apache2::Const::OK;
+}
+
+sub _do_mylist_delete {
+ my $self = shift;
+ my @rec_ids = $self->cgi->param('record');
+
+ my ($cache_key, $list) = $self->fetch_mylist(0, 1);
+ foreach my $rec_id (@rec_ids) {
+ $list = [ grep { $_ ne $rec_id } @$list ];
+ }
+
+ $cache_key = $U->simplereq(
+ 'open-ils.actor',
+ 'open-ils.actor.anon_cache.set_value',
+ $cache_key, (ref $self)->ANON_CACHE_MYLIST, $list);
+
+ return ($cache_key, $list);
+}
+
sub load_mylist_move {
my $self = shift;
my @rec_ids = $self->cgi->param('record');