View | Details | Raw Unified | Return to bug 28910
Collapse All | Expand All

(-)a/koha-tmpl/opac-tmpl/bootstrap/js/basket.js (-83 / +40 lines)
Lines 1-20 Link Here
1
/* global __ __p */
1
/* global __ __p */
2
2
/* exported addMultiple delSingleRecord vShelfAdd openBiblio addSelToShelf delBasket sendBasket showMore showLess delSelRecords holdSel selRecord */
3
//////////////////////////////////////////////////////////////////////////////
3
//////////////////////////////////////////////////////////////////////////////
4
// BASIC FUNCTIONS FOR COOKIE MANAGEMENT //
4
// BASIC FUNCTIONS FOR COOKIE MANAGEMENT //
5
//////////////////////////////////////////////////////////////////////////////
5
//////////////////////////////////////////////////////////////////////////////
6
6
7
function basketCount(){
7
function basketCount(){
8
    var valCookie = readCookie("bib_list");
8
    var valCookie = readCookie("bib_list");
9
    var basketcount = 0;
9
    if(valCookie){
10
    if(valCookie){
10
        var arrayRecords = valCookie.split("/");
11
        var arrayRecords = valCookie.split("/");
11
        if(arrayRecords.length > 0){
12
        if(arrayRecords.length > 0){
12
            var basketcount = arrayRecords.length-1;
13
            basketcount = arrayRecords.length-1;
13
        } else {
14
        } else {
14
            var basketcount = 0;
15
            basketcount = 0;
15
        }
16
        }
16
    } else {
17
    } else {
17
            var basketcount = 0;
18
        basketcount = 0;
18
    }
19
    }
19
    return basketcount;
20
    return basketcount;
20
}
21
}
Lines 28-43 function writeCookie(name, val, wd) { Link Here
28
    }
29
    }
