From 11f88ae50ea8dbeab65579b4fe15fcfc706ad35b Mon Sep 17 00:00:00 2001
From: Ere Maijala <ere.maijala@helsinki.fi>
Date: Thu, 12 Oct 2017 21:50:54 +0300
Subject: [PATCH] Library card bug fixes (#1041)

- Fix library card selection in holdings screen when the tab is loaded asynchronously.
- Fix username comparison to be case-insensitive.
---
 themes/bootstrap3/js/common.js                            | 7 ++++++-
 themes/bootstrap3/js/record.js                            | 3 ++-
 themes/bootstrap3/templates/librarycards/selectcard.phtml | 2 +-
 3 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/themes/bootstrap3/js/common.js b/themes/bootstrap3/js/common.js
index b58310d703c..2963b97669e 100644
--- a/themes/bootstrap3/js/common.js
+++ b/themes/bootstrap3/js/common.js
@@ -376,6 +376,11 @@ function setupIeSupport() {
   }
 }
 
+function setupJumpMenus(_container) {
+  var container = _container || $('body');
+  container.find('select.jumpMenu').change(function jumpMenu(){ $(this).parent('form').submit(); });
+}
+
 $(document).ready(function commonDocReady() {
   // Start up all of our submodules
   VuFind.init();
@@ -387,7 +392,7 @@ $(document).ready(function commonDocReady() {
   keyboardShortcuts();
 
   // support "jump menu" dropdown boxes
-  $('select.jumpMenu').change(function jumpMenu(){ $(this).parent('form').submit(); });
+  setupJumpMenus();
 
   // Checkbox select all
   $('.checkbox-select-all').change(function selectAllCheckboxes() {
diff --git a/themes/bootstrap3/js/record.js b/themes/bootstrap3/js/record.js
index 07dfebbf637..9681b4090e4 100644
--- a/themes/bootstrap3/js/record.js
+++ b/themes/bootstrap3/js/record.js
@@ -1,4 +1,4 @@
-/*global deparam, getUrlRoot, grecaptcha, recaptchaOnLoad, resetCaptcha, syn_get_widget, userIsLoggedIn, VuFind */
+/*global deparam, getUrlRoot, grecaptcha, recaptchaOnLoad, resetCaptcha, syn_get_widget, userIsLoggedIn, VuFind, setupJumpMenus */
 /*exported ajaxTagUpdate, recordDocReady */
 
 /**
@@ -180,6 +180,7 @@ function ajaxLoadTab($newTab, tabid, setHash) {
     } else {
       removeHashFromLocation();
     }
+    setupJumpMenus($newTab);
   });
   return false;
 }
diff --git a/themes/bootstrap3/templates/librarycards/selectcard.phtml b/themes/bootstrap3/templates/librarycards/selectcard.phtml
index 1622d4410e4..c0ba02e53b2 100644
--- a/themes/bootstrap3/templates/librarycards/selectcard.phtml
+++ b/themes/bootstrap3/templates/librarycards/selectcard.phtml
@@ -15,7 +15,7 @@
               $display .= ' (' . $this->transEsc("source_$target", null, $target) . ')';
             }
           ?>
-          <option value="<?=$this->escapeHtmlAttr($card->id)?>"<?=$card->cat_username == $this->user->cat_username ? ' selected="selected"' : ''?>><?=$display ?></option>
+          <option value="<?=$this->escapeHtmlAttr($card->id)?>"<?=strcasecmp($card->cat_username, $this->user->cat_username) == 0 ? ' selected="selected"' : ''?>><?=$display ?></option>
         <? endforeach; ?>
       </select>
       <noscript><input type="submit" class="btn btn-default" value="<?=$this->transEsc("Set")?>" /></noscript>
-- 
GitLab