From 3d836a6ab9a12f35f94b0a69ffbaf56f873a828b Mon Sep 17 00:00:00 2001
From: Chris Hallberg <crhallberg@gmail.com>
Date: Tue, 28 Oct 2014 13:25:24 -0400
Subject: [PATCH] Bootstrap3 cart confirms and close fixes. The permenant close
 fix is temporary until jsobjects is implemented in 2.4.

---
 themes/bootstrap3/js/cart.js                    |  7 +++++--
 themes/bootstrap3/js/lightbox.js                | 13 ++++++++++++-
 themes/bootstrap3/templates/layout/layout.phtml |  1 +
 3 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/themes/bootstrap3/js/cart.js b/themes/bootstrap3/js/cart.js
index 4a351c132e6..a2c447a7296 100644
--- a/themes/bootstrap3/js/cart.js
+++ b/themes/bootstrap3/js/cart.js
@@ -171,8 +171,11 @@ function cartSubmit($form) {
     } else {
       Lightbox.displayError(vufindString['bulk_noitems_advice']);
     }
-  } else {
+  } else if ((submit != 'empty' || confirm(vufindString['confirmEmpty']))
+  && (submit != 'delete' || confirm(vufindString['confirmDelete']))) {
     Lightbox.submit($form, Lightbox.changeContent);
+  } else {
+    $('#modal').find('.fa.fa-spinner').remove();
   }
 }
 
@@ -247,7 +250,7 @@ $(document).ready(function() {
     });
     return false;
   });
-  Lightbox.addCloseAction(function() {
+  Lightbox.addPermenantCloseAction(function() {
     // Update cart items (add to cart, remove from cart, cart lightbox interface)
     var cartCount = $('#cartItems strong');
     if(cartCount.length > 0) {
diff --git a/themes/bootstrap3/js/lightbox.js b/themes/bootstrap3/js/lightbox.js
index 384afb29689..35ca402c109 100644
--- a/themes/bootstrap3/js/lightbox.js
+++ b/themes/bootstrap3/js/lightbox.js
@@ -12,7 +12,8 @@ var Lightbox = {
   shown: false,      // Is the lightbox deployed?
   XHR: false,        // Used for current in-progress XHR lightbox request
   openStack: [],     // Array of functions to be called after changeContent or the lightbox event 'shown'
-  closeStack: [],    // Array of functions to be called after the lightbox event 'hidden'
+  closeStack: [],    // Array of functions to be called and cleared after the lightbox event 'hidden'
+  closeStackPerm: [],// Array of functions to be called after the lightbox event 'hidden'
   formHandlers: [],  // Full custom handlers for forms; by name
   formCallbacks: [], // Custom functions for forms, called after .submit(); by name
 
@@ -44,6 +45,12 @@ var Lightbox = {
   addCloseAction: function(func) {
     this.closeStack.push(func);
   },
+  /**
+   * Register custom close event handlers
+   */
+  addPermenantCloseAction: function(func) {
+    this.closeStackPerm.push(func);
+  },
   /**
    * For when you want to handle that form all by yourself
    *
@@ -127,6 +134,10 @@ var Lightbox = {
   closeActions: function() {
     Lightbox.shown = false;
     Lightbox.openingURL = false;
+    // Permenant close actions
+    for(var i=Lightbox.closeStackPerm.length;i--;) {
+      Lightbox.closeStackPerm[i]();
+    }
     // Clean out stack
     while(Lightbox.closeStack.length > 0) {
       var f = Lightbox.closeStack.pop();
diff --git a/themes/bootstrap3/templates/layout/layout.phtml b/themes/bootstrap3/templates/layout/layout.phtml
index d8e7e5adceb..08cfe146a2b 100644
--- a/themes/bootstrap3/templates/layout/layout.phtml
+++ b/themes/bootstrap3/templates/layout/layout.phtml
@@ -42,6 +42,7 @@
           $this->jsTranslations()->addStrings(
             array(
               'bulk_noitems_advice' => 'bulk_noitems_advice',
+              'confirmDelete' => 'confirm_delete',
               'confirmEmpty' => 'bookbag_confirm_empty',
               'viewBookBag' => 'View Book Bag',
               'addBookBag' => 'Add to Book Bag',
-- 
GitLab