Bug 29042: Improve formatting of entry form in Additional Contents
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / tools / additional-contents.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>Additional contents &rsaquo; Tools &rsaquo; Koha</title>
9 [% INCLUDE 'doc-head-close.inc' %]
10 [% UNLESS ( wysiwyg ) %]
11     [% Asset.css("lib/codemirror/codemirror.css") | $raw %]
12     [% Asset.css("lib/codemirror/lint.min.css") | $raw %]
13     <style>
14         .CodeMirror {
15             resize: vertical;
16             z-index: 0;
17         }
18     </style>
19 [% END %]
20 </head>
21
22 <body id="tools_additional-contents" class="tools">
23 [% INCLUDE 'header.inc' %]
24 [% INCLUDE 'cat-search.inc' %]
25
26 <nav id="breadcrumbs" aria-label="Breadcrumb" class="breadcrumb">
27     <ol>
28         <li>
29             <a href="/cgi-bin/koha/mainpage.pl">Home</a>
30         </li>
31         <li>
32             <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a>
33         </li>
34
35             <li>
36                 <a href="/cgi-bin/koha/tools/additional-contents.pl">Additional contents</a>
37             </li>
38         [% IF op == 'add_form' %]
39             <li>
40                 [% IF category == 'news' %]
41                     <a href="/cgi-bin/koha/tools/additional-contents.pl?category=news">News</a>
42                 [% ELSE %]
43                     <a href="/cgi-bin/koha/tools/additional-contents.pl?category=html_customizations">HTML customizations</a>
44                 [% END %]
45             </li>
46             <li>
47                 <a href="#" aria-current="page">
48                     [% IF additional_content.idnew %]
49                         Modify additional content
50                     [% ELSE %]
51                         Add additional content
52                     [% END %]
53                 </a>
54             </li>
55         [% ELSE %]
56             <li>
57                 <a href="#" aria-current="page">
58                     [% IF category == 'news' %]
59                         News
60                     [% ELSE %]
61                         HTML customizations
62                     [% END %]
63                 </a>
64             </li>
65         [% END %]
66
67     </ol>
68 </nav>
69
70 [% IF op == 'add_form' %]
71 <div class="main container-fluid">
72     <div class="row">
73         <div class="col-md-10 col-md-offset-1 col-lg-8 col-lg-offset-2">
74 [% ELSE %]
75 <div class="main container-fluid">
76     <div class="row">
77         <div class="col-sm-10 col-sm-push-2">
78 [% END %]
79
80 <main>
81
82     [% FOR m IN messages %]
83         <div class="dialog [% m.type | html %]">
84             [% SWITCH m.code %]
85             [% CASE 'error_on_update' %]
86                 An error occurred when updating this content. Perhaps it already exists.
87             [% CASE 'error_on_insert' %]
88                 An error occurred when adding this content. Check the logs
89             [% CASE 'error_on_delete' %]
90                 An error occurred when deleting this content. Check the logs.
91             [% CASE 'success_on_update' %]
92                 Content updated successfully.
93             [% CASE 'success_on_insert' %]
94                 Content added successfully.
95             [% CASE 'success_on_delete' %]
96                 Content deleted successfully.
97             [% CASE %]
98                 [% m.code | html %]
99             [% END %]
100         </div>
101     [% END %]
102
103     [% IF op == 'add_form' %]
104         [% PROCESS add_form %]
105     [% ELSE %]
106         [% PROCESS list %]
107     [% END %]
108
109 </main>
110
111         [% IF op != 'add_form' %]
112             </div> <!-- /.col-sm-10.col-sm-push-2 -->
113
114             <div class="col-sm-2 col-sm-pull-10">
115                 <aside>
116
117                     <div id="news-filter">
118                         <form action="/cgi-bin/koha/tools/additional-contents.pl" method="get">
119                             <h4>Filter</h4>
120                             <fieldset class="brief">
121                                 <ol>
122                                     <li>
123                                         <label for="news_keyword">Keyword:</label>
124                                         <input type="text" name="news_keyword" id="news_keyword" />
125                                     </li>
126                                     <li>
127                                         <label for="news_display_location">Display location:</label>
128                                         <select name="news_display_location" id="news_display_location">
129                                             <option value="">All</option>
130                                             [% PROCESS locations_options category => category %]
131                                         </select>
132                                     </li>
133                                     <li>
134                                         <label for="news_library">Library: </label>
135                                         <select id="news_library" name="news_library">
136                                             <option value=""></option>
137                                             <option value="">All libraries</option>
138                                             [% PROCESS options_for_libraries libraries => Branches.all( selected => branchcode, unfiltered => 1, ) %]
139                                         </select>
140                                     </li>
141                                     <li>
142                                         <label>
143                                             <input type="checkbox" name="show_expired" id="show_expired" /> Show expired
144                                         </label>
145                                     </li>
146                                 </ol>
147                             </fieldset>
148                         </form>
149                     </div>
150
151                     [% INCLUDE 'tools-menu.inc' %]
152                 </aside>
153             </div> <!-- /.col-sm-2.col-sm-pull-10 -->
154         [% END %]
155     </div> <!-- /.row -->
156 </div> <!-- /.main.container-fluid -->
157
158 [% BLOCK add_form %]
159     [% IF additional_content %]
160         <h1>Modify an additional content</h1>
161     [% ELSE %]
162         <h1>New additional content ([% IF category == 'news' %]News[% ELSE %]HTML customizations[% END %])</h1>
163     [% END %]
164
165     <div id="toolbar" class="btn-toolbar">
166         <div class="btn-group">
167             <button class="btn btn-default" id="submit_form"><i class="fa fa-save"></i> Save</button>
168         </div>
169         <a class="btn btn-default cancel" href="/cgi-bin/koha/tools/additional-contents.pl"><i class="fa fa-remove"></i> Cancel</a>
170     </div>
171
172     <form id="add_additional_content" method="post" action="/cgi-bin/koha/tools/additional-contents.pl" class="validate">
173         <input type="hidden" name="op" value="add_validate" />
174         <input type="hidden" name="id" value="[% additional_content.idnew | html %]" />
175         <input type="hidden" name="category" value="[% category | html %]" />
176         <fieldset class="rows">
177             <ol>
178                 <li>
179                     [% IF additional_content %]
180                         <span class="label">Code:</span> [% additional_content.code | html %]
181                         <input type="hidden" id="code" name="code" value="[% additional_content.code | html %]" />
182                     [% ELSE %]
183                         <label for="code" class="required">Code:</label>
184                         <input type="text" id="code" name="code" size="20" maxlength="20" value="" required="required"/>
185                         <span class="required">Required</span>
186                     [% END %]
187                 </li>
188                 <li>
189                     <label for="location">Display location:</label>
190                     <select id="location" name="location">
191                         [% PROCESS locations_options location => additional_content.location %]
192                     </select>
193                 </li>
194                 <li>
195                     <label for="branchcode">Library: </label>
196                     <select id="branchcode" name="branchcode">
197                         [% IF additional_content.branchcode == '' %]
198                             <option value="" selected="selected">All libraries</option>
199                         [% ELSE %]
200                             <option value="">All libraries</option>
201                         [% END %]
202                         [% PROCESS options_for_libraries libraries => Branches.all( selected => additional_content.branchcode, unfiltered => 1, ) %]
203                     </select>
204                 </li>
205                 [% UNLESS languages.size %]
206                     <li>
207                         <label for="title" class="required">Title: </label>
208                         <input id="title" size="100" maxlength="250" type="text" name="title" value="[% additional_content.title | html %]" required="required" class="required" /> <span class="required">Required</span>
209                     </li>
210                 [% END %]
211                 <li>
212                     <label for="from">Publication date: </label>
213                     <input id="from" type="text" name="published_on" size="15" value="[% additional_content.published_on | html %]" class="flatpickrfrom" />
214                     <div class="hint">[% INCLUDE 'date-format.inc' %]</div>
215                 </li>
216                 <li>
217                     <label for="to">Expiration date: </label>
218                     <input id="to" type="text" name="expirationdate" size="15" value="[% additional_content.expirationdate | html %]" class="flatpickrto" />
219                     <div class="hint">
220                         [% INCLUDE 'date-format.inc' %]
221                         [% IF category == 'news' %]
222                             <br>News will still be accessible by direct URL if expired.
223                         [% END %]
224                     </div>
225                 </li>
226                 <li>
227                     <label for="number">Appear in position: </label>
228                     [% IF ( additional_content.number ) %]
229                         <input id="number" size="3" name="number" type="text" value="[% additional_content.number | html %]" />
230                     [% ELSE %]
231                         <input id="number" size="3" name="number" type="text" />
232                     [% END %]
233                 </li>
234             </ol>
235         </fieldset>
236
237         [% IF languages.size %]
238             <div style="clear:both"></div>
239             <div id="tabs">
240                 <ul>
241                     [% FOR language IN languages %]
242                         [% IF language.lang == 'default' %]
243                             <li><a href="#lang_default">Default</a></li>
244                         [% ELSE %]
245                             <li><a href="#lang_[% language.lang | uri %]">[% language.description | html %]</a></li>
246                         [% END %]
247                     [% END %]
248                 </ul>
249
250                 [% FOR language IN languages %]
251                     <div id="lang_[% language.lang | uri %]" class="lang clearfix" data-lang="[% language.description | html %]">
252                         <fieldset class="rows">
253                             <ol>
254                                 <li style="list-style: none;">
255                                     <label for="title_[% language.lang | html %]">Title: </label>
256                                     <input id="title_[% language.lang| html %]" size="100" maxlength="250" type="text" name="title" value="[% translated_contents.item(language.lang).title | html %]">
257                                 </li>
258                                 <li style="list-style: none;">
259                                     <label for="content_[% language.lang | html %]">Content: </label>
260                                     <textarea name="content" id="content_[% language.lang | html %]"  cols="75" rows="10">[% translated_contents.item(language.lang).content | html %]</textarea>
261                                     <input type="hidden" name="lang" value="[% language.lang | html %]" />
262                                 </li>
263                             </ol>
264                         </fieldset>
265                     </div>
266                 [% END %]
267             </div>
268         [% ELSE %]
269             <div id="lang_default">
270                 <div class="clearfix">
271                     <textarea name="content" id="content_default"  cols="75" rows="10">[% additional_content.content | html %]</textarea>
272                 </div>
273             </div>
274         [% END %]
275     </form>
276 [% END %]
277
278 [% BLOCK list %]
279
280     <div id="toolbar" class="btn-toolbar">
281         <a class="btn btn-default" id="newentry" href="/cgi-bin/koha/tools/additional-contents.pl?op=add_form&category=[% category | html %]"><i class="fa fa-plus"></i> New entry</a>
282     </div>
283
284     <h2>Additional contents ([% IF category == 'news' %]News[% ELSE %]HTML customizations[% END %])</h2>
285     [% IF category == 'news' %]
286         See <a href="/cgi-bin/koha/tools/additional-contents.pl?category=html_customizations">HTML customizations</a>
287     [% ELSE %]
288         See <a href="/cgi-bin/koha/tools/additional-contents.pl?category=news">News</a>
289     [% END %]
290
291     [% IF additional_contents.count %]
292         <form id="del_form" method="post" action="/cgi-bin/koha/tools/additional-contents.pl">
293             <table id="table_additional_contents">
294                 <thead>
295                     <tr>
296                         <th class="NoSort">&nbsp;</th>
297                         <th>Location</th>
298                         <th>Library</th>
299                         <th>Number</th>
300                         <th>Publication date</th>
301                         <th>Expiration date</th>
302                         <th class="anti-the">Title</th>
303                         <th>Author</th>
304                         <th class="anti-the">News</th>
305                         <th class="NoSort noExport">Actions</th>
306                     </tr>
307                 </thead>
308                 <tbody>
309                     [% FOREACH c IN additional_contents%]
310                         [% IF ( c.is_expired ) %]<tr class="expired">[% ELSE %]<tr>[% END %]
311                         <td>
312                             <input type="checkbox" name="ids" value="[% c.idnew | html %]" />
313                         </td>
314                         <td>
315                             [% IF c.category == 'news' %]
316                                 [% IF c.location == 'staff_and_opac' %]All
317                                 [% ELSIF c.location == 'staff_only' %]Librarian interface
318                                 [% ELSIF c.location == 'opac_only' %]OPAC
319                                 [% ELSIF c.location == 'slip' %]Slip
320                                 [% ELSE %]Unknown ('[% location | html %]')
321                                 [% END %]
322                             [% ELSE %]
323                                 [% c.location | html %]
324                             [% END %]
325                         </td>
326                         <td>
327                             [% IF ( c.branchcode == "" ) -%]
328                             All libraries
329                             [% ELSE %][% c.library.branchname | html %]
330                             [% END %]
331                         </td>
332                         <td>[% c.number | html %]</td>
333                         <td data-order="[% c.published_on | html %]">[% c.published_on | $KohaDates %]</td>
334                         <td data-order="[% c.expirationdate | html %]">[% c.expirationdate | $KohaDates %] [% IF ( c.is_expired ) %](<span class="expired">expired</span>)[% END %]</td>
335                         <td>[% c.title | html %]</td>
336                         <td>[% IF ( c.author) %][% INCLUDE 'patron-title.inc' patron=c.author %][% END %]</td>
337                         <td>
338                             <div class="btn-group">
339                                 <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>
340                             </div>
341                             <div id="contentModal[% loop.count | html %]" class="modal" tabindex="-1" role="dialog" data-number="[% loop.count | html %]">
342                                 <div class="modal-dialog" role="document">
343                                     <div class="modal-content modal-lg">
344                                         <div class="modal-header">
345                                             <h5 class="modal-title">Preview of: "[% c.title | html %]"</h5>
346                                         </div>
347                                     <div class="modal-body">
348                                         [% c.content | $raw %]
349                                     </div>
350                                     <div class="modal-footer">
351                                         <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
352                                     </div>
353                                 </div>
354                             </div>
355                         </td>
356                         <td class="actions">
357                             [% IF ( wysiwyg ) %]
358                                 [% SET editmode = "wysiwyg" %]
359                             [% ELSE %]
360                                 [% SET editmode = "text" %]
361                             [% END %]
362                             <div class="btn-group dropup">
363                                 <a href="/cgi-bin/koha/tools/additional-contents.pl?op=add_form&amp;id=[% c.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">
364                                     <span class="caret"></span>
365                                 </button>
366                                 <ul class="dropdown-menu pull-right">
367                                     <li>
368                                         [% IF ( wysiwyg ) %]
369                                             <a href="/cgi-bin/koha/tools/additional-contents.pl?op=add_form&amp;id=[% c.idnew | uri %]&editmode=text"><i class="fa fa-pencil"></i> Edit with text editor</a>
370                                         [% ELSE %]
371                                             <a href="/cgi-bin/koha/tools/additional-contents.pl?op=add_form&amp;id=[% c.idnew | uri %]&editmode=wysiwyg"><i class="fa fa-pencil"></i> Edit with WYSIWYG editor</a>
372                                         [% END %]
373                                     </li>
374                                 </ul>
375                             </div>
376                             <div class="btn-group">
377                                 <a href="#" class="delete_news btn btn-default btn-xs" data-idnew="[% c.idnew | html %]"><i class="fa fa-trash"></i> Delete</a>
378                             </div>
379                         </td>
380                     </tr>
381                     [% END %]
382                 </tbody>
383             </table>
384             <input type="hidden" name="op" value="delete_confirmed" />
385             <input type="hidden" name="category" value="[% category | html %]" />
386             <fieldset class="action"><input type="submit" class="button" value="Delete selected" /></fieldset>
387         </form>
388         <form action="/cgi-bin/koha/tools/additional-contents.pl" method="post" id="delete_single">
389             <input type="hidden" id="del_op" name="op" value="delete_confirmed" />
390             <input type="hidden" id="del_category" name="category" value="[% category | html %]" />
391             <input type="hidden" id="del_ids" name="ids" />
392         </form>
393     [% ELSE %]
394         <div class="dialog message">There are no additional contents.</div>
395     [% END %]
396 [% END %]
397
398 [% BLOCK locations_options %]
399     [% IF category == 'news' %]
400         [% IF location == "staff_and_opac" %]
401             <option value="staff_and_opac" selected="selected">Librarian and OPAC interfaces</option>
402         [% ELSE %]
403             <option value="staff_and_opac">Librarian and OPAC interfaces</option>
404         [% END %]
405
406         [% IF location == "staff_only" %]
407             <option value="staff_only" selected="selected">Librarian interface</option>
408         [% ELSE %]
409             <option value="staff_only">Librarian interface</option>
410         [% END %]
411
412         [% IF location == "opac_only" %]
413             <option value="opac_only" selected="selected">OPAC</option>
414         [% ELSE %]
415             <option value="opac_only">OPAC</option>
416         [% END %]
417
418         [% IF location == "slip" %]
419             <option value="slip" selected="selected">Slip</option>
420         [% ELSE %]
421             <option value="slip">Slip</option>
422         [% END %]
423     [% ELSE %]
424         [% FOREACH l IN [ 'OpacNavRight', 'opacheader', 'OpacCustomSearch', 'OpacMainUserBlock', 'opaccredits', 'OpacLoginInstructions', 'OpacSuggestionInstructions', 'ArticleRequestsDisclaimerText' ] %]
425             [% IF l == location %]
426                 <option value="[% l | html %]" selected="selected">[% l | html %]</option>
427             [% ELSE %]
428                 <option value="[% l | html %]">[% l | html %]</option>
429             [% END %]
430         [% END %]
431     [% END %]
432 [% END %]
433
434 [% MACRO jsinclude BLOCK %]
435     [% INCLUDE 'calendar.inc' %]
436     [% Asset.js("js/tools-menu.js") | $raw %]
437     [% Asset.js("lib/hc-sticky.js") | $raw %]
438     [% IF additional_contents.count %]
439         [% INCLUDE 'datatables.inc' %]
440         <script>
441             $('.preview_news').click( function() {
442                 modalNumber = $(this).attr('data-number');
443                 $('.modal[data-number="'+modalNumber+'"]').modal('show');
444             })
445             function Checkbox(){
446                 var form = document.getElementById('del_form');
447                 var inputs = form.getElementsByTagName('input');
448                 var checked = false;
449                 for (var i=0; i<inputs.length; i++) {
450                     if (inputs[i].type == 'checkbox' && inputs[i].name == 'ids') {
451                         checked = inputs[i].checked;
452                         if (checked) return true;
453                     }
454                 }
455             }
456
457             function filterDataTable( table, column, term ){
458                 if( column ){
459                     table.column( column ).search( term ).draw();
460                 } else {
461                     table.search( term ).draw();
462                 }
463                 clearFilter( term );
464             }
465
466             function clearFilter( term ){
467                 if( term == "" ){
468                     $(".dt_button_clear_filter").addClass("disabled");
469                 } else {
470                     $(".dt_button_clear_filter").removeClass("disabled");
471                 }
472             }
473
474             /* Custom table search configuration: If a table row
475                has an "expired" class, hide it UNLESS the
476                show_expired checkbox is checked */
477             $.fn.dataTable.ext.search.push(
478                 function( settings, searchData, index, rowData, counter ) {
479                     var row = $(settings.aoData[index].nTr);
480                     if( row.hasClass("expired") && !$("#show_expired").prop("checked") ){
481                         return false;
482                     } else {
483                         return true;
484                     }
485                 }
486             );
487
488             $(document).ready(function() {
489
490                 var table = $("#table_additional_contents").DataTable($.extend(true, {}, dataTablesDefaults, {
491                     "order": [[ 4, "desc" ]],
492                     "aoColumnDefs": [
493                         { "sortable": false, "searchable": false, 'targets': [ 'NoSort' ] },
494                         { "type": "anti-the", "targets": [ "anti-the" ] }
495                     ],
496                     "sPaginationType": "full_numbers"
497                 }));
498
499                 $("#del_form").on("click", ".delete_news", function(e){
500                     e.preventDefault();
501                     if( confirmDelete( _("Are you sure you want to delete this content? This cannot be undone.") ) ){
502                         $("#del_ids").val( $(this).data("idnew") );
503                         $("#delete_single").submit();
504                     }
505                 });
506
507                 $("#del_form").on("submit",function(){
508                     if ( Checkbox() ) {
509                         return confirmDelete( _("Are you sure you want to delete the selected content?") );
510                     } else {
511                         alert(_("Please select content to delete."));
512                         return false;
513                     }
514                 });
515
516                 $("#show_expired").on("change", function(){
517                     /* redraw the DataTable according to the custom search function */
518                     table.draw();
519                 });
520
521                 table.on( 'search.dt', function () {
522                     var term = table.search();
523                     $("#news_keyword").val( term );
524                 });
525
526                 $("#news_keyword").on("keyup", function(){
527                     var term = $(this).val();
528                     filterDataTable( table, null, term );
529                 });
530
531                 $("#news_display_location").on("change", function(){
532                     var term = $(this).val();
533                     filterDataTable( table, 1, term );
534                 });
535
536                 $("#news_library").on("change", function(){
537                     // Table must be filtered by the <option>'s text, not its value
538                     var opt = $(this).find("option:selected").text();
539                     filterDataTable( table, 2, opt );
540                 });
541
542                 $(".dt_button_clear_filter").on("click", function(){
543                     table.search('').columns().search('').draw();
544                     $("#news-filter select").each(function(){
545                         $(this).val("");
546                     });
547                 });
548             });
549         </script>
550     [% ELSE %]
551         <script>
552             $(document).ready(function() {
553                 $("#tabs").tabs();
554                 $("#add_additional_content").validate({
555                     submitHandler: function(form){
556                         if ( ! $("#title_default").val().length > 0 ) {
557                             alert(__("Please specify a title for 'Default'"));
558                             return false;
559                         }
560
561                         form.submit();
562                     }
563                 });
564
565                 $("#submit_form").on("click",function(){
566                     $("#add_additional_content").submit();
567                 });
568
569                 Sticky = $("#toolbar");
570                 Sticky.hcSticky({
571                     stickTo: ".main",
572                     stickyClass: "floating"
573                 });
574
575             });
576         </script>
577     [% END %]
578     [% UNLESS ( wysiwyg ) %]
579         [% Asset.js( "lib/codemirror/codemirror.min.js" ) | $raw %]
580         [% Asset.js( "lib/codemirror/xml.min.js" ) | $raw %]
581         [% Asset.js( "lib/codemirror/lint.min.js" ) | $raw %]
582         [% Asset.js( "lib/linters/htmlhint.min.js" ) | $raw %]
583         [% Asset.js( "lib/codemirror/html-lint.min.js" ) | $raw %]
584         <script>
585             var editor = CodeMirror.fromTextArea(document.getElementById('content'), {
586                 lineNumbers: true,
587                 lineWrapping: true,
588                 lint: true,
589                 mode: "text/html",
590                 gutters: ["CodeMirror-lint-markers"],
591                 viewportMargin: Infinity,
592             });
593         </script>
594     [% ELSE %]
595         [% Asset.js("lib/tiny_mce/tinymce.min.js") | $raw %]
596         [% INCLUDE 'str/tinymce_i18n.inc' %]
597         <script>
598             tinyMCE.init({
599                 verify_html: false,
600                 force_br_newlines : false,
601                 force_p_newlines : false,
602                 forced_root_block : '',
603                 branding : false,
604                 relative_urls : false,
605                 content_css : "[% interface | html %]/[% theme | html %]/css/tinymce.css",
606                 menubar : "file edit view insert format tools table",
607                 mode : "specific_textareas",
608                 plugins : "autoresize table hr link image charmap lists code emoticons",
609                 extended_valid_elements:"style,link[href|rel]",
610                 custom_elements:"style,link,~link",
611                 toolbar : [
612                     "formatselect | bold italic | cut copy paste | alignleft aligncenter alignright | outdent indent | image link unlink anchor cleanup hr",
613                     "table | bullist numlist | undo redo | removeformat | emoticons charmap | forecolor backcolor | code"
614                 ],
615             });
616         </script>
617     [% END # /UNLESS wysiwyg %]
618 [% END %]
619
620 [% INCLUDE 'intranet-bottom.inc' %]