From d6727a3b10f6c412379177ce5a31858db9dfaa2e Mon Sep 17 00:00:00 2001
From: Chris Hallberg <crhallberg@gmail.com>
Date: Tue, 28 Oct 2014 13:52:14 -0400
Subject: [PATCH] Bootstrap 2 cart fixes. Checkbox fixes in BS2 and BS3.

Conflicts:
	themes/bootstrap3/js/cart.js
---
 themes/bootstrap/js/cart.js                   | 22 ++++++++++---------
 themes/bootstrap/js/common.js                 | 11 +++++-----
 themes/bootstrap/js/lightbox.js               |  9 +++++++-
 .../bootstrap/templates/layout/layout.phtml   |  1 +
 themes/bootstrap3/js/cart.js                  | 19 ++++++++--------
 themes/bootstrap3/js/common.js                | 21 ++++++------------
 themes/bootstrap3/js/lightbox.js              |  6 ++---
 7 files changed, 46 insertions(+), 43 deletions(-)

diff --git a/themes/bootstrap/js/cart.js b/themes/bootstrap/js/cart.js
index df788886ebb..fd456bc761b 100644
--- a/themes/bootstrap/js/cart.js
+++ b/themes/bootstrap/js/cart.js
@@ -159,20 +159,22 @@ 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 checks = $form.find('input.checkbox-select-item:checked');
-    if(checks.length > 0) {
-      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.displayError(vufindString['bulk_noitems_advice']);
+    var url = path+'/Records/Home?print=true';
+    for(var i=0;i<checks.length;i++) {
+      url += '&id[]='+checks[i].value;
     }
-  } else {
+    document.location.href = url;
+  } else if ((submit != 'empty' || confirm(vufindString['confirmEmpty']))
+  && (submit != 'delete' || confirm(vufindString['confirmDelete']))) {
     Lightbox.submit($form, Lightbox.changeContent);
+  } else {
+    $('#modal').find('.icon-spinner').remove();
   }
 }
 
