]> git.koha-community.org Git - koha.git/blob - koha-tmpl/intranet-tmpl/prog/en/modules/tools/koha-news.tt
Bug 23279: In news management interface, sort news by publication date descending
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / tools / koha-news.tt
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>
12
13 <body id="tools_koha-news" class="tools">
14 [% INCLUDE 'header.inc' %]
15 [% INCLUDE 'cat-search.inc' %]
16
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>
19
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>
30
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 %]
40
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 class="NoSort">&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 class="anti-the">Title</th>
114                         <th>Author</th>
115                         <th class="anti-the">News</th>
116                         <th class="NoSort">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 %]
164
165                 </main>
166             [% UNLESS ( add_form ) %]
167                 </div> <!-- /.col-sm-10.col-sm-push-2 -->
168
169                 <div class="col-sm-2 col-sm-pull-10">
170                     <aside>
171
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>
199
200                         [% INCLUDE 'tools-menu.inc' %]
201                     </aside>
202                 </div> <!-- /.col-sm-2.col-sm-pull-10 -->
203             [% END %]
204         </div> <!-- /.row -->
205
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             }
223
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             }
232
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             }
240
241             $(document).ready(function() {
242                 var newst = $("#newst").DataTable($.extend(true, {}, dataTablesDefaults, {
243                     "order": [[ 4, "desc" ]],
244                     "aoColumnDefs": [
245                         { "sortable": false, "searchable": false, 'targets': [ 'NoSort' ] },
246                         { "type": "anti-the", "targets": [ "anti-the" ] },
247                         { "type": "title-string", "targets" : [ "title-string"] }
248                     ],
249                     "sPaginationType": "full_numbers"
250                 }));
251
252                 $(".delete_news").on("click", function(){
253                     return confirmDelete( _("Are you sure you want to delete this news item? This cannot be undone.") );
254                 });
255
256                 $("#del_form").on("submit",function(){
257                     if ( Checkbox() ) {
258                         return confirmDelete( _("Are you sure you want to delete the selected news?") );
259                     } else {
260                         alert(_("Please select a news item to delete."));
261                         return false;
262                     }
263                 });
264
265                 newst.on( 'search.dt', function () {
266                     var term = newst.search();
267                     $("#news_keyword").val( term );
268                 });
269
270                 $("#news_keyword").on("keyup", function(){
271                     var term = $(this).val();
272                     filterDataTable( newst, null, term );
273                 });
274
275                 $("#news_display_location").on("change", function(){
276                     var term = $(this).val();
277                     filterDataTable( newst, 1, term );
278                 });
279
280                 $("#news_library").on("change", function(){
281                     // Table must be filtered by the <option>'s text, not its value
282                     var opt = $(this).find("option:selected").text();
283                     filterDataTable( newst, 2, opt );
284                 });
285
286                 $(".dt_button_clear_filter").on("click", function(){
287                     newst.search('').columns().search('').draw();
288                     $("#news-filter select").each(function(){
289                         $(this).val("");
290                     });
291                 });
292             });
293         </script>
294     [% END %]
295     [% Asset.js("lib/tiny_mce/tiny_mce.js") | $raw %]
296     <script>
297         tinyMCE.baseURL = "[% interface | html %]/lib/tiny_mce";
298         tinyMCE.init({
299             mode : "textareas",
300             theme : "advanced",
301             convert_urls : false,
302             relative_urls : false,
303             content_css : "[% interface | html %]/[% theme | html %]/css/tinymce.css",
304             plugins : "table,save,advhr,advlink,searchreplace,print,contextmenu",
305             theme_advanced_buttons1 : "save,|,bold,italic,|,cut,copy,paste,|,search,replace,|,justifyleft,justifycenter,justifyright,justifyfull,|,formatselect,|,link,unlink,anchor,cleanup,help,code,advhr,|,print",
306             theme_advanced_buttons2 : "tablecontrols,|,bullist,numlist,|,outdent,indent,|,undo,redo,|,removeformat,|,visualaid,|,sub,sup,|,charmap",
307             theme_advanced_buttons3 : "",
308             theme_advanced_toolbar_location : "top",
309             theme_advanced_toolbar_align : "left",
310             theme_advanced_path_location : "bottom",
311             theme_advanced_resizing : true,
312             plugin_insertdate_dateFormat : "%Y-%m-%d",
313             plugin_insertdate_timeFormat : "%H:%M:%S",
314             apply_source_formatting : true,
315             height : "300",
316             width : "700"
317         });
318     </script>
319 [% END %]
320
321 [% BLOCK lang_locations %]
322     [% IF ( language == "" ) %]
323         <option value="" selected="selected"></option>
324     [% ELSE %]
325         <option value="">All</option>
326     [% END %]
327     [% IF ( language == "koha" ) %]
328         <option value="koha" selected="selected">Librarian interface</option>
329     [% ELSE %]
330         <option value="koha">Librarian interface</option>
331     [% END %]
332     [% IF ( language == "slip" ) %]
333         <option value="slip" selected="selected">Slip</option>
334     [% ELSE %]
335         <option value="slip">Slip</option>
336     [% END %]
337     [% FOREACH lang_lis IN lang_list %]
338         <optgroup label="[% lang_lis.language | html %]">
339             [% FOREACH location IN [ '', 'OpacNavRight' ] %]
340                 [% IF ( location == '' ) %]
341                     [% SET location_lang = lang_lis.language %]
342                     [% location = BLOCK %]OPAC news[% END %]
343                 [% ELSE %]
344                     [% SET location_lang = location _ "_" _ lang_lis.language %]
345                 [% END %]
346                 [% IF ( location_lang == language ) %]
347                     <option value="[% location_lang | html %]" selected="selected">[% location | html %] ([% lang_lis.language | html %])</option>
348                 [% ELSE %]
349                     <option value="[% location_lang | html %]">[% location | html %] ([% lang_lis.language | html %])</option>
350                 [% END %]
351             [% END %]
352         </optgroup>
353     [% END %]
354 [% END %]
355
356 [% INCLUDE 'intranet-bottom.inc' %]