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