diff --git a/themes/bootstrap/js/common.js b/themes/bootstrap/js/common.js
index 211d33e2e85..9e0b893a258 100644
--- a/themes/bootstrap/js/common.js
+++ b/themes/bootstrap/js/common.js
@@ -115,12 +115,10 @@ function registerLightboxEvents() {
   });
   // Select all checkboxes
   $(modal).find('.checkbox-select-all').change(function() {
-    $(this).closest('.modal-body').find('.checkbox-select-item').attr('checked', this.checked);
+    $(this).closest('.modal-body').find('.checkbox-select-item').prop('checked', this.checked);
   });
   $(modal).find('.checkbox-select-item').change(function() {
-    if(!this.checked) { // Uncheck all selected if one is unselected
-      $(this).closest('.modal-body').find('.checkbox-select-all').attr('checked', false);
-    }
+    $(this).closest('.modal-body').find('.checkbox-select-all').prop('checked', false);
   });
   // Highlight which submit button clicked
   $(modal).find("form input[type=submit]").click(function() {
@@ -360,7 +358,10 @@ $(document).ready(function() {
 
   // Checkbox select all
   $('.checkbox-select-all').change(function() {
-    $(this).closest('form').find('.checkbox-select-item').attr('checked', this.checked);
+    $(this).closest('form').find('.checkbox-select-item').prop('checked', this.checked);
+  });
+  $('.checkbox-select-item').change(function() {
+    $(this).closest('form').find('.checkbox-select-all').prop('checked', false);
   });
 
   // handle QR code links
diff --git a/themes/bootstrap/js/lightbox.js b/themes/bootstrap/js/lightbox.js
index fcf57bce401..1df725df4fe 100644
--- a/themes/bootstrap/js/lightbox.js
+++ b/themes/bootstrap/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 permanent close event handlers
+   */
+  addPermanentCloseAction: function(func) {
+    this.closeStackPerm.push(func);
+  },
   /**
    * For when you want to handle that form all by yourself
    *
diff --git a/themes/bootstrap/templates/layout/layout.phtml b/themes/bootstrap/templates/layout/layout.phtml
index 569380385cc..3fee1463119 100644
--- a/themes/bootstrap/templates/layout/layout.phtml
+++ b/themes/bootstrap/templates/layout/layout.phtml
@@ -40,6 +40,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',
diff --git a/themes/bootstrap3/js/cart.js b/themes/bootstrap3/js/cart.js
index a2c447a7296..c0942d86744 100644
--- a/themes/bootstrap3/js/cart.js
+++ b/themes/bootstrap3/js/cart.js
@@ -159,18 +159,17 @@ 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 checks = $form.find('input.checkbox-select-item:checked');
-    if(checks.length > 0) {
-      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.displayError(vufindString['bulk_noitems_advice']);
+    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 if ((submit != 'empty' || confirm(vufindString['confirmEmpty']))
   && (submit != 'delete' || confirm(vufindString['confirmDelete']))) {
     Lightbox.submit($form, Lightbox.changeContent);
@@ -250,7 +249,7 @@ $(document).ready(function() {
     });
     return false;
   });
-  Lightbox.addPermenantCloseAction(function() {
+  Lightbox.addPermanentCloseAction(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/common.js b/themes/bootstrap3/js/common.js
index 90314f67a65..56273cf3d41 100644
--- a/themes/bootstrap3/js/common.js
+++ b/themes/bootstrap3/js/common.js
@@ -117,12 +117,10 @@ function registerLightboxEvents() {
   });
   // Select all checkboxes
   $(modal).find('.checkbox-select-all').change(function() {
-    $(this).closest('.modal-body').find('.checkbox-select-item').attr('checked', this.checked);
+    $(this).closest('.modal-body').find('.checkbox-select-item').prop('checked', this.checked);
   });
   $(modal).find('.checkbox-select-item').change(function() {
-    if(!this.checked) { // Uncheck all selected if one is unselected
-      $(this).closest('.modal-body').find('.checkbox-select-all').attr('checked', false);
-    }
+    $(this).closest('.modal-body').find('.checkbox-select-all').prop('checked', false);
   });
   // Highlight which submit button clicked
   $(modal).find("form input[type=submit]").click(function() {
@@ -323,16 +321,11 @@ $(document).ready(function() {
   );
 
   // Checkbox select all
-  $('.checkbox-select-all').click(function(event) {
-    if(this.checked) {
-      $(this).closest('form').find('.checkbox-select-item').each(function() {
-        this.checked = true;
-      });
-    } else {
-      $(this).closest('form').find('.checkbox-select-item').each(function() {
-        this.checked = false;
-      });
-    }
+  $('.checkbox-select-all').change(function() {
+    $(this).closest('form').find('.checkbox-select-item').prop('checked', this.checked);
+  });
+  $('.checkbox-select-item').change(function() {
+    $(this).closest('form').find('.checkbox-select-all').prop('checked', false);
   });
 
   // handle QR code links
diff --git a/themes/bootstrap3/js/lightbox.js b/themes/bootstrap3/js/lightbox.js
index 35ca402c109..f50be405d2d 100644
--- a/themes/bootstrap3/js/lightbox.js
+++ b/themes/bootstrap3/js/lightbox.js
@@ -46,9 +46,9 @@ var Lightbox = {
     this.closeStack.push(func);
   },
   /**
-   * Register custom close event handlers
+   * Register permanent close event handlers
    */
-  addPermenantCloseAction: function(func) {
+  addPermanentCloseAction: function(func) {
     this.closeStackPerm.push(func);
   },
   /**
@@ -134,7 +134,7 @@ var Lightbox = {
   closeActions: function() {
     Lightbox.shown = false;
     Lightbox.openingURL = false;
-    // Permenant close actions
+    // permanent close actions
     for(var i=Lightbox.closeStackPerm.length;i--;) {
       Lightbox.closeStackPerm[i]();
     }
-- 
GitLab