|
Line 0
Link Here
|
|
|
1 |
////////////////////////////////////////////////////////////////////////////// |
| 2 |
// BASIC FUNCTIONS FOR COOKIE MANAGEMENT // |
| 3 |
////////////////////////////////////////////////////////////////////////////// |
| 4 |
|
| 5 |
var CGIBIN = "/cgi-bin/koha/"; |
| 6 |
|
| 7 |
|
| 8 |
var nameCookie = "bib_list"; |
| 9 |
var valCookie = readCookie(nameCookie); |
| 10 |
|
| 11 |
if(valCookie){ |
| 12 |
var arrayRecords = valCookie.split("/"); |
| 13 |
if(arrayRecords.length > 0){ |
| 14 |
var basketcount = arrayRecords.length-1; |
| 15 |
} else { |
| 16 |
var basketcount = ""; |
| 17 |
} |
| 18 |
} else { |
| 19 |
var basketcount = ""; |
| 20 |
} |
| 21 |
|
| 22 |
function writeCookie(name, val, wd) { |
| 23 |
if (wd) { |
| 24 |
parent.opener.document.cookie = name + "=" + val; |
| 25 |
} |
| 26 |
else { |
| 27 |
parent.document.cookie = name + "=" + val; |
| 28 |
} |
| 29 |
} |
| 30 |
|
| 31 |
function readCookieValue (str, val_beg) { |
| 32 |
var val_end = str.indexOf(";", val_end); |
| 33 |
if (val_end == -1) |
| 34 |
val_end = str.length; |
| 35 |
return str.substring(val_beg, val_end); |
| 36 |
} |
| 37 |
|
| 38 |
function readCookie(name, wd) { |
| 39 |
var str_name = name + "="; |
| 40 |
var str_len = str_name.length; |
| 41 |
var str_cookie = ""; |
| 42 |
if (wd) { |
| 43 |
str_cookie = parent.opener.document.cookie; |
| 44 |
} |
| 45 |
else { |
| 46 |
str_cookie = parent.document.cookie; |
| 47 |
} |
| 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); |
| 54 |
} |
| 55 |
return null; |
| 56 |
} |
| 57 |
|
| 58 |
function delCookie(name) { |
| 59 |
var exp = new Date(); |
| 60 |
exp.setTime(exp.getTime()-1); |
| 61 |
if(parent.opener){ |
| 62 |
parent.opener.document.cookie = name + "=null; expires=" + exp.toGMTString(); |
| 63 |
} else { |
| 64 |
document.cookie = name + "=null; expires=" + exp.toGMTString(); |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
/////////////////////////////////////////////////////////////////// |
| 69 |
// SPECIFIC FUNCTIONS USING COOKIES // |
| 70 |
/////////////////////////////////////////////////////////////////// |
| 71 |
|
| 72 |
function openBasket() { |
| 73 |
var strCookie = ""; |
| 74 |
var nameCookie = "bib_list"; |
| 75 |
var valCookie = readCookie(nameCookie); |
| 76 |
if ( valCookie ) { |
| 77 |
strCookie = nameCookie + "=" + valCookie; |
| 78 |
} |
| 79 |
|
| 80 |
if ( strCookie ) { |
| 81 |
var iW = 820; |
| 82 |
var iH = 450; |
| 83 |
var optWin = "dependant=yes,status=yes,scrollbars=yes,resizable=yes,toolbar=no,location=yes,height="+iH+",width="+iW; |
| 84 |
var loc = CGIBIN + "opac-basket.pl?" + strCookie; |
| 85 |
var basket = open(loc, "basket", optWin); |
| 86 |
if (window.focus) {basket.focus()} |
| 87 |
} |
| 88 |
else { |
| 89 |
showCartUpdate(MSG_BASKET_EMPTY); |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
function addRecord(val, selection,NoMsgAlert) { |
| 94 |
var nameCookie = "bib_list"; |
| 95 |
var valCookie = readCookie(nameCookie); |
| 96 |
var write = 0; |
| 97 |
|
| 98 |
if ( ! valCookie ) { // empty basket |
| 99 |
valCookie = val + '/'; |
| 100 |
write = 1; |
| 101 |
updateBasket(1); |
| 102 |
} |
| 103 |
else { |
| 104 |
// is this record already in the basket ? |
| 105 |
var found = false; |
| 106 |
var arrayRecords = valCookie.split("/"); |
| 107 |
for (var i = 0; i < valCookie.length - 1; i++) { |
| 108 |
if (val == arrayRecords[i]) { |
| 109 |
found = true; |
| 110 |
break; |
| 111 |
} |
| 112 |
} |
| 113 |
if ( found ) { |
| 114 |
if (selection) { |
| 115 |
return 0; |
| 116 |
} |
| 117 |
if (! NoMsgAlert ) { |
| 118 |
showCartUpdate(MSG_RECORD_IN_BASKET); |
| 119 |
} |
| 120 |
} |
| 121 |
else { |
| 122 |
valCookie += val + '/'; |
| 123 |
write = 1; |
| 124 |
updateBasket(arrayRecords.length); |
| 125 |
} |
| 126 |
} |
| 127 |
|
| 128 |
if (write) { |
| 129 |
writeCookie(nameCookie, valCookie); |
| 130 |
if (selection) { // when adding a selection of records |
| 131 |
updateLink(val,"add"); |
| 132 |
return 1; |
| 133 |
} |
| 134 |
if (! NoMsgAlert ) { |
| 135 |
showCartUpdate(MSG_RECORD_ADDED); |
| 136 |
updateLink(val,"add"); |
| 137 |
} |
| 138 |
} |
| 139 |
} |
| 140 |
|
| 141 |
function AllAreChecked(s){ |
| 142 |
if (! s.length) { return false;} |
| 143 |
var l = s.length; |
| 144 |
for (var i=0; i < l; i++) { |
| 145 |
if(! s[i].checked) { return false; } |
| 146 |
} |
| 147 |
return true; |
| 148 |
} |
| 149 |
|
| 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; |
| 156 |
} |
| 157 |
} |
| 158 |
} |
| 159 |
|
| 160 |
function addMultiple(){ |
| 161 |
var c_value = ""; |
| 162 |
if(document.bookbag_form.biblionumber.length > 0) { |
| 163 |
for (var i=0; i < document.bookbag_form.biblionumber.length; i++) { |
| 164 |
if (document.bookbag_form.biblionumber[i].checked) { |
| 165 |
c_value = c_value + document.bookbag_form.biblionumber[i].value + "/"; |
| 166 |
} |
| 167 |
} |
| 168 |
addSelRecords(c_value); |
| 169 |
} else { |
| 170 |
c_value = c_value + document.bookbag_form.biblionumber.value + "/"; |
| 171 |
addSelRecords(c_value); |
| 172 |
} |
| 173 |
} |
| 174 |
|
| 175 |
function addSelRecords(valSel) { // function for adding a selection of biblios to the basket |
| 176 |
// from the results list |
| 177 |
var arrayRecords = valSel.split("/"); |
| 178 |
var i = 0; |
| 179 |
var nbAdd = 0; |
| 180 |
for (i=0;i<arrayRecords.length;i++) { |
| 181 |
if (arrayRecords[i]) { |
| 182 |
nbAdd += addRecord(arrayRecords[i], 1); |
| 183 |
} |
| 184 |
else { |
| 185 |
break; |
| 186 |
} |
| 187 |
} |
| 188 |
var msg = ""; |
| 189 |
if (nbAdd) { |
| 190 |
if (i > nbAdd) { |
| 191 |
msg = nbAdd+" "+MSG_NRECORDS_ADDED+", "+(i-nbAdd)+" "+MSG_NRECORDS_IN_BASKET; |
| 192 |
} |
| 193 |
else { |
| 194 |
msg = nbAdd+" "+MSG_NRECORDS_ADDED; |
| 195 |
} |
| 196 |
} |
| 197 |
else { |
| 198 |
if (i < 1) { |
| 199 |
msg = MSG_NO_RECORD_SELECTED; |
| 200 |
} |
| 201 |
else { |
| 202 |
msg = MSG_NO_RECORD_ADDED+" ("+MSG_NRECORDS_IN_BASKET+") !"; |
| 203 |
} |
| 204 |
} |
| 205 |
showCartUpdate(msg); |
| 206 |
} |
| 207 |
|
| 208 |
function showCartUpdate(msg){ |
| 209 |
// set body of popup window |
| 210 |
$("#cartDetails").html(msg); |
| 211 |
showCart(); |
| 212 |
setTimeout("hideCart()",2000); |
| 213 |
} |
| 214 |
|
| 215 |
function showListsUpdate(msg){ |
| 216 |
// set body of popup window |
| 217 |
$("#listsDetails").html(msg); |
| 218 |
showLists(); |
| 219 |
setTimeout("hideLists()",2000); |
| 220 |
} |
| 221 |
|
| 222 |
function selRecord(num, status) { |
| 223 |
var str = document.myform.records.value |
| 224 |
if (status){ |
| 225 |
str += num+"/"; |
| 226 |
} |
| 227 |
else { |
| 228 |
str = delRecord(num, str); |
| 229 |
} |
| 230 |
|
| 231 |
document.myform.records.value = str; |
| 232 |
} |
| 233 |
|
| 234 |
function delSingleRecord(biblionumber){ |
| 235 |
var nameCookie = "bib_list"; |
| 236 |
var valCookie = readCookie(nameCookie); |
| 237 |
var arrayRecords = valCookie.split("/"); |
| 238 |
var pos = jQuery.inArray(biblionumber,arrayRecords); |
| 239 |
arrayRecords.splice(pos,1); |
| 240 |
valCookie = arrayRecords.join("/"); |
| 241 |
writeCookie( nameCookie, valCookie ); |
| 242 |
updateBasket( arrayRecords.length-1 ); |
| 243 |
updateLink(biblionumber,"del"); |
| 244 |
showCartUpdate(MSG_RECORD_REMOVED); |
| 245 |
} |
| 246 |
|
| 247 |
function delSelRecords() { |
| 248 |
var recordsSel = 0; |
| 249 |
var end = 0; |
| 250 |
var nameCookie = "bib_list"; |
| 251 |
var valCookie = readCookie(nameCookie, 1); |
| 252 |
if (valCookie) { |
| 253 |
var str = document.myform.records.value; |
| 254 |
if (str.length > 0){ |
| 255 |
recordsSel = 1; |
| 256 |
var str2 = valCookie; |
| 257 |
while (!end){ |
| 258 |
s = str.indexOf("/"); |
| 259 |
if (s>0){ |
| 260 |
num = str.substring(0, s); |
| 261 |
str = delRecord(num,str); |
| 262 |
str2 = delRecord(num,str2); |
| 263 |
updateLink(num,"del",top.opener); |
| 264 |
} else { |
| 265 |
end = 1; |
| 266 |
} |
| 267 |
} |
| 268 |
|
| 269 |
if (str2.length == 0) { // equivalent to emptying the basket |
| 270 |
var rep = false; |
| 271 |
rep = confirm(MSG_CONFIRM_DEL_BASKET); |
| 272 |
if (rep) { |
| 273 |
delCookie(nameCookie); |
| 274 |
document.location = "about:blank"; |
| 275 |
updateBasket(0,top.opener); |
| 276 |
window.close(); |
| 277 |
} else { |
| 278 |
return; |
| 279 |
} |
| 280 |
} else { |
| 281 |
writeCookie(nameCookie, str2, 1); |
| 282 |
} |
| 283 |
} |
| 284 |
} |
| 285 |
|
| 286 |
if (recordsSel) { |
| 287 |
var strCookie = ""; |
| 288 |
var nameCookie = "bib_list"; |
| 289 |
var valCookie = readCookie(nameCookie, 1); |
| 290 |
strCookie = nameCookie + "=" + valCookie; |
| 291 |
var arrayRecords = valCookie.split("/"); |
| 292 |
updateBasket(arrayRecords.length-1,top.opener); |
| 293 |
document.location = CGIBIN + "opac-basket.pl?" + strCookie; |
| 294 |
} |
| 295 |
else { |
| 296 |
alert(MSG_NO_RECORD_SELECTED); |
| 297 |
} |
| 298 |
} |
| 299 |
|
| 300 |
function delRecord (n, s) { |
| 301 |
var re = /\d/; |
| 302 |
var aux = s; |
| 303 |
var found = 0; |
| 304 |
var pos = -1; |
| 305 |
|
| 306 |
while (!found) { |
| 307 |
pos = aux.indexOf(n, pos+1); |
| 308 |
var charAfter = aux.charAt(pos+n.length); // character right after the researched string |
| 309 |
if (charAfter.match(re)) { // record number inside another one |
| 310 |
continue; |
| 311 |
} |
| 312 |
else { // good record number |
| 313 |
aux = s.substring(0, pos)+ s.substring(pos+n.length+1, s.length); |
| 314 |
s = aux; |
| 315 |
found = 1; |
| 316 |
} |
| 317 |
} |
| 318 |
|
| 319 |
return s; |
| 320 |
} |
| 321 |
|
| 322 |
|
| 323 |
function delBasket() { |
| 324 |
var nameCookie = "bib_list"; |
| 325 |
|
| 326 |
var rep = false; |
| 327 |
rep = confirm(MSG_CONFIRM_DEL_BASKET); |
| 328 |
if (rep) { |
| 329 |
delCookie(nameCookie); |
| 330 |
updateAllLinks(top.opener); |
| 331 |
document.location = "about:blank"; |
| 332 |
updateBasket(0,top.opener); |
| 333 |
window.close(); |
| 334 |
} |
| 335 |
} |
| 336 |
|
| 337 |
|
| 338 |
function quit() { |
| 339 |
if (document.myform.records.value) { |
| 340 |
var rep = false; |
| 341 |
rep = confirm(MSG_CONFIRM_DEL_RECORDS); |
| 342 |
if (rep) { |
| 343 |
delSelRecords(); |
| 344 |
} |
| 345 |
} |
| 346 |
updateBasket(arrayRecords.length-1,top.opener); |
| 347 |
window.close(); |
| 348 |
} |
| 349 |
|
| 350 |
function sendBasket() { |
| 351 |
var nameCookie = "bib_list"; |
| 352 |
var valCookie = readCookie(nameCookie); |
| 353 |
var strCookie = nameCookie + "=" + valCookie; |
| 354 |
|
| 355 |
var loc = CGIBIN + "opac-sendbasket.pl?" + strCookie; |
| 356 |
|
| 357 |
var optWin="dependant=yes,scrollbars=no,resizable=no,height=300,width=450,top=50,left=100"; |
| 358 |
var win_form = open(loc,"win_form",optWin); |
| 359 |
} |
| 360 |
|
| 361 |
function downloadBasket() { |
| 362 |
var nameCookie = "bib_list"; |
| 363 |
var valCookie = readCookie(nameCookie); |
| 364 |
var strCookie = nameCookie + "=" + valCookie; |
| 365 |
|
| 366 |
var loc = CGIBIN + "opac-downloadcart.pl?" + strCookie; |
| 367 |
|
| 368 |
open(loc,"win_form",'dependant=yes,scrollbars=no,resizable=no,height=300,width=450,top=50,left=100'); |
| 369 |
} |
| 370 |
|
| 371 |
function printBasket() { |
| 372 |
var loc = document.location + "&print=1"; |
| 373 |
document.location = loc; |
| 374 |
} |
| 375 |
|
| 376 |
function showMore() { |
| 377 |
var strCookie = ""; |
| 378 |
|
| 379 |
var nameCookie = "bib_list"; |
| 380 |
var valCookie = readCookie(nameCookie); |
| 381 |
if (valCookie) { |
| 382 |
strCookie = nameCookie + "=" + valCookie; |
| 383 |
} |
| 384 |
var loc = CGIBIN + "opac-basket.pl?" + strCookie + "&verbose=1"; |
| 385 |
document.location = loc; |
| 386 |
} |
| 387 |
|
| 388 |
function showLess() { |
| 389 |
var strCookie = ""; |
| 390 |
|
| 391 |
var nameCookie = "bib_list"; |
| 392 |
var valCookie = readCookie(nameCookie); |
| 393 |
if (valCookie) { |
| 394 |
strCookie = nameCookie + "=" + valCookie; |
| 395 |
} |
| 396 |
var loc = CGIBIN + "opac-basket.pl?" + strCookie + "&verbose=0"; |
| 397 |
document.location = loc; |
| 398 |
} |
| 399 |
|
| 400 |
function updateBasket(updated_value,target) { |
| 401 |
if(target){ |
| 402 |
target.$('#basketcount').html("<span>"+updated_value+"</span>"); |
| 403 |
target.$('#cartDetails').html(MSG_IN_YOUR_CART+updated_value); |
| 404 |
} else { |
| 405 |
$('#basketcount').html("<span>"+updated_value+"</span>"); |
| 406 |
$('#cartDetails').html(MSG_IN_YOUR_CART+updated_value); |
| 407 |
} |
| 408 |
var basketcount = updated_value; |
| 409 |
} |
| 410 |
|
| 411 |
function openBiblio(dest,biblionumber) { |
| 412 |
openerURL=dest+"?biblionumber="+biblionumber; |
| 413 |
opener.document.location = openerURL; |
| 414 |
opener.focus(); |
| 415 |
} |
| 416 |
|
| 417 |
function addSelToShelf() { |
| 418 |
var items = document.getElementById('records').value; |
| 419 |
if(items){ |
| 420 |
document.location = "/cgi-bin/koha/opac-addbybiblionumber.pl?biblionumber="+items; |
| 421 |
} else { |
| 422 |
alert(MSG_NO_RECORD_SELECTED); |
| 423 |
} |
| 424 |
} |
| 425 |
|
| 426 |
/// vShelfAdd() builds url string for multiple-biblio adds. |
| 427 |
|
| 428 |
function vShelfAdd() { |
| 429 |
bibs= new Array; |
| 430 |
if(document.bookbag_form.biblionumber.length > 0) { |
| 431 |
for (var i=0; i < document.bookbag_form.biblionumber.length; i++) { |
| 432 |
if (document.bookbag_form.biblionumber[i].checked) { |
| 433 |
bibs.push("biblionumber=" + document.bookbag_form.biblionumber[i].value); |
| 434 |
} |
| 435 |
} |
| 436 |
if (bibs.length == 0) { showListsUpdate(MSG_NO_RECORD_SELECTED); } |
| 437 |
return bibs.join("&"); |
| 438 |
} else { |
| 439 |
if (document.bookbag_form.biblionumber.checked) { |
| 440 |
return "biblionumber=" + document.bookbag_form.biblionumber.value; |
| 441 |
} |
| 442 |
} |
| 443 |
} |
| 444 |
|
| 445 |
function showCart(){ |
| 446 |
var position = $("#cartmenulink").offset(); |
| 447 |
var scrolld = $(window).scrollTop(); |
| 448 |
var top = position.top + $("#cartmenulink").outerHeight(); |
| 449 |
if( scrolld > top ){ |
| 450 |
top = scrolld + 15; |
| 451 |
} |
| 452 |
var menuWidth = 200; |
| 453 |
var buttonWidth = $("#cartmenulink").innerWidth(); |
| 454 |
var buttonOffset = menuWidth - buttonWidth; |
| 455 |
var left = position.left; |
| 456 |
$("#cartDetails").css("position","fixed").css("left",left); |
| 457 |
$("#cartDetails").fadeIn("fast"); |
| 458 |
} |
| 459 |
|
| 460 |
function showLists(){ |
| 461 |
var position = $("#listsmenulink").offset(); |
| 462 |
var top = position.top + $("#listsmenulink").outerHeight(); |
| 463 |
var menuWidth = 200; |
| 464 |
var buttonWidth = $("#listsmenulink").innerWidth(); |
| 465 |
var buttonOffset = menuWidth - buttonWidth; |
| 466 |
var left = position.left; |
| 467 |
$("#listsDetails").css("position","fixed").css("top",top); |
| 468 |
$("#listsDetails").css("position","fixed").css("left",left); |
| 469 |
$("#listsDetails").fadeIn("fast"); |
| 470 |
} |
| 471 |
|
| 472 |
function hideCart(){ |
| 473 |
$("#cartDetails").fadeOut("fast"); |
| 474 |
} |
| 475 |
|
| 476 |
function hideLists(){ |
| 477 |
$("#listsDetails").fadeOut("fast"); |
| 478 |
} |
| 479 |
|
| 480 |
function updateLink(val,op,target){ |
| 481 |
if(target){ |
| 482 |
if(op == "add"){ |
| 483 |
target.$("a.cart"+val).html(MSG_ITEM_IN_CART).addClass("incart"); |
| 484 |
target.$("a.cartR"+val).show(); |
| 485 |
} else { |
| 486 |
target.$("a.cart"+val).html(MSG_ITEM_NOT_IN_CART).removeClass("incart").addClass("addtocart cart"+val); |
| 487 |
target.$("a.cartR"+val).hide(); |
| 488 |
} |
| 489 |
} else { |
| 490 |
if(op == "add"){ |
| 491 |
$("a.cart"+val).html(MSG_ITEM_IN_CART).addClass("incart"); |
| 492 |
$("a.cartR"+val).show(); |
| 493 |
} else { |
| 494 |
$("a.cart"+val).html(MSG_ITEM_NOT_IN_CART).removeClass("incart").addClass("addtocart cart"+val); |
| 495 |
$("a.cartR"+val).hide(); |
| 496 |
} |
| 497 |
} |
| 498 |
} |
| 499 |
|
| 500 |
function updateAllLinks(target){ |
| 501 |
if(target){ |
| 502 |
target.$("a.incart").html(MSG_ITEM_NOT_IN_CART).removeClass("incart").addClass("addtocart"); |
| 503 |
target.$("a.cartRemove").hide(); |
| 504 |
} else { |
| 505 |
$("a.incart").html(MSG_ITEM_NOT_IN_CART).removeClass("incart").addClass("addtocart"); |
| 506 |
$("a.cartRemove").hide(); |
| 507 |
} |
| 508 |
} |
| 509 |
|
| 510 |
$("#cartDetails").ready(function(){ |
| 511 |
$("#cartDetails,#cartmenulink").click(function(){ hideCart(); }); |
| 512 |
$("#cartmenulink").click(function(){ openBasket(); return false; }); |
| 513 |
$("#cartmenulink").hoverIntent(function(){ |
| 514 |
showCart(); |
| 515 |
},function(){ |
| 516 |
hideCart(); |
| 517 |
}); |
| 518 |
if(basketcount){ updateBasket(basketcount) } |
| 519 |
}); |
| 520 |
|
| 521 |
$("#listsmenu").ready(function(){ |
| 522 |
$("#listsmenulink").mouseenter(function(){ |
| 523 |
var position = $("#listsmenulink").offset(); |
| 524 |
var top = position.top + $("#listsmenulink").outerHeight(); |
| 525 |
var menuWidth = 200; |
| 526 |
var buttonWidth = $("#listsmenulink").innerWidth(); |
| 527 |
var buttonOffset = menuWidth - buttonWidth; |
| 528 |
var left = position.left; |
| 529 |
$("#listsmenu").css("position","fixed").css("top",top); |
| 530 |
$("#listsmenu").css("position","fixed").css("left",left); |
| 531 |
$("#listsmenu").fadeIn("fast"); |
| 532 |
}); |
| 533 |
$("#listsmenulink").mouseleave(function(){ |
| 534 |
$("#listsmenu").fadeOut("fast"); |
| 535 |
}); |
| 536 |
}); |
| 537 |
|