1 //////////////////////////////////////////////////////////////////////////////
2 // BASIC FUNCTIONS FOR COOKIE MANAGEMENT //
3 //////////////////////////////////////////////////////////////////////////////
5 var CGIBIN = "/cgi-bin/koha/";
8 var nameCookie = "bib_list";
9 var valCookie = readCookie(nameCookie);
12 var arrayRecords = valCookie.split("/");
13 if(arrayRecords.length > 0){
14 var basketcount = arrayRecords.length-1;
22 function writeCookie(name, val, wd) {
24 parent.opener.document.cookie = name + "=" + val;
27 parent.document.cookie = name + "=" + val;
31 function readCookieValue (str, val_beg) {
32 var val_end = str.indexOf(";", val_end);
35 return str.substring(val_beg, val_end);
38 function readCookie(name, wd) {
39 var str_name = name + "=";
40 var str_len = str_name.length;
43 str_cookie = parent.opener.document.cookie;
46 str_cookie = parent.document.cookie;
48 // fixed - getting the part of the basket that is bib_list
49 var cookie_parts = str_cookie.split(";");
50 for(var i=0;i < cookie_parts.length;i++) {
51 var c = cookie_parts[i];
52 while (c.charAt(0)==' ') c = c.substring(1,c.length);
53 if(c.indexOf(str_name) == 0) return c.substring(str_name.length,c.length);
58 function delCookie(name) {
60 exp.setTime(exp.getTime()-1);
62 parent.opener.document.cookie = name + "=null; expires=" + exp.toGMTString();
64 document.cookie = name + "=null; expires=" + exp.toGMTString();
68 ///////////////////////////////////////////////////////////////////
69 // SPECIFIC FUNCTIONS USING COOKIES //
70 ///////////////////////////////////////////////////////////////////
72 function openBasket() {
74 var nameCookie = "bib_list";
75 var valCookie = readCookie(nameCookie);
77 strCookie = nameCookie + "=" + valCookie;
83 var optWin = "dependant=yes,status=yes,scrollbars=yes,resizable=yes,toolbar=no,location=yes,height="+iH+",width="+iW;
84 var loc = CGIBIN + "opac-basket.pl?" + strCookie;
85 var basket = open(loc, "basket", optWin);
86 if (window.focus) {basket.focus()}
89 showCartUpdate(MSG_BASKET_EMPTY);
93 function addRecord(val, selection,NoMsgAlert) {
94 var nameCookie = "bib_list";
95 var valCookie = readCookie(nameCookie);
98 if ( ! valCookie ) { // empty basket
99 valCookie = val + '/';
104 // is this record already in the basket ?
106 var arrayRecords = valCookie.split("/");
107 for (var i = 0; i < valCookie.length - 1; i++) {
108 if (val == arrayRecords[i]) {
118 showCartUpdate(MSG_RECORD_IN_BASKET);
122 valCookie += val + '/';
124 updateBasket(arrayRecords.length);
129 writeCookie(nameCookie, valCookie);
130 if (selection) { // when adding a selection of records
134 showCartUpdate(MSG_RECORD_ADDED);
139 function AllAreChecked(s){
140 if (! s.length) { return false;}
142 for (var i=0; i < l; i++) {
143 if(! s[i].checked) { return false; }
148 function SelectAll(){
149 if(document.bookbag_form.biblionumber.length > 0) {
150 var checky = AllAreChecked(document.bookbag_form.biblionumber);
151 var l = document.bookbag_form.biblionumber.length;
152 for (var i=0; i < l; i++) {
153 document.bookbag_form.biblionumber[i].checked = (checky) ? false : true;
158 function addMultiple(){
160 if(document.bookbag_form.biblionumber.length > 0) {
161 for (var i=0; i < document.bookbag_form.biblionumber.length; i++) {
162 if (document.bookbag_form.biblionumber[i].checked) {
163 c_value = c_value + document.bookbag_form.biblionumber[i].value + "/";
166 addSelRecords(c_value);
168 c_value = c_value + document.bookbag_form.biblionumber.value + "/";
169 addSelRecords(c_value);
173 function addSelRecords(valSel) { // function for adding a selection of biblios to the basket
174 // from the results list
175 var arrayRecords = valSel.split("/");
178 for (i=0;i<arrayRecords.length;i++) {
179 if (arrayRecords[i]) {
180 nbAdd += addRecord(arrayRecords[i], 1);
189 msg = nbAdd+" "+MSG_NRECORDS_ADDED+", "+(i-nbAdd)+" "+MSG_NRECORDS_IN_BASKET;
192 msg = nbAdd+" "+MSG_NRECORDS_ADDED;
197 msg = MSG_NO_RECORD_SELECTED;
200 msg = MSG_NO_RECORD_ADDED+" ("+MSG_NRECORDS_IN_BASKET+") !";
206 function showCartUpdate(msg){
207 // set body of popup window
208 $("#cartDetails").html(msg);
210 setTimeout("hideCart()",2000);
213 function showListsUpdate(msg){
214 // set body of popup window
215 $("#listsDetails").html(msg);
217 setTimeout("hideLists()",2000);
220 function selRecord(num, status) {
221 var str = document.myform.records.value
226 str = delRecord(num, str);
229 document.myform.records.value = str;
232 function delSelRecords() {
235 var nameCookie = "bib_list";
236 var valCookie = readCookie(nameCookie, 1);
239 var str = document.myform.records.value;
242 var str2 = valCookie;
244 s = str.indexOf("/");
246 num = str.substring(0, s)
247 str = delRecord(num,str);
248 str2 = delRecord(num,str2);
254 if (str2.length == 0) { // equivalent to emptying the basket
256 rep = confirm(MSG_CONFIRM_DEL_BASKET);
258 delCookie(nameCookie);
259 document.location = "about:blank";
260 updateBasket(0,top.opener);
266 writeCookie(nameCookie, str2, 1);
273 var nameCookie = "bib_list";
274 var valCookie = readCookie(nameCookie, 1);
275 strCookie = nameCookie + "=" + valCookie;
276 var arrayRecords = valCookie.split("/");
277 updateBasket(arrayRecords.length-1,top.opener);
278 document.location = CGIBIN + "opac-basket.pl?" + strCookie;
281 alert(MSG_NO_RECORD_SELECTED);
285 function delRecord (n, s) {
292 pos = aux.indexOf(n, pos+1);
293 var charAfter = aux.charAt(pos+n.length); // character right after the researched string
294 if (charAfter.match(re)) { // record number inside another one
297 else { // good record number
298 aux = s.substring(0, pos)+ s.substring(pos+n.length+1, s.length);
308 function delBasket() {
309 var nameCookie = "bib_list";
312 rep = confirm(MSG_CONFIRM_DEL_BASKET);
314 delCookie(nameCookie);
315 document.location = "about:blank";
316 updateBasket(0,top.opener);
323 if (document.myform.records.value) {
325 rep = confirm(MSG_CONFIRM_DEL_RECORDS);
330 updateBasket(arrayRecords.length-1,top.opener);
334 function sendBasket() {
335 var nameCookie = "bib_list";
336 var valCookie = readCookie(nameCookie);
337 var strCookie = nameCookie + "=" + valCookie;
339 var loc = CGIBIN + "opac-sendbasket.pl?" + strCookie;
341 var optWin="dependant=yes,scrollbars=no,resizable=no,height=300,width=450,top=50,left=100";
342 var win_form = open(loc,"win_form",optWin);
345 function downloadBasket() {
346 var nameCookie = "bib_list";
347 var valCookie = readCookie(nameCookie);
348 var strCookie = nameCookie + "=" + valCookie;
350 var loc = CGIBIN + "opac-downloadcart.pl?" + strCookie;
352 open(loc,"win_form",'dependant=yes,scrollbars=no,resizable=no,height=300,width=450,top=50,left=100');
355 function printBasket() {
356 var loc = document.location + "&print=1";
357 document.location = loc;
360 function showMore() {
363 var nameCookie = "bib_list";
364 var valCookie = readCookie(nameCookie);
366 strCookie = nameCookie + "=" + valCookie;
368 var loc = CGIBIN + "opac-basket.pl?" + strCookie + "&verbose=1";
369 document.location = loc;
372 function showLess() {
375 var nameCookie = "bib_list";
376 var valCookie = readCookie(nameCookie);
378 strCookie = nameCookie + "=" + valCookie;
380 var loc = CGIBIN + "opac-basket.pl?" + strCookie + "&verbose=0";
381 document.location = loc;
384 function updateBasket(updated_value,target) {
386 target.$('#basketcount').html("<span>"+updated_value+"</span>");
387 target.$('#cartDetails').html(_("Your cart contains ")+updated_value+_(" items"));
389 $('#basketcount').html("<span>"+updated_value+"</span>");
390 $('#cartDetails').html(_("Your cart contains ")+updated_value+_(" items"));
392 var basketcount = updated_value;
395 function openBiblio(dest,biblionumber) {
396 openerURL=dest+"?biblionumber="+biblionumber;
397 opener.document.location = openerURL;
401 function addSelToShelf() {
402 var items = document.getElementById('records').value;
404 document.location = "/cgi-bin/koha/opac-addbybiblionumber.pl?biblionumber="+items;
406 alert(MSG_NO_RECORD_SELECTED);
410 /// vShelfAdd() builds url string for multiple-biblio adds.
412 function vShelfAdd() {
414 if(document.bookbag_form.biblionumber.length > 0) {
415 for (var i=0; i < document.bookbag_form.biblionumber.length; i++) {
416 if (document.bookbag_form.biblionumber[i].checked) {
417 bibs.push("biblionumber=" + document.bookbag_form.biblionumber[i].value);
420 if (bibs.length == 0) { showListsUpdate(MSG_NO_RECORD_SELECTED); }
421 return bibs.join("&");
423 if (document.bookbag_form.biblionumber.checked) {
424 return "biblionumber=" + document.bookbag_form.biblionumber.value;
430 var position = $("#cartmenulink").offset();
431 var top = position.top + $("#cartmenulink").outerHeight();
433 var buttonWidth = $("#cartmenulink").innerWidth();
434 var buttonOffset = menuWidth - buttonWidth;
435 var left = position.left - buttonOffset;
436 $("#cartDetails").css("position","absolute").css("top",top);
437 $("#cartDetails").css("position","absolute").css("left",left);
438 $("#cartDetails").fadeIn("fast");
441 function showLists(){
442 var position = $("#listsmenulink").offset();
443 var top = position.top + $("#listsmenulink").outerHeight();
445 var buttonWidth = $("#listsmenulink").innerWidth();
446 var buttonOffset = menuWidth - buttonWidth;
447 var left = position.left - buttonOffset;
448 $("#listsDetails").css("position","absolute").css("top",top);
449 $("#listsDetails").css("position","absolute").css("left",left);
450 $("#listsDetails").fadeIn("fast");
454 $("#cartDetails").fadeOut("fast");
457 function hideLists(){
458 $("#listsDetails").fadeOut("fast");
461 $("#cartDetails").ready(function(){
462 $("#cartDetails,#cartmenulink").click(function(){ hideCart(); });
463 $("#cartmenulink").click(function(){ openBasket(); return false; });
464 $("#cartmenulink").hoverIntent(function(){
469 if(basketcount){ updateBasket(basketcount) }