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