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