Bug 12075: fix keyboard shortcuts broken by jQueryUI upgrade
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / js / staff-global.js
1 // staff-global.js
2 if ( KOHA === undefined ) var KOHA = {};
3
4 function _(s) { return s; } // dummy function for gettext
5
6 // http://stackoverflow.com/questions/14859281/select-tab-by-name-in-jquery-ui-1-10-0/16550804#16550804
7 $.fn.tabIndex = function () {
8     return $(this).parent().find(this).index() - 1;
9 };
10 $.fn.selectTabByID = function (tabID) {
11     $(this).tabs("option", "active", $(tabID).tabIndex());
12 };
13
14  $(document).ready(function() {
15     $('#header_search').tabs().on( "tabsactivate", function(e, ui) { $(this).find("div:visible").find('input').eq(0).focus(); });
16
17     $(".close").click(function(){ window.close(); });
18
19     if($("#header_search #checkin_search").length > 0){ shortcut.add('Alt+r',function (){ $("#header_search").selectTabByID("#checkin_search"); $("#ret_barcode").focus(); }); } else { shortcut.add('Alt+r',function (){ location.href="/cgi-bin/koha/circ/returns.pl"; }); }
20     if($("#header_search #circ_search").length > 0){ shortcut.add('Alt+u',function (){ $("#header_search").selectTabByID("#circ_search"); $("#findborrower").focus(); }); } else { shortcut.add('Alt+u',function(){ location.href="/cgi-bin/koha/circ/circulation.pl"; }); }
21     if($("#header_search #catalog_search").length > 0){ shortcut.add('Alt+q',function (){ $("#header_search").selectTabByID("#catalog_search"); $("#search-form").focus(); }); } else { shortcut.add('Alt+q',function(){ location.href="/cgi-bin/koha/catalogue/search.pl"; }); }
22
23     $(".focus").focus();
24     $(".validated").each(function() {
25         $(this).validate();
26     });
27
28     $("#logout").on("click",function(){
29         logOut();
30     });
31     $("#helper").on("click",function(){
32         openHelp();
33         return false;
34     });
35
36     $("body").on("keypress", ".noEnterSubmit", function(e){
37         return checkEnter(e);
38     });
39 });
40
41 // http://jennifermadden.com/javascript/stringEnterKeyDetector.html
42 function checkEnter(e){ //e is event object passed from function invocation
43     var characterCode; // literal character code will be stored in this variable
44     if(e && e.which){ //if which property of event object is supported (NN4)
45         e = e;
46         characterCode = e.which; //character code is contained in NN4's which property
47     } else {
48         e = window.event;
49         characterCode = e.keyCode; //character code is contained in IE's keyCode property
50     }
51
52     if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
53         return false;
54     } else {
55         return true;
56     }
57 }
58
59 function clearHoldFor(){
60         $.cookie("holdfor",null, { path: "/", expires: 0 });
61 }
62
63 function logOut(){
64     if( typeof delBasket == 'function' ){
65         delBasket('main', true);
66     }
67     clearHoldFor();
68 }
69
70 function openHelp(){
71     openWindow("/cgi-bin/koha/help.pl","Koha help",600,600);
72 }
73
74 jQuery.fn.preventDoubleFormSubmit = function() {
75     jQuery(this).submit(function() {
76     $("body, form input[type='submit'], form button[type='submit'], form a").addClass('waiting');
77         if (this.beenSubmitted)
78             return false;
79         else
80             this.beenSubmitted = true;
81     });
82 };
83
84 function openWindow(link,name,width,height) {
85     name = (typeof name == "undefined")?'popup':name;
86     width = (typeof width == "undefined")?'600':width;
87     height = (typeof height == "undefined")?'400':height;
88     var newin=window.open(link,name,'width='+width+',height='+height+',resizable=yes,toolbar=false,scrollbars=yes,top');
89 }
90
91 // Use this function to remove the focus from any element for
92 // repeated scanning actions on errors so the librarian doesn't
93 // continue scanning and miss the error.
94 function removeFocus() {
95     $(':focus').blur();
96 }
97
98 function toUC(f) {
99     var x=f.value.toUpperCase();
100     f.value=x;
101     return true;
102 }
103
104 function confirmDelete(message) {
105     return (confirm(message) ? true : false);
106 }