1 /* global __ total_pages */
2 //z3950_search.js for Authorities, Bib records and Acquisitions module
6 function validate_goto_page() {
7 var page = $('#goto_page').val();
9 alert( __("The page entered is not a number.") );
11 } else if (page < 1 || page > total_pages) {
12 alert( __("The page should be a number between 1 and %s.").format(total_pages) );
19 $( document ).ready( function() {
21 $( "#CheckAll" ).click( function(e) {
23 $( ".checkboxed input:checkbox" ).prop("checked", true);
25 $( "#CheckNone" ).click( function(e) {
27 $( ".checkboxed input:checkbox" ).prop("checked", false);
30 $( ".submit" ).on( "click", function() {
31 $( "body" ).css( "cursor", "wait" );
33 $( "[name='changepage_prev']" ).on( "click", function() {
34 var data_current_page_prev = $( this ).data( "currentpage" );
35 $( '#current_page' ).val( data_current_page_prev - 1 );
36 $( '#page_form' ).submit();
38 $( "[name='changepage_next']" ).on( "click", function() {
39 var data_current_page_next = $( this ).data( "currentpage" );
40 $( '#current_page' ).val( data_current_page_next + 1 );
41 $( '#page_form' ).submit();
43 $( "[name='changepage_goto']" ).on( "click", function() {
44 return validate_goto_page();
46 $( "#resetZ3950Search" ).click( function(e) {
48 $( "form[name='f']" ).find( "input[type=text]" ).val( "" );
50 $( "form[name='f']" ).submit( function() {
51 if ( $( 'input[type=checkbox]' ).filter( ':checked' ).length == 0 ) {
52 alert( __("Please choose at least one external target") );
53 $( "body" ).css( "cursor", "default" );
60 /* Display actions menu anywhere the table is clicked */
61 /* Note: The templates where this is included must have a search results
62 table with the id "resultst" and "action" table cells with the class "actions" */
63 $("#resultst").on("click", "td", function(event){
64 event.preventDefault();
65 var tgt = $(event.target);
66 var row = $(this).closest('tr');
67 /* Remove highlight from all rows and add to the clicked row */
68 $("tr").removeClass("highlighted-row");
69 row.addClass("highlighted-row");
70 /* Remove any menus created on the fly for other rows */
71 $(".btn-wrapper").remove();
73 if( tgt.hasClass("z3950actions") ) { // direct button click
74 var link = $( "a[title='" + tgt.text() + "']", row );
75 if( link.length == 1) link.click();
76 row.find('ul.dropdown-menu').hide();
78 event.stopPropagation();
79 /* Remove the "open" class from all dropup menus in case one is open */
80 $(".dropup").removeClass("open");
81 /* Create a clone of the Bootstrap dropup menu in the "Actions" column */
82 var menu_clone = $(".dropdown-menu", row)
84 .addClass("menu-clone")
87 "position" : "absolute",
93 /* Append the menu clone to the table cell which was clicked.
94 The menu must first be wrapped in a block-level div to clear
95 the table cell's text contents and then a relative-positioned
96 div to allow the menu to be positioned correctly */
97 if( tgt.prop('nodeName') != 'TD' ) {
98 // handling click on caret to improve menu position
99 tgt = tgt.closest('td');
102 $('<div/>', {'class': 'btn-wrapper'}).append(
103 $('<div/>', {'class': 'btn-group'}).append(
111 $( "#dataPreview" ).on( "hidden", function() {
112 $( "#dataPreviewLabel" ).html( "" );
113 $( "#dataPreview .modal-body" ).html( "<div id='loading'><img src='" + interface + "/" + theme + "/img/spinner-small.gif' alt='' /> " + __("Loading") + "</div>" );
116 $( "#resultst" ).on("click", ".previewData", function(e) {
118 ChangeLastAction( $(this).data('action'), $(this).attr('title') );
119 var long_title = $( this ).text();
120 var page = $( this ).attr( "href" );
121 $( "#dataPreviewLabel" ).text( long_title );
122 $( "#dataPreview .modal-body" ).load( page + " div" );
123 $( '#dataPreview' ).modal( {show:true} );
126 $( "#resultst" ).on("click", ".chosen", function(e) {
128 var action = $(this).data('action');
129 ChangeLastAction( action );
130 if( action == 'order' ) window.location = $(this).attr('href');
132 opener.document.location = $(this).attr('href');
138 function InitLastAction() {
139 if( $("#resultst").length == 0 ) return;
140 try { last_action = localStorage.getItem('z3950search_last_action'); } catch (err) {}
142 // get short title from attr
143 var short_title = $(".z3950actions:eq(0)").siblings(".dropdown-menu").find("a[data-action='"+last_action+"']").attr('title');
144 if( short_title && last_action != 'show_marc' ) {
145 $( ".z3950actions" ).text( short_title );
150 function ChangeLastAction( action, short_title ) {
151 if( last_action && last_action == action ) return;
152 last_action = action;
153 if( short_title ) { // Save choice for preview (MARC or Card)
154 $( ".z3950actions" ).text( short_title );
155 try { localStorage.setItem('z3950search_last_action', last_action ); } catch(err) {}