move away from some instances of location.path/search for building URLs
authorBill Erickson <berick@esilibrary.com>
Mon, 12 May 2014 17:04:45 +0000 (13:04 -0400)
committerBill Erickson <berick@esilibrary.com>
Mon, 12 May 2014 17:04:45 +0000 (13:04 -0400)
Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/web/js/ui/default/staff/services/navbar.js

index eb0d25e..ed017af 100644 (file)
@@ -30,11 +30,13 @@ angular.module('egCoreMod')
 
                 function navTo(path) {                                           
                     // $location.path() does not want a leading ".",
-                    // which <a>'s will have
+                    // which <a>'s will have.  
+                    // Note: avoid using $location.path() to derive the new
+                    // URL, since it creates an intermediate path change.
                     path = path.replace(/^\./,'');
-
-                    // navigates to the requested path as a new page
-                    $window.location.href = $location.path(path).absUrl();                
+                    var reg = new RegExp($location.path());
+                    $window.location.href = 
+                        $window.location.href.replace(reg, path);
                 }       
 
                 // adds a keyboard shortcut
@@ -45,8 +47,15 @@ angular.module('egCoreMod')
 
                 $scope.applyLocale = function(locale) {
                     // EGWeb.pm can change the locale for us w/ the right param
+                    // Note: avoid using $location.search() to derive a new
+                    // URL, since it creates an intermediate path change.
+                    // Instead, use the ham-fisted approach of killing any
+                    // search args and applying the args we want.
                     $window.location.href = 
-                        $location.search('set_eg_locale', locale).absUrl();
+                        $window.location.href.replace(
+                            /(\?|\&).*/,
+                            '?set_eg_locale=' + encodeURIComponent(locale)
+                        );
                 }
 
                 // tied to logout link