Bug 26988: Add API route to fetch hold pickup locations and use it in the holds table
[koha.git] / koha-tmpl / intranet-tmpl / prog / js / z3950_search.js
1 /* global __ total_pages */
2 //z3950_search.js for Authorities, Bib records and Acquisitions module
3 function Import(Breeding, recordid, AuthType, FrameworkCode) {
4
5     if ( AuthType == false ) {
6         opener.document.location="../cataloguing/addbiblio.pl?biblionumber="+recordid+"&z3950=1&frameworkcode="+FrameworkCode+"&breedingid="+Breeding;
7     } else {
8         opener.document.location="../authorities/authorities.pl?breedingid="+Breeding+"&authtypecode="+AuthType+"&authid="+recordid;
9     }
10     window.close();
11     return false;
12
13 }
14
15 function validate_goto_page() {
16     var page = $('#goto_page').val();
17     if (isNaN(page)) {
18         alert( __("The page entered is not a number.") );
19         return false;
20     } else if (page < 1 || page > total_pages) {
21         alert( __("The page should be a number between 1 and %s.").format(total_pages) );
22         return false;
23     } else {
24         return true;
25     }
26 }
27
28 $( document ).ready( function() {
29
30     $( "#CheckAll" ).click( function(e) {
31         e.preventDefault();
32         $( ".checkboxed input:checkbox" ).prop("checked", true);
33     });
34     $( "#CheckNone" ).click( function(e) {
35         e.preventDefault();
36         $( ".checkboxed input:checkbox" ).prop("checked", false);
37     });
38
39     $( ".submit" ).on( "click", function() {
40         $( "body" ).css( "cursor", "wait" );
41     });
42     $( "[name='changepage_prev']" ).on( "click", function() {
43         var data_current_page_prev = $( this ).data( "currentpage" );
44         $( '#current_page' ).val( data_current_page_prev - 1 );
45         $( '#page_form' ).submit();
46     });
47     $( "[name='changepage_next']" ).on( "click", function() {
48         var data_current_page_next = $( this ).data( "currentpage" );
49         $( '#current_page' ).val( data_current_page_next + 1 );
50         $( '#page_form' ).submit();
51     });
52     $( "[name='changepage_goto']" ).on( "click", function() {
53         return validate_goto_page();
54     });
55     $( "#resetZ3950Search" ).click( function(e) {
56         e.preventDefault();
57         $( "form[name='f']" ).find( "input[type=text]" ).val( "" );
58     });
59     $( "form[name='f']" ).submit( function() {
60         if ( $( 'input[type=checkbox]' ).filter( ':checked' ).length == 0 ) {
61             alert( __("Please choose at least one external target") );
62             $( "body" ).css( "cursor", "default" );
63             return false;
64         } else {
65             return true;
66         }
67     });
68
69     /* Display actions menu anywhere the table is clicked */
70     /* Note: The templates where this is included must have a search results
71        table with the id "resultst" and "action" table cells with the class "actions" */
72     $("#resultst").on("click", "td", function(event){
73         var tgt = $(event.target);
74         var row = $(this).parent();
75         /* Remove highlight from all rows and add to the clicked row */
76         $("tr").removeClass("highlighted-row");
77         row.addClass("highlighted-row");
78         /* Remove any menus created on the fly for other rows */
79         $(".btn-wrapper").remove();
80
81         if( tgt.is("a") || tgt.hasClass("actions") ){
82             /* Don't show inline links for cells containing links of their own. */
83         } else {
84             event.stopPropagation();
85             /* Remove the "open" class from all dropup menus in case one is open */
86             $(".dropup").removeClass("open");
87             /* Create a clone of the Bootstrap dropup menu in the "Actions" column */
88             var menu_clone = $(".dropdown-menu", row)
89                 .clone()
90                 .addClass("menu-clone")
91                 .css({
92                     "display" : "block",
93                     "position" : "absolute",
94                     "top" : "auto",
95                     "bottom" : "100%",
96                     "right" : "auto",
97                     "left" : "0",
98                 });
99             /* Append the menu clone to the table cell which was clicked.
100                 The menu must first be wrapped in a block-level div to clear
101                 the table cell's text contents and then a relative-positioned
102                 div to allow the menu to be positioned correctly */
103             tgt.append(
104                 $('<div/>', {'class': 'btn-wrapper'}).append(
105                     $('<div/>', {'class': 'btn-group'}).append(
106                         menu_clone
107                     )
108                 )
109             );
110         }
111     });
112
113     $( "#resultst" ).on("click", ".previewMARC", function(e) {
114         e.preventDefault();
115         var ltitle = $( this ).text();
116         var page = $( this ).attr( "href" );
117         $( "#marcPreviewLabel" ).text( ltitle );
118         $( "#marcPreview .modal-body" ).load( page + " pre" );
119         $( '#marcPreview' ).modal( {show:true} );
120     });
121     $( "#marcPreview" ).on( "hidden", function() {
122         $( "#marcPreviewLabel" ).html( "" );
123         $( "#marcPreview .modal-body" ).html( "<div id='loading'><img src='" + interface + "/" + theme + "/img/spinner-small.gif' alt='' /> " + __("Loading") + "</div>" );
124     });
125     $( "#resultst" ).on("click", ".previewData", function(e) {
126         e.preventDefault();
127         var ltitle = $( this ).text();
128         var page = $( this ).attr( "href" );
129         $( "#dataPreviewLabel" ).text( ltitle );
130         $( "#dataPreview .modal-body" ).load( page + " div" );
131         $( '#dataPreview' ).modal( {show:true} );
132     });
133     $( "#dataPreview" ).on( "hidden", function() {
134         $( "#dataPreviewLabel" ).html( "" );
135         $( "#dataPreview .modal-body" ).html( "<div id='loading'><img src='" + interface + "/" + theme + "/img/spinner-small.gif' alt='' /> " + __("Loading") + "</div>" );
136     });
137     $( "#resultst" ).on("click", ".import_record", function(e) {
138         e.preventDefault();
139         var data_breedingid = $( this ).data( "breedingid" );
140         var data_headingcode = $( this ).data( "heading_code" );
141         var data_authid = $( this ).data( "authid" );
142         var data_biblionumber = $( this ).data( "biblionumber" );
143         var data_frameworkcode = $( this ).data( "frameworkcode" );
144         if ( data_headingcode == undefined ) {
145             Import( data_breedingid, data_biblionumber, false , data_frameworkcode );
146         } else {
147             Import( data_breedingid, data_authid, data_headingcode );
148         }
149         return false;
150     });
151
152 });