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

Lightbox fixes for bulk actions and cart.

parent eb12bd5b
No related merge requests found
/*global confirm, Cookies, newAccountHandler, path, vufindString, Lightbox, updatePageForLogin */ /*global bulkActionSubmit, Cookies, newAccountHandler, path, vufindString, Lightbox, updatePageForLogin */
var _CART_COOKIE = 'vufind_cart'; var _CART_COOKIE = 'vufind_cart';
var _CART_COOKIE_SOURCES = 'vufind_cart_src'; var _CART_COOKIE_SOURCES = 'vufind_cart_src';
var _CART_COOKIE_DELIM = "\t"; var _CART_COOKIE_DELIM = "\t";
var currentId,currentSource; var currentId,currentSource;
var lastCartSubmit = false;
function getCartItems() { function getCartItems() {
var items = Cookies.getItem(_CART_COOKIE); var items = Cookies.getItem(_CART_COOKIE);
...@@ -154,27 +155,6 @@ function registerUpdateCart($form) { ...@@ -154,27 +155,6 @@ function registerUpdateCart($form) {
} }
} }
// Ajax cart submission for the lightbox
var lastCartSubmit = false;
function cartSubmit($form) {
lastCartSubmit = $form;
var submit = $form.find('input[type="submit"][clicked=true]').attr('name');
var checks = $form.find('input.checkbox-select-item:checked');
if(checks.length == 0 && submit != 'empty') {
return Lightbox.displayError(vufindString['bulk_noitems_advice']);
}
if (submit == 'print') {
//redirect page
var url = path+'/Records/Home?print=true';
for(var i=0;i<checks.length;i++) {
url += '&id[]='+checks[i].value;
}
document.location.href = url;
} else {
Lightbox.submit($form, Lightbox.changeContent);
}
}
$(document).ready(function() { $(document).ready(function() {
// Record buttons // Record buttons
var cartId = $('#cartId'); var cartId = $('#cartId');
...@@ -214,7 +194,8 @@ $(document).ready(function() { ...@@ -214,7 +194,8 @@ $(document).ready(function() {
} }
}); });
Lightbox.addFormHandler('cartForm', function(evt) { Lightbox.addFormHandler('cartForm', function(evt) {
cartSubmit($(evt.target)); lastCartSubmit = $(evt.target);
bulkActionSubmit($(evt.target));
return false; return false;
}); });
Lightbox.addFormCallback('bulkEmail', function(html) { Lightbox.addFormCallback('bulkEmail', function(html) {
......
...@@ -100,6 +100,24 @@ function setupOrFacets() { ...@@ -100,6 +100,24 @@ function setupOrFacets() {
* This is a default open action, so it runs every time changeContent * This is a default open action, so it runs every time changeContent
* is called and the 'shown' lightbox event is triggered * is called and the 'shown' lightbox event is triggered
*/ */
function bulkActionSubmit($form) {
var submit = $form.find('input[type="submit"][clicked=true]').attr('name');
var checks = $form.find('input.checkbox-select-item:checked');
if(checks.length == 0 && submit != 'empty') {
return Lightbox.displayError(vufindString['bulk_noitems_advice']);
}
if (submit == 'print') {
//redirect page
var url = path+'/Records/Home?print=true';
for(var i=0;i<checks.length;i++) {
url += '&id[]='+checks[i].value;
}
document.location.href = url;
} else {
Lightbox.submit($form, Lightbox.changeContent);
}
return false;
}
function registerLightboxEvents() { function registerLightboxEvents() {
var modal = $("#modal"); var modal = $("#modal");
// New list // New list
...@@ -356,6 +374,18 @@ $(document).ready(function() { ...@@ -356,6 +374,18 @@ $(document).ready(function() {
// Advanced facets // Advanced facets
setupOrFacets(); setupOrFacets();
$('[name=bulkActionForm]').submit(function() {
return bulkActionSubmit($(this));
});
$('[name=bulkActionForm]').find("input[type=submit]").click(function() {
// Abort requests triggered by the lightbox
$('#modal .fa-spinner').remove();
// Remove other clicks
$(this).closest('form').find('input[type="submit"][clicked=true]').attr('clicked', false);
// Add useful information
$(this).attr("clicked", "true");
});
/****************************** /******************************
* LIGHTBOX DEFAULT BEHAVIOUR * * LIGHTBOX DEFAULT BEHAVIOUR *
******************************/ ******************************/
......
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