1 /* global KOHA biblionumber new_results_browser addMultiple vShelfAdd openWindow search_result SEARCH_RESULTS PREF_AmazonCoverImages PREF_LocalCoverImages PREF_IntranetCoce PREF_CoceProviders CoceHost CoceProviders addRecord delSingleRecord PREF_BrowseResultSelection resetSearchContext addBibToContext delBibToContext getContextBiblioNumbers holdfor_cardnumber holdforclub strQuery PREF_NotHighlightedWords PLACE_HOLD __ */
3 if( PREF_AmazonCoverImages ){
4 $(window).load(function() {
13 $(document).ready(function() {
15 $(".moretoggle").click(function(e) {
17 $(this).siblings(".collapsible-facet").toggle();
18 $(this).siblings(".moretoggle").toggle();
22 Sticky = $("#searchheader");
25 stickyClass: "floating"
28 $("#cartsubmit").click(function(e){
33 $(".addtolist").on("click",function(e){
35 var shelfnumber = $(this).data("shelfnumber");
36 var vshelf = vShelfAdd();
38 if( $(this).hasClass("morelists") ){
39 openWindow('/cgi-bin/koha/virtualshelves/addbybiblionumber.pl?' + vshelf);
40 } else if( $(this).hasClass("newlist") ){
41 openWindow('/cgi-bin/koha/virtualshelves/addbybiblionumber.pl?newshelf=1&' + vshelf);
43 openWindow('/cgi-bin/koha/virtualshelves/addbybiblionumber.pl?shelfnumber='+shelfnumber+'&confirm=1&' + vshelf);
48 $("#z3950submit").click(function(){
53 $("#searchheader").on("click", ".browse_selection", function(){
58 $("#searchheader").on("click",".placehold", function(){
59 $("#holdFor").val("");
60 $("#holdForClub").val("");
62 $(".btn-group").removeClass("open");
66 $(".placeholdfor").click(function(){
68 $(".btn-group").removeClass("open");
72 $(".placeholdforclub").click(function(){
74 $(".btn-group").removeClass("open");
78 $("#forgetholdfor, #forgetholdforclub").click(function(){
79 forgetPatronAndClub();
80 $(".btn-group").removeClass("open");
84 $(".selection").show();
86 if( search_result.query_desc ){
87 toHighlight = $("p,span.results_summary,a.title");
88 q_array = search_result.query_desc.split(" ");
89 // ensure that we don't have "" at the end of the array, which can
90 // break the highlighter
91 while ( q_array.length > 0 && q_array[q_array.length-1] == "") {
92 q_array = q_array.splice(0,-1);
95 $("#highlight_toggle_on" ).hide().click(function(e) {
99 $("#highlight_toggle_off").show().click(function(e) {
105 if( SEARCH_RESULTS ){
106 var browser = KOHA.browser( search_result.searchid, parseInt( biblionumber, 10));
107 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 );
110 if( search_result.gotoPage && search_result.gotoNumber){
111 if( search_result.gotoNumber == 'first' ){
112 window.location = "/cgi-bin/koha/catalogue/" + search_result.gotoPage + "?biblionumber=" + search_result.first_biblionumber + "&searchid=" + search_result.searchid;
113 } else if( search_result.gotoNumber == "last" ){
114 window.location = "/cgi-bin/koha/catalogue/" + search_result.gotoPage + "?biblionumber=" + search_result.last_biblionumber + "&searchid=" + search_result.searchid;
118 if( PREF_LocalCoverImages ){
119 KOHA.LocalCover.LoadResultsCovers();
122 if( PREF_IntranetCoce && PREF_CoceProviders ){
123 KOHA.coce.getURL( CoceHost, CoceProviders );
126 $("#select_all").on("click",function(e){
131 $("#clear_all").on("click",function(e){
136 $("#searchresults").on("click",".addtocart",function(e){
138 var selection_id = this.id;
139 var biblionumber = selection_id.replace("cart","");
140 addRecord(biblionumber);
143 $("#searchresults").on("click",".cartRemove",function(e){
145 var selection_id = this.id;
146 var biblionumber = selection_id.replace("cartR","");
147 delSingleRecord(biblionumber);
150 if( !PREF_BrowseResultSelection ){
151 resetSearchContext();
154 $(".selection").change(function(){
155 if( $(".selection:checked").length > 0 ){
156 toggleBatchOp( true );
158 toggleBatchOp( false );
160 if ( $(this).is(':checked') == true ) {
161 addBibToContext( $(this).val() );
163 delBibToContext( $(this).val() );
166 $("#bookbag_form").ready(function(){
167 $("#bookbag_form input:checkbox").prop("checked", false);
168 var bibnums = getContextBiblioNumbers();
170 for (var i=0; i < bibnums.length; i++) {
171 var id = ('#bib' + bibnums[i]);
173 $(id).attr('checked', true);
179 if( $(".selection:checked") > 0 ){
180 toggleBatchOp( true );
183 $(".results_batch_op").on("click", function(e){
185 var op = $(this).data("op");
186 resultsBatchProcess( op );
191 function highlightOff() {
192 if( toHighlight.length > 0 ){
193 toHighlight.removeHighlight();
194 $(".highlight_toggle").toggle();
198 function highlightOn() {
199 if( toHighlight.length > 0 ){
202 q_array[x] = q_array[x].toLowerCase();
203 var myStopwords = PREF_NotHighlightedWords.toLowerCase().split('|');
204 if ( (q_array[x].length > 0) && ($.inArray(q_array[x], myStopwords) == -1) ) {
205 toHighlight.highlight(q_array[x]);
208 $(".highlight_toggle").toggle();
213 function selectAll () {
214 $("#bookbag_form").find("input[type='checkbox'][name='biblionumber']").each(function(){
215 $(this).prop("checked", true ).change();
218 function clearAll () {
219 $("#bookbag_form").find("input[type='checkbox'][name='biblionumber']").each(function(){
220 $(this).prop("checked", false).change();
223 function placeHold () {
224 var checkedItems = $(".selection:checked");
225 if ($(checkedItems).size() == 0) {
226 alert( __("Nothing is selected") );
231 $(checkedItems).each(function() {
232 var bib = $(this).val();
233 if ($("#reserve_" + bib).size() == 0) {
234 alert( __("One or more selected items cannot be placed on hold.") );
243 $("#hold_form_biblios").val(bibs);
244 $("#hold_form").submit();
248 function forgetPatronAndClub(){
249 $.removeCookie("holdfor", { path: '/' });
250 $.removeCookie("holdforclub", { path: '/' });
251 $(".holdforlink").remove();
252 $("#placeholdc").html("<a class=\"btn btn-default btn-xs placehold\" href=\"#\"><i class=\"fa fa-sticky-note-o\"></i> " + __("Place hold") + "</a>");
255 function browse_selection () {
256 var bibnums = getContextBiblioNumbers();
257 if ( bibnums && bibnums.length > 0 ) {
258 var browser = KOHA.browser('', parseInt( biblionumber, 10));
259 browser.create(1, search_result.query_cgi, search_result.limit_cgi, search_result.sort_by, bibnums, bibnums.length);
260 window.location = '/cgi-bin/koha/catalogue/detail.pl?biblionumber=' + bibnums[0] + '&searchid='+browser.searchid;
262 alert( __("Nothing is selected") );
267 function addToList () {
268 var checkedItems = $(".selection:checked");
269 if ($(checkedItems).size() == 0) {
270 alert( __("Nothing is selected") );
274 $(checkedItems).each(function() {
275 bibs += $(this).val() + "/";
278 var url = "/cgi-bin/koha/virtualshelves/addbybiblionumber.pl?biblionumbers=" + bibs;
279 window.open(url, 'Add_to_virtualshelf', 'width=500, height=400, toolbar=false, scrollbars=yes');
283 /* this function open a popup to search on z3950 server. */
284 function PopupZ3950() {
286 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');
291 $("#holdFor").val("");
292 $("#holdForClub").val("");
296 function holdForPatron() {
297 $("#holdFor").val( holdfor_cardnumber );
301 function holdForClub() {
302 $("#holdForClub").val( holdforclub );
306 // http://www.oreillynet.com/pub/a/javascript/2003/10/21/amazonhacks.html
307 function verify_images() {
308 $("img").each(function(){
309 if ((this.src.indexOf('images-amazon.com') >= 0) || (this.src.indexOf('images.amazon.com') >=0)) {
312 if ((w == 1) || (h == 1)) {
313 $(this).parent().html('<span class="no-image">'+ __("No cover image available") +'</span>');
314 } else if ((this.complete != null) && (!this.complete)) {
315 $(this).parent().html('<span class="no-image">'+ __("No cover image available") +'</span>');
321 function toggleBatchOp( b ){
322 var results_batch_ops = $("#results_batch_ops");
324 results_batch_ops.removeClass("disabled");
326 results_batch_ops.addClass("disabled");
330 function resultsBatchProcess( op ){
331 var selected = $(".selection:checked");
335 // batch edit selected records
336 if ( selected.length < 1 ){
337 alert( __("You must select at least one record") );
339 selected.each(function() {
340 params.push( $(this).val() );
342 url = "/cgi-bin/koha/tools/batch_record_modification.pl?op=list&bib_list=" + params.join("/");
345 } else if( op == "delete" ){
346 // batch delete selected records
347 if ( selected.length < 1) {
348 alert( __("You must select at least one record") );
350 selected.each(function() {
351 params.push( $(this).val() );
353 url = "/cgi-bin/koha/tools/batch_delete_records.pl?op=list&type=biblio&bib_list=" + params.join("/");
356 } else if( op == "merge" ){
357 // merge selected records
358 if ( selected.length < 2) {
359 alert( __("At least two records must be selected for merging") );
361 selected.each(function() {
362 params.push('biblionumber=' + $(this).val());
364 url = "/cgi-bin/koha/cataloguing/merge.pl?" + params.join("&");