]> git.koha-community.org Git - koha.git/blob - koha-tmpl/intranet-tmpl/prog/en/includes/js_includes.inc
Bug 10902: (follow-up) Fix patron search autocomplete
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / includes / js_includes.inc
1 [% USE raw %]
2 [% USE Asset %]
3 [% USE AudioAlerts %]
4 [% USE Branches %]
5 [% USE To %]
6 [% USE Koha %]
7 [%# Prevent XFS attacks -%]
8 [% UNLESS popup %]
9     <script>
10        if (self === top) {
11            var antiClickjack = document.getElementById("antiClickjack");
12            antiClickjack.parentNode.removeChild(antiClickjack);
13        } else {
14            top.location = self.location;
15        }
16     </script>
17 [% END %]
18
19 [% Asset.js("lib/jquery/jquery-2.2.3.min.js") | $raw %]
20 [% Asset.js("lib/jquery/jquery-migrate-1.3.0.min.js") | $raw %]
21 [% Asset.js("lib/jquery/jquery-ui-1.11.4.min.js") | $raw %]
22 [% Asset.js("lib/shortcut/shortcut.js") | $raw %]
23 [% Asset.js("lib/jquery/plugins/jquery.cookie.min.js") | $raw %]
24 [% Asset.js("lib/js-cookie/js.cookie-2.2.1.min.js") | $raw %]
25 [% Asset.js("lib/jquery/plugins/jquery.highlight-3.js") | $raw %]
26 [% Asset.js("lib/bootstrap/bootstrap.min.js") | $raw %]
27 [% Asset.js("lib/jquery/plugins/jquery.validate.min.js") | $raw %]
28 <!-- koha core js -->
29 [% Asset.js("js/staff-global.js") | $raw %]
30
31 [% INCLUDE 'validator-strings.inc' %]
32 [% IF ( IntranetUserJS ) %]
33     <!-- js_includes.inc: IntranetUserJS -->
34     <script>
35     [% IntranetUserJS | $raw %]
36     </script>
37     <!-- / js_includes.inc: IntranetUserJS -->
38 [% END %]
39
40 <!-- js_includes.inc -->
41 [% IF ( Koha.Preference('virtualshelves') || Koha.Preference('intranetbookbag') ) %]
42     [% Asset.js("js/basket.js") | $raw %]
43 [% END %]
44
45 [% IF LocalCoverImages %]
46     [% Asset.js("js/localcovers.js") | $raw %]
47 [% END %]
48
49 [% IF Koha.Preference('AudioAlerts') || AudioAlertsPage %]
50     <script>
51         // AudioAlerts
52         var AUDIO_ALERT_PATH = '[% interface | html %]/[% theme | html %]/sound/';
53         var AUDIO_ALERTS = JSON.parse( "[% To.json(AudioAlerts.AudioAlerts) | $raw %]" );
54
55         $( document ).ready(function() {
56             if ( AUDIO_ALERTS ) {
57                 for ( var k in AUDIO_ALERTS ) {
58                     var alert = AUDIO_ALERTS[k];
59                     if ( $( alert.selector ).length ) {
60                         playSound( alert.sound );
61                         break;
62                     }
63                 }
64             }
65         });
66     </script>
67 [% END %]
68
69 [% IF ( CAN_user_circulate_circulate_remaining_permissions ) %]
70     [% IF ( PatronAutoComplete ) %]
71         <script>
72             // PatronAutoComplete && CAN_user_circulate_circulate_remaining_permissions
73             var loggedInLibrary = '[% Branches.GetLoggedInBranchcode | html %]';
74             var loggedInClass = "";
75             $(document).ready(function(){
76                 var obj = $( "#findborrower" ).autocomplete({
77                     source: "/cgi-bin/koha/circ/ysearch.pl",
78                     minLength: 3,
79                     select: function( event, ui ) {
80                         window.location.href = ui.item.link;
81                     }
82                 }).data( "ui-autocomplete" );
83                 if( obj ) {
84                     obj._renderItem = function( ul, item ) {
85                         item.link = "/cgi-bin/koha/circ/circulation.pl?borrowernumber=" + item.borrowernumber;
86                         var cardnumber = "";
87                         if( item.cardnumber != "" ){
88                             // Display card number in parentheses if it exists
89                             cardnumber = " (" + item.cardnumber + ") ";
90                         }
91                         var itemString = "<a href=\"" + item.link + "\">" + ( item.surname ? item.surname.escapeHtml() : "" ) + ", " + ( item.firstname ? item.firstname.escapeHtml() : "" ) + cardnumber.escapeHtml() + " <small>";
92
93                         if( item.branchcode == loggedInLibrary ){
94                             loggedInClass = "ac-currentlibrary";
95                         } else {
96                             loggedInClass = "";
97                         }
98
99                         if( item.dateofbirth ) {
100                             itemString += ( item.dateofbirth ? item.dateofbirth.escapeHtml() : "" )
101                                         + "<span class=\"age_years\"> (" + ( item.age ? item.age.escapeHtml() : "" ) + " " +  _("years") + ")</span>, ";
102                         }
103                         itemString += ( item.address ? item.address.escapeHtml() : "" ) + " "
104                                     + ( item.city    ? item.city.escapeHtml()    : "" ) + " "
105                                     + ( item.zipcode ? item.zipcode.escapeHtml() : "" ) + " "
106                                     + ( item.country ? item.country.escapeHtml() : "" )
107                                     + "</small></a>";
108                         itemString += " <span class=\"ac-library\">" + item.branchname + "</span> " + "</a>";
109                         return $( "<li></li>" )
110                         .addClass( loggedInClass )
111                         .data( "ui-autocomplete-item", item )
112                         .append( itemString )
113                         .appendTo( ul );
114                     };
115                 }
116             });
117         </script>
118     [% END %]
119 [% END %]
120 [% IF ( PatronAutoComplete ) %]
121     <script>
122     // PatronAutoComplete
123     var loggedInLibrary = '[% Branches.GetLoggedInBranchcode | html %]';
124     var loggedInClass = "";
125     $(document).ready(function(){
126         var obj = $( "#searchmember" ).autocomplete({
127             source: "/cgi-bin/koha/circ/ysearch.pl",
128             minLength: 3,
129             select: function( event, ui ) {
130                 window.location.href = ui.item.link;
131             }
132         }).data( "ui-autocomplete" );
133         if( obj ) {
134             obj._renderItem = function( ul, item ) {
135                 item.link = "/cgi-bin/koha/members/moremember.pl?borrowernumber=" + item.borrowernumber;
136                 var cardnumber = "";
137                 if( item.cardnumber != "" ){
138                     // Display card number in parentheses if it exists
139                     cardnumber = " (" + item.cardnumber + ") ";
140                 }
141                 if( item.branchcode == loggedInLibrary ){
142                     loggedInClass = "ac-currentlibrary";
143                 } else {
144                     loggedInClass = "";
145                 }
146                 return $( "<li></li>" )
147                 .addClass( loggedInClass )
148                 .data( "ui-autocomplete-item", item )
149                 .append(
150                     "<a href=\"" + item.link + "\">" + ( item.surname ? item.surname.escapeHtml() : "" ) + ", "
151                         + ( item.firstname ? item.firstname.escapeHtml() : "" )
152                         + cardnumber.escapeHtml()
153                         + " <small>"
154                             + ( item.dateofbirth ? item.dateofbirth.escapeHtml() : "" ) + " "
155                             + ( item.address     ? item.address.escapeHtml() : "" )     + " "
156                             + ( item.city        ? item.city.escapeHtml() : "" )        + " "
157                             + ( item.zipcode     ? item.zipcode.escapeHtml() : "" )     + " "
158                             + ( item.country     ? item.country.escapeHtml() : "" ) + " "
159                             + "<span class=\"ac-library\">"
160                             + ( item.branchname  ? item.branchname.escapeHtml() : "" )
161                             + "</span>"
162                         + "</small>"
163                     + "</a>" )
164                 .appendTo( ul );
165             };
166         }
167     });
168     </script>
169 [% END %]
170 <!-- / js_includes.inc -->