1 //////////////////////////////////////////////////////////////////////////////
2 // BASIC FUNCTIONS FOR COOKIE MANAGEMENT //
3 //////////////////////////////////////////////////////////////////////////////
5 var CGIBIN = "/cgi-bin/koha/";
7 var nameCookie = "intranet_bib_list";
8 var nameParam = "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 + "; path=/";
27 parent.document.cookie = name + "=" + val + "; path=/";
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; path=/; expires=" + exp.toGMTString();
64 document.cookie = name + "=null; path=/; expires=" + exp.toGMTString();
68 ///////////////////////////////////////////////////////////////////
69 // SPECIFIC FUNCTIONS USING COOKIES //
70 ///////////////////////////////////////////////////////////////////
72 function openBasket() {
74 var valCookie = readCookie(nameCookie);
76 strCookie = nameParam + "=" + valCookie;
82 var optWin = "status=yes,scrollbars=yes,resizable=yes,toolbar=no,location=yes,height="+iH+",width="+iW;
83 var loc = CGIBIN + "basket/basket.pl?" + strCookie;
84 var basket = open(loc, "basket", optWin);
85 if (window.focus) {basket.focus()}
88 showCartUpdate(MSG_BASKET_EMPTY);
92 function addRecord(val, selection,NoMsgAlert) {
93 var valCookie = readCookie(nameCookie);
96 if ( ! valCookie ) { // empty basket
97 valCookie = val + '/';
102 // is this record already in the basket ?
104 var arrayRecords = valCookie.split("/");
105 for (var i = 0; i < valCookie.length - 1; i++) {
106 if (val == arrayRecords[i]) {
116 showCartUpdate(MSG_RECORD_IN_BASKET);
120 valCookie += val + '/';
122 updateBasket(arrayRecords.length);
127 writeCookie(nameCookie, valCookie);
128 if (selection) { // when adding a selection of records
132 showCartUpdate(MSG_RECORD_ADDED);
137 function AllAreChecked(s){
138 if (! s.length) { return false;}
140 for (var i=0; i < l; i++) {
141 if(! s[i].checked) { return false; }
146 function SelectAll(){
147 if(document.bookbag_form.biblionumber.length > 0) {
148 var checky = AllAreChecked(document.bookbag_form.biblionumber);
149 var l = document.bookbag_form.biblionumber.length;
150 for (var i=0; i < l; i++) {
151 document.bookbag_form.biblionumber[i].checked = (checky) ? false : true;
156 function addMultiple(biblist){
158 if(biblist.length > 0) {
159 for (var i=0; i < biblist.length; i++) {
160 if (biblist[i].checked) {
161 c_value = c_value + biblist[i].value + "/";
164 addSelRecords(c_value);
166 c_value = c_value + biblist.value + "/";
167 addSelRecords(c_value);
171 function addSelRecords(valSel) { // function for adding a selection of biblios to the basket
172 // from the results list
173 var arrayRecords = valSel.split("/");
176 for (i=0;i<arrayRecords.length;i++) {
177 if (arrayRecords[i]) {
178 nbAdd += addRecord(arrayRecords[i], 1);
187 msg = MSG_NRECORDS_ADDED.format(nbAdd);
189 msg += MSG_NRECORDS_IN_BASKET.format((i-nbAdd));
192 msg = MSG_NRECORDS_ADDED.format(nbAdd);
197 msg = MSG_NO_RECORD_SELECTED;
200 msg = MSG_NO_RECORD_ADDED;
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
218 function selRecord(num, status) {
219 var str = document.myform.records.value
224 str = delRecord(num, str);
227 document.myform.records.value = str;
230 function delSelRecords() {
233 var valCookie = readCookie(nameCookie, 1);
236 var str = document.myform.records.value;
239 var str2 = valCookie;
241 s = str.indexOf("/");
243 num = str.substring(0, s)
244 str = delRecord(num,str);
245 str2 = delRecord(num,str2);
251 if (str2.length == 0) { // equivalent to emptying the basket
253 rep = confirm(MSG_CONFIRM_DEL_BASKET);
255 delCookie(nameCookie);
256 document.location = "about:blank";
257 updateBasket(0,top.opener);
263 writeCookie(nameCookie, str2, 1);
270 var valCookie = readCookie(nameCookie, 1);
271 strCookie = nameParam + "=" + valCookie;
272 var arrayRecords = valCookie.split("/");
273 updateBasket(arrayRecords.length-1,top.opener);
274 document.location = CGIBIN + "basket/basket.pl?" + strCookie;
277 alert(MSG_NO_RECORD_SELECTED);
281 function delRecord (n, s) {
288 pos = aux.indexOf(n, pos+1);
289 var charAfter = aux.charAt(pos+n.length); // character right after the researched string
290 if (charAfter.match(re)) { // record number inside another one
293 else { // good record number
294 aux = s.substring(0, pos)+ s.substring(pos+n.length+1, s.length);
304 function delBasket(context,rep) {
305 if (rep == undefined){
306 rep = confirm(MSG_CONFIRM_DEL_BASKET);
309 if(context == "popup"){
310 delCookie(nameCookie);
311 document.location = "about:blank";
312 updateBasket(0,top.opener);
315 delCookie(nameCookie);
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 valCookie = readCookie(nameCookie);
336 var strCookie = nameParam + "=" + valCookie;
338 var loc = CGIBIN + "basket/sendbasket.pl?" + strCookie;
340 var optWin="scrollbars=no,resizable=no,height=300,width=450,top=50,left=100";
341 var win_form = open(loc,"win_form",optWin);
344 function downloadBasket() {
345 var valCookie = readCookie(nameCookie);
346 var strCookie = nameParam + "=" + valCookie;
348 var loc = CGIBIN + "basket/downloadcart.pl?" + strCookie;
350 open(loc,"win_form",'scrollbars=no,resizable=no,height=300,width=450,top=50,left=100');
353 function printBasket() {
354 var loc = document.location + "&print=1";
355 document.location = loc;
358 function showMore() {
361 var valCookie = readCookie(nameCookie);
363 strCookie = nameParam + "=" + valCookie;
365 var loc = CGIBIN + "basket/basket.pl?" + strCookie + "&verbose=1";
366 document.location = loc;
369 function showLess() {
372 var valCookie = readCookie(nameCookie);
374 strCookie = nameParam + "=" + valCookie;
376 var loc = CGIBIN + "basket/basket.pl?" + strCookie + "&verbose=0";
377 document.location = loc;
380 function updateBasket(updated_value,target) {
382 target.$('#basketcount').html(" <span>("+updated_value+")</span>");
383 target.$('#cartDetails').html(MSG_IN_YOUR_CART.format(updated_value));
385 $('#basketcount').html(" <span>("+updated_value+")</span>");
386 $('#cartDetails').html(MSG_IN_YOUR_CART.format(updated_value));
388 var basketcount = updated_value;
391 function openBiblio(dest,biblionumber) {
392 openerURL=dest+"?biblionumber="+biblionumber;
393 opener.document.location = openerURL;
397 function addSelToShelf() {
398 var items = document.getElementById('records').value;
400 document.location = "/cgi-bin/koha/virtualshelves/addbybiblionumber.pl?biblionumber="+items;
402 alert(MSG_NO_RECORD_SELECTED);
406 /// vShelfAdd() builds url string for multiple-biblio adds.
408 function vShelfAdd(biblist) {
410 if(biblist.length > 0) {
411 for (var i=0; i < biblist.length; i++) {
412 if (biblist[i].checked) {
413 bibs.push("biblionumber=" + biblist[i].value);
416 if (bibs.length == 0) { showListsUpdate(MSG_NO_RECORD_SELECTED); }
417 return bibs.join("&");
419 if (biblist.checked) {
420 return "biblionumber=" + biblist.value;
426 var position = $("#cartmenulink").offset();
427 var scrolld = $(window).scrollTop();
428 var top = position.top + $("#cartmenulink").outerHeight();
432 var left = position.left
433 $("#cartDetails").css("position","absolute").css("top",top);
434 $("#cartDetails").css("position","absolute").css("left",left);
435 $("#cartDetails").fadeIn("fast");
439 $("#cartDetails").fadeOut("fast");
442 $(document).ready(function(){
443 $("#cartmenulink").click(function(){ openBasket(); return false; });
444 if(basketcount){ updateBasket(basketcount); }