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