1 /* global KOHA biblionumber new_results_browser addMultiple vShelfAdd openWindow search_result SEARCH_RESULTS PREF_LocalCoverImages PREF_IntranetCoce PREF_CoceProviders CoceHost CoceProviders addRecord delSingleRecord PREF_BrowseResultSelection resetSearchContext addBibToContext delBibToContext getContextBiblioNumbers holdfor_cardnumber holdforclub strQuery PREF_StaffHighlightedWords PREF_NotHighlightedWords __ */
3 function verify_cover_images() {
4 /* Loop over each container in the template which contains covers */
5 var coverSlides = $(".cover-slides"); /* One coverSlides for each search result */
6 coverSlides.each( function( index ){
8 var biblionumber = $(this).data("biblionumber");
9 var coverImages = $(".cover-image", slide ); /* Multiple coverImages for each coverSlides */
11 coverImages.each( function( index ){
13 var coverId = div.attr("id");
14 /* Find the image in the container */
15 var img = div.find("img")[0];
16 if( $(img).length > 0 ){
17 if( (img.complete != null) && (!img.complete) || img.naturalHeight == 0 ){
18 /* No image loaded in the container. Remove the slide */
19 blanks.push( coverId );
22 /* Check if Amazon image is present */
23 if ( div.hasClass("amazon-bookcoverimg") ) {
26 if ((w == 1) || (h == 1)) {
27 /* Amazon returned single-pixel placeholder */
28 /* Remove the container */
29 blanks.push( coverId );
33 /* Check if Local image is present */
34 if ( div.hasClass("local-coverimg" ) ) {
37 if ((w == 1) || (h == 1)) {
38 /* Local cover image returned single-pixel placeholder */
39 /* Remove the container */
40 blanks.push( coverId );
44 if( div.hasClass("custom-img") ){
45 /* Check for image from CustomCoverImages system preference */
46 if ( (img.complete != null) && (!img.complete) || img.naturalHeight == 0 ) {
47 /* No image was loaded via the CustomCoverImages system preference */
48 /* Remove the container */
49 blanks.push( coverId );
54 if( div.hasClass("coce-coverimg") ){
55 /* Identify which service's image is being loaded by IntranetCoce system pref */
56 if( $(img).attr("src").indexOf('amazon.com') >= 0 ){
57 div.find(".hint").html(_("Coce image from Amazon.com"));
58 } else if( $(img).attr("src").indexOf('google.com') >= 0 ){
59 div.find(".hint").html(_("Coce image from Google Books"));
60 } else if( $(img).attr("src").indexOf('openlibrary.org') >= 0 ){
61 div.find(".hint").html(_("Coce image from Open Library"));
63 blanks.push( coverId );
67 if( coverImages.length > 1 ){
68 if( blanks.includes( coverId ) ){
69 /* Don't add covernav link */
71 var covernav = $("<a href=\"#\" data-coverid=\"" + coverId + "\" data-biblionumber=\"" + biblionumber + "\" class=\"cover-nav\"></a>");
72 $(covernav).html("<i class=\"fa fa-circle\"></i>");
73 slide.addClass("cover-slides").append( covernav );
76 } /* /IF image loaded */
78 blanks.push( coverId );
80 } /* /IF there is an image tag */
81 /* console.log( coverImages ); */
84 /* Show the first cover image slide after empty ones have been removed */
85 $(".cover-image", slide).eq(0).show();
86 /* Remove "loading" background gif */
87 $(".bookcoverimg").css("background","unset");
89 if( $(".cover-image", slide).length < 2 ){
90 /* Don't show controls for switching between covers if there is only 1 */
91 $(".cover-nav", slide).remove();
93 /* Set the first navigation link as active */
94 $(".cover-nav", slide).eq(0).addClass("nav-active");
96 /* If no slides contain any cover images, remove the container */
97 if( $(".cover-image:visible", slide).length < 1 ){
98 slide.html('<div class="no-image">' + __("No cover image available") + '</div>');
103 $(window).load(function() {
104 verify_cover_images();
108 var toHighlight = {};
111 $(document).ready(function() {
113 $("#searchresults").on("click",".cover-nav", function(e){
115 /* Adding click handler for cover image navigation links */
116 var coverid = $(this).data("coverid");
117 var biblionumber = $(this).data("biblionumber");
118 var slides = $("#cover-slides-" + biblionumber );
120 $(".cover-nav", slides).removeClass("nav-active");
121 $(this).addClass("nav-active");
122 $(".cover-image", slides).hide();
123 $( "#" + coverid ).show();
126 $(".moretoggle").click(function(e) {
128 $(this).siblings(".collapsible-facet").toggle();
129 $(this).siblings(".moretoggle").toggle();
133 Sticky = $("#searchheader");
136 stickyClass: "floating"
139 $("#cartsubmit").click(function(e){
144 $(".addtolist").on("click",function(e){
146 var shelfnumber = $(this).data("shelfnumber");
147 var vshelf = vShelfAdd();
149 if( $(this).hasClass("morelists") ){
150 openWindow('/cgi-bin/koha/virtualshelves/addbybiblionumber.pl?' + vshelf);
151 } else if( $(this).hasClass("newlist") ){
152 openWindow('/cgi-bin/koha/virtualshelves/addbybiblionumber.pl?newshelf=1&' + vshelf);
154 openWindow('/cgi-bin/koha/virtualshelves/addbybiblionumber.pl?shelfnumber='+shelfnumber+'&confirm=1&' + vshelf);
159 $("#z3950submit").click(function(){
164 $("#searchheader").on("click", ".browse_selection", function(){
169 $("#searchheader").on("click",".placehold", function(){
170 $("#holdFor").val("");
171 $("#holdForClub").val("");
173 $(".btn-group").removeClass("open");
177 $(".placeholdfor").click(function(){
179 $(".btn-group").removeClass("open");
183 $(".placeholdforclub").click(function(){
185 $(".btn-group").removeClass("open");
189 $("#forgetholdfor, #forgetholdforclub").click(function(){
190 forgetPatronAndClub();
191 $(".btn-group").removeClass("open");
195 $(".selection").show();
197 if( search_result.query_desc ){
198 toHighlight = $("p,span.results_summary,a.title");
199 q_array = search_result.query_desc.split(" ");
200 /* ensure that we don't have "" at the end of the array, which can */
201 /* break the highlighter */
202 while ( q_array.length > 0 && q_array[q_array.length-1] == "") {
203 q_array = q_array.splice(0,-1);
205 $("#highlight_toggle_off" ).hide().click(function(e) {
209 $("#highlight_toggle_on").show().click(function(e) {
213 if( PREF_StaffHighlightedWords == 1 ){
221 if( SEARCH_RESULTS ){
222 var browser = KOHA.browser( search_result.searchid, parseInt( biblionumber, 10));
223 browser.create( search_result.first_result_number, search_result.query_cgi, search_result.limit_cgi, search_result.sort_by, new_results_browser, search_result.total );
226 if( search_result.gotoPage && search_result.gotoNumber){
227 if( search_result.gotoNumber == 'first' ){
228 window.location = "/cgi-bin/koha/catalogue/" + search_result.gotoPage + "?biblionumber=" + search_result.first_biblionumber + "&searchid=" + search_result.searchid;
229 } else if( search_result.gotoNumber == "last" ){
230 window.location = "/cgi-bin/koha/catalogue/" + search_result.gotoPage + "?biblionumber=" + search_result.last_biblionumber + "&searchid=" + search_result.searchid;
234 if( PREF_LocalCoverImages ){
235 KOHA.LocalCover.LoadResultsCovers();
238 if( PREF_IntranetCoce && PREF_CoceProviders ){
239 KOHA.coce.getURL( CoceHost, CoceProviders );
242 $("#select_all").on("click",function(e){
247 $("#clear_all").on("click",function(e){
252 $("#searchresults").on("click",".addtocart",function(e){
254 var selection_id = this.id;
255 var biblionumber = selection_id.replace("cart","");
256 addRecord(biblionumber);
259 $("#searchresults").on("click",".cartRemove",function(e){
261 var selection_id = this.id;
262 var biblionumber = selection_id.replace("cartR","");
263 delSingleRecord(biblionumber);
266 if( !PREF_BrowseResultSelection ){
267 resetSearchContext();
270 $(".selection").change(function(){
271 if( $(".selection:checked").length > 0 ){
272 toggleBatchOp( true );
274 toggleBatchOp( false );
276 if ( $(this).is(':checked') == true ) {
277 addBibToContext( $(this).val() );
279 delBibToContext( $(this).val() );
282 $("#bookbag_form").ready(function(){
283 $("#bookbag_form input:checkbox").prop("checked", false);
284 var bibnums = getContextBiblioNumbers();
286 for (var i=0; i < bibnums.length; i++) {
287 var id = ('#bib' + bibnums[i]);
289 $(id).attr('checked', true);
295 if( $(".selection:checked") > 0 ){
296 toggleBatchOp( true );
299 $(".results_batch_op").on("click", function(e){
301 var op = $(this).data("op");
302 resultsBatchProcess( op );
307 function highlightOff() {
308 if( toHighlight.length > 0 ){
309 toHighlight.removeHighlight();
310 $(".highlight_toggle").toggle();
314 function highlightOn() {
315 if( toHighlight.length > 0 ){
318 q_array[x] = q_array[x].toLowerCase();
319 var myStopwords = PREF_NotHighlightedWords.toLowerCase().split('|');
320 if ( (q_array[x].length > 0) && ($.inArray(q_array[x], myStopwords) == -1) ) {
321 toHighlight.highlight(q_array[x]);
324 $(".highlight_toggle").toggle();
329 function selectAll () {
330 $("#bookbag_form").find("input[type='checkbox'][name='biblionumber']").each(function(){
331 $(this).prop("checked", true ).change();
334 function clearAll () {
335 $("#bookbag_form").find("input[type='checkbox'][name='biblionumber']").each(function(){
336 $(this).prop("checked", false).change();
339 function placeHold () {
340 var checkedItems = $(".selection:checked");
341 if ($(checkedItems).size() == 0) {
342 alert( __("Nothing is selected") );
346 $(checkedItems).each(function() {
347 var bib = $(this).val();
350 bibs.forEach(function (bib) {
351 var bib_param = $("<input>").attr("type", "hidden").attr("name", "biblionumber").val(bib);
352 $('#hold_form').append(bib_param);
354 $("#hold_form").submit();
358 function forgetPatronAndClub(){
359 Cookies.remove("holdfor", { path: '/' });
360 Cookies.remove("holdforclub", { path: '/' });
361 $(".holdforlink").remove();
362 $("#placeholdc").html("<a class=\"btn btn-default btn-xs placehold\" href=\"#\"><i class=\"fa fa-sticky-note-o\"></i> " + __("Place hold") + "</a>");
365 function browse_selection () {
366 var bibnums = getContextBiblioNumbers();
367 if ( bibnums && bibnums.length > 0 ) {
368 var browser = KOHA.browser('', parseInt( biblionumber, 10));
369 browser.create(1, search_result.query_cgi, search_result.limit_cgi, search_result.sort_by, bibnums, bibnums.length);
370 window.location = '/cgi-bin/koha/catalogue/detail.pl?biblionumber=' + bibnums[0] + '&searchid='+browser.searchid;
372 alert( __("Nothing is selected") );
377 function addToList () {
378 var checkedItems = $(".selection:checked");
379 if ($(checkedItems).size() == 0) {
380 alert( __("Nothing is selected") );
384 $(checkedItems).each(function() {
385 bibs += $(this).val() + "/";
388 var url = "/cgi-bin/koha/virtualshelves/addbybiblionumber.pl?biblionumbers=" + bibs;
389 window.open(url, 'Add_to_virtualshelf', 'width=500, height=400, toolbar=false, scrollbars=yes');
393 /* this function open a popup to search on z3950 server. */
394 function PopupZ3950() {
396 window.open("/cgi-bin/koha/cataloguing/z3950_search.pl?biblionumber=" + biblionumber + strQuery,"z3950search",'width=740,height=450,location=yes,toolbar=no,scrollbars=yes,resize=yes');
401 $("#holdFor").val("");
402 $("#holdForClub").val("");
406 function holdForPatron() {
407 $("#holdFor").val( holdfor_cardnumber );
411 function holdForClub() {
412 $("#holdForClub").val( holdforclub );
416 function toggleBatchOp( b ){
417 var results_batch_ops = $("#results_batch_ops");
419 results_batch_ops.removeClass("disabled");
421 results_batch_ops.addClass("disabled");
425 function resultsBatchProcess( op ){
426 var selected = $(".selection:checked");
430 /* batch edit selected records */
431 if ( selected.length < 1 ){
432 alert( __("You must select at least one record") );
434 selected.each(function() {
435 params.push( $(this).val() );
437 url = "/cgi-bin/koha/tools/batch_record_modification.pl?op=list&bib_list=" + params.join("/");
440 } else if( op == "delete" ){
441 /* batch delete selected records */
442 if ( selected.length < 1) {
443 alert( __("You must select at least one record") );
445 selected.each(function() {
446 params.push( $(this).val() );
448 url = "/cgi-bin/koha/tools/batch_delete_records.pl?op=list&type=biblio&bib_list=" + params.join("/");
451 } else if( op == "merge" ){
452 /* merge selected records */
453 if ( selected.length < 2) {
454 alert( __("At least two records must be selected for merging") );
456 selected.each(function() {
457 params.push('biblionumber=' + $(this).val());
459 url = "/cgi-bin/koha/cataloguing/merge.pl?" + params.join("&");