Bug 17981: Remove uneeded module JS var
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / tools / letter.tt
1 [% USE Koha %]
2 [% USE Branches %]
3 [% SET footerjs = 1 %]
4 [% INCLUDE 'doc-head-open.inc' %]
5 <title>Koha &rsaquo; Tools &rsaquo; Notices[% IF ( add_form or copy_form ) %][% IF ( modify ) %] &rsaquo; Modify notice[% ELSE %] &rsaquo; Add notice[% END %][% END %][% IF ( add_validate or copy_validate) %] &rsaquo; Notice added[% END %][% IF ( delete_confirm ) %] &rsaquo; Confirm deletion[% END %]</title>
6 [% INCLUDE 'doc-head-close.inc' %]
7 <link rel="stylesheet" type="text/css" href="[% interface %]/[% theme %]/css/datatables_[% KOHA_VERSION %].css" />
8 </head>
9
10 <body id="tools_letter" class="tools">
11 [% INCLUDE 'header.inc' %]
12 [% INCLUDE 'letters-search.inc' %]
13
14 <div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a> &rsaquo; [% IF ( add_form or copy_form) %][% IF ( modify ) %]<a href="/cgi-bin/koha/tools/letter.pl">Notices &amp; Slips</a> &rsaquo; Modify notice[% ELSE %] <a href="/cgi-bin/koha/tools/letter.pl">Notices &amp; Slips</a> &rsaquo; Add notice[% END %][% ELSE %][% IF ( add_validate or copy_validate) %] <a href="/cgi-bin/koha/tools/letter.pl">Notices &amp; Slips</a> &rsaquo; Notice added[% ELSE %][% IF ( delete_confirm ) %] <a href="/cgi-bin/koha/tools/letter.pl">Notices &amp; Slips</a> &rsaquo; Confirm deletion[% ELSE %]Notices &amp; Slips[% END %][% END %][% END %]</div>
15
16 <div id="preview_template" class="modal in" tabindex="-1" role="dialog" aria-labelledby="preview_template_label" aria-hidden="true">
17     <div class="modal-dialog modal-lg">
18     <div class="modal-content">
19     <div class="modal-header">
20         <button type="button" class="closebtn" data-dismiss="modal" aria-hidden="true">×</button>
21         <h3 id="preview_template_label">Preview notice template</h3>
22     </div>
23     <div class="modal-body">
24         <div id="loading"> <img src="[% interface %]/[% theme %]/img/spinner-small.gif" alt="" /> Loading </div>
25     </div>
26     <div class="modal-footer">
27         <!-- TODO <a href="#" class="btn btn-default" id="preview_template_button" role="button" data-toggle="modal">Convert using the Template Toolkit syntax</a>-->
28         <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">Close</button>
29     </div>
30     </div>
31     </div>
32 </div>
33
34 [% IF add_form or copy_form %]
35     <div class="main container-fluid">
36         <div class="row">
37             <div class="col-md-8 col-md-offset-2">
38 [% ELSE %]
39     <div id="doc3" class="yui-t2">
40         <div id="bd">
41             <div id="yui-main">
42                 <div class="yui-b">
43 [% END %]
44
45 [% IF ( no_op_set ) %]
46     <h1>Notices and Slips</h1>
47     <form method="get" action="/cgi-bin/koha/tools/letter.pl" id="selectlibrary">
48       <input type="hidden" name="searchfield" value="[% searchfield | html %]" />
49     [% UNLESS independant_branch %]
50       <p>
51         Select a library :
52             <select name="branchcode" id="branch" style="width:20em;">
53                 <option value="*">All libraries</option>
54                 [% PROCESS options_for_libraries libraries => Branches.all( selected => branchcode ) %]
55             </select>
56       </p>
57     [% END %]
58       <div id="toolbar" class="btn-toolbar">
59           <button type="submit" class="btn btn-default btn-sm" id="newnotice"><i class="fa fa-plus"></i> New notice</button>
60         <input type="hidden" id="op" name="op" />
61       </div>
62     </form>
63
64                 [% IF ( search ) %]
65         <p>You searched for <b>[% searchfield | html %]</b></p>
66                 [% END %]
67                 [% IF ( letter && !independant_branch) %]
68             [% select_for_copy = BLOCK %]
69             <select name="branchcode">
70                 [% FOREACH l IN Branches.all() %]
71                 <option value="[% l.branchcode %]">Copy to [% l.branchname %]</option>
72                 [% END %]
73             </select>
74             [% END %]
75         [% END %]
76         [% IF letter %]
77           <table id="lettert">
78             <thead>
79               <tr>
80                 <th>Library</th>
81                 <th>Module</th>
82                 <th>Code</th>
83                 <th>Name</th>
84                 <th class="nosort">Copy notice</th>
85                 <th class="nosort">Actions</th>
86               </tr>
87             </thead>
88             <tbody>
89               [% FOREACH lette IN letter %]
90                 [% can_edit = lette.branchcode || !independant_branch %]
91                 <tr>
92                   <td>[% IF lette.branchname %][% lette.branchname %][% ELSE %](All libraries)[% END %]</td>
93                   <td>[% lette.module %]</td>
94                   <td>[% lette.code %]</td>
95                   <td>[% lette.name %]</td>
96                   <td class="actions">
97                     [% IF !independant_branch || !lette.branchcode %]
98                       <form method="post" action="/cgi-bin/koha/tools/letter.pl">
99                         <input type="hidden" name="op" value="copy_form" />
100                         <input type="hidden" name="oldbranchcode" value="[% lette.branchcode %]" />
101                         <input type="hidden" name="module" value="[% lette.module %]" />
102                         <input type="hidden" name="code" value="[% lette.code %]" />
103                         [% IF independant_branch %]
104                           <input type="hidden" name="branchcode" value="[% independant_branch %]" />
105                         [% ELSE %]
106                           [% select_for_copy %]
107                         [% END %]
108                         <button class="btn btn-default btn-xs"><i class="fa fa-clone"></i> Copy</button>
109                       </form>
110                     [% END %]
111                   </td>
112                   <td class="actions">
113                     [% IF can_edit %]
114                       <a class="btn btn-default btn-xs" href="/cgi-bin/koha/tools/letter.pl?op=add_form&amp;branchcode=[% lette.branchcode %]&amp;module=[% lette.module %]&amp;code=[% lette.code %]"><i class="fa fa-pencil"></i> Edit</a>
115                     [% END %]
116                     [% IF !lette.protected && can_edit %]
117                       <a class="btn btn-default btn-xs" href="/cgi-bin/koha/tools/letter.pl?op=delete_confirm&amp;branchcode=[%lette.branchcode %]&amp;module=[% lette.module %]&amp;code=[% lette.code %]"><i class="fa fa-trash"></i> Delete</a>
118                     [% END %]
119                   </td>
120                 </tr>
121               [% END %]
122             </tbody>
123           </table>
124         [% ELSE %]
125           <div class="dialog message">
126           [% IF ( branchcode ) %]
127              <p>There are no notices for this library.</p>
128           [% ELSE %]
129               <p>There are no notices.</p>
130           [% END %]
131           </div>
132         [% END %]
133 [% END %]
134
135         
136 [% IF add_form or copy_form %]
137 <h1>[% IF ( modify ) %]Modify notice[% ELSE %]Add notice[% END %]</h1>
138
139     <div id="toolbar" class="btn-toolbar">
140         <div class="btn-group">
141             <button class="btn btn-default btn-sm" id="submit_form"><i class="fa fa-save"></i> Save</button>
142             <button class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown">
143             <span class="caret"></span>
144             </button>
145             <ul class="dropdown-menu">
146                 <li><a id="saveandcontinue" href="#">Save and continue editing</a></li>
147             </ul>
148         </div>
149         <a class="btn btn-default btn-sm cancel" href="/cgi-bin/koha/tools/letter.pl"><i class="fa fa-remove"></i> Cancel</a>
150     </div>
151
152         <form id="add_notice" name="Aform" method="post" enctype="multipart/form-data" class="validate">
153         [% IF add_form %]
154           <input type="hidden" name="op" id="op" value="add_validate" />
155         [% ELSE %]
156           <input type="hidden" name="op" id="op" value="copy_validate" />
157         [% END %]
158
159                 <input type="hidden" name="checked" value="0" />
160                 [% IF ( modify ) %]
161                 <input type="hidden" name="add" value="0" />
162                 [% ELSE %]
163                 <input type="hidden" name="add" value="1" />
164                 [% END %]
165                 <fieldset class="rows">
166             <input type="hidden" name="oldbranchcode" value="[% oldbranchcode %]" />
167             <ol>
168             [% IF independant_branch %]
169                 <input type="hidden" name="branchcode" value="[% independant_branch %]" />
170             [% ELSE %]
171             <li>
172
173                 [% IF adding %]
174                     <label for="branch">Library:</label>
175                     <select name="branchcode" id="branch" style="width:20em;">
176                         <option value="">All libraries</option>
177                         [% PROCESS options_for_libraries libraries => Branches.all( selected => branchcode ) %]
178                     </select>
179                 [% ELSE %]
180                     <span class="label">Library:</span>
181                     <input type="hidden" id="branch" name="branchcode" value="[% branchcode %]" />
182                     [% IF ( branchcode ) %]
183                        [% Branches.GetName( branchcode ) %]
184                     [% ELSE %]
185                         All libraries
186                     [% END %]
187                 [% END %]
188             </li>
189             [% END %]
190                         <li>
191                                 <label for="module">Koha module:</label>
192                                 <input type="hidden" name="oldmodule" value="[% module %]" />
193                 [% IF adding  %]
194                   <select name="module" id="newmodule">
195                 [% ELSE %]
196                   <select name="module" id="module">
197                 [% END %]
198                                     [% IF ( module == "acquisition" ) %]
199                                       <option value="acquisition" selected="selected">Acquisition</option>
200                                     [% ELSE %]
201                                       <option value="acquisition" >Acquisition</option>
202                                     [% END %]
203                                     [% IF ( module == "catalogue" ) %]
204                                       <option value="catalogue" selected="selected">Catalog</option>
205                                     [% ELSE %]
206                                       <option value="catalogue" >Catalog</option>
207                                     [% END %]
208                                     [% IF ( module == "circulation" ) %]
209                                       <option value="circulation" selected="selected">Circulation</option>
210                                     [% ELSE %]
211                                       <option value="circulation">Circulation</option>
212                                     [% END %]
213                                     [% IF ( module == "orderacquisition" ) %]
214                                       <option value="orderacquisition" selected="selected">Order acquisition</option>
215                                     [% ELSE %]
216                                       <option value="orderacquisition">Order acquisition</option>
217                                     [% END %]
218                                     [% IF ( module == "claimacquisition" ) %]
219                                       <option value="claimacquisition" selected="selected">Claim acquisition</option>
220                                     [% ELSE %]
221                                       <option value="claimacquisition">Claim acquisition</option>
222                                     [% END %]
223                                     [% IF ( module == "claimissues" ) %]
224                                       <option value="claimissues" selected="selected">Claim serial issue</option>
225                                     [% ELSE %]
226                                       <option value="claimissues">Claim serial issue</option>
227                                     [% END %]
228                                     [% IF ( module == "reserves" ) %]
229                                       <option value="reserves" selected="selected">Holds</option>
230                                     [% ELSE %]
231                                       <option value="reserves">Holds</option>
232                                     [% END %]
233                                     [% IF ( module == "members" ) %]
234                                       <option value="members" selected="selected">Members</option>
235                                     [% ELSE %]
236                                       <option value="members">Members</option>
237                                     [% END %]
238                                     [% IF ( module == "serial" ) %]
239                                       <option value="serial" selected="selected">Serials (routing list)</option>
240                                     [% ELSE %]
241                                       <option value="serial">Serials (routing list)</option>
242                                     [% END %]
243                                     [% IF ( module == "suggestions" ) %]
244                                       <option value="suggestions" selected="selected">Suggestions</option>
245                                     [% ELSE %]
246                                       <option value="suggestions">Suggestions</option>
247                                     [% END %]
248                 </select>
249             </li>
250             <li>
251               [% IF adding %]
252                   <label for="code" class="required">Code:</label>
253                   <input type="text" id="code" name="code" size="20" maxlength="20" value="" required="required"/>
254                   <span class="required">Required</span>
255               [% ELSE %]
256                   <span class="label">Code:</span>
257                   <input type="hidden" id="code" name="code" value="[% code %]" />
258                   [% code %]
259               [% END %]
260             </li>
261             <li>
262               <label for="name" class="required">Name:</label>
263               <input type="text" id="name" name="name" size="60" value="[% letter_name %]" required="required" />
264               <span class="required">Required</span>
265             </li>
266             [% IF code and preview_is_available%]
267                 <li>
268                     <label for="name">Data for preview:</label>
269                     [% SWITCH code %]
270                     [% CASE 'CHECKIN' %]
271                         <input type="text" id="data_preview" name="data_preview" value="" placeholder="barcode" />
272                     [% CASE 'CHECKOUT' %]
273                         <input type="text" id="data_preview" name="data_preview" value="" placeholder="barcode|borrowernumber" />
274                     [% CASE 'HOLD_SLIP' %]
275                         <input type="text" id="data_preview" name="data_preview" value="" placeholder="biblionumber|borrowernumber" />
276                     [% CASE %]
277                         Not supported yet.
278                     [% END %]
279                     </li>
280             [% END %]
281         </ol>
282     </fieldset>
283         [% IF Koha.Preference('TranslateNotices') %]
284         <div style="clear:both"></div>
285             <div id="tabs">
286                 <ul>
287                     <li><a href="#lang_default">Default</a></li>
288                     [% FOR language IN languages %]
289                         [% FOR sublanguage IN language.sublanguages_loop %]
290                             [% IF language.plural %]
291                                 <li><a href="#lang_[% sublanguage.rfc4646_subtag %]">[% sublanguage.native_description %] [% sublanguage.region_description %] ([% sublanguage.rfc4646_subtag %])</a></li>
292                             [% ELSE %]
293                                 <li><a href="#lang_[% sublanguage.rfc4646_subtag %]">[% sublanguage.native_description %] ([% sublanguage.rfc4646_subtag %])</a></li>
294                             [% END %]
295                         [% END %]
296                     [% END %]
297                 </ul>
298         [% END %]
299
300         [% FOREACH lang IN letters.keys %]
301             <div id="lang_[% lang %]">
302         <div class="transport-types" style="clear:both">
303         [% FOR mtt IN letters.$lang.templates.keys.sort %]
304             [% SET letter = letters.$lang.templates.$mtt %]
305             <h3>
306                 [% SWITCH letter.message_transport_type %]
307                 [% CASE 'email' %]
308                   Email
309                 [% CASE 'print' %]
310                   Print
311                 [% CASE 'sms' %]
312                   SMS
313                 [% CASE 'feed' %]
314                   Feed
315                 [% CASE 'phone' %]
316                   Phone
317                 [% CASE %]
318                   [% letter.message_transport_type %]
319                 [% END %]
320             </h3>
321             [% IF letter.message_transport_type == "sms" and not Koha.Preference("SMSSendDriver") %]
322               <fieldset class="rows mtt" id="[% letter.message_transport_type %]_[% lang %]" disabled="disabled">
323                 <div class="dialog message">You should enable the SMSSendDriver preference to use the SMS templates.</div>
324             [% ELSIF letter.message_transport_type == "phone" and not Koha.Preference("TalkingTechItivaPhoneNotification") %]
325               <fieldset class="rows mtt" id="[% letter.message_transport_type %]_[% lang %]" disabled="disabled">
326                 <div class="dialog message">You should enable the TalkingTechItivaPhoneNotification preference to use the phone templates.</div>
327             [% ELSE %]
328               <fieldset class="rows mtt" id="[% letter.message_transport_type %]_[% lang %]">
329             [% END %]
330               <ol>
331                 <li>
332                   <input type="hidden" name="message_transport_type" value="[% letter.message_transport_type %]" />
333                   <input type="hidden" name="lang" value="[% lang %]" />
334                   <label for="is_html_[% letter.message_transport_type %]_[% lang %]">HTML message:</label>
335                   [% IF letter.is_html %]
336                     <input type="checkbox" name="is_html_[% letter.message_transport_type %]" id="is_html_[% letter.message_transport_type %]_[% lang %]" value="1" checked="checked" />
337                   [% ELSE %]
338                     <input type="checkbox" name="is_html_[% letter.message_transport_type %]" id="is_html_[% letter.message_transport_type %]_[% lang %]" value="1" />
339                   [% END %]
340                 </li>
341                 <li>
342                   <label for="title_[% letter.message_transport_type %]_[% lang %]">Message subject:</label><input type="text" id="title_[% letter.message_transport_type %]_[% lang %]" name="title" size="60" value="[% letter.title %]" />
343                 </li>
344                 <li>
345                   <label for="SQLfieldname_[% letter.message_transport_type %]_[% lang %]">Message body:</label>
346                   [% IF letter.message_transport_type == 'sms' %]
347                     <span class="sms_counter" id="sms_counter_[% lang %]">[% IF letter.content && letter.content.length > 0 %][% letter.content.length %][% ELSE %]0[% END %]/160 characters</span>
348                   [% END %]
349                   <table>
350                     <tr>
351                       <td>
352                         <select name="SQLfieldname" id="SQLfieldname_[% letter.message_transport_type %]_[% lang %]" multiple="multiple" size="9">
353                           [% FOREACH SQLfieldname IN SQLfieldnames %]
354                             <option value="[% SQLfieldname.value %]">[% SQLfieldname.text %]</option>
355                           [% END %]
356                         </select>
357                       </td>
358                         <td class="actions">
359                             <button type="button" data-containerid="[% letter.message_transport_type %]_[% lang %]" class="btn btn-default btn-sm insert">Insert <i class="fa fa-long-arrow-right"></i></button>
360                         </td>
361                       <td><textarea name="content" data-lang="[% lang %]" class="content_[% letter.message_transport_type %]" id="content_[% letter.message_transport_type %]_[% lang %]" cols="80" rows="15">[% letter.content %]</textarea></td>
362                     </tr>
363                   </table>
364                 </li>
365                 [% IF preview_is_available %]
366                     <li>
367                         <a href="/cgi-bin/koha/svc/letters/preview" class="preview_template btn btn-default btn-xs" title="Preview this notice template" data-mtt="[% letter.message_transport_type %]" data-lang="[% lang %]"><i class="fa fa-eye"></i> Preview</a>
368                     </li>
369                 [% END %]
370               </ol>
371             </fieldset>
372             [% END %]
373             </div>
374         </div> <!-- / #transport-types -->
375         [% END %]
376         [% IF Koha.Preference('TranslateNotices') %]
377         </div>
378         [% END %]
379
380         [% IF code.search('DGST') %] <span class="overdue">Warning, this is a template for a Digest, as such, any references to branch data ( e.g. branches.branchname ) will refer to the borrower's home branch.</span> [% END %]
381
382         <input type="hidden" id="redirect" name="redirect" value="" />
383         <input type="hidden" name="searchfield" value="[% searchfield %]" />
384     </form>
385 [% END %]
386
387 [% IF ( add_validate or copy_validate) %]
388         Data recorded
389         <form action="[% action %]" method="post">
390         <input type="submit" value="OK" />
391         </form>
392 [% END %]
393
394 [% IF ( delete_confirm ) %]
395     <div class="dialog alert">
396         <h3>Delete notice?</h3>
397         <table>
398             <thead>
399             <tr>
400                 <th>Library</th>
401                 <th>Module</th>
402                 <th>Code</th>
403                 <th>Name</th>
404             </tr>
405             </thead>
406             <tr>
407                 <td>[% IF letter.branchcode %][% Branches.GetName( letter.branchcode ) %][% ELSE %](All libraries)[% END %]</td>
408                 <td>[% letter.module %]</td>
409                 <td>[% letter.code %]</td>
410                 <td>[% letter.name %]</td>
411             </tr>
412         </table>
413             <form action="[% action %]" method="post">
414             <input type="hidden" name="op" value="delete_confirmed">
415             <input type="hidden" name="branchcode" value="[% letter.branchcode %]" />
416             <input type="hidden" name="code" value="[% letter.code %]" />
417             <input type="hidden" name="module" value="[% letter.module %]" />
418             <button type="submit" class="approve"><i class="fa fa-check"></i> Yes, delete</button>
419         </form>
420
421         <form action="[% action %]" method="get">
422             <button type="submit" class="deny"><i class="fa fa-times"></i> No, do not delete</button>
423         </form>
424     </div>
425 [% END %]
426
427 [% IF ( delete_confirmed ) %]
428         Data deleted
429         <form action="[% action %]" method="post">
430         <input type="submit" value="OK" />
431         </form>
432 [% END %]
433
434 </div>
435 </div>
436 [% UNLESS add_form or copy_form %]
437     <div class="yui-b noprint">
438         [% INCLUDE 'tools-menu.inc' %]
439     </div>
440 [% END %]
441 </div>
442
443 [% MACRO jsinclude BLOCK %]
444     <script type="text/javascript" src="[% interface %]/[% theme %]/js/tools-menu_[% KOHA_VERSION %].js"></script>
445     [% INCLUDE 'datatables.inc' %]
446     <script type="text/javascript" src="[% interface %]/lib/jquery/plugins/jquery.fixFloat_[% KOHA_VERSION %].js"></script>
447     <script type="text/javascript" src="[% interface %]/lib/jquery/plugins/jquery.insertatcaret_[% KOHA_VERSION %].js"></script>
448     <script type="text/javascript">
449         $(document).ready(function() {
450             [% IF add_form or copy_form %]
451                 $('#toolbar').fixFloat();
452             [% END %]
453             $("#lettert:has(tbody tr)").dataTable($.extend(true, {}, dataTablesDefaults, {
454                 "sDom": 't',
455                 "aoColumnDefs": [
456                     { "bSortable": false, "bSearchable": false, 'aTargets': [ 'nosort' ] }
457                 ],
458                 "bPaginate": false
459             }));
460             [% IF no_op_set %]
461                 $('#branch').change(function() {
462                     $('#op').val("");
463                     $('#selectlibrary').submit();
464                 });
465                 $('#newnotice').click(function() {
466                     $('#op').val("add_form");
467                     return true;
468                 });
469             [% END %]
470
471             $("#newmodule").on("change",function(){
472                 if( $("#branch").val() == ""){
473                     var branchcode = "*";
474                 } else {
475                     var branchcode = $("#branch").val();
476                 }
477                 window.location.href = "/cgi-bin/koha/tools/letter.pl?op=add_form&module=" + $(this).val() + "&branchcode=" + branchcode;
478             });
479
480             $("#submit_form").click( function(event) {
481                 event.preventDefault();
482                 var at_least_one_exists = 0;
483                 var are_valid = 1;
484                 $("fieldset.mtt").each( function(){
485                     var title = $(this).find('input[name="title"]').val();
486                     var content = $(this).find('textarea[name="content"]').val();
487                     if (
488                             ( title.length == 0 && content.length > 0 )
489                          || ( title.length > 0 && content.length == 0 )
490                     ) {
491                         var mtt = $(this).find('input[name="message_transport_type"]').val();
492                         var msg = _("Please specify title and content for %s");
493                         msg = msg.replace( "%s", mtt );
494                         at_least_one_exists = 1;
495                         alert(msg);
496                         return are_valid = false;
497                     } else if ( title.length > 0 && content.length > 0 ) {
498                         at_least_one_exists = 1;
499                     }
500                 } );
501                 if ( ! at_least_one_exists ) {
502                     alert( _("Please fill at least one template.") );
503                     return false;
504                 }
505                 if ( ! are_valid ) {
506                     return false;
507                 }
508
509                 // Test if code already exists in DB
510                 var new_lettercode = $("#code").val();
511                 var new_branchcode = $("#branch").val();
512                 [% IF ( add_form and code ) # IF edit %]
513                     if ( new_lettercode != '[% code %]' ) {
514                 [% END %]
515                     $.ajax({
516                         data: { code: new_lettercode, branchcode: new_branchcode },
517                         type: 'GET',
518                         url: '/cgi-bin/koha/svc/letters/get/',
519                         success: function (data) {
520                              if ( data.letters.length > 0 ) {
521                                  if( new_branchcode == '' ) {
522                                      alert( _("A default letter with the code '%s' already exists.").format(new_lettercode) );
523                                  } else {
524                                      alert( _("A letter with the code '%s' already exists for '%s'.").format(new_lettercode, new_branchcode) );
525                                  }
526                                  return false;
527                              } else {
528                                  $("#add_notice").submit();
529                              }
530                         },
531                     });
532                 [% IF ( add_form and code ) %]
533                     } else {
534                         $("#add_notice").submit();
535                     }
536                 [% END %]
537             });
538
539             var sms_limit = 160;
540             $(".content_sms").on("keyup", function(){
541                 var length = $(this).val().length;
542                 var sms_counter = ("#sms_counter_" + $(this).data('lang'));
543                 $(sms_counter).html(length + "/" + sms_limit + _(" characters"));
544                 if ( length  > sms_limit ) {
545                     $(sms_counter).css("color", "red");
546                 } else {
547                     $(sms_counter).css("color", "black");
548                 }
549             });
550             $( ".transport-types" ).accordion({ collapsible: true, active:false, animate: 200 });
551             $(".insert").on("click",function(){
552                 var containerid = $(this).data("containerid");
553                 insertValueQuery( containerid );
554             })
555
556             $("#tabs").tabs();
557
558             $("#saveandcontinue").on("click",function(e){
559                 e.preventDefault();
560                 $("#redirect").val("just_save");
561                 $("#submit_form").click();
562             });
563
564             $("body").on("click", ".preview_template", function(e){
565                 e.preventDefault();
566                 var mtt = $(this).data("mtt");
567                 var lang = $(this).data("lang");
568
569                 var code = $("#code").val();
570                 var content = $("#content_"+mtt+"_"+lang).val();
571                 var title = $("#title_"+mtt+"_"+lang).val();
572
573                 var is_html = $("#is_html_"+mtt+"_"+lang).val();
574                 var page = $(this).attr("href");
575                 var data_preview = $("#data_preview").val();
576                 page += '?code='+encodeURIComponent(code);
577                 page += '&title='+encodeURIComponent(title);
578                 page += '&content='+encodeURIComponent(content);
579                 page += '&data_preview='+encodeURIComponent(data_preview);
580                 page += '&is_html='+encodeURIComponent(is_html);
581                 $("#preview_template .modal-body").load(page);
582                 $('#preview_template').modal('show');
583                 $("#preview_template_button").attr("href", "/cgi-bin/koha/svc/letters/convert?code="+code+"&mtt="+mtt+"&lang="+lang);
584             });
585             $("#preview_template").on("hidden", function(){
586                 $("#preview_template_label").html("");
587                 $("#preview_template .modal-body").html("<div id=\"loading\"><img src=\"[% interface %]/[% theme %]/img/spinner-small.gif\" alt=\"\" /> "+_("Loading")+"</div>");
588             });
589             $("body").on("click", "#convert_template", function(e){
590                 e.preventDefault();
591                 var mtt = $(this).data("mtt");
592                 var lang = $(this).data("lang");
593
594                 var code = $("#code").val();
595                 var content = $("#content_"+mtt+"_"+lang).val();
596                 var title = $("#title_"+mtt+"_"+lang).val();
597
598                 var is_html = $("#is_html_"+mtt+"_"+lang).val();
599                 var page = $(this).attr("href");
600                 var data_preview = $("#data_preview").val();
601                 page += '?code='+encodeURIComponent(code);
602                 page += '&title='+encodeURIComponent(title);
603                 page += '&content='+encodeURIComponent(content);
604                 page += '&data_preview='+encodeURIComponent(data_preview);
605                 page += '&is_html='+encodeURIComponent(is_html);
606                 $("#preview_template .modal-body").load(page + " div");
607                 $('#preview_template').modal('show');
608                 $("#preview_template_button").attr("href", "/cgi-bin/koha/svc/letters/convert?code="+code+"&branchcode="+branchcode+"&mtt="+mtt+"&lang="+lang);
609             });
610             $("#convert_template").on("hidden", function(){
611                 $("#convert_template_label").html("");
612                 $("#convert_template .modal-body").html("<div id=\"loading\"><img src=\"[% interface %]/[% theme %]/img/spinner-small.gif\" alt=\"\" /> "+_("Loading")+"</div>");
613             });
614
615         });
616         [% IF add_form or copy_form %]
617             function cancel(f) {
618                 $('#op').val("");
619                 f.method = "get";
620                 f.submit();
621             }
622
623             function isNotNull(f,noalert) {
624               if (f.value.length ==0) {
625                   return false;
626               }
627               return true;
628             }
629
630             function isNum(v,maybenull) {
631                 var n = new Number(v.value);
632                 if (isNaN(n)) {
633                     return false;
634                 }
635                 if (maybenull==0 && v.value==''){
636                   return false;
637                 }
638                 return true;
639             }
640             function insertValueQuery(containerid) {
641                 var fieldset = $("#" + containerid);
642                 var myQuery = $(fieldset).find('textarea[name="content"]');
643                 var myListBox = $(fieldset).find('select[name="SQLfieldname"]');
644
645                 if($(myListBox).find('option').length > 0) {
646                     $(myListBox).find('option').each( function (){
647                         if ( $(this).attr('selected') && $(this).val().length > 0 ) {
648                             $(myQuery).insertAtCaret("<<" + $(this).val() + ">>");
649                         }
650                     });
651                 }
652             }
653         [% END %]
654     </script>
655 [% END %]
656
657 [% INCLUDE 'intranet-bottom.inc' %]