bb50498ae4381ac7efbbd4b98302285c86a8d92d
[srvgit] / koha-tmpl / intranet-tmpl / prog / en / modules / catalogue / search-history.tt
1 [% USE raw %]
2 [% USE Asset %]
3 [% SET footerjs = 1 %]
4 [% INCLUDE 'doc-head-open.inc' %]
5 [% USE Koha %]
6 [% USE KohaDates %]
7 <title>Koha &rsaquo; Catalog &rsaquo; Search history</title>
8 [% INCLUDE 'doc-head-close.inc' %]
9 </head>
10
11 <body id="catalogue_search-history" class="catalogue">
12
13 [% INCLUDE 'header.inc' %]
14 [% INCLUDE 'cat-search.inc' %]
15
16 <div id="breadcrumbs">
17   <a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/catalogue/search.pl">Catalog</a>  &rsaquo; Search history
18 </div>
19
20 <div class="container-fluid">
21     <div class="row">
22         <div class="col-sm-12 col-md-8 col-md-offset-2">
23
24       <h1>Search history</h1>
25       <div id="tabs" class="toptabs">
26         <ul>
27           <li><a href="#biblio_tab">Catalog</a></li>
28           <li><a href="#authority_tab">Authority</a></li>
29         </ul>
30         <div id="biblio_tab">
31           [% IF ( current_biblio_searches ) %]
32             <h2>Current session</h2>
33             <form id="current_cat" action="/cgi-bin/koha/catalogue/search-history.pl" method="post">
34               <p class="selections-toolbar">
35                 <a class="CheckAll" data-form="current_cat" href="#"><i class="fa fa-check"></i> Select all visible rows</a>
36                 <span class="sep">|</span>
37                 <a class="CheckNone" data-form="current_cat" href="#"><i class="fa fa-remove"></i> Clear selection on visible rows</a>
38                 <span class="sep">|</span>
39                 <span class="links">
40                   <span class="selections">Select searches to: </span>
41                   <a href="#" class="action_delete disabled">Delete</a>
42                 </span>
43               </p>
44               <input type="hidden" name="action" value="delete" />
45               <table class="historyt">
46                 <thead>
47                   <tr>
48                     <th></th>
49                     <th>Date</th>
50                     <th>Search</th>
51                     <th>Results</th>
52                   </tr>
53                 </thead>
54                 <tbody>
55                 [% FOREACH s IN current_biblio_searches %]
56                   <tr>
57                     <td><input type="checkbox" name="id" value="[% s.id | html %]" /></td>
58                     <td><span title="[% s.time | html %]">[% s.time |$KohaDates  with_hours => 1 %]</span></td>
59                     <td><a href="/cgi-bin/koha/catalogue/search.pl?[% s.query_cgi | $raw %]">[% s.query_desc | html %]</a></td>
60                     <td>[% s.total | html %]</td>
61                   </tr>
62                 [% END %]
63                 </tbody>
64               </table>
65             </form>
66           [% END %]
67
68             [% IF ( current_biblio_searches && previous_biblio_searches) %]
69                 <hr />
70             [% END %]
71
72           [% IF ( previous_biblio_searches ) %]
73             <h2>Previous sessions</h2>
74             <form id="previous_cat" action="/cgi-bin/koha/catalogue/search-history.pl" method="post">
75               <p class="selections-toolbar">
76                 <a class="CheckAll" data-form="previous_cat" href="#"><i class="fa fa-check"></i> Select all visible rows</a>
77                 <span class="sep">|</span>
78                 <a class="CheckNone" data-form="previous_cat" href="#"><i class="fa fa-remove"></i> Clear selection on visible rows</a>
79                 <span class="sep">|</span>
80                 <span class="links">
81                   <span class="selections">Select searches to: </span>
82                   <a href="#" class="action_delete disabled">Delete</a>
83                 </span>
84               </p>
85               <input type="hidden" name="action" value="delete" />
86               <table class="historyt">
87                 <thead>
88                   <tr>
89                     <th></th>
90                     <th>Date</th>
91                     <th>Search</th>
92                     <th>Results</th>
93                   </tr>
94                 </thead>
95                 <tbody>
96                 [% FOREACH s IN previous_biblio_searches %]
97                   <tr>
98                     <td><input type="checkbox" name="id" value="[% s.id | html %]" /></td>
99                     <td><span title="[% s.time | html %]">[% s.time |$KohaDates  with_hours => 1 %]</span></td>
100                     <td><a href="/cgi-bin/koha/catalogue/search.pl?[% s.query_cgi | $raw %]">[% s.query_desc | html %]</a></td>
101                     <td>[% s.total | html %]</td>
102                   </tr>
103                 [% END %]
104                 </tbody>
105               </table>
106             </form>
107           [% END %]
108
109           [% IF !current_biblio_searches && !previous_biblio_searches %]
110             <p>Your catalog search history is empty.</p>
111           [% END %]
112         </div>
113
114         <div id="authority_tab">
115           [% IF ( current_authority_searches ) %]
116             <h2>Current session</h2>
117             <form id="current_auth" action="/cgi-bin/koha/catalogue/search-history.pl" method="post">
118               <p class="selections-toolbar">
119                 <a class="CheckAll" data-form="current_auth" href="#"><i class="fa fa-check"></i> Select all visible rows</a>
120                 <span class="sep">|</span>
121                 <a class="CheckNone" data-form="current_auth" href="#"><i class="fa fa-remove"></i> Clear selection on visible rows</a>
122                 <span class="sep">|</span>
123                 <span class="links">
124                   <span class="selections">Select searches to: </span>
125                   <a href="#" class="action_delete disabled">Delete</a>
126                 </span>
127               </p>
128               <input type="hidden" name="action" value="delete" />
129               <table class="historyt">
130                 <thead>
131                   <tr>
132                     <th></th>
133                     <th>Date</th>
134                     <th>Search</th>
135                     <th>Results</th>
136                   </tr>
137                 </thead>
138                 <tbody>
139                 [% FOREACH s IN current_authority_searches %]
140                   <tr>
141                     <td><input type="checkbox" name="id" value="[% s.id | html %]" /></td>
142                     <td><span title="[% s.time | html %]">[% s.time |$KohaDates  with_hours => 1 %]</span></td>
143                     <td><a href="/cgi-bin/koha/authorities/authorities-home.pl?[% s.query_cgi | $raw %]">[% s.query_desc | html %]</a></td>
144                     <td>[% s.total | html %]</td>
145                   </tr>
146                 [% END %]
147                 </tbody>
148               </table>
149             </form>
150           [% END %]
151
152             [% IF ( current_authority_searches && previous_authority_searches) %]
153                 <hr />
154             [% END %]
155
156           [% IF ( previous_authority_searches ) %]
157             <h2>Previous sessions</h2>
158             <form id="previous_auth" action="/cgi-bin/koha/catalogue/search-history.pl" method="post">
159               <p class="selections-toolbar">
160                 <a class="CheckAll" data-form="previous_auth" href="#"><i class="fa fa-check"></i> Select all visible rows</a>
161                 <span class="sep">|</span>
162                 <a class="CheckNone" data-form="previous_auth" href="#"><i class="fa fa-remove"></i> Clear selection on visible rows</a>
163                 <span class="sep">|</span>
164                 <span class="links">
165                   <span class="selections">Select searches to: </span>
166                   <a href="#" class="action_delete disabled">Delete</a>
167                 </span>
168               </p>
169               <input type="hidden" name="action" value="delete" />
170               <table class="historyt">
171                 <thead>
172                   <tr>
173                     <th></th>
174                     <th>Date</th>
175                     <th>Search</th>
176                     <th>Results</th>
177                   </tr>
178                 </thead>
179                 <tbody>
180                 [% FOREACH s IN previous_authority_searches %]
181                   <tr>
182                     <td><input type="checkbox" name="id" value="[% s.id | html %]" /></td>
183                     <td><span title="[% s.time | html %]">[% s.time |$KohaDates  with_hours => 1 %]</span></td>
184                     <td><a href="/cgi-bin/koha/authorities/authorities-home.pl?[% s.query_cgi | $raw %]">[% s.query_desc | html %]</a></td>
185                     <td>[% s.total | html %]</td>
186                   </tr>
187                 [% END %]
188                 </tbody>
189               </table>
190             </form>
191           [% END %]
192
193           [% IF !current_authority_searches && !previous_authority_searches %]
194             <p>Your authority search history is empty.</p>
195           [% END %]
196         </div> [% # /authority_tab %]
197       </div> [% # /tabs %]
198     </div> [% # /div.col-md-8 %]
199   </div> [% # /div.row %]
200
201 [% MACRO jsinclude BLOCK %]
202     [% INCLUDE 'datatables.inc' %]
203     <script>
204     $(document).ready(function() {
205         // We show table ordered by descending dates by default
206         // (so that the more recent query is shown first)
207         $(".historyt").dataTable($.extend(true, {}, dataTablesDefaults, {
208             "aaSorting": [[ 1, "desc" ]],
209             "aoColumnDefs": [
210                 { "aTargets": [ 0 ], "bSortable": false, "bSearchable": false },
211                 { "aTargets": [ 1 ], "sType": "title-string" },
212             ],
213             "sPaginationType": "full_numbers"
214         }));
215
216         $('#tabs').tabs();
217
218         // DataTables removes hidden rows from the DOM, so we can't expect a
219         // "regular" submit to work and we need to build another form containing
220         // all form elements, and then submit this form.
221         $('#tabs form').submit(function(e) {
222             e.preventDefault();
223
224             var form = $(this);
225             var table = form.find('table').dataTable();
226
227             var new_form = $('<form>')
228                 .attr('action', form.attr('action'))
229                 .attr('method', form.attr('method'));
230             form.find('input[type="hidden"]')
231                 .add(table.$('input:checkbox:checked'))
232                 .each(function() {
233                     var input = $('<input type="hidden">')
234                         .attr('name', $(this).attr('name'))
235                         .attr('value', $(this).attr('value'));
236                     new_form.append(input);
237                 });
238             $(document.body).append(new_form);
239             new_form.submit();
240         });
241
242         $(".CheckNone").click(function(e){
243             e.preventDefault();
244             var form = $(this).data("form");
245             $("#" + form ).find('table input[type="checkbox"]').prop('checked', false);
246             enableCheckboxActions($("#" + form ));
247         });
248         $(".CheckAll").click(function(e){
249             e.preventDefault();
250             var form = $(this).data("form");
251             $("#" + form ).find('table input[type="checkbox"]').prop('checked', true);
252             enableCheckboxActions($("#" + form ));
253         });
254
255         $('#tabs table').on('click', 'input:checkbox', function() {
256             var form = $(this).parents("form").first();
257             enableCheckboxActions(form);
258         });
259
260         $(".action_delete").click(function(e){
261             e.preventDefault();
262             var form = $(this).parents("form").first();
263             var table = form.find('table').dataTable();
264             var ids = table.$("input:checkbox:checked");
265             if ( $(ids).length < 1 ) {
266                 return false;
267             }
268
269             var msg;
270             if (ids.length == 1) {
271               msg = _("Are you sure you want to delete the selected search history entry?");
272             } else {
273               msg = _("Are you sure you want to delete the %s selected search history entries?").format(ids.length);
274             }
275
276             if ( confirm(msg) ) {
277                 form.submit();
278             }
279             return false;
280         });
281
282         $('#tabs form').each(function() {
283             enableCheckboxActions($(this));
284         });
285     });
286
287     function enableCheckboxActions(form){
288         // Enable/disable controls if checkboxes are checked
289         var table = form.find('table').dataTable();
290         var checked_count = table.$("input:checkbox:checked").length;
291         if (checked_count) {
292           if (checked_count == 1) {
293             form.find(".selections").html(_("With selected search: "));
294           } else {
295             form.find(".selections").html(_("With %s selected searches: ").format(checked_count));
296           }
297           form.find(".selections-toolbar .links a").removeClass("disabled");
298         } else {
299           form.find(".selections").html(_("Select searches to: "));
300           form.find(".selections-toolbar .links a").addClass("disabled");
301         }
302     }
303
304     </script>
305 [% END %]
306
307 [% INCLUDE 'intranet-bottom.inc' %]