Bug 1859 - Notice fields: can't select multiple fields at once
[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="[% themelang %]/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             { "aTargets": [ -1,-2, -3 ], "bSortable": false, "bSearchable": false }
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') ) {
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             [% FOREACH branchloo IN branchloop %]
169                 [% IF ( branchloo.selected ) %]<option value="[% branchloo.value %]" selected="selected">[% branchloo.branchname %]</option>[% ELSE %]<option value="[% branchloo.value %]">[% branchloo.branchname %]</option>[% END %]
170             [% END %]
171             </select>
172       </p>
173     [% END %]
174       <div id="toolbar" class="btn-toolbar">
175           <button type="submit" class="btn btn-small" id="newnotice"><i class="fa fa-plus"></i> New notice</button>
176         <input type="hidden" id="op" name="op" />
177       </div>
178     </form>
179
180                 [% IF ( search ) %]
181         <p>You searched for <b>[% searchfield %]</b></p>
182                 [% END %]
183                 [% IF ( letter && !independant_branch) %]
184             [% select_for_copy = BLOCK %]
185             <select name="branchcode">
186                 [% FOREACH branchloo IN branchloop %]
187                 <option value="[% branchloo.value %]">Copy to [% branchloo.branchname %]</option>
188                 [% END %]
189             </select>
190             [% END %]
191         [% END %]
192         [% IF letter %]
193           <table id="lettert">
194             <thead>
195               <tr>
196                 <th>Library</th>
197                 <th>Module</th>
198                 <th>Code</th>
199                 <th>Name</th>
200                 <th>Copy notice</th>
201                 <th>&nbsp;</th>
202                 <th>&nbsp;</th>
203               </tr>
204             </thead>
205             <tbody>
206               [% FOREACH lette IN letter %]
207                 [% can_edit = lette.branchcode || !independant_branch %]
208                 <tr>
209                   <td>[% IF lette.branchname %][% lette.branchname %][% ELSE %](All libraries)[% END %]</td>
210                   <td>[% lette.module %]</td>
211                   <td>[% lette.code %]</td>
212                   <td>[% lette.name %]</td>
213                   <td style="white-space: nowrap">
214                     [% IF !independant_branch || !lette.branchcode %]
215                       <form method="post" action="/cgi-bin/koha/tools/letter.pl">
216                         <input type="hidden" name="op" value="copy_form" />
217                         <input type="hidden" name="oldbranchcode" value="[% lette.branchcode %]" />
218                         <input type="hidden" name="module" value="[% lette.module %]" />
219                         <input type="hidden" name="code" value="[% lette.code %]" />
220                         [% IF independant_branch %]
221                           <input type="hidden" name="branchcode" value="[% independant_branch %]" />
222                         [% ELSE %]
223                           [% select_for_copy %]
224                         [% END %]
225                         <input type="submit" value="Copy" />
226                       </form>
227                     [% END %]
228                   </td>
229                   <td>
230                     [% IF can_edit %]
231                       <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>
232                     [% END %]
233                   </td>
234                   <td>
235                     [% IF !lette.protected && can_edit %]
236                       <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>
237                     [% END %]
238                   </td>
239                 </tr>
240               [% END %]
241             </tbody>
242           </table>
243         [% ELSE %]
244           <div class="dialog message">
245           [% IF ( branchcode ) %]
246              <p>There are no notices for this library.</p>
247           [% ELSE %]
248               <p>There are no notices.</p>
249           [% END %]
250           </div>
251         [% END %]
252 [% END %]
253
254         
255 [% IF add_form or copy_form %]
256 <h1>[% IF ( modify ) %]Modify notice[% ELSE %]Add notice[% END %]</h1>
257         <form id="add_notice" name="Aform" method="post" enctype="multipart/form-data" class="validate">
258         [% IF add_form %]
259           <input type="hidden" name="op" id="op" value="add_validate" />
260         [% ELSE %]
261           <input type="hidden" name="op" id="op" value="copy_validate" />
262         [% END %]
263
264                 <input type="hidden" name="checked" value="0" />
265                 [% IF ( modify ) %]
266                 <input type="hidden" name="add" value="0" />
267                 [% ELSE %]
268                 <input type="hidden" name="add" value="1" />
269                 [% END %]
270                 <fieldset class="rows">
271             <input type="hidden" name="oldbranchcode" value="[% oldbranchcode %]" />
272             <ol>
273             [% IF independant_branch %]
274                 <input type="hidden" name="branchcode" value="[% independant_branch %]" />
275             [% ELSE %]
276             <li>
277
278                 [% IF adding %]
279                     <label for="branch">Library:</label>
280                     <select name="branchcode" id="branch" style="width:20em;">
281                         <option value="">All libraries</option>
282                     [% FOREACH branchloo IN branchloop %]
283                         [% IF ( branchloo.selected ) %]<option value="[% branchloo.value %]" selected="selected">[% branchloo.branchname %]</option>[% ELSE %]<option value="[% branchloo.value %]">[% branchloo.branchname %]</option>[% END %]
284                     [% END %]
285                     </select>
286                 [% ELSE %]
287                     <span class="label">Library:</span>
288                     <input type="hidden" id="branch" name="branchcode" value="[% branchcode %]" />
289                     [% IF ( branchcode ) %]
290                        [% Branches.GetName( branchcode ) %]
291                     [% ELSE %]
292                         All libraries
293                     [% END %]
294                 [% END %]
295             </li>
296             [% END %]
297                         <li>
298                                 <label for="module">Koha module:</label>
299                                 <input type="hidden" name="oldmodule" value="[% module %]" />
300                 [% IF adding  %]
301                   <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;">
302                 [% ELSE %]
303                   <select name="module" id="module">
304                 [% END %]
305                                     [% IF ( module == "acquisition" ) %]
306                                       <option value="acquisition" selected="selected">Acquisition</option>
307                                     [% ELSE %]
308                                       <option value="acquisition" >Acquisition</option>
309                                     [% END %]
310                                     [% IF ( module == "catalogue" ) %]
311                                       <option value="catalogue" selected="selected">Catalog</option>
312                                     [% ELSE %]
313                                       <option value="catalogue" >Catalog</option>
314                                     [% END %]
315                                     [% IF ( module == "circulation" ) %]
316                                       <option value="circulation" selected="selected">Circulation</option>
317                                     [% ELSE %]
318                                       <option value="circulation">Circulation</option>
319                                     [% END %]
320                                     [% IF ( module == "claimacquisition" ) %]
321                                       <option value="claimacquisition" selected="selected">Claim acquisition</option>
322                                     [% ELSE %]
323                                       <option value="claimacquisition">Claim acquisition</option>
324                                     [% END %]
325                                     [% IF ( module == "claimissues" ) %]
326                                       <option value="claimissues" selected="selected">Claim serial issue</option>
327                                     [% ELSE %]
328                                       <option value="claimissues">Claim serial issue</option>
329                                     [% END %]
330                                     [% IF ( module == "reserves" ) %]
331                                       <option value="reserves" selected="selected">Holds</option>
332                                     [% ELSE %]
333                                       <option value="reserves">Holds</option>
334                                     [% END %]
335                                     [% IF ( module == "members" ) %]
336                                       <option value="members" selected="selected">Members</option>
337                                     [% ELSE %]
338                                       <option value="members">Members</option>
339                                     [% END %]
340                                     [% IF ( module == "serial" ) %]
341                                       <option value="serial" selected="selected">Serials (routing list)</option>
342                                     [% ELSE %]
343                                       <option value="serial">Serials (routing list)</option>
344                                     [% END %]
345                                     [% IF ( module == "suggestions" ) %]
346                                       <option value="suggestions" selected="selected">Suggestions</option>
347                                     [% ELSE %]
348                                       <option value="suggestions">Suggestions</option>
349                                     [% END %]
350                 </select>
351             </li>
352             <li>
353               [% IF adding %]
354                   <label for="code" class="required">Code:</label>
355                   <input type="text" id="code" name="code" size="20" maxlength="20" value="" required="required"/>
356                   <span class="required">Required</span>
357               [% ELSE %]
358                   <span class="label">Code:</span>
359                   <input type="hidden" id="code" name="code" value="[% code %]" />
360                   [% code %]
361               [% END %]
362             </li>
363             <li>
364               <label for="name" class="required">Name:</label>
365               <input type="text" id="name" name="name" size="60" value="[% letter_name %]" required="required" />
366               <span class="required">Required</span>
367             </li>
368         </ol>
369     </fieldset>
370         <div id="transport-types" style="clear:both">
371         [% FOREACH letter IN letters %]
372             <h3>
373                 [% SWITCH letter.message_transport_type %]
374                 [% CASE 'email' %]
375                   Email
376                 [% CASE 'print' %]
377                   Print
378                 [% CASE 'sms' %]
379                   SMS
380                 [% CASE 'feed' %]
381                   Feed
382                 [% CASE 'phone' %]
383                   Phone
384                 [% CASE %]
385                   [% letter.message_transport_type %]
386                 [% END %]
387             </h3>
388             [% IF letter.message_transport_type == "sms" and not Koha.Preference("SMSSendDriver") %]
389               <fieldset class="rows mtt" id="[% letter.message_transport_type %]" disabled="disabled">
390                 <div class="dialog message">You should enable the SMSSendDriver preference to use the SMS templates.</div>
391             [% ELSIF letter.message_transport_type == "phone" and not Koha.Preference("TalkingTechItivaPhoneNotification") %]
392               <fieldset class="rows mtt" id="[% letter.message_transport_type %]" disabled="disabled">
393                 <div class="dialog message">You should enable the TalkingTechItivaPhoneNotification preference to use the phone templates.</div>
394             [% ELSE %]
395               <fieldset class="rows mtt" id="[% letter.message_transport_type %]">
396             [% END %]
397               <ol>
398                 <li>
399                   <input type="hidden" name="message_transport_type" value="[% letter.message_transport_type %]" />
400                   <label for="is_html_[% letter.message_transport_type %]">HTML message:</label>
401                   [% IF letter.is_html %]
402                     <input type="checkbox" name="is_html_[% letter.message_transport_type %]" id="is_html_[% letter.message_transport_type %]" value="1" checked="checked" />
403                   [% ELSE %]
404                     <input type="checkbox" name="is_html_[% letter.message_transport_type %]" id="is_html_[% letter.message_transport_type %]" value="1" />
405                   [% END %]
406                 </li>
407                 <li>
408                   <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 %]" />
409                 </li>
410                 <li>
411                   <label for="SQLfieldname_[% letter.message_transport_type %]">Message body:</label>
412                   [% IF letter.message_transport_type == 'sms' %]
413                     <span id="sms_counter">[% IF letter.content && letter.content.length > 0 %][% letter.content.length %][% ELSE %]0[% END %]/160 characters</span>
414                   [% END %]
415                   <table>
416                     <tr>
417                       <td>
418                         <select name="SQLfieldname" id="SQLfieldname_[% letter.message_transport_type %]" multiple="multiple" size="9">
419                           [% FOREACH SQLfieldname IN SQLfieldnames %]
420                             <option value="[% SQLfieldname.value %]">[% SQLfieldname.text %]</option>
421                           [% END %]
422                         </select>
423                       </td>
424                         <td class="actions">
425                             <button type="button" data-containerid="[% letter.message_transport_type %]" class="btn btn-small insert">Insert <i class="fa fa-long-arrow-right"></i></button>
426                         </td>
427                       <td><textarea name="content" id="content_[% letter.message_transport_type %]" cols="80" rows="15">[% letter.content %]</textarea></td>
428                     </tr>
429                   </table>
430                 </li>
431               </ol>
432             </fieldset>
433         [% END %]
434         </div> <!-- / #transport-types -->
435
436         [% 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 %]
437         <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>
438       <input type="hidden" name="searchfield" value="[% searchfield %]" />
439     </form>
440 [% END %]
441
442 [% IF ( add_validate or copy_validate) %]
443         Data recorded
444         <form action="[% action %]" method="post">
445         <input type="submit" value="OK" />
446         </form>
447 [% END %]
448
449 [% IF ( delete_confirm ) %]
450     <div class="dialog alert">
451         <h3>Delete notice?</h3>
452         <table>
453             <thead>
454             <tr>
455                 <th>Library</th>
456                 <th>Module</th>
457                 <th>Code</th>
458                 <th>Name</th>
459             </tr>
460             </thead>
461             <tr>
462                 <td>[% IF letter.branchcode %][% Branches.GetName( letter.branchcode ) %][% ELSE %](All libraries)[% END %]</td>
463                 <td>[% letter.module %]</td>
464                 <td>[% letter.code %]</td>
465                 <td>[% letter.name %]</td>
466             </tr>
467         </table>
468             <form action="[% action %]" method="post">
469             <input type="hidden" name="op" value="delete_confirmed">
470             <input type="hidden" name="branchcode" value="[% letter.branchcode %]" />
471             <input type="hidden" name="code" value="[% letter.code %]" />
472             <input type="hidden" name="module" value="[% letter.module %]" />
473             <input type="submit" value="Yes, delete" class="approve" />
474         </form>
475
476         <form action="[% action %]" method="get">
477             <input type="submit" value="No, do not delete" class="deny" />
478         </form>
479     </div>
480 [% END %]
481
482 [% IF ( delete_confirmed ) %]
483         Data deleted
484         <form action="[% action %]" method="post">
485         <input type="submit" value="OK" />
486         </form>
487 [% END %]
488
489 </div>
490 </div>
491 [% UNLESS add_form or copy_form %]
492     <div class="yui-b noprint">
493         [% INCLUDE 'tools-menu.inc' %]
494     </div>
495 [% END %]
496 </div>
497 [% INCLUDE 'intranet-bottom.inc' %]