1 /* global __ total_pages */
2 //z3950_search.js for Authorities, Bib records and Acquisitions module
4 var last_action, previewed = 0;
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 $( "#resultst" ).on("click", ".previewData", function(e) {
114 ChangeLastAction( $(this).attr('title'), 1 );
115 var ltitle = $( this ).text();
116 var page = $( this ).attr( "href" );
117 $( "#dataPreviewLabel" ).text( ltitle );
118 $( "#dataPreview .modal-body" ).load( page + " div" );
119 $( '#dataPreview' ).modal( {show:true} );
122 $( "#dataPreview" ).on( "hidden", function() {
123 $( "#dataPreviewLabel" ).html( "" );
124 $( "#dataPreview .modal-body" ).html( "<div id='loading'><img src='" + interface + "/" + theme + "/img/spinner-small.gif' alt='' /> " + __("Loading") + "</div>" );
127 $( "#resultst" ).on("click", ".chosen", function(e) {
129 var title = $(this).attr('title');
130 ChangeLastAction( title, 0 );
131 if( title == 'Order' ) window.location = $(this).attr('href');
133 opener.document.location = $(this).attr('href');
139 function InitLastAction() {
140 if( $("#resultst").length == 0 ) return;
141 try { last_action = localStorage.getItem('z3950search_last_action'); } catch (err) {}
143 var linkcount = $(".z3950actions:eq(0)").siblings(".dropdown-menu").find("a[title='"+last_action+"']").length;
144 if( linkcount == 0 ) return;
145 if( last_action != 'MARC' ) $( ".z3950actions" ).text( last_action );
149 function ChangeLastAction(title, change_text) {
150 if( last_action && last_action == title ) return;
152 if( change_text ) $( ".z3950actions" ).text( last_action );
153 if( previewed == 0 || change_text == 1 )
154 try { localStorage.setItem('z3950search_last_action', last_action); } catch(err) {}