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

(-)a/koha-tmpl/intranet-tmpl/js/browser.js (-40 / +41 lines)
Lines 7-64 KOHA.browser = function (searchid, biblionumber) { Link Here
7
        // We are generating a clean numeric datetime representation so we can easily compare them using the default javascript lexigraphic sorter.
7
        // We are generating a clean numeric datetime representation so we can easily compare them using the default javascript lexigraphic sorter.
8
        searchid = 'scs_' + (new Date()).getTime(); // scs for Staff Client Search
8
        searchid = 'scs_' + (new Date()).getTime(); // scs for Staff Client Search
9
    }
9
    }
10
    this.searchid = searchid;
10
    me.searchid = searchid;
11
11
12
    var cookie = $.cookie(me.searchid)
12
    var searches_stored = sessionStorage.getItem('searches');
13
    if (cookie) {
13
    var current_search;
14
        me.searchCookie = JSON.parse(cookie);
14
    var searches = {};
15
    if ( searches_stored ) {
16
        searches = JSON.parse(searches_stored);
17
        current_search = searches[me.searchid];
18
19
        // Remove old entries
20
        var searchids = Object.keys(searches);
21
        var nb_searches = searchids.length;
22
        if ( nb_searches > 20 ) { // No need to keep more than 20 searches
23
            searchids = searchids.sort();
24
            for ( var i = 0 ; i < nb_searches - 20 ; i++ ) {
25
                delete searches[searchids[i]];
26
            }
27
        }
15
    }
28
    }
16
29
17
    var browseRecords = function (movement) {
30
    var browseRecords = function (movement) {
18
        var newSearchPos = me.curPos + movement;
31
        var newSearchPos = me.curPos + movement;
19
        if (newSearchPos > me.searchCookie.results.length - 1) {
32
        if (newSearchPos > current_search.results.length - 1) {
20
            window.location = '/cgi-bin/koha/catalogue/search.pl?' + decodeURIComponent(me.searchCookie.query) + '&limit=' + decodeURIComponent(me.searchCookie.limit) + '&sort=' + me.searchCookie.sort + '&gotoPage=detail.pl&gotoNumber=first&searchid=' + me.searchid + '&offset=' + newSearchPos;
33
            window.location = '/cgi-bin/koha/catalogue/search.pl?' + decodeURIComponent(current_search.query) + '&limit=' + decodeURIComponent(current_search.limit) + '&sort=' + current_search.sort + '&gotoPage=detail.pl&gotoNumber=first&searchid=' + me.searchid + '&offset=' + newSearchPos;
21
        } else if (newSearchPos < 0) {
34
        } else if (newSearchPos < 0) {
22
            window.location = '/cgi-bin/koha/catalogue/search.pl?' + decodeURIComponent(me.searchCookie.query) + '&limit=' + decodeURIComponent(me.searchCookie.limit) + '&sort=' + me.searchCookie.sort + '&gotoPage=detail.pl&gotoNumber=last&searchid=' + me.searchid + '&offset=' + (me.offset - me.searchCookie.pagelen);
35
            window.location = '/cgi-bin/koha/catalogue/search.pl?' + decodeURIComponent(current_search.query) + '&limit=' + decodeURIComponent(current_search.limit) + '&sort=' + current_search.sort + '&gotoPage=detail.pl&gotoNumber=last&searchid=' + me.searchid + '&offset=' + (me.offset - current_search.pagelen);
23
        } else {
36
        } else {
24
            window.location = window.location.href.replace('biblionumber=' + biblionumber, 'biblionumber=' + me.searchCookie.results[newSearchPos]);
37
            window.location = window.location.href.replace('biblionumber=' + biblionumber, 'biblionumber=' + current_search.results[newSearchPos]);
25
        }
38
        }
26
    }
39
    }
