1 /* global MSG_BASKET_EMPTY MSG_RECORD_IN_BASKET MSG_RECORD_ADDED MSG_NRECORDS_IN_BASKET MSG_NRECORDS_ADDED MSG_NO_RECORD_ADDED MSG_RECORD_REMOVED MSG_CONFIRM_DEL_BASKET MSG_CONFIRM_DEL_RECORDS MSG_IN_YOUR_CART MSG_NO_RECORD_SELECTED MSG_ITEM_IN_CART MSG_ITEM_NOT_IN_CART */
3 //////////////////////////////////////////////////////////////////////////////
4 // BASIC FUNCTIONS FOR COOKIE MANAGEMENT //
5 //////////////////////////////////////////////////////////////////////////////
7 var CGIBIN = "/cgi-bin/koha/";
9 var nameCookie = "intranet_bib_list";
10 var nameParam = "bib_list";
11 var valCookie = readCookie(nameCookie);
14 var arrayRecords = valCookie.split("/");
15 if(arrayRecords.length > 0){
16 var basketcount = arrayRecords.length-1;
24 function writeCookie(name, val, wd) {
26 parent.opener.document.cookie = name + "=" + val + "; path=/";
29 parent.document.cookie = name + "=" + val + "; path=/";
33 function readCookieValue (str, val_beg) {
34 var val_end = str.indexOf(";", val_end);
37 return str.substring(val_beg, val_end);
40 function readCookie(name, wd) {
41 var str_name = name + "=";
42 var str_len = str_name.length;
45 str_cookie = parent.opener.document.cookie;
48 str_cookie = parent.document.cookie;
50 // fixed - getting the part of the basket that is bib_list
51 var cookie_parts = str_cookie.split(";");
52 for(var i=0;i < cookie_parts.length;i++) {
53 var c = cookie_parts[i];
54 while (c.charAt(0)==' ') c = c.substring(1,c.length);
55 if(c.indexOf(str_name) === 0) return c.substring(str_name.length,c.length);
60 function delCookie(name) {
62 exp.setTime(exp.getTime()-1);
64 parent.opener.document.cookie = name + "=null; path=/; expires=" + exp.toGMTString();
66 document.cookie = name + "=null; path=/; expires=" + exp.toGMTString();
70 ///////////////////////////////////////////////////////////////////
71 // SPECIFIC FUNCTIONS USING COOKIES //
72 ///////////////////////////////////////////////////////////////////
74 function openBasket() {
76 var valCookie = readCookie(nameCookie);
78 strCookie = nameParam + "=" + valCookie;
84 var optWin = "status=yes,scrollbars=yes,resizable=yes,toolbar=no,location=yes,height="+iH+",width="+iW;
85 var loc = CGIBIN + "basket/basket.pl?" + strCookie;
86 var basket = open(loc, "basket", optWin);
87 if (window.focus) { basket.focus(); }
90 showCartUpdate(MSG_BASKET_EMPTY);
94 function addRecord(val, selection,NoMsgAlert) {
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
131 updateLink(val,"add");
135 showCartUpdate(MSG_RECORD_ADDED);
136 updateLink(val,"add");
141 function AllAreChecked(s){
142 if (! s.length) { return false;}
144 for (var i=0; i < l; i++) {
145 if(! s[i].checked) { return false; }
150 function SelectAll(){
151 if(document.bookbag_form.biblionumber.length > 0) {
152 var checky = AllAreChecked(document.bookbag_form.biblionumber);
153 var l = document.bookbag_form.biblionumber.length;
154 for (var i=0; i < l; i++) {
155 document.bookbag_form.biblionumber[i].checked = (checky) ? false : true;
160 function addMultiple(biblist){
162 if( biblist && biblist.length > 0 ) {
163 for (var i=0; i < biblist.length; i++) {
164 if (biblist[i].checked) {
165 c_value = c_value + biblist[i].value + "/";
169 var bibnums = getContextBiblioNumbers();
170 if ( bibnums.length > 0 ) {
171 for ( var i = 0 ; i < bibnums.length ; i++ ) {
172 c_value = c_value + bibnums[i] + "/";
175 if(document.bookbag_form.biblionumber.length > 0) {
176 for (var i=0; i < document.bookbag_form.biblionumber.length; i++) {
177 if (document.bookbag_form.biblionumber[i].checked) {
178 c_value = c_value + document.bookbag_form.biblionumber[i].value + "/";
182 c_value = c_value + document.bookbag_form.biblionumber.value + "/";
186 addSelRecords(c_value);
189 function addSelRecords(valSel) { // function for adding a selection of biblios to the basket
190 // from the results list
191 var arrayRecords = valSel.split("/");
194 for (i=0;i<arrayRecords.length;i++) {
195 if (arrayRecords[i]) {
196 nbAdd += addRecord(arrayRecords[i], 1);
205 msg = MSG_NRECORDS_ADDED.format(nbAdd);
207 msg += MSG_NRECORDS_IN_BASKET.format((i-nbAdd));
210 msg = MSG_NRECORDS_ADDED.format(nbAdd);
215 msg = MSG_NO_RECORD_SELECTED;
218 msg = MSG_NO_RECORD_ADDED;
224 function showCartUpdate(msg){
225 // set body of popup window
227 $("#cartDetails").html(msg);
229 setTimeout(hideCart,2000);
232 function showListsUpdate(msg){
233 // set body of popup window
237 function selRecord(num, status) {
238 var str = document.myform.records.value;
243 str = delRecord(num, str);
246 document.myform.records.value = str;
249 function delSingleRecord(biblionumber){
250 var valCookie = readCookie(nameCookie);
251 var arrayRecords = valCookie.split("/");
252 var pos = jQuery.inArray(biblionumber,arrayRecords);
253 arrayRecords.splice(pos,1);
254 valCookie = arrayRecords.join("/");
255 writeCookie( nameCookie, valCookie );
256 updateBasket( arrayRecords.length-1 );
257 updateLink(biblionumber,"del");
258 showCartUpdate(MSG_RECORD_REMOVED);
261 function delSelRecords() {
264 var valCookie = readCookie(nameCookie, 1);
267 var str = document.myform.records.value;
270 var str2 = valCookie;
272 s = str.indexOf("/");
274 num = str.substring(0, s);
275 str = delRecord(num,str);
276 str2 = delRecord(num,str2);
277 updateLink(num,"del",top.opener);
283 if (str2.length === 0) { // equivalent to emptying the basket
285 rep = confirm(MSG_CONFIRM_DEL_BASKET);
287 delCookie(nameCookie);
288 document.location = "about:blank";
289 updateBasket(0,top.opener);
295 writeCookie(nameCookie, str2, 1);
302 valCookie = readCookie(nameCookie, 1);
303 strCookie = nameParam + "=" + valCookie;
304 var arrayRecords = valCookie.split("/");
305 updateBasket(arrayRecords.length-1,top.opener);
306 document.location = CGIBIN + "basket/basket.pl?" + strCookie;
309 alert(MSG_NO_RECORD_SELECTED);
313 function delRecord (n, s) {
320 pos = aux.indexOf(n, pos+1);
321 var charAfter = aux.charAt(pos+n.length); // character right after the researched string
322 if (charAfter.match(re)) { // record number inside another one
325 else { // good record number
326 aux = s.substring(0, pos)+ s.substring(pos+n.length+1, s.length);
336 function delBasket(context,rep) {
337 if (rep === undefined){
338 rep = confirm(MSG_CONFIRM_DEL_BASKET);
341 if(context == "popup"){
342 delCookie(nameCookie);
343 updateAllLinks(top.opener);
344 document.location = "about:blank";
345 updateBasket(0,top.opener);
348 delCookie(nameCookie);
349 updateBasket(0,top.opener);
356 if (document.myform.records.value) {
358 rep = confirm(MSG_CONFIRM_DEL_RECORDS);
363 updateBasket(arrayRecords.length-1,top.opener);
367 function sendBasket() {
368 var valCookie = readCookie(nameCookie);
369 var strCookie = nameParam + "=" + valCookie;
371 var loc = CGIBIN + "basket/sendbasket.pl?" + strCookie;
373 var optWin="scrollbars=no,resizable=no,height=400,width=650,top=50,left=100";
374 var win_form = open(loc,"win_form",optWin);
377 function downloadBasket() {
378 var valCookie = readCookie(nameCookie);
379 var strCookie = nameParam + "=" + valCookie;
381 var loc = CGIBIN + "basket/downloadcart.pl?" + strCookie;
383 open(loc,"win_form",'scrollbars=no,resizable=no,height=300,width=450,top=50,left=100');
386 function printBasket() {
390 function showMore() {
393 var valCookie = readCookie(nameCookie);
395 strCookie = nameParam + "=" + valCookie;
397 var loc = CGIBIN + "basket/basket.pl?" + strCookie + "&verbose=1";
398 document.location = loc;
401 function showLess() {
404 var valCookie = readCookie(nameCookie);
406 strCookie = nameParam + "=" + valCookie;
408 var loc = CGIBIN + "basket/basket.pl?" + strCookie + "&verbose=0";
409 document.location = loc;
412 function updateBasket(updated_value,target) {
414 target.$('#basketcount').html(" <span>("+updated_value+")</span>");
415 target.$('#cartDetails').html(MSG_IN_YOUR_CART.format(updated_value));
417 $('#basketcount').html(" <span>("+updated_value+")</span>");
418 $('#cartDetails').html(MSG_IN_YOUR_CART.format(updated_value));
420 var basketcount = updated_value;
423 function openBiblio(openerURL) {
424 opener.document.location = openerURL;
428 function addSelToShelf() {
429 var items = document.getElementById('records').value;
431 document.location = "/cgi-bin/koha/virtualshelves/addbybiblionumber.pl?biblionumber="+items;
433 alert(MSG_NO_RECORD_SELECTED);
437 /// vShelfAdd() builds url string for multiple-biblio adds.
439 function vShelfAdd(biblist) {
440 var bibs = new Array;
441 if( biblist && biblist.length > 0 ) {
442 for (var i=0; i < biblist.length; i++) {
443 if (biblist[i].checked) {
444 bibs.push("biblionumber=" + biblist[i].value);
447 if (bibs.length === 0) { showListsUpdate(MSG_NO_RECORD_SELECTED); }
448 return bibs.join("&");
450 var bibnums = getContextBiblioNumbers();
451 if ( bibnums.length > 0 ) {
452 for ( var i = 0 ; i < bibnums.length ; i++ ) {
453 bibs.push("biblionumber=" + bibnums[i]);
455 return bibs.join("&");
461 var position = $("#cartmenulink").offset();
462 var toolbarh = $(".floating").outerHeight();
463 var scrolld = $(window).scrollTop();
464 var top = position.top + $("#cartmenulink").outerHeight();
466 top = scrolld + toolbarh + 15;
468 var left = position.left;
470 .css("position","absolute")
473 .css("z-index",1000);
474 $("#cartDetails").fadeIn("fast");
478 $("#cartDetails").fadeOut("fast");
481 function updateLink(val, op, target){
482 var cart = target ? target.$("#cart" + val) : $("#cart" + val);
483 var cartR = target ? target.$("#cartR" + val) : $("#cartR" + val);
486 cart.html(MSG_ITEM_IN_CART).addClass("incart");
489 cart.html(MSG_ITEM_NOT_IN_CART).removeClass("incart").addClass("addtocart");
494 function updateAllLinks(target){
496 target.$("a.incart").html(MSG_ITEM_NOT_IN_CART).removeClass("incart").addClass("addtocart");
497 target.$(".cartRemove").hide();
499 $("a.incart").html(MSG_ITEM_NOT_IN_CART).removeClass("incart").addClass("addtocart");
500 $(".cartRemove").hide();
504 $(document).ready(function(){
505 $("#cartmenulink").click(function( e ){
509 if(basketcount){ updateBasket(basketcount); }