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