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);
188 msg += MSG_NRECORDS_IN_BASKET.format((i-nbAdd));
191 msg = MSG_NRECORDS_ADDED.format(nbAdd);
196 msg = MSG_NO_RECORD_SELECTED;
199 msg = MSG_NO_RECORD_ADDED;
205 function showCartUpdate(msg){
206 // set body of popup window
207 $("#cartDetails").html(msg);
209 setTimeout("hideCart()",2000);
212 function showListsUpdate(msg){
213 // set body of popup window
217 function selRecord(num, status) {
218 var str = document.myform.records.value
223 str = delRecord(num, str);
226 document.myform.records.value = str;
229 function delSelRecords() {
232 var valCookie = readCookie(nameCookie, 1);
235 var str = document.myform.records.value;
238 var str2 = valCookie;
240 s = str.indexOf("/");
242 num = str.substring(0, s)
243 str = delRecord(num,str);
244 str2 = delRecord(num,str2);
250 if (str2.length == 0) { // equivalent to emptying the basket
252 rep = confirm(MSG_CONFIRM_DEL_BASKET);
254 delCookie(nameCookie);
255 document.location = "about:blank";
256 updateBasket(0,top.opener);
262 writeCookie(nameCookie, str2, 1);
269 var valCookie = readCookie(nameCookie, 1);
270 strCookie = nameParam + "=" + valCookie;
271 var arrayRecords = valCookie.split("/");
272 updateBasket(arrayRecords.length-1,top.opener);
273 document.location = CGIBIN + "basket/basket.pl?" + strCookie;
276 alert(MSG_NO_RECORD_SELECTED);
280 function delRecord (n, s) {
287 pos = aux.indexOf(n, pos+1);
288 var charAfter = aux.charAt(pos+n.length); // character right after the researched string
289 if (charAfter.match(re)) { // record number inside another one
292 else { // good record number
293 aux = s.substring(0, pos)+ s.substring(pos+n.length+1, s.length);
303 function delBasket(context,rep) {
304 if (rep == undefined){
305 rep = confirm(MSG_CONFIRM_DEL_BASKET);
308 if(context == "popup"){
309 delCookie(nameCookie);
310 document.location = "about:blank";
311 updateBasket(0,top.opener);
314 delCookie(nameCookie);
315 updateBasket(0,top.opener);
322 if (document.myform.records.value) {
324 rep = confirm(MSG_CONFIRM_DEL_RECORDS);
329 updateBasket(arrayRecords.length-1,top.opener);
333 function sendBasket() {
334 var valCookie = readCookie(nameCookie);
335 var strCookie = nameParam + "=" + valCookie;
337 var loc = CGIBIN + "basket/sendbasket.pl?" + strCookie;
339 var optWin="scrollbars=no,resizable=no,height=300,width=450,top=50,left=100";
340 var win_form = open(loc,"win_form",optWin);
343 function downloadBasket() {
344 var valCookie = readCookie(nameCookie);
345 var strCookie = nameParam + "=" + valCookie;
347 var loc = CGIBIN + "basket/downloadcart.pl?" + strCookie;
349 open(loc,"win_form",'scrollbars=no,resizable=no,height=300,width=450,top=50,left=100');
352 function printBasket() {
353 var loc = document.location + "&print=1";
354 document.location = loc;
357 function showMore() {
360 var valCookie = readCookie(nameCookie);
362 strCookie = nameParam + "=" + valCookie;
364 var loc = CGIBIN + "basket/basket.pl?" + strCookie + "&verbose=1";
365 document.location = loc;
368 function showLess() {
371 var valCookie = readCookie(nameCookie);
373 strCookie = nameParam + "=" + valCookie;
375 var loc = CGIBIN + "basket/basket.pl?" + strCookie + "&verbose=0";
376 document.location = loc;
379 function updateBasket(updated_value,target) {
381 target.$('#basketcount').html(" <span>("+updated_value+")</span>");
382 target.$('#cartDetails').html(MSG_IN_YOUR_CART.format(updated_value));
384 $('#basketcount').html(" <span>("+updated_value+")</span>");
385 $('#cartDetails').html(MSG_IN_YOUR_CART.format(updated_value));
387 var basketcount = updated_value;
390 function openBiblio(dest,biblionumber) {
391 openerURL=dest+"?biblionumber="+biblionumber;
392 opener.document.location = openerURL;
396 function addSelToShelf() {
397 var items = document.getElementById('records').value;
399 document.location = "/cgi-bin/koha/virtualshelves/addbybiblionumber.pl?biblionumber="+items;
401 alert(MSG_NO_RECORD_SELECTED);
405 /// vShelfAdd() builds url string for multiple-biblio adds.
407 function vShelfAdd(biblist) {
409 if(biblist.length > 0) {
410 for (var i=0; i < biblist.length; i++) {
411 if (biblist[i].checked) {
412 bibs.push("biblionumber=" + biblist[i].value);
415 if (bibs.length == 0) { showListsUpdate(MSG_NO_RECORD_SELECTED); }
416 return bibs.join("&");
418 if (biblist.checked) {
419 return "biblionumber=" + biblist.value;
425 var position = $("#cartmenulink").offset();
426 var scrolld = $(window).scrollTop();
427 var top = position.top + $("#cartmenulink").outerHeight();
431 var left = position.left
432 $("#cartDetails").css("position","absolute").css("top",top);
433 $("#cartDetails").css("position","absolute").css("left",left);
434 $("#cartDetails").fadeIn("fast");
438 $("#cartDetails").fadeOut("fast");
441 $(document).ready(function(){
442 $("#cartmenulink").click(function(){ openBasket(); return false; });
443 if(basketcount){ updateBasket(basketcount); }