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 window.addEventListener('pageshow', function( e ){
20 $('body').css("cursor", "default");
23 $( document ).ready( function() {
25 $( "#CheckAll" ).click( function(e) {
27 $( ".checkboxed input:checkbox" ).prop("checked", true);
29 $( "#CheckNone" ).click( function(e) {
31 $( ".checkboxed input:checkbox" ).prop("checked", false);
34 $( "#submit_z3950_search" ).on( "click", function() {
35 $( "body" ).css( "cursor", "wait" );
37 $( "[name='changepage_prev']" ).on( "click", function() {
38 var data_current_page_prev = $( this ).data( "currentpage" );
39 $( '#current_page' ).val( data_current_page_prev - 1 );
40 $( '#page_form' ).submit();
42 $( "[name='changepage_next']" ).on( "click", function() {
43 var data_current_page_next = $( this ).data( "currentpage" );
44 $( '#current_page' ).val( data_current_page_next + 1 );
45 $( '#page_form' ).submit();
47 $( "[name='changepage_goto']" ).on( "click", function() {
48 return validate_goto_page();
50 $( "#resetZ3950Search" ).click( function(e) {
52 $( "form[name='f']" ).find( "input[type=text]" ).val( "" );
54 $( "form[name='f']" ).submit( function() {
55 if ( $( 'input[type=checkbox]' ).filter( ':checked' ).length == 0 ) {
56 alert( __("Please choose at least one external target") );
57 $( "body" ).css( "cursor", "default" );
64 /* Display actions menu anywhere the table is clicked */
65 /* Note: The templates where this is included must have a search results
66 table with the id "resultst" and "action" table cells with the class "actions" */
67 $("#resultst").on("click", "td", function(event){
68 event.preventDefault();
69 var tgt = $(event.target);
70 var row = $(this).closest('tr');
71 /* Remove highlight from all rows and add to the clicked row */
72 $("tr").removeClass("highlighted-row");
73 row.addClass("highlighted-row");
74 /* Remove any menus created on the fly for other rows */
75 $(".btn-wrapper").remove();
77 if( tgt.hasClass("z3950actions") ) { // direct button click
78 var link = $( "a[title='" + tgt.text() + "']", row );
79 if( link.length == 1) link.click();
80 row.find('ul.dropdown-menu').hide();
82 event.stopPropagation();
83 /* Remove the "open" class from all dropup menus in case one is open */
84 $(".dropup").removeClass("open");
85 /* Create a clone of the Bootstrap dropup menu in the "Actions" column */
86 var menu_clone = $(".dropdown-menu", row)
88 .addClass("menu-clone")
91 "position" : "absolute",
97 /* Append the menu clone to the table cell which was clicked.
98 The menu must first be wrapped in a block-level div to clear
99 the table cell's text contents and then a relative-positioned
100 div to allow the menu to be positioned correctly */
101 if( tgt.prop('nodeName') != 'TD' ) {
102 // handling click on caret to improve menu position
103 tgt = tgt.closest('td');
106 $('<div/>', {'class': 'btn-wrapper'}).append(
107 $('<div/>', {'class': 'btn-group'}).append(
115 $( "#dataPreview" ).on( "hidden", function() {
116 $( "#dataPreviewLabel" ).html( "" );
117 $( "#dataPreview .modal-body" ).html( "<div id='loading'><img src='" + interface + "/" + theme + "/img/spinner-small.gif' alt='' /> " + __("Loading") + "</div>" );
120 $( "#resultst" ).on("click", ".previewData", function(e) {
122 ChangeLastAction( $(this).data('action'), $(this).attr('title') );
123 var long_title = $( this ).text();
124 var page = $( this ).attr( "href" );
125 $( "#dataPreviewLabel" ).text( long_title );
126 $( "#dataPreview .modal-body" ).load( page + " div" );
127 $( '#dataPreview' ).modal( {show:true} );
130 $( "#resultst" ).on("click", ".chosen", function(e) {
132 var action = $(this).data('action');
133 ChangeLastAction( action );
134 if( action == 'order' ) window.location = $(this).attr('href');
136 opener.document.location = $(this).attr('href');
142 function InitLastAction() {
143 if( $("#resultst").length == 0 ) return;
144 try { last_action = localStorage.getItem('z3950search_last_action'); } catch (err) {}
146 // get short title from attr
147 var short_title = $(".z3950actions:eq(0)").siblings(".dropdown-menu").find("a[data-action='"+last_action+"']").attr('title');
148 if( short_title && last_action != 'show_marc' ) {
149 $( ".z3950actions" ).text( short_title );
154 function ChangeLastAction( action, short_title ) {
155 if( last_action && last_action == action ) return;
156 last_action = action;
157 if( short_title ) { // Save choice for preview (MARC or Card)
158 $( ".z3950actions" ).text( short_title );
159 try { localStorage.setItem('z3950search_last_action', last_action ); } catch(err) {}