2 /* exported addMultiple delSingleRecord vShelfAdd openBiblio addSelToShelf delBasket sendBasket showMore showLess delSelRecords holdSel selRecord */
3 //////////////////////////////////////////////////////////////////////////////
4 // BASIC FUNCTIONS FOR COOKIE MANAGEMENT //
5 //////////////////////////////////////////////////////////////////////////////
7 function basketCount(){
8 var valCookie = readCookie("bib_list");
11 var arrayRecords = valCookie.split("/");
12 if(arrayRecords.length > 0){
13 basketcount = arrayRecords.length-1;
23 function writeCookie(name, val, wd) {
25 parent.opener.document.cookie = name + "=" + val + ";path=/";
28 parent.document.cookie = name + "=" + val + ";path=/";
32 function readCookie(name, wd) {
33 var str_name = name + "=";
36 str_cookie = parent.opener.document.cookie;
39 str_cookie = parent.document.cookie;
41 // fixed - getting the part of the basket that is bib_list
42 var cookie_parts = str_cookie.split(";");
43 for(var i=0;i < cookie_parts.length;i++) {
44 var c = cookie_parts[i];
45 while (c.charAt(0)==' ') c = c.substring(1,c.length);
46 if(c.indexOf(str_name) == 0) return c.substring(str_name.length,c.length);
51 function delCookie(name) {
53 exp.setTime(exp.getTime()-1);
55 parent.opener.document.cookie = name + "=null; path=/; expires=" + exp.toGMTString();
57 document.cookie = name + "=null; path=/; expires=" + exp.toGMTString();
61 ///////////////////////////////////////////////////////////////////
62 // SPECIFIC FUNCTIONS USING COOKIES //
63 ///////////////////////////////////////////////////////////////////
65 function openBasket() {
67 var nameCookie = "bib_list";
68 var valCookie = readCookie(nameCookie);
70 strCookie = nameCookie + "=" + valCookie;
76 var optWin = "status=yes,scrollbars=yes,resizable=yes,toolbar=no,location=yes,height="+iH+",width="+iW;
77 var loc = "/cgi-bin/koha/opac-basket.pl?" + strCookie;
78 var basket = open(loc, "basket", optWin);
79 if (window.focus) { basket.focus(); }
82 showCartUpdate( __("Your cart is currently empty") );
86 function addRecord(val, selection,NoMsgAlert) {
87 var nameCookie = "bib_list";
88 var valCookie = readCookie(nameCookie);
91 if ( ! valCookie ) { // empty basket
92 valCookie = val + '/';
97 // is this record already in the basket ?
99 var arrayRecords = valCookie.split("/");
100 for (var i = 0; i < valCookie.length - 1; i++) {
101 if (val == arrayRecords[i]) {
111 showCartUpdate( __p("Bibliographic record", "The item is already in your cart") );
115 valCookie += val + '/';
117 updateBasket(arrayRecords.length);
122 writeCookie(nameCookie, valCookie);
123 if (selection) { // when adding a selection of records
124 updateLink(val,"add");
128 showCartUpdate( __p("Bibliographic record", "The item has been added to your cart") );
129 updateLink(val,"add");
135 function addMultiple(){
137 if(document.bookbag_form.biblionumber.length > 0) {
138 for (var i=0; i < document.bookbag_form.biblionumber.length; i++) {
139 if (document.bookbag_form.biblionumber[i].checked) {
140 c_value = c_value + document.bookbag_form.biblionumber[i].value + "/";
143 addSelRecords(c_value);
145 c_value = c_value + document.bookbag_form.biblionumber.value + "/";
146 addSelRecords(c_value);
150 /* function for adding a selection of biblios to the basket from the results list */
151 function addSelRecords(valSel) {
152 var arrayRecords = valSel.split("/");
155 for (i=0;i<arrayRecords.length;i++) {
156 if (arrayRecords[i]) {
157 nbAdd += addRecord(arrayRecords[i], 1);
166 msg = nbAdd+" "+ __p("Bibliographic record", " item(s) added to your cart") +", "+(i-nbAdd)+" " + __("already in your cart");
169 msg = nbAdd+" "+ __p("Bibliographic record", " item(s) added to your cart");
174 msg = __p("Bibliographic record", "No item was selected");
177 msg = __p("Bibliographic record", "No item was added to your cart") + " (" + __("already in your cart") + ") !";
183 function showCartUpdate(msg){
184 // set body of popup window
185 $("#cartDetails").html(msg);
187 setTimeout("hideCart()",2000);
190 function showListsUpdate(msg){
191 // set body of popup window
195 function selRecord(num, status) {
196 var str = document.myform.records.value;
201 str = delRecord(num, str);
204 document.myform.records.value = str;
207 function delSingleRecord(biblionumber){
208 biblionumber = String( biblionumber );
209 var nameCookie = "bib_list";
210 var valCookie = readCookie(nameCookie);
211 var arrayRecords = valCookie.split("/");
212 var pos = jQuery.inArray(biblionumber,arrayRecords);
213 arrayRecords.splice( pos, 1 );
214 valCookie = arrayRecords.join("/");
215 writeCookie( nameCookie, valCookie );
216 updateBasket( arrayRecords.length-1 );
217 updateLink(biblionumber,"del");
218 showCartUpdate( __p("Bibliographic record", "The item has been removed from your cart") );
221 function delSelRecords() {
224 var nameCookie = "bib_list";
225 var valCookie = readCookie(nameCookie, 1);
227 var str = document.myform.records.value;
230 var str2 = valCookie;
232 var s = str.indexOf("/");
234 var num = str.substring(0, s);
235 str = delRecord(num,str);
236 str2 = delRecord(num,str2);
237 updateLink(num,"del",top.opener);
243 if (str2.length == 0) { // equivalent to emptying the basket
245 rep = confirm( __("Are you sure you want to empty your cart?") );
247 delCookie(nameCookie);
248 document.location = "about:blank";
249 updateBasket(0,top.opener);
255 writeCookie(nameCookie, str2, 1);
262 valCookie = readCookie(nameCookie, 1);
263 strCookie = nameCookie + "=" + valCookie;
264 var arrayRecords = valCookie.split("/");
265 updateBasket(arrayRecords.length-1,top.opener);
266 document.location = "/cgi-bin/koha/opac-basket.pl?" + strCookie;
269 alert( __p("Bibliographic record", "No item was selected") );
273 function delRecord (n, s) {
280 pos = aux.indexOf(n, pos+1);
281 var charAfter = aux.charAt(pos+n.length); // character right after the researched string
282 if (charAfter.match(re)) { // record number inside another one
285 else { // good record number
286 aux = s.substring(0, pos)+ s.substring(pos+n.length+1, s.length);
296 function delBasket() {
297 var nameCookie = "bib_list";
300 rep = confirm( __("Are you sure you want to empty your cart?") );
302 delCookie(nameCookie);
303 updateAllLinks(top.opener);
304 document.location = "about:blank";
305 updateBasket(0,top.opener);
310 function sendBasket() {
311 var nameCookie = "bib_list";
312 var valCookie = readCookie(nameCookie);
313 var strCookie = nameCookie + "=" + valCookie;
315 var loc = "/cgi-bin/koha/opac-sendbasket.pl?" + strCookie;
317 var optWin="scrollbars=yes,resizable=yes,height=600,width=900,top=50,left=100";
318 open(loc,"win_form",optWin);
321 function showMore() {
324 var nameCookie = "bib_list";
325 var valCookie = readCookie(nameCookie);
327 strCookie = nameCookie + "=" + valCookie;
329 var loc = "/cgi-bin/koha/opac-basket.pl?" + strCookie + "&verbose=1";
330 document.location = loc;
333 function showLess() {
336 var nameCookie = "bib_list";
337 var valCookie = readCookie(nameCookie);
339 strCookie = nameCookie + "=" + valCookie;
341 var loc = "/cgi-bin/koha/opac-basket.pl?" + strCookie + "&verbose=0";
342 document.location = loc;
346 var items = document.getElementById('records').value;
348 parent.opener.document.location = "/cgi-bin/koha/opac-reserve.pl?biblionumbers=" + items;
351 alert( __p("Bibliographic record", "No item was selected") );
355 function updateBasket(updated_value,target) {
357 if(updated_value > 0){
358 bcount = "<span>"+updated_value+"</span>";
361 target.$('#basketcount').html(bcount);
363 $('#basketcount').html(bcount);
367 function openBiblio(dest,biblionumber) {
368 var openerURL = dest + "?biblionumber=" + biblionumber;
369 opener.document.location = openerURL;
373 function addSelToShelf() {
374 var items = document.getElementById('records').value;
378 var optWin = "status=yes,scrollbars=yes,resizable=yes,toolbar=no,location=yes,height="+iH+",width="+iW;
379 var loc = "/cgi-bin/koha/opac-addbybiblionumber.pl?biblionumber="+items;
380 open(loc, "shelf", optWin);
382 alert( __p("Bibliographic record", "No item was selected") );
386 /// vShelfAdd() builds url string for multiple-biblio adds.
388 function vShelfAdd() {
389 var bibs = new Array;
390 if(document.bookbag_form.biblionumber.length > 0) {
391 for (var i=0; i < document.bookbag_form.biblionumber.length; i++) {
392 if (document.bookbag_form.biblionumber[i].checked) {
393 bibs.push("biblionumber=" + document.bookbag_form.biblionumber[i].value);
396 if (bibs.length == 0) {
397 showListsUpdate( __p("Bibliographic record", "No item was selected") );
399 return bibs.join("&");
401 if (document.bookbag_form.biblionumber.checked) {
402 return "biblionumber=" + document.bookbag_form.biblionumber.value;
408 $("#cartDetails").fadeIn("fast");
412 $("#cartDetails").fadeOut("fast");
415 function updateLink(val,op,target){
418 target.$("a.cart"+val).html( "<i class=\"fa fa-fw fa-shopping-cart\"></i> " + __("In your cart") ).addClass("incart");
419 target.$("a.cartR"+val).show();
421 target.$("a.cart"+val).html( "<i class=\"fa fa-fw fa-shopping-cart\"></i> " + __("Add to cart") ).removeClass("incart").addClass("addtocart cart"+val);
422 target.$("a.cartR"+val).hide();
426 $("a.cart"+val).html( "<i class=\"fa fa-fw fa-shopping-cart\"></i> " + __("In your cart") ).addClass("incart");
427 $("a.cartR"+val).show();
429 $("a.cart"+val).html( "<i class=\"fa fa-fw fa-shopping-cart\"></i> " + __("Add to cart") ).removeClass("incart").addClass("addtocart cart"+val);
430 $("a.cartR"+val).hide();
435 function updateAllLinks(target){
437 target.$("a.incart").html( "<i class=\"fa fa-fw fa-shopping-cart\"></i> " + __("Add to cart") ).removeClass("incart").addClass("addtocart");
438 target.$("a.cartRemove").hide();
440 $("a.incart").html( "<i class=\"fa fa-fw fa-shopping-cart\"></i> " + __("Add to cart") ).removeClass("incart").addClass("addtocart");
441 $("a.cartRemove").hide();
445 $("#cartDetails").ready(function(){
446 $("#cartDetails,#cartmenulink").on("click",function(){ hideCart(); });
447 $("#cartmenulink").click(function(e){
450 $("li").closest().removeClass("open");
452 updateBasket(basketCount());