Bug 35650: (follow-up) Other cases found
[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 [% PROCESS 'i18n.inc' %]
7 [% SET footerjs = 1 %]
8 [% INCLUDE 'doc-head-open.inc' %]
9 [% BLOCK page_heading %]
10     [% IF additional_content.id %]
11         [% IF category == 'news' %]
12             [% t("Modify news item") | html %]
13         [% ELSIF category == 'pages' %]
14             [% t("Modify page") | html %]
15         [% ELSE %]
16             [% t("Modify HTML customization") | html %]
17         [% END %]
18     [% ELSE %]
19         [% IF category == 'news' %]
20             [% t("New news item") | html %]
21         [% ELSIF category == 'pages' %]
22             [% t("New page") | html %]
23         [% ELSE %]
24             [% t("New HTML customization") | html %]
25         [% END %]
26     [% END %]
27 [% END %]
28 [% BLOCK page_section %]
29     [% IF category == 'news' %]
30         [% t("News") | html %]
31     [% ELSIF category == 'pages' %]
32         [% t("Pages") | html %]
33     [% ELSE %]
34         [% t("HTML customizations") | html %]
35     [% END %]
36 [% END %]
37 <title>[% FILTER collapse %]
38     [% IF op == 'add_form' %]
39         [% PROCESS page_heading %] &rsaquo;
40     [% END %]
41     [% PROCESS page_section %] &rsaquo;
42     [% t("Additional content") | html %] &rsaquo;
43     [% t("Tools") | html %] &rsaquo;
44     [% t("Koha") | html %]
45 [% END %]</title>
46 [% INCLUDE 'doc-head-close.inc' %]
47 [% IF ( wysiwyg ) %]
48     [% SET editmode = "wysiwyg" %]
49 [% ELSE %]
50     [% SET editmode = "text" %]
51     [% Asset.css("lib/codemirror/codemirror.css") | $raw %]
52     [% Asset.css("lib/codemirror/lint.min.css") | $raw %]
53     <style>
54         .CodeMirror {
55             resize: vertical;
56             z-index: 0;
57         }
58     </style>
59 [% END %]
60     <style>
61         .syspref-link::before {
62             content: " | ";
63         }
64         .customization-link::before {
65             content: " | ";
66         }
67         .customization-link:first-child::before {
68             content: none;
69         }
70         label[for^="title_"],
71         label[for^="content_"] {
72             font-weight: 700;
73         }
74         .customization_note {
75             display: none;
76         }
77     </style>
78 </head>
79
80 <body id="tools_additional-contents" class="tools">
81 [% WRAPPER 'header.inc' %]
82     [% INCLUDE 'cat-search.inc' %]
83 [% END %]
84
85 [% WRAPPER 'sub-header.inc' %]
86     [% WRAPPER breadcrumbs %]
87         [% WRAPPER breadcrumb_item %]
88             <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a>
89         [% END %]
90         [% WRAPPER breadcrumb_item %]
91             <a href="/cgi-bin/koha/tools/additional-contents.pl">Additional content</a>
92         [% END %]
93         [% IF op == 'add_form' %]
94             [% WRAPPER breadcrumb_item %]
95                 [% IF category == 'news' %]
96                     <a href="/cgi-bin/koha/tools/additional-contents.pl?category=news">News</a>
97                 [% ELSIF category == 'pages' %]
98                     <a href="/cgi-bin/koha/tools/additional-contents.pl?category=pages">Pages</a>
99                 [% ELSE %]
100                     <a href="/cgi-bin/koha/tools/additional-contents.pl?category=html_customizations">HTML customizations</a>
101                 [% END %]
102             [% END %]
103             [% WRAPPER breadcrumb_item bc_active= 1 %]
104                 [% PROCESS page_heading %]
105             [% END %]
106         [% ELSE %]
107             [% WRAPPER breadcrumb_item bc_active= 1 %]
108                 [% PROCESS page_section %]
109             [% END %]
110         [% END %]
111     [% END #/ WRAPPER breadcrumbs %]
112 [% END #/ WRAPPER sub-header.inc %]
113
114 [% IF op == 'add_form' %]
115 <div class="main container-fluid">
116     <div class="row">
117         <div class="col-md-10 col-md-offset-1 col-lg-8 col-lg-offset-2">
118 [% ELSE %]
119 <div class="main container-fluid">
120     <div class="row">
121         <div class="col-sm-10 col-sm-push-2">
122 [% END %]
123
124 <main>
125
126     [% FOR m IN messages %]
127         <div class="dialog [% m.type | html %]">
128             [% SWITCH m.code %]
129             [% CASE 'error_on_update' %]
130                 <span>An error occurred when updating this content. Perhaps it already exists.</span>
131             [% CASE 'error_on_insert' %]
132                 <span>An error occurred when adding this content. Check the logs for details.</span>
133             [% CASE 'error_on_delete' %]
134                 <span>An error occurred when deleting this content. Check the logs for details.</span>
135             [% CASE 'success_on_update' %]
136                 <span>Content updated successfully.</span>
137             [% CASE 'success_on_insert' %]
138                 <span>Content added successfully.</span>
139             [% CASE 'success_on_delete' %]
140                 <span>Content deleted successfully.</span>
141             [% CASE %]
142                 <span>[% m.code | html %]</span>
143             [% END %]
144         </div>
145     [% END %]
146
147     [% IF op == 'add_form' %]
148         [% PROCESS add_form %]
149     [% ELSE %]
150         [% PROCESS list %]
151     [% END %]
152
153 </main>
154
155         [% IF op != 'add_form' %]
156             </div> <!-- /.col-sm-10.col-sm-push-2 -->
157
158             <div class="col-sm-2 col-sm-pull-10">
159                 <aside>
160
161                     <div id="news-filter">
162                         <form action="/cgi-bin/koha/tools/additional-contents.pl" method="get">
163                             <h4>Filter</h4>
164                             <fieldset class="brief">
165                                 <ol>
166                                     <li>
167                                         <label for="news_keyword">Keyword:</label>
168                                         <input type="text" name="news_keyword" id="news_keyword" />
169                                     </li>
170                                     <li>
171                                         <label for="news_display_location">Display location:</label>
172                                         <select name="news_display_location" id="news_display_location">
173                                             <option value="">All</option>
174                                             [% PROCESS locations_options category => category %]
175                                         </select>
176                                     </li>
177                                     <li>
178                                         <label for="news_library">Library: </label>
179                                         <select id="news_library" name="news_library">
180                                             <option value=""></option>
181                                             <option value="">All libraries</option>
182                                             [% PROCESS options_for_libraries libraries => Branches.all( selected => branchcode, unfiltered => 1, ) %]
183                                         </select>
184                                     </li>
185                                     <li>
186                                         <label>
187                                             <input type="checkbox" name="show_expired" id="show_expired" /> Show expired
188                                         </label>
189                                     </li>
190                                 </ol>
191                             </fieldset>
192                         </form>
193                     </div>
194
195                     [% INCLUDE 'tools-menu.inc' %]
196                 </aside>
197             </div> <!-- /.col-sm-2.col-sm-pull-10 -->
198         [% END %]
199     </div> <!-- /.row -->
200 </div> <!-- /.main.container-fluid -->
201
202 [% BLOCK add_form %]
203     <h1>[% PROCESS page_heading %]</h1>
204
205     <div id="toolbar" class="btn-toolbar">
206         <div class="btn-group">
207             <button class="btn btn-primary" id="submit_form"><i class="fa fa-save"></i> Save</button>
208             <button class="btn btn-primary dropdown-toggle" data-toggle="dropdown">
209             <span class="caret"></span>
210             </button>
211             <ul class="dropdown-menu">
212                 <li><a id="saveandcontinue" href="#">Save and continue editing</a></li>
213             </ul>
214         </div>
215         [% IF category == 'news' %]
216             <a class="btn btn-default cancel" href="/cgi-bin/koha/tools/additional-contents.pl"><i class="fa fa-times"></i> Cancel</a>
217         [% ELSIF category == 'pages' %]
218             <a class="btn btn-default cancel" href="/cgi-bin/koha/tools/additional-contents.pl?category=pages"><i class="fa fa-times"></i> Cancel</a>
219         [% ELSE %]
220             <a class="btn btn-default cancel" href="/cgi-bin/koha/tools/additional-contents.pl?category=html_customizations"><i class="fa fa-times"></i> Cancel</a>
221         [% END %]
222     </div>
223
224     <form id="add_additional_content" method="post" action="/cgi-bin/koha/tools/additional-contents.pl" class="validate">
225         [% INCLUDE 'csrf-token.inc' %]
226         <input type="hidden" name="op" value="add_validate" />
227         <input type="hidden" name="category" value="[% category | html %]" />
228         <input type="hidden" name="code" value="[% additional_content.code | html %]" />
229         <input type="hidden" name="id" value="[% additional_content.id | html %]" />
230         <input type="hidden" id="redirect" name="redirect" value="" />
231         <input type="hidden" id="editmode" name="editmode" value="[% editmode | html %]" />
232         <fieldset class="rows">
233             <ol>
234                 <li>
235                     <label for="location">Display location:</label>
236                     <select id="location" name="location">
237                         [% PROCESS locations_options location => additional_content.location %]
238                     </select>
239                     [% INCLUDE 'html-customization-help.inc' %]
240                 </li>
241                 <li>
242                     <label for="branchcode">Library: </label>
243                     <select id="branchcode" name="branchcode">
244                         [% IF additional_content.branchcode == '' %]
245                             <option value="" selected="selected">All libraries</option>
246                         [% ELSE %]
247                             <option value="">All libraries</option>
248                         [% END %]
249                         [% PROCESS options_for_libraries libraries => Branches.all( selected => additional_content.branchcode, unfiltered => 1, ) %]
250                     </select>
251                 </li>
252                 [% UNLESS languages.size %]
253                     <li>
254                         [% IF category == 'news' %]
255                             <label for="title" class="required">Title: </label>
256                             <input id="title" size="100" maxlength="250" type="text" name="title_default" value="[% additional_content.title | html %]" required="required" class="required" /> <span class="required">Required</span>
257                         [% ELSE %]
258                             <label for="title">Title: </label>
259                             <input id="title" size="100" maxlength="250" type="text" name="title_default" value="[% additional_content.title | html %]" />
260                         [% END %]
261                     </li>
262                 [% END %]
263                 <li>
264                     <label for="from">Publication date: </label>
265                     <input id="from" type="text" name="published_on" size="15" value="[% additional_content.published_on | html %]" class="flatpickr" data-date_to="to" />
266                     <div class="hint">[% INCLUDE 'date-format.inc' %]</div>
267                 </li>
268                 <li>
269                     <label for="to">Expiration date: </label>
270                     <input id="to" type="text" name="expirationdate" size="15" value="[% additional_content.expirationdate | html %]" class="flatpickr" />
271                     <div class="hint">
272                         [% INCLUDE 'date-format.inc' %]
273                         [% IF category == 'news' %]
274                             <br>News will still be accessible by direct URL if expired.
275                         [% END %]
276                     </div>
277                 </li>
278                 [% UNLESS category == 'pages' %]
279                 <li>
280                     <label for="number">Appear in position: </label>
281                     [% IF ( additional_content.number ) %]
282                         <input id="number" size="3" name="number" type="text" value="[% additional_content.number | html %]" />
283                     [% ELSE %]
284                         <input id="number" size="3" name="number" type="text" />
285                     [% END %]
286                 </li>
287                 [% END %]
288             </ol>
289         </fieldset>
290
291         <hr aria-hidden="true" />
292
293         [% IF languages.size %]
294             [% WRAPPER tabs id= "tabs" %]
295                 [% WRAPPER tabs_nav %]
296                     [% FOR language IN languages %]
297                         [% IF language.lang == 'default' %]
298                             [% WRAPPER tab_item tabname= "lang_default" %] <span>Default</span> [% END %]
299                         [% ELSE %]
300                             [% WRAPPER tab_item tabname= "lang_${language.lang}" %] [% language.description | html %] [% END %]
301                         [% END %]
302                     [% END %]
303                 [% END # /WRAPPER tabs_nav %]
304
305                 [% WRAPPER tab_panels %]
306                     [% FOR language IN languages %]
307                         [% SET translated_content = translated_contents.item(language.lang) %]
308                         [% WRAPPER tab_panel tabname="lang_${language.lang}" %]
309                             <fieldset>
310                                 <ol>
311                                     <li>
312                                         <label for="title_[% language.lang | html %]">Title: </label>
313                                         <input id="title_[% language.lang| html %]" size="100" maxlength="250" type="text" name="title_[% language.lang | html %]" value="[% translated_content.title | html %]">
314                                     </li>
315                                     <li>
316                                         <label for="content_[% language.lang | html %]">Content: </label>
317                                         <textarea name="content_[% language.lang | html %]" id="content_[% language.lang | html %]" data-lang="[% language.lang | html%]" cols="75" rows="10">[% translated_content.content | html %]</textarea>
318                                         <input type="hidden" name="id_[% language.lang | html %]" value="[% translated_content.id | html %]" />
319                                         <input type="hidden" name="lang" value="[% language.lang | html %]" />
320                                     </li>
321                                 </ol>
322                             </fieldset>
323                         [% END # /WRAPPER tab_panel#lang %]
324                     [% END # /FOR language %]
325                 [% END # /WRAPPER tab_panels %]
326             [% END # /WRAPPER tabs %]
327         [% ELSE %]
328             <div id="lang_default">
329                 <div class="clearfix">
330                     <textarea name="content" id="content_default" data-lang="[% language.lang | html %]"  cols="75" rows="10">[% additional_content.content | html %]</textarea>
331                 </div>
332             </div>
333         [% END # /IF languages.size %]
334     </form>
335 [% END %]
336
337 [% BLOCK list %]
338
339     <div id="toolbar" class="btn-toolbar">
340         <div class="btn-group">
341             <a href="/cgi-bin/koha/tools/additional-contents.pl?op=add_form&category=[% category | uri %]&editmode=[% editmode | uri %]" class="btn btn-default" id="newentry"> <i class="fa fa-plus"></i> New entry</a><button class="btn btn-default dropdown-toggle" data-toggle="dropdown">
342                 <span class="caret"></span>
343             </button>
344             <ul class="dropdown-menu pull-right">
345                 <li>
346                     [% IF ( wysiwyg ) %]
347                         <a href="/cgi-bin/koha/tools/additional-contents.pl?op=add_form&category=[% category | uri %]&editmode=text">New entry using text editor</a>
348                     [% ELSE %]
349                         <a href="/cgi-bin/koha/tools/additional-contents.pl?op=add_form&category=[% category | uri %]&editmode=wysiwyg">New entry using WYSIWYG editor</a>
350                     [% END %]
351                 </li>
352             </ul>
353         </div>
354     </div>
355
356     <h2>
357         Additional content:
358         [% IF category == 'news' %]
359             [% t("News") | html %]
360         [% ELSIF category == 'pages' %]
361             [% t("Pages") | html %]
362         [% ELSE %]
363             [% t("HTML customizations") | html %]
364         [% END %]
365     </h2>
366     <span id="additional_contents_links">
367         See
368         <a class="customization-link" href="/cgi-bin/koha/tools/additional-contents.pl?category=news">News</a>
369         <a class="customization-link" href="/cgi-bin/koha/tools/additional-contents.pl?category=html_customizations">HTML customizations</a>
370         <a class="customization-link" href="/cgi-bin/koha/tools/additional-contents.pl?category=pages">Pages</a>
371         [% IF ( CAN_user_parameters_manage_sysprefs ) %]
372             <a class="syspref-link" href='/cgi-bin/koha/admin/preferences.pl?op=search&searchfield=OPACUserJS'>OPACUserJS</a>
373             <a class="syspref-link" href='/cgi-bin/koha/admin/preferences.pl?op=search&searchfield=OPACUserCSS'>OPACUserCSS</a>
374         [% END %]
375     </span>
376
377     [% IF additional_contents.count %]
378         <div class="page-section">
379             <form id="del_form" method="post" action="/cgi-bin/koha/tools/additional-contents.pl">
380                 <table id="table_additional_contents">
381                     <thead>
382                         <tr>
383                             <th class="NoSort">&nbsp;</th>
384                             <th>Location</th>
385                             <th>Library</th>
386                             <th>Number</th>
387                             <th>Publication date</th>
388                             <th>Expiration date</th>
389                             <th class="anti-the">Title</th>
390                             <th>Author</th>
391                             [% IF category == 'pages' %]
392                                 <th>Page URL</th>
393                                 <th class="anti-the">Page</th>
394                             [% ELSE %]
395                                 <th class="anti-the">News</th>
396                             [% END %]
397                             <th class="NoSort noExport">Actions</th>
398                         </tr>
399                     </thead>
400                     <tbody>
401                         [% FOREACH c IN additional_contents%]
402                             [% SET default_localization = c.default_localization %]
403                             [% IF ( c.is_expired ) %]<tr class="expired">[% ELSE %]<tr>[% END %]
404                             <td>
405                                 <input type="checkbox" name="ids" value="[% c.id | html %]" />
406                             </td>
407                             <td>
408                                 [% IF c.category == 'news' || c.category == 'pages' %]
409                                     [% IF c.location == 'staff_and_opac' %]<span>All</span>
410                                     [% ELSIF c.location == 'staff_only' %]<span>Staff interface</span>
411                                     [% ELSIF c.location == 'opac_only' %]<span>OPAC</span>
412                                     [% ELSIF c.location == 'slip' %]<span>Slip</span>
413                                     [% ELSE %]<span>Unknown ('[% location | html %]')</span>
414                                     [% END %]
415                                 [% ELSE %]
416                                     [% c.location | html %]
417                                 [% END %]
418                             </td>
419                             <td>
420                                 [% IF ( c.branchcode == "" ) -%]
421                                 All libraries
422                                 [% ELSE %][% c.library.branchname | html %]
423                                 [% END %]
424                             </td>
425                             <td>[% c.number | html %]</td>
426                             <td data-order="[% c.published_on | html %]">[% c.published_on | $KohaDates %]</td>
427                             <td data-order="[% c.expirationdate | html %]">[% c.expirationdate | $KohaDates %] [% IF ( c.is_expired ) %](<span class="expired">expired</span>)[% END %]</td>
428                             <td>[% default_localization.title | html %]</td>
429                             <td>[% IF ( c.author) %][% INCLUDE 'patron-title.inc' patron=c.author %][% END %]</td>
430                             [% IF category == 'pages' %]
431                                 <td class="actions">
432                                     [% IF c.location == 'opac_only' OR c.location == 'staff_and_opac' %]
433                                         <a target="_blank" href="[% Koha.Preference('OPACBaseURL') | url %]/cgi-bin/koha/opac-page.pl?page_id=[% c.id | uri %]" title="View on OPAC"><strong>OPAC</strong></a>
434                                     [% END %]
435                                     [% IF c.location == 'staff_only' OR c.location == 'staff_and_opac' %]
436                                         [% IF c.location == 'staff_and_opac' %]<br/>[% END %]
437                                         <a target="_blank" href="/cgi-bin/koha/tools/page.pl?page_id=[% c.id | uri %]" title="View on staff interface"><strong>Staff</strong></a>
438                                     [% END %]
439                                 </td>
440                             [% END %]
441                             <td>
442                                 <div class="btn-group">
443                                     <a class="preview_news btn btn-default btn-xs" data-number="[% loop.count | html %]"><i class="fa-solid fa-eye" aria-hidden="true"></i> Preview content</a>
444                                 </div>
445                                 <div id="contentModal[% loop.count | html %]" class="modal" tabindex="-1" role="dialog" data-number="[% loop.count | html %]">
446                                     <div class="modal-dialog" role="document">
447                                         <div class="modal-content modal-lg">
448                                             <div class="modal-header">
449                                                 <h5 class="modal-title">Preview of: "[% default_localization.title | html %]"</h5>
450                                             </div>
451                                         <div class="modal-body">
452                                             [% default_localization.content | $raw %]
453                                         </div>
454                                         <div class="modal-footer">
455                                             <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
456                                         </div>
457                                     </div>
458                                 </div>
459                             </td>
460                             <td class="actions">
461                                 <div class="btn-group dropup">
462                                     <a href="/cgi-bin/koha/tools/additional-contents.pl?op=add_form&amp;id=[% c.id | uri %]&editmode=[% editmode | uri %]" class="btn btn-default btn-xs"> <i class="fa-solid fa-pencil"></i> Edit</a><button class="btn btn-default btn-xs dropdown-toggle" data-toggle="dropdown">
463                                         <span class="caret"></span>
464                                     </button>
465                                     <ul class="dropdown-menu pull-right">
466                                         <li>
467                                             [% IF ( wysiwyg ) %]
468                                                 <a href="/cgi-bin/koha/tools/additional-contents.pl?op=add_form&amp;id=[% c.id | uri %]&editmode=text"><i class="fa-solid fa-pencil"></i> Edit with text editor</a>
469                                             [% ELSE %]
470                                                 <a href="/cgi-bin/koha/tools/additional-contents.pl?op=add_form&amp;id=[% c.id | uri %]&editmode=wysiwyg"><i class="fa-solid fa-pencil"></i> Edit with WYSIWYG editor</a>
471                                             [% END %]
472                                         </li>
473                                     </ul>
474                                 </div>
475                                 <div class="btn-group">
476                                     <a href="#" class="delete_news btn btn-default btn-xs" data-id="[% c.id | html %]"><i class="fa fa-trash-can"></i> Delete</a>
477                                 </div>
478                             </td>
479                         </tr>
480                         [% END %]
481                     </tbody>
482                 </table>
483                 <input type="hidden" name="op" value="delete_confirmed" />
484                 <input type="hidden" name="category" value="[% category | html %]" />
485                 <fieldset class="action"><input type="submit" class="btn btn-primary" value="Delete selected" /></fieldset>
486             </form>
487             <form action="/cgi-bin/koha/tools/additional-contents.pl" method="post" id="delete_single">
488                 [% INCLUDE 'csrf-token.inc' %]
489                 <input type="hidden" id="del_op" name="op" value="delete_confirmed" />
490                 <input type="hidden" id="del_category" name="category" value="[% category | html %]" />
491                 <input type="hidden" id="del_ids" name="ids" />
492             </form>
493         </div> <!-- /.page-section -->
494     [% ELSE %]
495         <div class="dialog message">There are no additional contents.</div>
496     [% END %]
497 [% END %]
498
499 [% BLOCK locations_options %]
500     [% IF category == 'news' || category == 'pages' %]
501         [% IF location == "staff_and_opac" %]
502             <option value="staff_and_opac" selected="selected">Staff interface and OPAC</option>
503         [% ELSE %]
504             <option value="staff_and_opac">Staff interface and OPAC</option>
505         [% END %]
506
507         [% IF location == "staff_only" %]
508             <option value="staff_only" selected="selected">Staff interface</option>
509         [% ELSE %]
510             <option value="staff_only">Staff interface</option>
511         [% END %]
512
513         [% IF location == "opac_only" %]
514             <option value="opac_only" selected="selected">OPAC</option>
515         [% ELSE %]
516             <option value="opac_only">OPAC</option>
517         [% END %]
518
519         [% UNLESS category == 'pages' %]
520             [% IF location == "slip" %]
521                 <option value="slip" selected="selected">Slip</option>
522             [% ELSE %]
523                 <option value="slip">Slip</option>
524             [% END %]
525         [% END %]
526     [% ELSE %]
527         [% SET opac_available_options = [ 'OpacNavRight', 'opacheader', 'OpacCustomSearch', 'OpacMainUserBlock', 'opaccredits', 'OpacLoginInstructions', 'OpacNav', 'OpacNavBottom', 'OpacSuggestionInstructions', 'ArticleRequestsDisclaimerText', 'OpacMoreSearches', 'OpacMySummaryNote', 'OpacLibraryInfo', 'OpacMaintenanceNotice', 'OPACResultsSidebar', 'OpacSuppressionMessage', 'SCOMainUserBlock', 'SelfCheckInMainUserBlock', 'SelfCheckHelpMessage', 'CatalogConcernHelp', 'CatalogConcernTemplate', 'CookieConsentBar', 'CookieConsentPopup', 'PatronSelfRegistrationAdditionalInstructions' ] %]
528         <optgroup label="OPAC">
529             [% FOREACH l IN opac_available_options.sort %]
530                 [% IF l == location %]
531                     <option value="[% l | html %]" selected="selected">[% l | html %]</option>
532                 [% ELSE %]
533                     <option value="[% l | html %]">[% l | html %]</option>
534                 [% END %]
535             [% END %]
536         </optgroup>
537         [% SET staff_available_options = [ 'StaffAcquisitionsHome', 'StaffAuthoritiesHome', 'StaffCataloguingHome', 'StaffListsHome', 'StaffPatronsHome', 'StaffPOSHome', 'StaffSerialsHome' ] %]
538         <optgroup label="Staff">
539             [% FOREACH l IN staff_available_options.sort %]
540                 [% IF l == location %]
541                     <option value="[% l | html %]" selected="selected">[% l | html %]</option>
542                 [% ELSE %]
543                     <option value="[% l | html %]">[% l | html %]</option>
544                 [% END %]
545             [% END %]
546         </optgroup>
547     [% END %]
548 [% END %]
549
550 [% MACRO jsinclude BLOCK %]
551     [% INCLUDE 'calendar.inc' %]
552     [% INCLUDE 'select2.inc' %]
553     [% Asset.js("js/tools-menu.js") | $raw %]
554     [% Asset.js("lib/hc-sticky.js") | $raw %]
555     <script>
556         $("#saveandcontinue").on("click",function(e){
557             e.preventDefault();
558             $("#redirect").val("just_save");
559             $("#submit_form").click();
560         });
561     </script>
562     [% IF additional_contents.count %]
563         [% INCLUDE 'datatables.inc' %]
564         <script>
565             $('.preview_news').click( function() {
566                 modalNumber = $(this).attr('data-number');
567                 $('.modal[data-number="'+modalNumber+'"]').modal('show');
568             })
569             function Checkbox(){
570                 var form = document.getElementById('del_form');
571                 var inputs = form.getElementsByTagName('input');
572                 var checked = false;
573                 for (var i=0; i<inputs.length; i++) {
574                     if (inputs[i].type == 'checkbox' && inputs[i].name == 'ids') {
575                         checked = inputs[i].checked;
576                         if (checked) return true;
577                     }
578                 }
579             }
580
581             function filterDataTable( table, column, term ){
582                 if( column ){
583                     table.column( column ).search( term ).draw();
584                 } else {
585                     table.search( term ).draw();
586                 }
587                 clearFilter( term );
588             }
589
590             function clearFilter( term ){
591                 if( term == "" ){
592                     $(".dt_button_clear_filter").addClass("disabled");
593                 } else {
594                     $(".dt_button_clear_filter").removeClass("disabled");
595                 }
596             }
597
598             /* Custom table search configuration: If a table row
599                has an "expired" class, hide it UNLESS the
600                show_expired checkbox is checked */
601             $.fn.dataTable.ext.search.push(
602                 function( settings, searchData, index, rowData, counter ) {
603                     var row = $(settings.aoData[index].nTr);
604                     if( row.hasClass("expired") && !$("#show_expired").prop("checked") ){
605                         return false;
606                     } else {
607                         return true;
608                     }
609                 }
610             );
611
612             $(document).ready(function() {
613
614                 var table = $("#table_additional_contents").DataTable($.extend(true, {}, dataTablesDefaults, {
615                     "order": [[ 4, "desc" ]],
616                     "aoColumnDefs": [
617                         { "sortable": false, "searchable": false, 'targets': [ 'NoSort' ] },
618                         { "type": "anti-the", "targets": [ "anti-the" ] }
619                     ],
620                     "sPaginationType": "full_numbers"
621                 }));
622
623                 $("#del_form").on("click", ".delete_news", function(e){
624                     e.preventDefault();
625                     if( confirmDelete( _("Are you sure you want to delete this content? This cannot be undone.") ) ){
626                         $("#del_ids").val( $(this).data("id") );
627                         $("#delete_single").submit();
628                     }
629                 });
630
631                 $("#del_form").on("submit",function(){
632                     if ( Checkbox() ) {
633                         return confirmDelete( _("Are you sure you want to delete the selected content?") );
634                     } else {
635                         alert(_("Please select content to delete."));
636                         return false;
637                     }
638                 });
639
640                 $("#show_expired").on("change", function(){
641                     /* redraw the DataTable according to the custom search function */
642                     table.draw();
643                 });
644
645                 table.on( 'search.dt', function () {
646                     var term = table.search();
647                     $("#news_keyword").val( term );
648                 });
649
650                 $("#news_keyword").on("keyup", function(){
651                     var term = $(this).val();
652                     filterDataTable( table, null, term );
653                 });
654
655                 $("#news_display_location").on("change", function(){
656                     var term = $(this).val();
657                     filterDataTable( table, 1, term );
658                 });
659
660                 $("#news_library").on("change", function(){
661                     // Table must be filtered by the <option>'s text, not its value
662                     var opt = $(this).find("option:selected").text();
663                     filterDataTable( table, 2, opt );
664                 });
665
666                 $(".dt_button_clear_filter").on("click", function(){
667                     table.search('').columns().search('').draw();
668                     $("#news-filter select").each(function(){
669                         $(this).val("");
670                     });
671                 });
672             });
673         </script>
674     [% ELSE %]
675         <script>
676             function showLocationNotes( location ){
677                 $(".customization_note").hide();
678                 $( "#" + location + "_notes" ).show();
679             }
680
681             $(document).ready(function() {
682                 [% IF category == 'news' %]
683                 $("#add_additional_content").validate({
684                     submitHandler: function(form){
685                         if ( ! $("#title_default").val().length > 0 ) {
686                             alert(_("Please specify a title for 'Default'"));
687                             return false;
688                         }
689                         else {
690                             [% UNLESS wysiwyg %]
691                                 let content = $('#content_default').siblings(".CodeMirror")[0].CodeMirror.getValue();
692                             [% ELSE %]
693                                 let content = tinyMCE.get('content_default').getContent();
694                             [% END %]
695
696                             if ( ! content.length > 0 ) {
697                                 alert(_("Please specify a content for 'Default'"));
698                                 return false;
699                             }
700                         }
701
702                         form.submit();
703                     }
704                 });
705                 [% END %]
706
707                 showLocationNotes( $("#location").val() );
708
709                 $("#location").on("change", function(){
710                     showLocationNotes( $(this).val() );
711                 });
712
713                 $("#submit_form").on("click",function(){
714                     $("#add_additional_content").submit();
715                 });
716
717                 Sticky = $("#toolbar");
718                 Sticky.hcSticky({
719                     stickTo: ".main",
720                     stickyClass: "floating"
721                 });
722                 $("#location").select2({ width: '50%' });
723             });
724         </script>
725     [% END %]
726     [% UNLESS ( wysiwyg ) %]
727         [% Asset.js( "lib/codemirror/codemirror.min.js" ) | $raw %]
728         [% Asset.js( "lib/codemirror/xml.min.js" ) | $raw %]
729         [% Asset.js( "lib/codemirror/lint.min.js" ) | $raw %]
730         [% Asset.js( "lib/linters/htmlhint.min.js" ) | $raw %]
731         [% Asset.js( "lib/codemirror/html-lint.min.js" ) | $raw %]
732         <script>
733             let editors = new Object(); /* Keeps track of initialized CodeMirror instances */
734             $(document).ready(function(){
735
736                 if( $("#tabs .tab-pane.active").length < 1 ){
737                     /* Activate first tab and initialize its CodeMirror instance */
738                     let firstTab = $("#tabs a:first");
739                     firstTab.tab("show");
740                     if ( firstTab[0] ) {
741                         initCodeMirror( firstTab[0].hash );
742                     }
743                 }
744
745                 $("#tabs a[data-toggle='tab']").on("shown.bs.tab", function (e) {
746                     /* Try to initialize CodeMirror instance when tab opens */
747                     initCodeMirror( e.target.hash );
748                 });
749             });
750
751             function initCodeMirror( container ){
752                 /* Initialize CodeMirror instance only if it doesn't exist */
753                 if( !editors[ container ] ){
754                     let textarea = $( container ).find("textarea[name^='content_']");
755                     let this_lang = textarea.attr('data-lang');
756                     let editor = CodeMirror.fromTextArea( document.getElementById('content_' + this_lang), {
757                         lineNumbers: true,
758                         lineWrapping: true,
759                         lint: true,
760                         mode: "text/html",
761                         gutters: ["CodeMirror-lint-markers"],
762                         viewportMargin: Infinity,
763                     });
764                     editors[ container ] = editor;
765                     return editor;
766                 }
767             }
768         </script>
769     [% ELSE %]
770         [% Asset.js("lib/tiny_mce/tinymce.min.js") | $raw %]
771         [% INCLUDE 'str/tinymce_i18n.inc' %]
772         <script>
773
774             $(document).ready(function(){
775                 if( $("#tabs").length > 0 && $("#tabs .tab-pane.active").length < 1 ){
776                     /* Activate first tab and initialize its tinyMCE instance */
777                     let firstTab = $("#tabs a:first");
778                     firstTab.tab("show");
779                     initTinyMce( firstTab[0].hash );
780                 }
781
782                 $("#tabs a[data-toggle='tab']").on("shown.bs.tab", function (e) {
783                     /* Try to initialize tinyMCE instance when tab opens */
784                     initTinyMce( e.target.hash );
785                 });
786             });
787
788             function initTinyMce( container ){
789                 let textarea = $( container ).find("textarea[name^='content_']");
790                 /* TinyMCE seems to do its own check to prevent double-initialization
791                    so We don't need to keep track of it */
792                 let editor = tinyMCE.init({
793                     branding : false,
794                     block_unsupported_drop : false,
795                     content_css : "[% interface | html %]/[% theme | html %]/css/tinymce.css",
796                     custom_elements:"style,link,~link",
797                     extended_valid_elements:"style,link[href|rel]",
798                     force_br_newlines : false,
799                     force_p_newlines : false,
800                     forced_root_block : '',
801                     menubar : "file edit view insert format tools table",
802                     plugins : "autoresize table hr link image charmap lists code emoticons",
803                     autoresize_bottom_margin: 60,
804                     relative_urls : false,
805                     selector: "#" + textarea[0].id,
806                     verify_html: false,
807                     toolbar : [
808                         "formatselect | bold italic | cut copy paste | alignleft aligncenter alignright | outdent indent | image link unlink anchor cleanup hr",
809                         "table | bullist numlist | undo redo | removeformat | emoticons charmap | forecolor backcolor | code"
810                     ],
811                 });
812                 return editor;
813             }
814         </script>
815     [% END # /UNLESS wysiwyg %]
816 [% END %]
817
818 [% INCLUDE 'intranet-bottom.inc' %]