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