PageSourceSearch

https://koha.eaeu.edu.sd/opac-tmpl/bootstrap/js/basket_26.0503000.js

js eaeu.edu.sd collected 2026-10-05 23:07:38 UTC 15,213 bytes, 529 lines download raw bytes

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

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.