27
40
28
    this.create = function (offset, query, limit, sort, newresults, total) {
41
    me.create = function (offset, query, limit, sort, newresults, total) {
29
        if (me.searchCookie) {
42
        if (current_search) {
30
            if (offset === me.searchCookie.offset - newresults.length) {
43
            if (offset === current_search.offset - newresults.length) {
31
                me.searchCookie.results = newresults.concat(me.searchCookie.results);
44
                current_search.results = newresults.concat(current_search.results);
32
            } else if (searchOffset = me.searchCookie.offset + newresults.length) {
45
            } else if (searchOffset = current_search.offset + newresults.length) {
33
                me.searchCookie.results = me.searchCookie.results.concat(newresults);
46
                current_search.results = current_search.results.concat(newresults);
34
            } else {
47
            } else {
35
                delete me.searchCookie;
48
                delete current_search;
36
            }
49
            }
37
        }
50
        }
38
        if (!me.searchCookie) {
51
        if (!current_search) {
39
            me.searchCookie = { offset: offset,
52
            current_search = { offset: offset,
40
                query: query,
53
                query: query,
41
                limit: limit,
54
                limit: limit,
42
                sort:  sort,
55
                sort:  sort,
43
                pagelen: newresults.length,
56
                pagelen: newresults.length,
44
                results: newresults,
57
                results: newresults,
45
                total: total
58
                total: total,
59
                searchid: searchid
46
            };
60
            };
47
48
            //Bug_11369 Cleaning up excess searchCookies to prevent cookie overflow in the browser memory.
49
            var allVisibleCookieKeys = Object.keys( $.cookie() );
50
            var scsCookieKeys = $.grep( allVisibleCookieKeys,
51
                function(elementOfArray, indexInArray) {
52
                    return ( elementOfArray.search(/^scs_\d/) != -1 ); //We are looking for specifically staff client searchCookies.
53
                }
54
            );
55
            if (scsCookieKeys.length >= 10) {
56
                scsCookieKeys.sort(); //Make sure they are in order, oldest first!
57
                $.removeCookie( scsCookieKeys[0], { path: '/' } );
58
            }
59
            //EO Bug_11369
60
        }
61
        }
61
        $.cookie(me.searchid, JSON.stringify(me.searchCookie), { path: '/' });
62
        searches[me.searchid] = current_search;
63
        sessionStorage.setItem('searches', JSON.stringify(searches));
62
        $(document).ready(function () {
64
        $(document).ready(function () {
63
            //FIXME It's not a good idea to modify the click events
65
            //FIXME It's not a good idea to modify the click events
64
            $('#searchresults table tr a[href*="detail.pl"]').on('click', function (ev) {
66
            $('#searchresults table tr a[href*="detail.pl"]').on('click', function (ev) {
Lines 80-101 KOHA.browser = function (searchid, biblionumber) { Link Here
80
        });
82
        });
81
    };
83
    };
82
84
83
    this.show = function () {
85
    me.show = function () {
84
        if (me.searchCookie) {
86
        if (current_search) {
85
            me.curPos = $.inArray(biblionumber, me.searchCookie.results);
87
            me.curPos = $.inArray(biblionumber, current_search.results);
86
            me.offset = Math.floor((me.searchCookie.offset + me.curPos - 1) / me.searchCookie.pagelen) * me.searchCookie.pagelen;
88
            me.offset = Math.floor((current_search.offset + me.curPos - 1) / current_search.pagelen) * current_search.pagelen;
87
89
88
            $(document).ready(function () {
90
            $(document).ready(function () {
89
                if (me.curPos > -1) {
91
                if (me.curPos > -1) {
90
                    var searchURL = '/cgi-bin/koha/catalogue/search.pl?' + decodeURIComponent(me.searchCookie.query) + '&limit=' + decodeURIComponent(me.searchCookie.limit) + '&sort=' + me.searchCookie.sort + '&searchid=' + me.searchid + '&offset=' + me.offset;
92
                    var searchURL = '/cgi-bin/koha/catalogue/search.pl?' + decodeURIComponent(current_search.query) + '&limit=' + decodeURIComponent(current_search.limit) + '&sort=' + current_search.sort + '&searchid=' + me.searchid + '&offset=' + me.offset;
91
                    var prevbutton;
93
                    var prevbutton;
92
                    var nextbutton;
94
                    var nextbutton;
93
                    if (me.curPos === 0 && me.searchCookie.offset === 1) {
95
                    if (me.curPos === 0 && current_search.offset === 1) {
94
                        prevbutton = '<span id="browse-previous" class="browse-button">« ' + BROWSER_PREVIOUS + '</span>';
96
                        prevbutton = '<span id="browse-previous" class="browse-button">« ' + BROWSER_PREVIOUS + '</span>';
95
                    } else {
97
                    } else {
96
                        prevbutton = '<a href="#" id="browse-previous" class="browse-button">« ' + BROWSER_PREVIOUS + '</a>';
98
                        prevbutton = '<a href="#" id="browse-previous" class="browse-button">« ' + BROWSER_PREVIOUS + '</a>';
97
                    }
99
                    }
98
                    if (me.searchCookie.offset + me.curPos == me.searchCookie.total) {
100
                    if (current_search.offset + me.curPos == current_search.total) {
99
                        nextbutton = '<span id="browse-next" class="browse-button">' + BROWSER_NEXT + ' »</span>';
101
                        nextbutton = '<span id="browse-next" class="browse-button">' + BROWSER_NEXT + ' »</span>';
100
                    } else {
102
                    } else {
101
                        nextbutton = '<a href="#" id="browse-next" class="browse-button">' + BROWSER_NEXT + ' »</a>';
103
                        nextbutton = '<a href="#" id="browse-next" class="browse-button">' + BROWSER_NEXT + ' »</a>';
102
- 

Return to bug 13265