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