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