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 = "dependant=yes,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(){
158 if(document.bookbag_form.biblionumber.length > 0) {
159 for (var i=0; i < document.bookbag_form.biblionumber.length; i++) {
160 if (document.bookbag_form.biblionumber[i].checked) {
161 c_value = c_value + document.bookbag_form.biblionumber[i].value + "/";
164 addSelRecords(c_value);
166 c_value = c_value + document.bookbag_form.biblionumber.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 = nbAdd+" "+MSG_NRECORDS_ADDED+", "+(i-nbAdd)+" "+MSG_NRECORDS_IN_BASKET;
190 msg = nbAdd+" "+MSG_NRECORDS_ADDED;
195 msg = MSG_NO_RECORD_SELECTED;
198 msg = MSG_NO_RECORD_ADDED+" ("+MSG_NRECORDS_IN_BASKET+") !";
204 function showCartUpdate(msg){
205 // set body of popup window
206 $("#cartDetails").html(msg);
208 setTimeout("hideCart()",2000);
211 function showListsUpdate(msg){
212 // set body of popup window
216 function selRecord(num, status) {
217 var str = document.myform.records.value
222 str = delRecord(num, str);
225 document.myform.records.value = str;
228 function delSelRecords() {
231 var valCookie = readCookie(nameCookie, 1);
234 var str = document.myform.records.value;
237 var str2 = valCookie;
239 s = str.indexOf("/");
241 num = str.substring(0, s)
242 str = delRecord(num,str);
243 str2 = delRecord(num,str2);
249 if (str2.length == 0) { // equivalent to emptying the basket
251 rep = confirm(MSG_CONFIRM_DEL_BASKET);
253 delCookie(nameCookie);
254 document.location = "about:blank";
255 updateBasket(0,top.opener);
261 writeCookie(nameCookie, str2, 1);
268 var valCookie = readCookie(nameCookie, 1);
269 strCookie = nameParam + "=" + valCookie;
270 var arrayRecords = valCookie.split("/");
271 updateBasket(arrayRecords.length-1,top.opener);
272 document.location = CGIBIN + "basket/basket.pl?" + strCookie;
275 alert(MSG_NO_RECORD_SELECTED);
279 function delRecord (n, s) {
286 pos = aux.indexOf(n, pos+1);
287 var charAfter = aux.charAt(pos+n.length); // character right after the researched string
288 if (charAfter.match(re)) { // record number inside another one
291 else { // good record number
292 aux = s.substring(0, pos)+ s.substring(pos+n.length+1, s.length);
302 function delBasket(context,rep) {
303 if (rep == undefined){
304 rep = confirm(MSG_CONFIRM_DEL_BASKET);
307 if(context == "popup"){
308 delCookie(nameCookie);
309 document.location = "about:blank";
310 updateBasket(0,top.opener);
313 delCookie(nameCookie);
314 updateBasket(0,top.opener);
321 if (document.myform.records.value) {
323 rep = confirm(MSG_CONFIRM_DEL_RECORDS);
328 updateBasket(arrayRecords.length-1,top.opener);
332 function sendBasket() {
333 var valCookie = readCookie(nameCookie);
334 var strCookie = nameParam + "=" + valCookie;
336 var loc = CGIBIN + "basket/sendbasket.pl?" + strCookie;
338 var optWin="dependant=yes,scrollbars=no,resizable=no,height=300,width=450,top=50,left=100";
339 var win_form = open(loc,"win_form",optWin);
342 function downloadBasket() {
343 var valCookie = readCookie(nameCookie);
344 var strCookie = nameParam + "=" + valCookie;
346 var loc = CGIBIN + "basket/downloadcart.pl?" + strCookie;
348 open(loc,"win_form",'dependant=yes,scrollbars=no,resizable=no,height=300,width=450,top=50,left=100');
351 function printBasket() {
352 var loc = document.location + "&print=1";
353 document.location = loc;
356 function showMore() {
359 var valCookie = readCookie(nameCookie);
361 strCookie = nameParam + "=" + valCookie;
363 var loc = CGIBIN + "basket/basket.pl?" + strCookie + "&verbose=1";
364 document.location = loc;
367 function showLess() {
370 var valCookie = readCookie(nameCookie);
372 strCookie = nameParam + "=" + valCookie;
374 var loc = CGIBIN + "basket/basket.pl?" + strCookie + "&verbose=0";
375 document.location = loc;
378 function updateBasket(updated_value,target) {
380 target.$('#basketcount').html(" <span>("+updated_value+")</span>");
381 target.$('#cartDetails').html(MSG_IN_YOUR_CART+updated_value);
383 $('#basketcount').html(" <span>("+updated_value+")</span>");
384 $('#cartDetails').html(MSG_IN_YOUR_CART+updated_value);
386 var basketcount = updated_value;
389 function openBiblio(dest,biblionumber) {
390 openerURL=dest+"?biblionumber="+biblionumber;
391 opener.document.location = openerURL;
395 function addSelToShelf() {
396 var items = document.getElementById('records').value;
398 document.location = "/cgi-bin/koha/virtualshelves/addbybiblionumber.pl?biblionumber="+items;
400 alert(MSG_NO_RECORD_SELECTED);
404 /// vShelfAdd() builds url string for multiple-biblio adds.
406 function vShelfAdd() {
408 if(document.bookbag_form.biblionumber.length > 0) {
409 for (var i=0; i < document.bookbag_form.biblionumber.length; i++) {
410 if (document.bookbag_form.biblionumber[i].checked) {
411 bibs.push("biblionumber=" + document.bookbag_form.biblionumber[i].value);
414 if (bibs.length == 0) { showListsUpdate(MSG_NO_RECORD_SELECTED); }
415 return bibs.join("&");
417 if (document.bookbag_form.biblionumber.checked) {
418 return "biblionumber=" + document.bookbag_form.biblionumber.value;
424 var position = $("#cartmenulink").offset();
425 var scrolld = $(window).scrollTop();
426 var top = position.top + $("#cartmenulink").outerHeight();
430 var left = position.left
431 $("#cartDetails").css("position","absolute").css("top",top);
432 $("#cartDetails").css("position","absolute").css("left",left);
433 $("#cartDetails").fadeIn("fast");
437 $("#cartDetails").fadeOut("fast");
440 $(document).ready(function(){
441 $("#cartmenulink").click(function(){ openBasket(); return false; });
442 if(basketcount){ updateBasket(basketcount); }