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