Bug 27929: Allow regex for subfield linked with cataloguing plugin
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / tools / koha-news.tt
1 [% USE raw %]
2 [% USE Asset %]
3 [% USE Koha %]
4 [% USE KohaDates %]
5 [% USE Branches %]
6 [% SET footerjs = 1 %]
7 [% INCLUDE 'doc-head-open.inc' %]
8 <title>News &rsaquo; Tools &rsaquo; Koha</title>
9 [% INCLUDE 'doc-head-close.inc' %]
10 [% IF ( opac_news_count ) %]
11 [% END %]
12 [% UNLESS ( wysiwyg ) %]
13     [% Asset.css("lib/codemirror/codemirror.css") | $raw %]
14     [% Asset.css("lib/codemirror/lint.min.css") | $raw %]
15     <style>
16         .CodeMirror {
17             resize: vertical;
18             z-index: 0;
19         }
20     </style>
21 [% END %]
22 </head>
23
24 <body id="tools_koha-news" class="tools">
25 [% INCLUDE 'header.inc' %]
26 [% INCLUDE 'cat-search.inc' %]
27
28 <nav id="breadcrumbs" aria-label="Breadcrumb" class="breadcrumb">
29     <ol>
30         <li>
31             <a href="/cgi-bin/koha/mainpage.pl">Home</a>
32         </li>
33         <li>
34             <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a>
35         </li>
36
37         [% IF ( add_form ) %]
38             <li>
39                 <a href="/cgi-bin/koha/tools/koha-news.pl">News</a>
40             </li>
41             <li>
42                 <a href="#" aria-current="page">
43                     [% IF ( id ) %]
44                         Edit news item
45                     [% ELSE %]
46                         Add news item
47                     [% END %]
48                 </a>
49             </li>
50         [% ELSE %]
51             <li>
52                 <a href="#" aria-current="page">
53                     News
54                 </a>
55             </li>
56         [% END %]
57     </ol>
58 </nav>
59
60 [% IF ( add_form ) %]
61     <div class="main container-fluid">
62         <div class="row">
63             <div class="col-md-10 col-md-offset-1 col-lg-8 col-lg-offset-2">
64 [% ELSE %]
65     <div class="main container-fluid">
66         <div class="row">
67             <div class="col-sm-10 col-sm-push-2">
68 [% END %]
69                 <main>
70
71 [% UNLESS ( add_form ) %]
72     [% IF error_message == 'title_missing' %]
73         <div class="dialog alert">Error: Required news title missing!</div>
74     [% END %]
75 <h2>News</h2>
76 <div id="toolbar" class="btn-toolbar">
77     <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>
78 </div>
79 [% END %]
80
81 [% IF ( add_form ) %]
82     [% IF ( op == 'add' ) %]
83         [% default_lang = lang %]
84     [% ELSE %]
85         [% default_lang = new_detail.lang %]
86     [% END %]
87         <form name="add_form" method="post" action="/cgi-bin/koha/tools/koha-news.pl" >
88             <input type="hidden" name="op" value="[% op | html %]" />
89             <input type="hidden" name="id" value="[% id | html %]" />
90                         <fieldset class="rows">
91             <legend>OPAC and Koha news</legend>
92            <ol> <li>
93             <label for="lang">Display location:</label>
94             <select id="lang" name="lang">
95                 [% PROCESS lang_locations language => default_lang %]
96             </select>
97             </li>
98             <li>
99                 <label for="branch">Library: </label>
100                 <select id="branch" name="branch">
101                     [% IF ( new_detail.branchcode == '' ) %]
102                         <option value="" selected="selected">All libraries</option>
103                     [% ELSE %]
104                         <option value=""         >All libraries</option>
105                     [% END %]
106                     [% PROCESS options_for_libraries libraries => Branches.all( selected => new_detail.branchcode, unfiltered => 1, ) %]
107                 </select>
108             </li>
109             <li>
110                 <label for="title" class="required">Title: </label>
111                 <input id="title" size="30" type="text" name="title" value="[% new_detail.title | html %]" required="required" class="required" /> <span class="required">Required</span>
112             </li>
113             <li>
114                 <label for="from">Publication date: </label>
115                 <input id="from" type="text" name="published_on" size="15" value="[% new_detail.published_on | html %]" class="datepickerfrom" />
116                                 <div class="hint">[% INCLUDE 'date-format.inc' %]</div>
117             </li>
118             <li>
119                 <label for="to">Expiration date: </label>
120                 <input id="to" type="text" name="expirationdate" size="15" value="[% new_detail.expirationdate | html %]" class="datepickerto" />
121                 <div class="hint">
122                     [% INCLUDE 'date-format.inc' %]
123                     <br>News will still be accessible by direct URL if expired.
124                 </div>
125             </li>
126             <li>
127                 <label for="number">Appear in position: </label>
128                 [% IF ( new_detail.number ) %]
129                     <input id="number" size="3" name="number" type="text" value="[% new_detail.number | html %]" />
130                 [% ELSE %]
131                     <input id="number" size="3" name="number" type="text" />
132                 [% END %]
133             </li>
134             <li><label for="content">News: </label>
135             <textarea name="content" id="content"  cols="75" rows="10">[% new_detail.content | html %]</textarea>
136             </li>
137             </ol>
138                         </fieldset>
139   
140                 <fieldset class="action"><input class="button" type="submit" value="Submit" /> <a class="cancel" href="/cgi-bin/koha/tools/koha-news.pl">Cancel</a></fieldset>
141         </form>
142     [% ELSE %]
143         [% IF ( opac_news_count ) %]
144         <form id="del_form" method="post" action="/cgi-bin/koha/tools/koha-news.pl">
145                 <table id="newst">
146                    <thead> <tr>
147                         <th class="NoSort">&nbsp;</th>
148                         <th>Location</th>
149                         <th>Library</th>
150                         <th>Number</th>
151                         <th>Publication date</th>
152                         <th>Expiration date</th>
153                         <th class="anti-the">Title</th>
154                         <th>Author</th>
155                         <th class="anti-the">News</th>
156                         <th class="NoSort noExport">Actions</th>
157                     </tr></thead>
158                     <tbody>[% FOREACH opac_new IN opac_news %]
159                          [% IF ( opac_new.expired ) %]
160                             <tr class="expired">
161                             [% ELSE %]
162                             <tr>
163                             [% END %]
164                             <td>
165                                 <input type="checkbox" name="ids" value="[% opac_new.idnew | html %]" />
166                             </td>
167                             <td>[% SWITCH opac_new.lang %]
168                                 [%   CASE "koha" %]
169                                     Librarian interface
170                                 [%   CASE "slip" %]
171                                     Slip
172                                 [%   CASE "" %]
173                                     All
174                                 [%   CASE %]
175                                     OPAC ([% opac_new.lang | html %])
176                                 [% END %]
177                              </td>
178                             <td>[% IF ( opac_new.branchcode == "" ) -%]
179                                 All libraries
180                                 [% ELSE %][% opac_new.branchname | html %]
181                                 [% END %]</td>
182                             <td>[% opac_new.number | html %]</td>
183                             <td data-order="[% opac_new.newdate | html %]">[% opac_new.newdate | $KohaDates %]</td>
184                             <td data-order="[% opac_new.expirationdate | html %]">[% opac_new.expirationdate | $KohaDates %] [% IF ( opac_new.expired ) %](<span class="expired">expired</span>)[% END %]</td>
185                             <td>[% opac_new.title | html %]</td>
186                             <td>[% opac_new.author_title | html %] [% opac_new.author_firstname | html %] [% opac_new.author_surname | html %]</td>
187                             <td>
188                                 <div class="btn-group">
189                                     <a class="preview_news btn btn-default btn-xs" data-number="[% loop.count | html %]"><i class="fa fa-eye" aria-hidden="true"></i> Preview content</a>
190                                 </div>
191                                 <div id="contentModal[% loop.count | html %]" class="modal" tabindex="-1" role="dialog" data-number="[% loop.count | html %]">
192                                     <div class="modal-dialog" role="document">
193                                         <div class="modal-content modal-lg">
194                                             <div class="modal-header">
195                                                 <h5 class="modal-title">Preview of: "[% opac_new.title | html %]"</h5>
196                                             </div>
197                                         <div class="modal-body">
198                                             [% opac_new.content | $raw %]
199                                         </div>
200                                         <div class="modal-footer">
201                                             <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
202                                         </div>
203                                     </div>
204                                 </div>
205                             </td>
206                             <td class="actions">
207                                 [% IF ( wysiwyg ) %]
208                                     [% SET editmode = "wysiwyg" %]
209                                 [% ELSE %]
210                                     [% SET editmode = "text" %]
211                                 [% END %]
212                                 <div class="btn-group dropup">
213                                     <a href="/cgi-bin/koha/tools/koha-news.pl?op=add_form&amp;id=[% opac_new.idnew | uri %]&editmode=[% editmode | uri %]" class="btn btn-default btn-xs"> <i class="fa fa-pencil"></i> Edit</a><button class="btn btn-default btn-xs dropdown-toggle" data-toggle="dropdown">
214                                         <span class="caret"></span>
215                                     </button>
216                                     <ul class="dropdown-menu pull-right">
217                                         <li>
218                                             [% IF ( wysiwyg ) %]
219                                                 <a href="/cgi-bin/koha/tools/koha-news.pl?op=add_form&amp;id=[% opac_new.idnew | uri %]&editmode=text"><i class="fa fa-pencil"></i> Edit with text editor</a>
220                                             [% ELSE %]
221                                                 <a href="/cgi-bin/koha/tools/koha-news.pl?op=add_form&amp;id=[% opac_new.idnew | uri %]&editmode=wysiwyg"><i class="fa fa-pencil"></i> Edit with WYSIWYG editor</a>
222                                             [% END %]
223                                         </li>
224                                     </ul>
225                                 </div>
226                                 <div class="btn-group">
227                                     <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>
228                                 </div>
229                             </td>
230                         </tr>
231                     [% END %]</tbody>
232                 </table>
233                 <input type="hidden" name="op" value="del" />
234                 <fieldset class="action"><input type="submit" class="button" value="Delete selected" /></fieldset>
235             </form>
236         [% ELSE %]
237             <div class="dialog message">There are no news items.</div>
238         [% END %]
239     [% END %]
240
241                 </main>
242             [% UNLESS ( add_form ) %]
243                 </div> <!-- /.col-sm-10.col-sm-push-2 -->
244
245                 <div class="col-sm-2 col-sm-pull-10">
246                     <aside>
247
248                         <div id="news-filter">
249                             <form action="/cgi-bin/koha/tools/koha-news.pl" method="get">
250                                 <h4>Filter</h4>
251                                 <fieldset class="brief">
252                                     <ol>
253                                         <li>
254                                             <label for="news_keyword">Keyword:</label>
255                                             <input type="text" name="news_keyword" id="news_keyword" />
256                                         </li>
257                                         <li>
258                                             <label for="news_display_location">Display location:</label>
259                                             <select name="news_display_location" id="news_display_location">
260                                                 [% PROCESS lang_locations %]
261                                             </select>
262                                         </li>
263                                         <li>
264                                             <label for="news_library">Library: </label>
265                                             <select id="news_library" name="news_library">
266                                                 <option value=""></option>
267                                                 <option value="">All libraries</option>
268                                                 [% PROCESS options_for_libraries libraries => Branches.all( selected => branchcode, unfiltered => 1, ) %]
269                                             </select>
270                                         </li>
271                                         <li>
272                                             <label>
273                                                 <input type="checkbox" name="show_expired" id="show_expired" /> Show expired
274                                             </label>
275                                         </li>
276                                     </ol>
277                                 </fieldset>
278                             </form>
279                         </div>
280
281                         [% INCLUDE 'tools-menu.inc' %]
282                     </aside>
283                 </div> <!-- /.col-sm-2.col-sm-pull-10 -->
284             [% END %]
285         </div> <!-- /.row -->
286     </div> <!-- /.main.container-fluid -->
287
288
289 [% MACRO jsinclude BLOCK %]
290     [% INCLUDE 'calendar.inc' %]
291     [% Asset.js("js/tools-menu.js") | $raw %]
292     [% IF ( opac_news_count ) %]
293         [% INCLUDE 'datatables.inc' %]
294         <script>
295             $('.preview_news').click( function() {
296                 modalNumber = $(this).attr('data-number');
297                 $('.modal[data-number="'+modalNumber+'"]').modal('show');
298             })
299             function Checkbox(){
300                 var form = document.getElementById('del_form');
301                 var inputs = form.getElementsByTagName('input');
302                 var checked = false;
303                 for (var i=0; i<inputs.length; i++) {
304                     if (inputs[i].type == 'checkbox' && inputs[i].name == 'ids') {
305                         checked = inputs[i].checked;
306                         if (checked) return true;
307                     }
308                 }
309             }
310
311             function filterDataTable( table, column, term ){
312                 if( column ){
313                     table.column( column ).search( term ).draw();
314                 } else {
315                     table.search( term ).draw();
316                 }
317                 clearFilter( term );
318             }
319
320             function clearFilter( term ){
321                 if( term == "" ){
322                     $(".dt_button_clear_filter").addClass("disabled");
323                 } else {
324                     $(".dt_button_clear_filter").removeClass("disabled");
325                 }
326             }
327
328             /* Custom table search configuration: If a table row
329                has an "expired" class, hide it UNLESS the
330                show_expired checkbox is checked */
331             $.fn.dataTable.ext.search.push(
332                 function( settings, searchData, index, rowData, counter ) {
333                     var row = $(settings.aoData[index].nTr);
334                     if( row.hasClass("expired") && !$("#show_expired").prop("checked") ){
335                         return false;
336                     } else {
337                         return true;
338                     }
339                 }
340             );
341
342             $(document).ready(function() {
343                 var newst = $("#newst").DataTable($.extend(true, {}, dataTablesDefaults, {
344                     "order": [[ 4, "desc" ]],
345                     "aoColumnDefs": [
346                         { "sortable": false, "searchable": false, 'targets': [ 'NoSort' ] },
347                         { "type": "anti-the", "targets": [ "anti-the" ] }
348                     ],
349                     "sPaginationType": "full_numbers"
350                 }));
351
352                 $(".delete_news").on("click", function(){
353                     return confirmDelete( _("Are you sure you want to delete this news item? This cannot be undone.") );
354                 });
355
356                 $("#del_form").on("submit",function(){
357                     if ( Checkbox() ) {
358                         return confirmDelete( _("Are you sure you want to delete the selected news?") );
359                     } else {
360                         alert(_("Please select a news item to delete."));
361                         return false;
362                     }
363                 });
364
365                 $("#show_expired").on("change", function(){
366                     /* redraw the DataTable according to the custom search function */
367                     newst.draw();
368                 });
369
370                 newst.on( 'search.dt', function () {
371                     var term = newst.search();
372                     $("#news_keyword").val( term );
373                 });
374
375                 $("#news_keyword").on("keyup", function(){
376                     var term = $(this).val();
377                     filterDataTable( newst, null, term );
378                 });
379
380                 $("#news_display_location").on("change", function(){
381                     var term = $(this).val();
382                     filterDataTable( newst, 1, term );
383                 });
384
385                 $("#news_library").on("change", function(){
386                     // Table must be filtered by the <option>'s text, not its value
387                     var opt = $(this).find("option:selected").text();
388                     filterDataTable( newst, 2, opt );
389                 });
390
391                 $(".dt_button_clear_filter").on("click", function(){
392                     newst.search('').columns().search('').draw();
393                     $("#news-filter select").each(function(){
394                         $(this).val("");
395                     });
396                 });
397             });
398         </script>
399     [% END %]
400     [% UNLESS ( wysiwyg ) %]
401         [% Asset.js( "lib/codemirror/codemirror.min.js" ) | $raw %]
402         [% Asset.js( "lib/codemirror/xml.min.js" ) | $raw %]
403         [% Asset.js( "lib/codemirror/lint.min.js" ) | $raw %]
404         [% Asset.js( "lib/linters/htmlhint.min.js" ) | $raw %]
405         [% Asset.js( "lib/codemirror/html-lint.min.js" ) | $raw %]
406         <script>
407             var editor = CodeMirror.fromTextArea(document.getElementById('content'), {
408                 lineNumbers: true,
409                 lineWrapping: true,
410                 lint: true,
411                 mode: "text/html",
412                 gutters: ["CodeMirror-lint-markers"],
413                 viewportMargin: Infinity,
414             });
415         </script>
416     [% ELSE %]
417         [% Asset.js("lib/tiny_mce/tinymce.min.js") | $raw %]
418         [% INCLUDE 'str/tinymce_i18n.inc' %]
419         <script>
420             tinyMCE.init({
421                 verify_html: false,
422                 force_br_newlines : false,
423                 force_p_newlines : false,
424                 forced_root_block : '',
425                 branding : false,
426                 relative_urls : false,
427                 content_css : "[% interface | html %]/[% theme | html %]/css/tinymce.css",
428                 menubar : "file edit view insert format tools table",
429                 mode : "specific_textareas",
430                 plugins : "autoresize table hr link image charmap lists code emoticons",
431                 extended_valid_elements:"style,link[href|rel]",
432                 custom_elements:"style,link,~link",
433                 toolbar : [
434                     "formatselect | bold italic | cut copy paste | alignleft aligncenter alignright | outdent indent | image link unlink anchor cleanup hr",
435                     "table | bullist numlist | undo redo | removeformat | emoticons charmap | forecolor backcolor | code visualaid help"
436                 ],
437             });
438         </script>
439     [% END # /IF NewsToolEditor %]
440 [% END %]
441
442 [% BLOCK lang_locations %]
443     [% IF ( language == "" ) %]
444         <option value="" selected="selected"></option>
445     [% ELSE %]
446         <option value="">All</option>
447     [% END %]
448     [% IF ( language == "koha" ) %]
449         <option value="koha" selected="selected">Librarian interface</option>
450     [% ELSE %]
451         <option value="koha">Librarian interface</option>
452     [% END %]
453     [% IF ( language == "slip" ) %]
454         <option value="slip" selected="selected">Slip</option>
455     [% ELSE %]
456         <option value="slip">Slip</option>
457     [% END %]
458     [% FOREACH lang_lis IN lang_list %]
459         <optgroup label="[% lang_lis.language | html %]">
460             [% FOREACH location IN [ '', 'OpacNavRight', 'opacheader', 'OpacCustomSearch', 'OpacMainUserBlock', 'opaccredits', 'OpacLoginInstructions', 'OpacSuggestionInstructions'] %]
461                 [% IF ( location == '' ) %]
462                     [% SET location_lang = lang_lis.language %]
463                     [% location = BLOCK %]OPAC news[% END %]
464                 [% ELSE %]
465                     [% SET location_lang = location _ "_" _ lang_lis.language %]
466                 [% END %]
467                 [% IF ( location_lang == language ) %]
468                     <option value="[% location_lang | html %]" selected="selected">[% location | html %] ([% lang_lis.language | html %])</option>
469                 [% ELSE %]
470                     <option value="[% location_lang | html %]">[% location | html %] ([% lang_lis.language | html %])</option>
471                 [% END %]
472             [% END %]
473         </optgroup>
474     [% END %]
475 [% END %]
476
477 [% INCLUDE 'intranet-bottom.inc' %]