Bug 22888: Use DataTables for Koha news table filtering
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / tools / koha-news.tt
blobfe88908ff84296e06d99fcd84c26bf7a30a7fde9
1 [% USE raw %]
2 [% USE Asset %]
3 [% USE KohaDates %]
4 [% USE Branches %]
5 [% SET footerjs = 1 %]
6 [% INCLUDE 'doc-head-open.inc' %]
7 <title>Koha &rsaquo; Tools &rsaquo; News</title>
8 [% INCLUDE 'doc-head-close.inc' %]
9 [% IF ( opac_news_count ) %]
10 [% END %]
11 </head>
13 <body id="tools_koha-news" class="tools">
14 [% INCLUDE 'header.inc' %]
15 [% INCLUDE 'cat-search.inc' %]
17 <div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a> &rsaquo; [% IF ( add_form ) %]<a href="/cgi-bin/koha/tools/koha-news.pl">News</a> &rsaquo; [% IF ( id ) %]
18 Edit news item[% ELSE %]Add news item[% END %][% ELSE %]News[% END %]</div>
20 [% IF ( add_form ) %]
21     <div class="main container-fluid">
22         <div class="row">
23             <div class="col-md-10 col-md-offset-1 col-lg-8 col-lg-offset-2">
24 [% ELSE %]
25     <div class="main container-fluid">
26         <div class="row">
27             <div class="col-sm-10 col-sm-push-2">
28 [% END %]
29                 <main>
31 [% UNLESS ( add_form ) %]
32     [% IF error_message == 'title_missing' %]
33         <div class="dialog alert">Error: Required news title missing!</div>
34     [% END %]
35 <h2>News</h2>
36 <div id="toolbar" class="btn-toolbar">
37     <a class="btn btn-default" id="newentry" href="/cgi-bin/koha/tools/koha-news.pl?op=add_form&amp;lang=[% lang | html %]"><i class="fa fa-plus"></i> New entry</a>
38 </div>
39 [% END %]
41 [% IF ( add_form ) %]
42     [% IF ( op == 'add' ) %]
43         [% default_lang = lang %]
44     [% ELSE %]
45         [% default_lang = new_detail.lang %]
46     [% END %]
47         <form name="add_form" method="post" action="/cgi-bin/koha/tools/koha-news.pl" >
48             <input type="hidden" name="op" value="[% op | html %]" />
49             <input type="hidden" name="id" value="[% id | html %]" />
50                         <fieldset class="rows">
51             <legend>OPAC and Koha news</legend>
52            <ol> <li>
53             <label for="lang">Display location:</label>
54             <select id="lang" name="lang">
55                 [% PROCESS lang_locations language => default_lang %]
56             </select>
57             </li>
58             <li>
59                 <label for="branch">Library: </label>
60                 <select id="branch" name="branch">
61                     [% IF ( new_detail.branchcode == '' ) %]
62                         <option value="" selected="selected">All libraries</option>
63                     [% ELSE %]
64                         <option value=""         >All libraries</option>
65                     [% END %]
66                     [% PROCESS options_for_libraries libraries => Branches.all( selected => new_detail.branchcode, unfiltered => 1, ) %]
67                 </select>
68             </li>
69             <li>
70                 <label for="title" class="required">Title: </label>
71                 <input id="title" size="30" type="text" name="title" value="[% new_detail.title | html %]" required="required" class="required" /> <span class="required">Required</span>
72             </li>
73             <li>
74                 <label for="from">Publication date: </label>
75                 <input id="from" type="text" name="timestamp" size="15" value="[% new_detail.timestamp | html %]" class="datepickerfrom" />
76                                 <div class="hint">[% INCLUDE 'date-format.inc' %]</div>
77             </li>
78             <li>
79                 <label for="to">Expiration date: </label>
80                 <input id="to" type="text" name="expirationdate" size="15" value="[% new_detail.expirationdate | html %]" class="datepickerto" />
81                 <div class="hint">
82                     [% INCLUDE 'date-format.inc' %]
83                     <br>News will still be accessible by direct URL if expired.
84                 </div>
85             </li>
86             <li>
87                 <label for="number">Appear in position: </label>
88                 [% IF ( new_detail.number ) %]
89                     <input id="number" size="3" name="number" type="text" value="[% new_detail.number | html %]" />
90                 [% ELSE %]
91                     <input id="number" size="3" name="number" type="text" />
92                 [% END %]
93             </li>
94             <li><label for="content">News: </label>
95             <textarea name="content" id="content"  cols="75" rows="10">[% new_detail.content | $raw %]</textarea>
96             </li>
97             </ol>
98                         </fieldset>
99   
100                 <fieldset class="action"><input class="button" type="submit" value="Submit" /> <a class="cancel" href="/cgi-bin/koha/tools/koha-news.pl">Cancel</a></fieldset>
101         </form>
102     [% ELSE %]
103         [% IF ( opac_news_count ) %]
104         <form id="del_form" method="post" action="/cgi-bin/koha/tools/koha-news.pl">
105                 <table id="newst">
106                    <thead> <tr>
107                         <th>&nbsp;</th>
108                         <th>Location</th>
109                         <th>Library</th>
110                         <th>Number</th>
111                         <th class="title-string">Publication date</th>
112                         <th class="title-string">Expiration date</th>
113                         <th>Title</th>
114                         <th>Author</th>
115                         <th>News</th>
116                         <th>Actions</th>
117                     </tr></thead>
118                     <tbody>[% FOREACH opac_new IN opac_news %]
119                          [% IF ( opac_new.expired ) %]
120                             <tr class="expired">
121                             [% ELSE %]
122                             <tr>
123                             [% END %]
124                             <td>
125                                 <input type="checkbox" name="ids" value="[% opac_new.idnew | html %]" />
126                             </td>
127                             <td>[% SWITCH opac_new.lang %]
128                                 [%   CASE "koha" %]
129                                     Librarian interface
130                                 [%   CASE "slip" %]
131                                     Slip
132                                 [%   CASE "" %]
133                                     All
134                                 [%   CASE %]
135                                     OPAC ([% opac_new.lang | html %])
136                                 [% END %]
137                              </td>
138                             <td>[% IF ( opac_new.branchcode == "" ) -%]
139                                 All libraries
140                                 [% ELSE %][% opac_new.branchname | html %]
141                                 [% END %]</td>
142                             <td>[% opac_new.number | html %]</td>
143                             <td><span title="[% opac_new.newdate | html %]">[% opac_new.newdate | $KohaDates %]</span></td>
144                             <td><span title="[% opac_new.expirationdate | html %]">[% opac_new.expirationdate | $KohaDates %] [% IF ( opac_new.expired ) %](<span class="expired">expired</span>)[% END %]</span></td>
145                             <td>[% opac_new.title | html %]</td>
146                             <td>[% opac_new.author_title | html %] [% opac_new.author_firstname | html %] [% opac_new.author_surname | html %]</td>
147                            <td>
148                                 [% opac_new.content | $raw %]
149                             </td>
150                             <td class="actions">
151                                 <a href="/cgi-bin/koha/tools/koha-news.pl?op=add_form&amp;id=[% opac_new.idnew | uri %]" class="btn btn-default btn-xs"><i class="fa fa-pencil"></i> Edit</a>
152                                 <a href="/cgi-bin/koha/tools/koha-news.pl?op=del&amp;ids=[% opac_new.idnew | uri %]" class="delete_news btn btn-default btn-xs"><i class="fa fa-trash"></i> Delete</a>
153                             </td>
154                         </tr>
155                     [% END %]</tbody>
156                 </table>
157                 <input type="hidden" name="op" value="del" />
158                 <fieldset class="action"><input type="submit" class="button" value="Delete selected" /></fieldset>
159             </form>
160         [% ELSE %]
161             <div class="dialog message">There are no news items.</div>
162         [% END %]
163     [% END %]
165                 </main>
166             [% UNLESS ( add_form ) %]
167                 </div> <!-- /.col-sm-10.col-sm-push-2 -->
169                 <div class="col-sm-2 col-sm-pull-10">
170                     <aside>
172                         <div id="news-filter">
173                             <form action="/cgi-bin/koha/tools/koha-news.pl" method="get">
174                                 <h4>Filter</h4>
175                                 <fieldset class="brief">
176                                     <ol>
177                                         <li>
178                                             <label for="news_keyword">Keyword:</label>
179                                             <input type="text" name="news_keyword" id="news_keyword" />
180                                         </li>
181                                         <li>
182                                             <label for="news_display_location">Display location:</label>
183                                             <select name="news_display_location" id="news_display_location">
184                                                 [% PROCESS lang_locations %]
185                                             </select>
186                                         </li>
187                                         <li>
188                                             <label for="news_library">Library: </label>
189                                             <select id="news_library" name="news_library">
190                                                 <option value=""></option>
191                                                 <option value="">All libraries</option>
192                                                 [% PROCESS options_for_libraries libraries => Branches.all( selected => branchcode, unfiltered => 1, ) %]
193                                             </select>
194                                         </li>
195                                     </ol>
196                                 </fieldset>
197                             </form>
198                         </div>
200                         [% INCLUDE 'tools-menu.inc' %]
201                     </aside>
202                 </div> <!-- /.col-sm-2.col-sm-pull-10 -->
203             [% END %]
204         </div> <!-- /.row -->
206 [% MACRO jsinclude BLOCK %]
207     [% INCLUDE 'calendar.inc' %]
208     [% Asset.js("js/tools-menu.js") | $raw %]
209     [% IF ( opac_news_count ) %]
210         [% INCLUDE 'datatables.inc' %]
211         <script>
212             function Checkbox(){
213                 var form = document.getElementById('del_form');
214                 var inputs = form.getElementsByTagName('input');
215                 var checked = false;
216                 for (var i=0; i<inputs.length; i++) {
217                     if (inputs[i].type == 'checkbox' && inputs[i].name == 'ids') {
218                         checked = inputs[i].checked;
219                         if (checked) return true;
220                     }
221                 }
222             }
224             function filterDataTable( table, column, term ){
225                 if( column ){
226                     table.column( column ).search( term ).draw();
227                 } else {
228                     table.search( term ).draw();
229                 }
230                 clearFilter( term );
231             }
233             function clearFilter( term ){
234                 if( term == "" ){
235                     $(".dt_button_clear_filter").addClass("disabled");
236                 } else {
237                     $(".dt_button_clear_filter").removeClass("disabled");
238                 }
239             }
241             $(document).ready(function() {
242                 var newst = $("#newst").DataTable($.extend(true, {}, dataTablesDefaults, {
243                     "aoColumnDefs": [
244                         { "aTargets": [ 0,-1,-2 ], "bSortable": false },
245                         { "aTargets": [ 0, -1 ], "bSearchable": false },
246                         { 'sType': "title-string", 'aTargets' : [ 'title-string'] }
247                     ],
248                     "sPaginationType": "full_numbers"
249                 }));
251                 $(".delete_news").on("click", function(){
252                     return confirmDelete( _("Are you sure you want to delete this news item? This cannot be undone.") );
253                 });
255                 $("#del_form").on("submit",function(){
256                     if ( Checkbox() ) {
257                         return confirmDelete( _("Are you sure you want to delete the selected news?") );
258                     } else {
259                         alert(_("Please select a news item to delete."));
260                         return false;
261                     }
262                 });
264                 newst.on( 'search.dt', function () {
265                     var term = newst.search();
266                     $("#news_keyword").val( term );
267                 });
269                 $("#news_keyword").on("keyup", function(){
270                     var term = $(this).val();
271                     filterDataTable( newst, null, term );
272                 });
274                 $("#news_display_location").on("change", function(){
275                     var term = $(this).val();
276                     filterDataTable( newst, 1, term );
277                 });
279                 $("#news_library").on("change", function(){
280                     // Table must be filtered by the <option>'s text, not its value
281                     var opt = $(this).find("option:selected").text();
282                     filterDataTable( newst, 2, opt );
283                 });
285                 $(".dt_button_clear_filter").on("click", function(){
286                     newst.search('').columns().search('').draw();
287                     $("#news-filter select").each(function(){
288                         $(this).val("");
289                     });
290                 });
291             });
292         </script>
293     [% END %]
294     [% Asset.js("lib/tiny_mce/tiny_mce.js") | $raw %]
295     <script>
296         tinyMCE.baseURL = "[% interface | html %]/lib/tiny_mce";
297         tinyMCE.init({
298             mode : "textareas",
299             theme : "advanced",
300             convert_urls : false,
301             relative_urls : false,
302             content_css : "[% interface | html %]/[% theme | html %]/css/tinymce.css",
303             plugins : "table,save,advhr,advlink,searchreplace,print,contextmenu",
304             theme_advanced_buttons1 : "save,|,bold,italic,|,cut,copy,paste,|,search,replace,|,justifyleft,justifycenter,justifyright,justifyfull,|,formatselect,|,link,unlink,anchor,cleanup,help,code,advhr,|,print",
305             theme_advanced_buttons2 : "tablecontrols,|,bullist,numlist,|,outdent,indent,|,undo,redo,|,removeformat,|,visualaid,|,sub,sup,|,charmap",
306             theme_advanced_buttons3 : "",
307             theme_advanced_toolbar_location : "top",
308             theme_advanced_toolbar_align : "left",
309             theme_advanced_path_location : "bottom",
310             theme_advanced_resizing : true,
311             plugin_insertdate_dateFormat : "%Y-%m-%d",
312             plugin_insertdate_timeFormat : "%H:%M:%S",
313             apply_source_formatting : true,
314             height : "300",
315             width : "700"
316         });
317     </script>
318 [% END %]
320 [% BLOCK lang_locations %]
321     [% IF ( language == "" ) %]
322         <option value="" selected="selected"></option>
323     [% ELSE %]
324         <option value="">All</option>
325     [% END %]
326     [% IF ( language == "koha" ) %]
327         <option value="koha" selected="selected">Librarian interface</option>
328     [% ELSE %]
329         <option value="koha">Librarian interface</option>
330     [% END %]
331     [% IF ( language == "slip" ) %]
332         <option value="slip" selected="selected">Slip</option>
333     [% ELSE %]
334         <option value="slip">Slip</option>
335     [% END %]
336     [% FOREACH lang_lis IN lang_list %]
337         <optgroup label="[% lang_lis.language | html %]">
338             [% FOREACH location IN [ '', 'OpacNavRight' ] %]
339                 [% IF ( location == '' ) %]
340                     [% SET location_lang = lang_lis.language %]
341                     [% location = BLOCK %]OPAC news[% END %]
342                 [% ELSE %]
343                     [% SET location_lang = location _ "_" _ lang_lis.language %]
344                 [% END %]
345                 [% IF ( location_lang == language ) %]
346                     <option value="[% location_lang | html %]" selected="selected">[% location | html %] ([% lang_lis.language | html %])</option>
347                 [% ELSE %]
348                     <option value="[% location_lang | html %]">[% location | html %] ([% lang_lis.language | html %])</option>
349                 [% END %]
350             [% END %]
351         </optgroup>
352     [% END %]
353 [% END %]
355 [% INCLUDE 'intranet-bottom.inc' %]