Bug 22660: Add system pref to allow switching of editors in News Tool
[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 [% Asset.css("lib/codemirror/codemirror.css") | $raw %]
8 <style>
9 .CodeMirror {
10     resize: vertical;
11 }
12 </style>
13 <title>Koha &rsaquo; Tools &rsaquo; News</title>
14 [% INCLUDE 'doc-head-close.inc' %]
15 [% IF ( opac_news_count ) %]
16 [% END %]
17 </head>
18
19 <body id="tools_koha-news" class="tools">
20 [% INCLUDE 'header.inc' %]
21 [% INCLUDE 'cat-search.inc' %]
22
23 <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 ) %]
24 Edit news item[% ELSE %]Add news item[% END %][% ELSE %]News[% END %]</div>
25
26 [% IF ( add_form ) %]
27     <div class="main container-fluid">
28         <div class="row">
29             <div class="col-md-10 col-md-offset-1 col-lg-8 col-lg-offset-2">
30 [% ELSE %]
31     <div class="main container-fluid">
32         <div class="row">
33             <div class="col-sm-10 col-sm-push-2">
34 [% END %]
35                 <main>
36
37 [% UNLESS ( add_form ) %]
38     [% IF error_message == 'title_missing' %]
39         <div class="dialog alert">Error: Required news title missing!</div>
40     [% END %]
41 <h2>News</h2>
42 <div id="toolbar" class="btn-toolbar">
43     <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>
44 </div>
45 [% END %]
46
47 [% IF ( add_form ) %]
48     [% IF ( op == 'add' ) %]
49         [% default_lang = lang %]
50     [% ELSE %]
51         [% default_lang = new_detail.lang %]
52     [% END %]
53         <form name="add_form" method="post" action="/cgi-bin/koha/tools/koha-news.pl" >
54             <input type="hidden" name="op" value="[% op | html %]" />
55             <input type="hidden" name="id" value="[% id | html %]" />
56                         <fieldset class="rows">
57             <legend>OPAC and Koha news</legend>
58            <ol> <li>
59             <label for="lang">Display location:</label>
60             <select id="lang" name="lang">
61                 [% PROCESS lang_locations language => default_lang %]
62             </select>
63             </li>
64             <li>
65                 <label for="branch">Library: </label>
66                 <select id="branch" name="branch">
67                     [% IF ( new_detail.branchcode == '' ) %]
68                         <option value="" selected="selected">All libraries</option>
69                     [% ELSE %]
70                         <option value=""         >All libraries</option>
71                     [% END %]
72                     [% PROCESS options_for_libraries libraries => Branches.all( selected => new_detail.branchcode, unfiltered => 1, ) %]
73                 </select>
74             </li>
75             <li>
76                 <label for="title" class="required">Title: </label>
77                 <input id="title" size="30" type="text" name="title" value="[% new_detail.title | html %]" required="required" class="required" /> <span class="required">Required</span>
78             </li>
79             <li>
80                 <label for="from">Publication date: </label>
81                 <input id="from" type="text" name="timestamp" size="15" value="[% new_detail.timestamp | html %]" class="datepickerfrom" />
82                                 <div class="hint">[% INCLUDE 'date-format.inc' %]</div>
83             </li>
84             <li>
85                 <label for="to">Expiration date: </label>
86                 <input id="to" type="text" name="expirationdate" size="15" value="[% new_detail.expirationdate | html %]" class="datepickerto" />
87                 <div class="hint">
88                     [% INCLUDE 'date-format.inc' %]
89                     <br>News will still be accessible by direct URL if expired.
90                 </div>
91             </li>
92             <li>
93                 <label for="number">Appear in position: </label>
94                 [% IF ( new_detail.number ) %]
95                     <input id="number" size="3" name="number" type="text" value="[% new_detail.number | html %]" />
96                 [% ELSE %]
97                     <input id="number" size="3" name="number" type="text" />
98                 [% END %]
99             </li>
100             <li><label for="content">News: </label>
101             <textarea name="content" id="content"  cols="75" rows="10">[% new_detail.content | $raw %]</textarea>
102             </li>
103             </ol>
104                         </fieldset>
105   
106                 <fieldset class="action"><input class="button" type="submit" value="Submit" /> <a class="cancel" href="/cgi-bin/koha/tools/koha-news.pl">Cancel</a></fieldset>
107         </form>
108     [% ELSE %]
109         [% IF ( opac_news_count ) %]
110         <form id="del_form" method="post" action="/cgi-bin/koha/tools/koha-news.pl">
111                 <table id="newst">
112                    <thead> <tr>
113                         <th class="NoSort">&nbsp;</th>
114                         <th>Location</th>
115                         <th>Library</th>
116                         <th>Number</th>
117                         <th class="title-string">Publication date</th>
118                         <th class="title-string">Expiration date</th>
119                         <th class="anti-the">Title</th>
120                         <th>Author</th>
121                         <th class="anti-the">News</th>
122                         <th class="NoSort">Actions</th>
123                     </tr></thead>
124                     <tbody>[% FOREACH opac_new IN opac_news %]
125                          [% IF ( opac_new.expired ) %]
126                             <tr class="expired">
127                             [% ELSE %]
128                             <tr>
129                             [% END %]
130                             <td>
131                                 <input type="checkbox" name="ids" value="[% opac_new.idnew | html %]" />
132                             </td>
133                             <td>[% SWITCH opac_new.lang %]
134                                 [%   CASE "koha" %]
135                                     Librarian interface
136                                 [%   CASE "slip" %]
137                                     Slip
138                                 [%   CASE "" %]
139                                     All
140                                 [%   CASE %]
141                                     OPAC ([% opac_new.lang | html %])
142                                 [% END %]
143                              </td>
144                             <td>[% IF ( opac_new.branchcode == "" ) -%]
145                                 All libraries
146                                 [% ELSE %][% opac_new.branchname | html %]
147                                 [% END %]</td>
148                             <td>[% opac_new.number | html %]</td>
149                             <td><span title="[% opac_new.newdate | html %]">[% opac_new.newdate | $KohaDates %]</span></td>
150                             <td><span title="[% opac_new.expirationdate | html %]">[% opac_new.expirationdate | $KohaDates %] [% IF ( opac_new.expired ) %](<span class="expired">expired</span>)[% END %]</span></td>
151                             <td>[% opac_new.title | html %]</td>
152                             <td>[% opac_new.author_title | html %] [% opac_new.author_firstname | html %] [% opac_new.author_surname | html %]</td>
153                            <td>
154                                 [% opac_new.content | $raw %]
155                             </td>
156                             <td class="actions">
157                                 <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>
158                                 <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>
159                             </td>
160                         </tr>
161                     [% END %]</tbody>
162                 </table>
163                 <input type="hidden" name="op" value="del" />
164                 <fieldset class="action"><input type="submit" class="button" value="Delete selected" /></fieldset>
165             </form>
166         [% ELSE %]
167             <div class="dialog message">There are no news items.</div>
168         [% END %]
169     [% END %]
170
171                 </main>
172             [% UNLESS ( add_form ) %]
173                 </div> <!-- /.col-sm-10.col-sm-push-2 -->
174
175                 <div class="col-sm-2 col-sm-pull-10">
176                     <aside>
177
178                         <div id="news-filter">
179                             <form action="/cgi-bin/koha/tools/koha-news.pl" method="get">
180                                 <h4>Filter</h4>
181                                 <fieldset class="brief">
182                                     <ol>
183                                         <li>
184                                             <label for="news_keyword">Keyword:</label>
185                                             <input type="text" name="news_keyword" id="news_keyword" />
186                                         </li>
187                                         <li>
188                                             <label for="news_display_location">Display location:</label>
189                                             <select name="news_display_location" id="news_display_location">
190                                                 [% PROCESS lang_locations %]
191                                             </select>
192                                         </li>
193                                         <li>
194                                             <label for="news_library">Library: </label>
195                                             <select id="news_library" name="news_library">
196                                                 <option value=""></option>
197                                                 <option value="">All libraries</option>
198                                                 [% PROCESS options_for_libraries libraries => Branches.all( selected => branchcode, unfiltered => 1, ) %]
199                                             </select>
200                                         </li>
201                                     </ol>
202                                 </fieldset>
203                             </form>
204                         </div>
205
206                         [% INCLUDE 'tools-menu.inc' %]
207                     </aside>
208                 </div> <!-- /.col-sm-2.col-sm-pull-10 -->
209             [% END %]
210         </div> <!-- /.row -->
211
212 [% MACRO jsinclude BLOCK %]
213     [% INCLUDE 'calendar.inc' %]
214     [% Asset.js("js/tools-menu.js") | $raw %]
215     [% Asset.js("lib/d3c3/d3.min.js") | $raw %]
216     [% Asset.js("lib/d3c3/c3.min.js") | $raw %]
217     [% IF ( opac_news_count ) %]
218         [% INCLUDE 'datatables.inc' %]
219         <script>
220             function Checkbox(){
221                 var form = document.getElementById('del_form');
222                 var inputs = form.getElementsByTagName('input');
223                 var checked = false;
224                 for (var i=0; i<inputs.length; i++) {
225                     if (inputs[i].type == 'checkbox' && inputs[i].name == 'ids') {
226                         checked = inputs[i].checked;
227                         if (checked) return true;
228                     }
229                 }
230             }
231
232             function filterDataTable( table, column, term ){
233                 if( column ){
234                     table.column( column ).search( term ).draw();
235                 } else {
236                     table.search( term ).draw();
237                 }
238                 clearFilter( term );
239             }
240
241             function clearFilter( term ){
242                 if( term == "" ){
243                     $(".dt_button_clear_filter").addClass("disabled");
244                 } else {
245                     $(".dt_button_clear_filter").removeClass("disabled");
246                 }
247             }
248
249             $(document).ready(function() {
250                 var newst = $("#newst").DataTable($.extend(true, {}, dataTablesDefaults, {
251                     "order": [[ 4, "desc" ]],
252                     "aoColumnDefs": [
253                         { "sortable": false, "searchable": false, 'targets': [ 'NoSort' ] },
254                         { "type": "anti-the", "targets": [ "anti-the" ] },
255                         { "type": "title-string", "targets" : [ "title-string"] }
256                     ],
257                     "sPaginationType": "full_numbers"
258                 }));
259
260                 $(".delete_news").on("click", function(){
261                     return confirmDelete( _("Are you sure you want to delete this news item? This cannot be undone.") );
262                 });
263
264                 $("#del_form").on("submit",function(){
265                     if ( Checkbox() ) {
266                         return confirmDelete( _("Are you sure you want to delete the selected news?") );
267                     } else {
268                         alert(_("Please select a news item to delete."));
269                         return false;
270                     }
271                 });
272
273                 newst.on( 'search.dt', function () {
274                     var term = newst.search();
275                     $("#news_keyword").val( term );
276                 });
277
278                 $("#news_keyword").on("keyup", function(){
279                     var term = $(this).val();
280                     filterDataTable( newst, null, term );
281                 });
282
283                 $("#news_display_location").on("change", function(){
284                     var term = $(this).val();
285                     filterDataTable( newst, 1, term );
286                 });
287
288                 $("#news_library").on("change", function(){
289                     // Table must be filtered by the <option>'s text, not its value
290                     var opt = $(this).find("option:selected").text();
291                     filterDataTable( newst, 2, opt );
292                 });
293
294                 $(".dt_button_clear_filter").on("click", function(){
295                     newst.search('').columns().search('').draw();
296                     $("#news-filter select").each(function(){
297                         $(this).val("");
298                     });
299                 });
300             });
301         </script>
302     [% END %]
303     [% Asset.js( "lib/codemirror/codemirror.min.js" ) | $raw %]
304     [% Asset.js("lib/tiny_mce/tinymce.min.js") | $raw %]
305     [% INCLUDE 'str/tinymce_i18n.inc' %]
306     <script>
307         [% IF Koha.Preference('NewsToolEditor') == 'codemirror' %]
308         var editor = CodeMirror.fromTextArea(document.getElementById('content'), {
309             lineNumbers: true,
310             mode: "text/html",
311             lineWrapping: true
312         });
313         [% ELSE %]
314         tinyMCE.init({
315             verify_html: false,
316             force_br_newlines : false,
317             force_p_newlines : false,
318             forced_root_block : '',
319             branding : false,
320             relative_urls : false,
321             content_css : "[% interface | html %]/[% theme | html %]/css/tinymce.css",
322             menubar : "file edit view insert format tools table",
323             mode : "specific_textareas",
324             plugins : "autoresize table hr link image charmap lists code emoticons",
325             toolbar : [
326                 "formatselect | bold italic | cut copy paste | alignleft aligncenter alignright | outdent indent | image link unlink anchor cleanup hr",
327                 "table | bullist numlist | undo redo | removeformat | emoticons charmap | forecolor backcolor | code visualaid help"
328             ],
329         });
330         [% END %]
331     </script>
332 [% END %]
333
334 [% BLOCK lang_locations %]
335     [% IF ( language == "" ) %]
336         <option value="" selected="selected"></option>
337     [% ELSE %]
338         <option value="">All</option>
339     [% END %]
340     [% IF ( language == "koha" ) %]
341         <option value="koha" selected="selected">Librarian interface</option>
342     [% ELSE %]
343         <option value="koha">Librarian interface</option>
344     [% END %]
345     [% IF ( language == "slip" ) %]
346         <option value="slip" selected="selected">Slip</option>
347     [% ELSE %]
348         <option value="slip">Slip</option>
349     [% END %]
350     [% FOREACH lang_lis IN lang_list %]
351         <optgroup label="[% lang_lis.language | html %]">
352             [% FOREACH location IN [ '', 'OpacNavRight', 'opacheader', 'OpacCustomSearch', 'OpacMainUserBlock', 'opaccredits', 'OpacLoginInstructions'] %]
353                 [% IF ( location == '' ) %]
354                     [% SET location_lang = lang_lis.language %]
355                     [% location = BLOCK %]OPAC news[% END %]
356                 [% ELSE %]
357                     [% SET location_lang = location _ "_" _ lang_lis.language %]
358                 [% END %]
359                 [% IF ( location_lang == language ) %]
360                     <option value="[% location_lang | html %]" selected="selected">[% location | html %] ([% lang_lis.language | html %])</option>
361                 [% ELSE %]
362                     <option value="[% location_lang | html %]">[% location | html %] ([% lang_lis.language | html %])</option>
363                 [% END %]
364             [% END %]
365         </optgroup>
366     [% END %]
367 [% END %]
368
369 [% INCLUDE 'intranet-bottom.inc' %]