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