1 if ( KOHA === undefined ) var KOHA = {};
3 KOHA.browser = function (searchid, biblionumber) {
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
10 me.searchid = searchid;
12 var searches_stored = sessionStorage.getItem('searches');
15 if ( searches_stored ) {
16 searches = JSON.parse(searches_stored);
17 current_search = searches[me.searchid];
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]];
30 var browseRecords = function (movement) {
31 var newSearchPos = me.curPos + movement;
32 if (newSearchPos > current_search.results.length - 1) {
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;
34 } else if (newSearchPos < 0) {
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);
37 window.location = window.location.href.replace('biblionumber=' + biblionumber, 'biblionumber=' + current_search.results[newSearchPos]);
41 me.create = function (offset, query, limit, sort, newresults, total) {
43 if (offset === current_search.offset - newresults.length) {
44 current_search.results = newresults.concat(current_search.results);
45 } else if (searchOffset = current_search.offset + newresults.length) {
46 current_search.results = current_search.results.concat(newresults);
48 delete current_search;
51 if (!current_search) {
52 current_search = { offset: offset,
56 pagelen: newresults.length,
62 searches[me.searchid] = current_search;
63 sessionStorage.setItem('searches', JSON.stringify(searches));
64 $(document).ready(function () {
65 //FIXME It's not a good idea to modify the click events
66 $('#searchresults table tr a[href*="/detail.pl"]').on('click', function (ev) {
69 $('#searchresults table tr a[href*="/detail.pl"]').on('mousedown', function (ev) {
70 if ( ev.which == 2 || ev.which == 1 && ev.ctrlKey ) {
71 // Middle click or ctrl + click
73 var newwindow = window.open( $(this).attr('href') + '&searchid=' + me.searchid, '_blank' )
76 } else if ( ev.which == 1 ) {
79 window.location = $(this).attr('href') + '&searchid=' + me.searchid;
85 me.show = function () {
87 me.curPos = $.inArray(biblionumber, current_search.results);
88 me.offset = Math.floor((current_search.offset + me.curPos - 1) / current_search.pagelen) * current_search.pagelen;
90 $(document).ready(function () {
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;
95 if (me.curPos === 0 && current_search.offset === 1) {
96 prevbutton = '<span id="browse-previous" class="browse-button">« ' + BROWSER_PREVIOUS + '</span>';
98 prevbutton = '<a href="#" id="browse-previous" class="browse-button">« ' + BROWSER_PREVIOUS + '</a>';
100 if (current_search.offset + me.curPos == current_search.total) {
101 nextbutton = '<span id="browse-next" class="browse-button">' + BROWSER_NEXT + ' »</span>';
103 nextbutton = '<a href="#" id="browse-next" class="browse-button">' + BROWSER_NEXT + ' »</a>';
105 $('#menu').before('<div class="browse-controls"><div class="browse-controls-inner"><div class="browse-label"><a href="' + searchURL + '" id="browse-return-to-results" class="browse-button searchwithcontext">' + BROWSER_RETURN_TO_SEARCH + '</a></div><div class="browse-prev-next">' + prevbutton + nextbutton + '</div></div></div>');
106 $('a#browse-previous').click(function (ev) {
110 $('a#browse-next').click(function (ev) {
114 $('a[href*="biblionumber="]').not('a[target="_blank"]').click(function (ev) {
116 window.location = $(this).attr('href') + '&searchid=' + me.searchid;
118 $('form[name="f"]').append('<input type="hidden" name="searchid" value="' + me.searchid + '"></input>');