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
213 $("#listsDetails").html(msg);
215 setTimeout("hideLists()",2000);
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() {
307 rep = confirm(MSG_CONFIRM_DEL_BASKET);
309 delCookie(nameCookie);
310 document.location = "about:blank";
311 updateBasket(0,top.opener);
318 if (document.myform.records.value) {
320 rep = confirm(MSG_CONFIRM_DEL_RECORDS);
325 updateBasket(arrayRecords.length-1,top.opener);
329 function sendBasket() {
330 var valCookie = readCookie(nameCookie);
331 var strCookie = nameParam + "=" + valCookie;
333 var loc = CGIBIN + "basket/sendbasket.pl?" + strCookie;
335 var optWin="dependant=yes,scrollbars=no,resizable=no,height=300,width=450,top=50,left=100";
336 var win_form = open(loc,"win_form",optWin);
339 function downloadBasket() {
340 var valCookie = readCookie(nameCookie);
341 var strCookie = nameParam + "=" + valCookie;
343 var loc = CGIBIN + "basket/downloadcart.pl?" + strCookie;
345 open(loc,"win_form",'dependant=yes,scrollbars=no,resizable=no,height=300,width=450,top=50,left=100');
348 function printBasket() {
349 var loc = document.location + "&print=1";
350 document.location = loc;
353 function showMore() {
356 var valCookie = readCookie(nameCookie);
358 strCookie = nameParam + "=" + valCookie;
360 var loc = CGIBIN + "basket/basket.pl?" + strCookie + "&verbose=1";
361 document.location = loc;
364 function showLess() {
367 var valCookie = readCookie(nameCookie);
369 strCookie = nameParam + "=" + valCookie;
371 var loc = CGIBIN + "basket/basket.pl?" + strCookie + "&verbose=0";
372 document.location = loc;
375 function updateBasket(updated_value,target) {
377 target.$('#basketcount').html(" <span>("+updated_value+")</span>");
378 target.$('#cartDetails').html(_("Your cart contains ")+updated_value+_(" items"));
380 $('#basketcount').html(" <span>("+updated_value+")</span>");
381 $('#cartDetails').html(_("Your cart contains ")+updated_value+_(" items"));
383 var basketcount = updated_value;
386 function openBiblio(dest,biblionumber) {
387 openerURL=dest+"?biblionumber="+biblionumber;
388 opener.document.location = openerURL;
392 function addSelToShelf() {
393 var items = document.getElementById('records').value;
395 document.location = "/cgi-bin/koha/virtualshelves/addbybiblionumber.pl?biblionumber="+items;
397 alert(MSG_NO_RECORD_SELECTED);
401 /// vShelfAdd() builds url string for multiple-biblio adds.
403 function vShelfAdd() {
405 if(document.bookbag_form.biblionumber.length > 0) {
406 for (var i=0; i < document.bookbag_form.biblionumber.length; i++) {
407 if (document.bookbag_form.biblionumber[i].checked) {
408 bibs.push("biblionumber=" + document.bookbag_form.biblionumber[i].value);
411 if (bibs.length == 0) { showListsUpdate(MSG_NO_RECORD_SELECTED); }
412 return bibs.join("&");
414 if (document.bookbag_form.biblionumber.checked) {
415 return "biblionumber=" + document.bookbag_form.biblionumber.value;
421 var position = $("#cartmenulink").offset();
422 var top = position.top + $("#cartmenulink").outerHeight();
423 var left = position.left
424 $("#cartDetails").css("position","absolute").css("top",top);
425 $("#cartDetails").css("position","absolute").css("left",left);
426 $("#cartDetails").fadeIn("fast");
430 $("#cartDetails").fadeOut("fast");
433 $(document).ready(function(){
434 $("#cartmenulink").click(function(){ openBasket(); return false; });
435 if(basketcount){ updateBasket(basketcount); }