Bug 32939: Have a generic APIClient object
[koha-ffzg.git] / koha-tmpl / intranet-tmpl / prog / js / staff-global.js
index 5a7f7ff..c452e02 100644 (file)
@@ -1,5 +1,5 @@
-/* global shortcut delCookie delBasket Sticky */
-/* exported paramOfUrl addBibToContext delBibToContext */
+/* global shortcut delBasket Sticky AUDIO_ALERT_PATH Cookies */
+/* exported addBibToContext delBibToContext escape_str escape_price openWindow _ removeFocus toUC confirmDelete confirmClone playSound */
 if ( KOHA === undefined ) var KOHA = {};
 
 function _(s) { return s; } // dummy function for gettext
@@ -48,9 +48,19 @@ $.fn.selectTabByID = function (tabID) {
     $(this).tabs("option", "active", $( tabID ).tabIndex());
 };
 
- $(document).ready(function() {
-    $('#header_search').tabs().on( "tabsactivate", function(e, ui) { $(this).find("div:visible").find('input').eq(0).focus(); });
-
+$(document).ready(function() {
+    //check for a hash before setting focus
+    let hash = window.location.hash;
+    if ( ! hash ) {
+        $('#header_search').tabs({
+            create: function( e, ui ){
+                ui.panel.find("input:text:first").focus();
+            },
+            activate: function ( e, ui ) {
+                ui.newPanel.find("input:text:first").focus();
+            }
+        });
+    }
     $(".close").click(function(){ window.close(); });
 
     $("#checkin_search form").preventDoubleFormSubmit();
@@ -62,6 +72,15 @@ $.fn.selectTabByID = function (tabID) {
 
     $("#header_search > ul > li").show();
 
+    $('#header_search .form-extra-content-toggle').on('click', function () {
+        const extraContent = $(this).closest('form').find('.form-extra-content');
+        if (extraContent.is(':visible')) {
+            extraContent.hide();
+        } else {
+            extraContent.show();
+        }
+    });
+
     $(".focus").focus();
     $(".validated").each(function() {
         $(this).validate();
@@ -103,17 +122,16 @@ $.fn.selectTabByID = function (tabID) {
         $("a[href$=\"/" + path + params + "\"]", navmenulist).addClass("current");
     }
 
-    $("#catalog-search-link a").on("hover", function(){
+    $("#catalog-search-link a").on("mouseenter mouseleave", function(){
         $("#catalog-search-dropdown a").toggleClass("catalog-search-dropdown-hover");
     });
 
     if ( localStorage.getItem("lastborrowernumber") ){
         if( $("#hiddenborrowernumber").val() != localStorage.getItem("lastborrowernumber") ) {
-            $("#lastborrower-window").detach().appendTo("#breadcrumbs");
             $("#lastborrowerlink").show();
             $("#lastborrowerlink").prop("title", localStorage.getItem("lastborrowername") + " (" + localStorage.getItem("lastborrowercard") + ")");
             $("#lastborrowerlink").prop("href", "/cgi-bin/koha/circ/circulation.pl?borrowernumber=" + localStorage.getItem("lastborrowernumber"));
-            $("#lastborrower-window").css("display", "inline-block");
+            $("#lastborrower-window").css("display", "inline-flex");
         }
     }
 
@@ -194,7 +212,7 @@ function checkEnter(e){ //e is event object passed from function invocation
 }
 
 function clearHoldFor(){
-    $.removeCookie("holdfor", { path: '/' });
+    Cookies.remove("holdfor", { path: '/' });
 }
 
 function logOut(){
@@ -205,6 +223,8 @@ function logOut(){
     removeLastBorrower();
     localStorage.removeItem("sql_reports_activetab");
     localStorage.removeItem("searches");
+    localStorage.removeItem("bibs_selected");
+    localStorage.removeItem("patron_search_selections");
 }
 
 function openHelp(){
@@ -213,7 +233,7 @@ function openHelp(){
 
 jQuery.fn.preventDoubleFormSubmit = function() {
     jQuery(this).submit(function() {
-    $("body, form input[type='submit'], form button[type='submit'], form a").addClass('waiting');
+        $("body, form input[type='submit'], form button[type='submit'], form a").addClass('waiting');
         if (this.beenSubmitted)
             return false;
         else
@@ -225,12 +245,11 @@ function openWindow(link,name,width,height) {
     name = (typeof name == "undefined")?'popup':name;
     width = (typeof width == "undefined")?'600':width;
     height = (typeof height == "undefined")?'400':height;
-    var newwin;
     //IE <= 9 can't handle a "name" with whitespace
     try {
-        newin=window.open(link,name,'width='+width+',height='+height+',resizable=yes,toolbar=false,scrollbars=yes,top');
+        window.open(link,name,'width='+width+',height='+height+',resizable=yes,toolbar=false,scrollbars=yes,top');
     } catch(e) {
-        newin=window.open(link,null,'width='+width+',height='+height+',resizable=yes,toolbar=false,scrollbars=yes,top');
+        window.open(link,null,'width='+width+',height='+height+',resizable=yes,toolbar=false,scrollbars=yes,top');
     }
 }
 
@@ -267,7 +286,7 @@ function keep_text(clicked_index) {
     var searchboxes = document.getElementsByClassName("head-searchbox");
     var persist = searchboxes[0].value;
 
-    for (i = 0; i < searchboxes.length - 1; i++) {
+    for (var i = 0; i < searchboxes.length - 1; i++) {
         if (searchboxes[i].value != searchboxes[i+1].value) {
             if (i === searchboxes.length-2) {
                 if (searchboxes[i].value != searchboxes[0].value) {
@@ -306,18 +325,6 @@ function removeByValue(arr, val) {
     }
 }
 
-function paramOfUrl( url, param ) {
-    param = param.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
-    var regexS = "[\\?&]"+param+"=([^&#]*)";
-    var regex = new RegExp( regexS );
-    var results = regex.exec( url );
-    if( results == null ) {
-        return "";
-    } else {
-        return results[1];
-    }
-}
-
 function addBibToContext( bibnum ) {
     bibnum = parseInt(bibnum, 10);
     var bibnums = getContextBiblioNumbers();
@@ -333,11 +340,11 @@ function delBibToContext( bibnum ) {
 }
 
 function setContextBiblioNumbers( bibnums ) {
-    $.cookie('bibs_selected', JSON.stringify( bibnums ));
+    localStorage.setItem('bibs_selected', JSON.stringify( bibnums ) );
 }
 
 function getContextBiblioNumbers() {
-    var r = $.cookie('bibs_selected');
+    var r = localStorage.getItem('bibs_selected');
     if ( r ) {
         return JSON.parse(r);
     }
@@ -351,6 +358,8 @@ function resetSearchContext() {
 
 function saveOrClearSimpleSearchParams() {
     // Simple masthead search - pass value for display on details page
+    var pulldown_selection;
+    var searchbox_value;
     if( $("#cat-search-block select.advsearch").length ){
         pulldown_selection = $("#cat-search-block select.advsearch").val();
     } else {