29
}
30
}
30
31
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) {
32
function readCookie(name, wd) {
39
    var str_name = name + "=";
33
    var str_name = name + "=";
40
    var str_len = str_name.length;
41
    var str_cookie = "";
34
    var str_cookie = "";
42
    if (wd) {
35
    if (wd) {
43
        str_cookie = parent.opener.document.cookie;
36
        str_cookie = parent.opener.document.cookie;
Lines 45-57 function readCookie(name, wd) { Link Here
45
    else {
38
    else {
46
        str_cookie = parent.document.cookie;
39
        str_cookie = parent.document.cookie;
47
    }
40
    }
48
        // fixed - getting the part of the basket that is bib_list
41
    // fixed - getting the part of the basket that is bib_list
49
        var cookie_parts = str_cookie.split(";");
42
    var cookie_parts = str_cookie.split(";");
50
            for(var i=0;i < cookie_parts.length;i++) {
43
    for(var i=0;i < cookie_parts.length;i++) {
51
                var c = cookie_parts[i];
44
        var c = cookie_parts[i];
52
                    while (c.charAt(0)==' ') c = c.substring(1,c.length);
45
        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);
46
        if(c.indexOf(str_name) == 0) return c.substring(str_name.length,c.length);
54
            }
47
    }
55
    return null;
48
    return null;
56
}
49
}
57
50
Lines 83-89 function openBasket() { Link Here
83
        var optWin = "status=yes,scrollbars=yes,resizable=yes,toolbar=no,location=yes,height="+iH+",width="+iW;
76
        var optWin = "status=yes,scrollbars=yes,resizable=yes,toolbar=no,location=yes,height="+iH+",width="+iW;
84
        var loc = "/cgi-bin/koha/opac-basket.pl?" + strCookie;
77
        var loc = "/cgi-bin/koha/opac-basket.pl?" + strCookie;
85
        var basket = open(loc, "basket", optWin);
78
        var basket = open(loc, "basket", optWin);
86
        if (window.focus) {basket.focus()}
79
        if (window.focus) { basket.focus(); }
87
    }
80
    }
88
    else {
81
    else {
89
        showCartUpdate( __("Your cart is currently empty") );
82
        showCartUpdate( __("Your cart is currently empty") );
Lines 139-163 function addRecord(val, selection,NoMsgAlert) { Link Here
139
    }
132
    }
140
}
133
}
141
134
142
function AllAreChecked(s){
143
    if (! s.length) { return false;}
144
    var l = s.length;
145
    for (var i=0; i < l; i++) {
146
        if(! s[i].checked) { return false; }
147
    }
148
    return true;
149
}
150
151
function SelectAll(){
152
    if(document.bookbag_form.biblionumber.length > 0) {
153
        var checky = AllAreChecked(document.bookbag_form.biblionumber);
154
        var l = document.bookbag_form.biblionumber.length;
155
        for (var i=0; i < l; i++) {
156
            document.bookbag_form.biblionumber[i].checked = (checky) ? false : true;
157
        }
158
    }
159
}
160
161
function addMultiple(){
135
function addMultiple(){
162
    var c_value = "";
136
    var c_value = "";
163
    if(document.bookbag_form.biblionumber.length > 0) {
137
    if(document.bookbag_form.biblionumber.length > 0) {
Lines 173-180 function addMultiple(){ Link Here
173
    }
147
    }
174
}
148
}
175
149
176
function addSelRecords(valSel) { // function for adding a selection of biblios to the basket
150
/* function for adding a selection of biblios to the basket from the results list */
177
                                                // from the results list
151
function addSelRecords(valSel) {
178
    var arrayRecords = valSel.split("/");
152
    var arrayRecords = valSel.split("/");
179
    var i = 0;
153
    var i = 0;
180
    var nbAdd = 0;
154
    var nbAdd = 0;
Lines 214-225 function showCartUpdate(msg){ Link Here
214
}
188
}
215
189
216
function showListsUpdate(msg){
190
function showListsUpdate(msg){
217
       // set body of popup window
191
    // set body of popup window
218
       alert(msg);
192
    alert(msg);
219
}
193
}
220
194
221
function selRecord(num, status) {
195
function selRecord(num, status) {
222
    var str = document.myform.records.value
196
    var str = document.myform.records.value;
223
    if (status){
197
    if (status){
224
        str += num+"/";
198
        str += num+"/";
225
    }
199
    }
Lines 255-263 function delSelRecords() { Link Here
255
            recordsSel = 1;
229
            recordsSel = 1;
256
            var str2 = valCookie;
230
            var str2 = valCookie;
257
            while (!end){
231
            while (!end){
258
                s = str.indexOf("/");
232
                var s = str.indexOf("/");
259
                if (s>0){
233
                if (s>0){
260
                    num = str.substring(0, s);
234
                    var num = str.substring(0, s);
261
                    str = delRecord(num,str);
235
                    str = delRecord(num,str);
262
                    str2 = delRecord(num,str2);
236
                    str2 = delRecord(num,str2);
263
                    updateLink(num,"del",top.opener);
237
                    updateLink(num,"del",top.opener);
Lines 285-292 function delSelRecords() { Link Here
285
259
286
    if (recordsSel) {
260
    if (recordsSel) {
287
        var strCookie = "";
261
        var strCookie = "";
288
        var nameCookie = "bib_list";
262
        valCookie = readCookie(nameCookie, 1);
289
        var valCookie = readCookie(nameCookie, 1);
290
        strCookie = nameCookie + "=" + valCookie;
263
        strCookie = nameCookie + "=" + valCookie;
291
        var arrayRecords = valCookie.split("/");
264
        var arrayRecords = valCookie.split("/");
292
        updateBasket(arrayRecords.length-1,top.opener);
265
        updateBasket(arrayRecords.length-1,top.opener);
Lines 334-352 function delBasket() { Link Here
334
    }
307
    }
335
}
308
}
336
309
337
338
function quit() {
339
    if (document.myform.records.value) {
340
        var rep = false;
341
        rep = confirm( __p("Bibliographic records", "Are you sure you want to remove the selected items?") );
342
        if (rep) {
343
            delSelRecords();
344
        }
345
    }
346
    updateBasket(arrayRecords.length-1,top.opener);
347
    window.close();
348
}
349
350
function sendBasket() {
310
function sendBasket() {
351
    var nameCookie = "bib_list";
311
    var nameCookie = "bib_list";
352
    var valCookie = readCookie(nameCookie);
312
    var valCookie = readCookie(nameCookie);
Lines 355-361 function sendBasket() { Link Here
355
    var loc = "/cgi-bin/koha/opac-sendbasket.pl?" + strCookie;
315
    var loc = "/cgi-bin/koha/opac-sendbasket.pl?" + strCookie;
356
316
357
    var optWin="scrollbars=yes,resizable=yes,height=600,width=900,top=50,left=100";
317
    var optWin="scrollbars=yes,resizable=yes,height=600,width=900,top=50,left=100";
358
    var win_form = open(loc,"win_form",optWin);
318
    open(loc,"win_form",optWin);
359
}
319
}
360
320
361
function showMore() {
321
function showMore() {
Lines 393-402 function holdSel() { Link Here
393
}
353
}
394
354
395
function updateBasket(updated_value,target) {
355
function updateBasket(updated_value,target) {
356
    var bcount = "";
396
    if(updated_value > 0){
357
    if(updated_value > 0){
397
        bcount = "<span>"+updated_value+"</span>";
358
        bcount = "<span>"+updated_value+"</span>";
398
    } else {
399
        bcount = "";
400
    }
359
    }
401
    if(target){
360
    if(target){
402
        target.$('#basketcount').html(bcount);
361
        target.$('#basketcount').html(bcount);
Lines 406-412 function updateBasket(updated_value,target) { Link Here
406
}
365
}
407
366
408
function openBiblio(dest,biblionumber) {
367
function openBiblio(dest,biblionumber) {
409
    openerURL=dest+"?biblionumber="+biblionumber;
368
    var openerURL = dest + "?biblionumber=" + biblionumber;
410
    opener.document.location = openerURL;
369
    opener.document.location = openerURL;
411
    opener.focus();
370
    opener.focus();
412
}
371
}
Lines 418-424 function addSelToShelf() { Link Here
418
        var iH = 450;
377
        var iH = 450;
419
        var optWin = "status=yes,scrollbars=yes,resizable=yes,toolbar=no,location=yes,height="+iH+",width="+iW;
378
        var optWin = "status=yes,scrollbars=yes,resizable=yes,toolbar=no,location=yes,height="+iH+",width="+iW;
420
        var loc = "/cgi-bin/koha/opac-addbybiblionumber.pl?biblionumber="+items;
379
        var loc = "/cgi-bin/koha/opac-addbybiblionumber.pl?biblionumber="+items;
421
        var shelf = open(loc, "shelf", optWin);
380
        open(loc, "shelf", optWin);
422
    } else {
381
    } else {
423
        alert( __p("Bibliographic record", "No item was selected") );
382
        alert( __p("Bibliographic record", "No item was selected") );
424
    }
383
    }
Lines 427-446 function addSelToShelf() { Link Here
427
///  vShelfAdd()  builds url string for multiple-biblio adds.
386
///  vShelfAdd()  builds url string for multiple-biblio adds.
428
387
429
function vShelfAdd() {
388
function vShelfAdd() {
430
        bibs= new Array;
389
    var bibs = new Array;
431
        if(document.bookbag_form.biblionumber.length > 0) {
390
    if(document.bookbag_form.biblionumber.length > 0) {
432
                for (var i=0; i < document.bookbag_form.biblionumber.length; i++) {
391
        for (var i=0; i < document.bookbag_form.biblionumber.length; i++) {
433
                        if (document.bookbag_form.biblionumber[i].checked) {
392
            if (document.bookbag_form.biblionumber[i].checked) {
434
                                bibs.push("biblionumber=" +  document.bookbag_form.biblionumber[i].value);
393
                bibs.push("biblionumber=" +  document.bookbag_form.biblionumber[i].value);
435
                        }
436
                }
437
        if (bibs.length == 0) { showListsUpdate( __p("Bibliographic record", "No item was selected") ); }
438
            return bibs.join("&");
439
        } else {
440
            if (document.bookbag_form.biblionumber.checked) {
441
                return "biblionumber=" + document.bookbag_form.biblionumber.value;
442
            }
394
            }
443
        }
395
        }
396
        if (bibs.length == 0) {
397
            showListsUpdate( __p("Bibliographic record", "No item was selected") );
398
        }
399
        return bibs.join("&");
400
    } else {
401
        if (document.bookbag_form.biblionumber.checked) {
402
            return "biblionumber=" + document.bookbag_form.biblionumber.value;
403
        }
404
    }
444
}
405
}
445
406
446
function showCart(){
407
function showCart(){
Lines 450-459 function showCart(){ Link Here
450
    if( scrolld > top ){
411
    if( scrolld > top ){
451
        top = scrolld + 15;
412
        top = scrolld + 15;
452
    }
413
    }
453
    var menuWidth = 200;
414
    var left = position.left -  0;
454
    var buttonWidth = $("#cartmenulink").innerWidth();
455
    var buttonOffset = menuWidth - buttonWidth;
456
    var left = position.left -  0 // buttonOffset;
457
    $("#cartDetails")
415
    $("#cartDetails")
458
        .css({"position":"absolute", "top":top, "left":left})
416
        .css({"position":"absolute", "top":top, "left":left})
459
        .fadeIn("fast");
417
        .fadeIn("fast");
460
- 

Return to bug 28910