Marcel de Rooy
5233709984
Functional change: Instead of requiring two clicks for each option in the Actions menu, we add a default action based on previous activity. NOTE: In order to prioritize MARC and Card preview actions, we will only remember Import and Order when it is not preceded by a preview. In other words: If you directly click Import, Import comes back. If you click Card and Import, Card comes back. Technical changes: [1] Combine Preview and Order button on Acquisition Z3950 search. [2] Use Actions link as default action and add button with caret to open the dropdown. [3] Keep last action in localStorage (sessionStorage makes not much sense for the popups), prioritizing previews. [4] Where needed, add title attributes to dropdown links. Use class 'chosen' to differentiate preview popups from import/order actions. [5] Replace previewMARC by previewData in Authority Z3950 search. Remove duplicate code. [6] Use link href from template instead of constructing link in javascript. [7] Removing unused linktools markup from acqui template. Test plan: [1] Start on acqui Z3950. Choose Card once from the menu and then Order. [2] Start auth Z3950. Verify that Default is MARC now. Close popup. (Since Card is no option here.) [3] Start cataloguing Z3950. Verify that you have Card as default. Click Import rightaway. [4] Back to auth Z3950. Verify that Import is default. Click Import. [5] Back to acqui Z3950. Verify that MARC is default (no Import here). Click Order. Go back and verify that Order is now default. Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> Signed-off-by: Michal Denar <black23@gmail.com> Signed-off-by: Nick Clemens <nick@bywatersolutions.com> Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
155 lines
6 KiB
JavaScript
155 lines
6 KiB
JavaScript
/* global __ total_pages */
|
|
//z3950_search.js for Authorities, Bib records and Acquisitions module
|
|
|
|
var last_action, previewed = 0;
|
|
|
|
function validate_goto_page() {
|
|
var page = $('#goto_page').val();
|
|
if (isNaN(page)) {
|
|
alert( __("The page entered is not a number.") );
|
|
return false;
|
|
} else if (page < 1 || page > total_pages) {
|
|
alert( __("The page should be a number between 1 and %s.").format(total_pages) );
|
|
return false;
|
|
} else {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
$( document ).ready( function() {
|
|
|
|
$( "#CheckAll" ).click( function(e) {
|
|
e.preventDefault();
|
|
$( ".checkboxed input:checkbox" ).prop("checked", true);
|
|
});
|
|
$( "#CheckNone" ).click( function(e) {
|
|
e.preventDefault();
|
|
$( ".checkboxed input:checkbox" ).prop("checked", false);
|
|
});
|
|
|
|
$( ".submit" ).on( "click", function() {
|
|
$( "body" ).css( "cursor", "wait" );
|
|
});
|
|
$( "[name='changepage_prev']" ).on( "click", function() {
|
|
var data_current_page_prev = $( this ).data( "currentpage" );
|
|
$( '#current_page' ).val( data_current_page_prev - 1 );
|
|
$( '#page_form' ).submit();
|
|
});
|
|
$( "[name='changepage_next']" ).on( "click", function() {
|
|
var data_current_page_next = $( this ).data( "currentpage" );
|
|
$( '#current_page' ).val( data_current_page_next + 1 );
|
|
$( '#page_form' ).submit();
|
|
});
|
|
$( "[name='changepage_goto']" ).on( "click", function() {
|
|
return validate_goto_page();
|
|
});
|
|
$( "#resetZ3950Search" ).click( function(e) {
|
|
e.preventDefault();
|
|
$( "form[name='f']" ).find( "input[type=text]" ).val( "" );
|
|
});
|
|
$( "form[name='f']" ).submit( function() {
|
|
if ( $( 'input[type=checkbox]' ).filter( ':checked' ).length == 0 ) {
|
|
alert( __("Please choose at least one external target") );
|
|
$( "body" ).css( "cursor", "default" );
|
|
return false;
|
|
} else {
|
|
return true;
|
|
}
|
|
});
|
|
|
|
/* Display actions menu anywhere the table is clicked */
|
|
/* Note: The templates where this is included must have a search results
|
|
table with the id "resultst" and "action" table cells with the class "actions" */
|
|
$("#resultst").on("click", "td", function(event){
|
|
event.preventDefault();
|
|
var tgt = $(event.target);
|
|
var row = $(this).closest('tr');
|
|
/* Remove highlight from all rows and add to the clicked row */
|
|
$("tr").removeClass("highlighted-row");
|
|
row.addClass("highlighted-row");
|
|
/* Remove any menus created on the fly for other rows */
|
|
$(".btn-wrapper").remove();
|
|
|
|
if( tgt.hasClass("z3950actions") ) { // direct button click
|
|
var link = $( "a[title='" + tgt.text() + "']", row );
|
|
if( link.length == 1) link.click();
|
|
row.find('ul.dropdown-menu').hide();
|
|
} else {
|
|
event.stopPropagation();
|
|
/* Remove the "open" class from all dropup menus in case one is open */
|
|
$(".dropup").removeClass("open");
|
|
/* Create a clone of the Bootstrap dropup menu in the "Actions" column */
|
|
var menu_clone = $(".dropdown-menu", row)
|
|
.clone()
|
|
.addClass("menu-clone")
|
|
.css({
|
|
"display" : "block",
|
|
"position" : "absolute",
|
|
"top" : "auto",
|
|
"bottom" : "100%",
|
|
"right" : "auto",
|
|
"left" : "0",
|
|
});
|
|
/* Append the menu clone to the table cell which was clicked.
|
|
The menu must first be wrapped in a block-level div to clear
|
|
the table cell's text contents and then a relative-positioned
|
|
div to allow the menu to be positioned correctly */
|
|
if( tgt.prop('nodeName') != 'TD' ) {
|
|
// handling click on caret to improve menu position
|
|
tgt = tgt.closest('td');
|
|
}
|
|
tgt.append(
|
|
$('<div/>', {'class': 'btn-wrapper'}).append(
|
|
$('<div/>', {'class': 'btn-group'}).append(
|
|
menu_clone
|
|
)
|
|
)
|
|
);
|
|
}
|
|
});
|
|
|
|
$( "#resultst" ).on("click", ".previewData", function(e) {
|
|
e.preventDefault();
|
|
previewed = 1;
|
|
ChangeLastAction( $(this).attr('title'), 1 );
|
|
var ltitle = $( this ).text();
|
|
var page = $( this ).attr( "href" );
|
|
$( "#dataPreviewLabel" ).text( ltitle );
|
|
$( "#dataPreview .modal-body" ).load( page + " div" );
|
|
$( '#dataPreview' ).modal( {show:true} );
|
|
});
|
|
|
|
$( "#dataPreview" ).on( "hidden", function() {
|
|
$( "#dataPreviewLabel" ).html( "" );
|
|
$( "#dataPreview .modal-body" ).html( "<div id='loading'><img src='" + interface + "/" + theme + "/img/spinner-small.gif' alt='' /> " + __("Loading") + "</div>" );
|
|
});
|
|
|
|
$( "#resultst" ).on("click", ".chosen", function(e) {
|
|
e.preventDefault();
|
|
var title = $(this).attr('title');
|
|
ChangeLastAction( title, 0 );
|
|
if( title == 'Order' ) window.location = $(this).attr('href');
|
|
else {
|
|
opener.document.location = $(this).attr('href');
|
|
window.close();
|
|
}
|
|
});
|
|
});
|
|
|
|
function InitLastAction() {
|
|
if( $("#resultst").length == 0 ) return;
|
|
try { last_action = localStorage.getItem('z3950search_last_action'); } catch (err) {}
|
|
if( last_action ) {
|
|
var linkcount = $(".z3950actions:eq(0)").siblings(".dropdown-menu").find("a[title='"+last_action+"']").length;
|
|
if( linkcount == 0 ) return;
|
|
if( last_action != 'MARC' ) $( ".z3950actions" ).text( last_action );
|
|
}
|
|
}
|
|
|
|
function ChangeLastAction(title, change_text) {
|
|
if( last_action && last_action == title ) return;
|
|
last_action = title;
|
|
if( change_text ) $( ".z3950actions" ).text( last_action );
|
|
if( previewed == 0 || change_text == 1 )
|
|
try { localStorage.setItem('z3950search_last_action', last_action); } catch(err) {}
|
|
}
|