Bug 15758: Koha::Libraries - Remove GetBranchesLoop
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / tools / letter.tt
index 2a1fe8f..3d1eb15 100644 (file)
@@ -1,16 +1,18 @@
+[% USE Koha %]
+[% USE Branches %]
 [% INCLUDE 'doc-head-open.inc' %]
-<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>
+<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>
 [% INCLUDE 'doc-head-close.inc' %]
-<link rel="stylesheet" type="text/css" href="[% themelang %]/css/datatables.css" />
+<link rel="stylesheet" type="text/css" href="[% interface %]/[% theme %]/css/datatables.css" />
 [% INCLUDE 'datatables.inc' %]
-<script type="text/javascript" src="[% interface %]/[% theme %]/en/lib/jquery/plugins/jquery.insertatcaret.js"></script>
+<script type="text/javascript" src="[% interface %]/lib/jquery/plugins/jquery.insertatcaret.js"></script>
 <script type="text/javascript">
 //<![CDATA[
 $(document).ready(function() {
     $("#lettert:has(tbody tr)").dataTable($.extend(true, {}, dataTablesDefaults, {
         "sDom": 't',
         "aoColumnDefs": [
-            { "aTargets": [ -1,-2, -3 ], "bSortable": false, "bSearchable": false }
+            { "bSortable": false, "bSearchable": false, 'aTargets': [ 'nosort' ] }
         ],
         "bPaginate": false
     }));
@@ -25,8 +27,10 @@ $(document).ready(function() {
       });
     [% END %]
 
-    $("#submit").click( function(event) {
+    $("#submit_form").click( function(event) {
+        event.preventDefault();
         var at_least_one_exists = 0;
+        var are_valid = 1;
         $("fieldset.mtt").each( function(){
             var title = $(this).find('input[name="title"]').val();
             var content = $(this).find('textarea[name="content"]').val();
@@ -38,33 +42,67 @@ $(document).ready(function() {
                 var msg = _("Please specify title and content for %s");
                 msg = msg.replace( "%s", mtt );
                 at_least_one_exists = 1;
-                alert(msg)
-                event.preventDefault();
-                return false;
+                alert(msg);
+                return are_valid = false;
             } else if ( title.length > 0 && content.length > 0 ) {
                 at_least_one_exists = 1;
             }
         } );
         if ( ! at_least_one_exists ) {
             alert( _("Please fill at least one template.") );
-            event.preventDefault();
             return false;
         }
-        return true;
+        if ( ! are_valid ) {
+            return false;
+        }
+
+        // Test if code already exists in DB
+        var new_lettercode = $("#code").val();
+        var new_branchcode = $("#branch").val();
+        [% IF ( add_form and code ) # IF edit %]
+          if ( new_lettercode != '[% code %]' ) {
+        [% END %]
+          $.ajax({
+            data: { code: new_lettercode, branchcode: new_branchcode },
+            type: 'GET',
+            url: '/cgi-bin/koha/svc/letters/',
+            success: function (data) {
+              if ( data.letters.length > 0 ) {
+                if( new_branchcode == '' ) {
+                    alert( _("A default letter with the code '%s' already exists.").format(new_lettercode) );
+                } else {
+                    alert( _("A letter with the code '%s' already exists for '%s'.").format(new_lettercode, new_branchcode) );
+                }
+                return false;
+              } else {
+                $("#add_notice").submit();
+              }
+            },
+          });
+        [% IF ( add_form and code ) %]
+          } else {
+            $("#add_notice").submit();
+          }
+        [% END %]
     });
 
     var sms_limit = 160;
     $("#content_sms").on("keyup", function(){
         var length = $(this).val().length;
-        $("#sms_counter").html(length + "/" + sms_limit);
+        $("#sms_counter").html(length + "/" + sms_limit + _(" characters"));
         if ( length  > sms_limit ) {
             $("#sms_counter").css("color", "red");
         } else {
             $("#sms_counter").css("color", "black");
         }
     });
-}); 
-[% IF ( add_form ) %]
+    $( "#transport-types" ).accordion({ collapsible: true, active:false, animate: 200 });
+    $(".insert").on("click",function(){
+        var containerid = $(this).data("containerid");
+        insertValueQuery( containerid );
+    })
+});
+[% IF add_form or copy_form %]
        
     function cancel(f) {
         $('#op').val("");
@@ -95,17 +133,11 @@ $(document).ready(function() {
             var myListBox = $(fieldset).find('select[name="SQLfieldname"]');
 
             if($(myListBox).find('option').length > 0) {
-                var chaineAj = "";
-                var NbSelect = 0;
                 $(myListBox).find('option').each( function (){
-                    if ( $(this).attr('selected') ) {
-                        NbSelect++;
-                        if (NbSelect > 1)
-                            chaineAj += ", ";
-                        chaineAj += $(this).val();
+                    if ( $(this).attr('selected') && $(this).val().length > 0 ) {
+                        $(myQuery).insertAtCaret("<<" + $(this).val() + ">>");
                     }
-                } );
-                $(myQuery).insertAtCaret("<<" + chaineAj + ">>");
+                });
             }
         }
        [% END %]
@@ -116,9 +148,9 @@ $(document).ready(function() {
 [% INCLUDE 'header.inc' %]
 [% INCLUDE 'letters-search.inc' %]
 
-<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>
+<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>
 
-[% IF ( add_form ) %]<div id="doc" class="yui-t7">[% ELSE %]<div id="doc3" class="yui-t2">[% END %]
+[% IF add_form or copy_form %]<div id="doc" class="yui-t7">[% ELSE %]<div id="doc3" class="yui-t2">[% END %]
    
    <div id="bd">
        <div id="yui-main">
@@ -132,15 +164,13 @@ $(document).ready(function() {
       <p>
         Select a library :
             <select name="branchcode" id="branch" style="width:20em;">
-                <option value="">All libraries</option>
-            [% FOREACH branchloo IN branchloop %]
-                [% IF ( branchloo.selected ) %]<option value="[% branchloo.value %]" selected="selected">[% branchloo.branchname %]</option>[% ELSE %]<option value="[% branchloo.value %]">[% branchloo.branchname %]</option>[% END %]
-            [% END %]
+                <option value="*">All libraries</option>
+                [% PROCESS options_for_libraries libraries => Branches.all( selected => branchcode ) %]
             </select>
       </p>
     [% END %]
       <div id="toolbar" class="btn-toolbar">
-          <button type="submit" class="btn btn-small" id="newnotice"><i class="icon-plus"></i> New notice</button>
+          <button type="submit" class="btn btn-small" id="newnotice"><i class="fa fa-plus"></i> New notice</button>
         <input type="hidden" id="op" name="op" />
       </div>
     </form>
@@ -151,8 +181,8 @@ $(document).ready(function() {
                [% IF ( letter && !independant_branch) %]
             [% select_for_copy = BLOCK %]
             <select name="branchcode">
-                [% FOREACH branchloo IN branchloop %]
-                <option value="[% branchloo.value %]">Copy to [% branchloo.branchname %]</option>
+                [% FOREACH l IN Branches.all() %]
+                <option value="[% l.branchcode %]">Copy to [% l.branchname %]</option>
                 [% END %]
             </select>
             [% END %]
@@ -165,9 +195,8 @@ $(document).ready(function() {
                 <th>Module</th>
                 <th>Code</th>
                 <th>Name</th>
-                <th>Copy notice</th>
-                <th>&nbsp;</th>
-                <th>&nbsp;</th>
+                <th class="nosort">Copy notice</th>
+                <th class="nosort">Actions</th>
               </tr>
             </thead>
             <tbody>
@@ -178,10 +207,10 @@ $(document).ready(function() {
                   <td>[% lette.module %]</td>
                   <td>[% lette.code %]</td>
                   <td>[% lette.name %]</td>
-                  <td style="white-space: nowrap">
+                  <td class="actions">
                     [% IF !independant_branch || !lette.branchcode %]
                       <form method="post" action="/cgi-bin/koha/tools/letter.pl">
-                        <input type="hidden" name="op" value="copy" />
+                        <input type="hidden" name="op" value="copy_form" />
                         <input type="hidden" name="oldbranchcode" value="[% lette.branchcode %]" />
                         <input type="hidden" name="module" value="[% lette.module %]" />
                         <input type="hidden" name="code" value="[% lette.code %]" />
@@ -190,18 +219,16 @@ $(document).ready(function() {
                         [% ELSE %]
                           [% select_for_copy %]
                         [% END %]
-                        <input type="submit" value="Copy" />
+                        <button class="btn btn-mini"><i class="fa fa-clone"></i> Copy</button>
                       </form>
                     [% END %]
                   </td>
-                  <td>
+                  <td class="actions">
                     [% IF can_edit %]
-                      <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>
+                      <a class="btn btn-mini" href="/cgi-bin/koha/tools/letter.pl?op=add_form&amp;branchcode=[% lette.branchcode %]&amp;module=[% lette.module %]&amp;code=[% lette.code %]"><i class="fa fa-pencil"></i> Edit</a>
                     [% END %]
-                  </td>
-                  <td>
                     [% IF !lette.protected && can_edit %]
-                      <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>
+                      <a class="btn btn-mini" href="/cgi-bin/koha/tools/letter.pl?op=delete_confirm&amp;branchcode=[%lette.branchcode %]&amp;module=[% lette.module %]&amp;code=[% lette.code %]"><i class="fa fa-trash"></i> Delete</a>
                     [% END %]
                   </td>
                 </tr>
@@ -220,10 +247,15 @@ $(document).ready(function() {
 [% END %]
 
        
-[% IF ( add_form ) %]
+[% IF add_form or copy_form %]
 <h1>[% IF ( modify ) %]Modify notice[% ELSE %]Add notice[% END %]</h1>
-        <form name="Aform" method="post" enctype="multipart/form-data" class="validate">
-               <input type="hidden" name="op" id="op" value="add_validate" />
+        <form id="add_notice" name="Aform" method="post" enctype="multipart/form-data" class="validate">
+        [% IF add_form %]
+          <input type="hidden" name="op" id="op" value="add_validate" />
+        [% ELSE %]
+          <input type="hidden" name="op" id="op" value="copy_validate" />
+        [% END %]
+
                <input type="hidden" name="checked" value="0" />
                [% IF ( modify ) %]
                <input type="hidden" name="add" value="0" />
@@ -231,25 +263,43 @@ $(document).ready(function() {
                <input type="hidden" name="add" value="1" />
                [% END %]
                <fieldset class="rows">
-                               <input type="hidden" name="oldbranchcode" value="[% branchcode %]" />
+            <input type="hidden" name="oldbranchcode" value="[% oldbranchcode %]" />
+            <ol>
             [% IF independant_branch %]
                 <input type="hidden" name="branchcode" value="[% independant_branch %]" />
             [% ELSE %]
-               <ol>
-                       <li>
-                               <label for="branch">Library:</label>
-                <select name="branchcode" id="branch" style="width:20em;">
-                    <option value="">All libraries</option>
-                [% FOREACH branchloo IN branchloop %]
-                    [% IF ( branchloo.selected ) %]<option value="[% branchloo.value %]" selected="selected">[% branchloo.branchname %]</option>[% ELSE %]<option value="[% branchloo.value %]">[% branchloo.branchname %]</option>[% END %]
+            <li>
+
+                [% IF adding %]
+                    <label for="branch">Library:</label>
+                    <select name="branchcode" id="branch" style="width:20em;">
+                        <option value="">All libraries</option>
+                        [% PROCESS options_for_libraries libraries => Branches.all( selected => branchcode ) %]
+                    </select>
+                [% ELSE %]
+                    <span class="label">Library:</span>
+                    <input type="hidden" id="branch" name="branchcode" value="[% branchcode %]" />
+                    [% IF ( branchcode ) %]
+                       [% Branches.GetName( branchcode ) %]
+                    [% ELSE %]
+                        All libraries
+                    [% END %]
                 [% END %]
-                </select>
-                       </li>
+            </li>
             [% END %]
                        <li>
                                <label for="module">Koha module:</label>
                                <input type="hidden" name="oldmodule" value="[% module %]" />
-               [% 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 %]
+                [% 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;">
+                [% ELSE %]
+                  <select name="module" id="module">
+                [% END %]
+                                    [% IF ( module == "acquisition" ) %]
+                                      <option value="acquisition" selected="selected">Acquisition</option>
+                                    [% ELSE %]
+                                      <option value="acquisition" >Acquisition</option>
+                                    [% END %]
                                     [% IF ( module == "catalogue" ) %]
                                       <option value="catalogue" selected="selected">Catalog</option>
                                     [% ELSE %]
@@ -293,40 +343,50 @@ $(document).ready(function() {
                 </select>
             </li>
             <li>
-                [% IF adding %]
-                  <label for"code" class="required">Code:</label>
-                  <input type="text" id="code" name="code" size="20" maxlength="20" required="required" />
+              [% IF adding %]
+                  <label for="code" class="required">Code:</label>
+                  <input type="text" id="code" name="code" size="20" maxlength="20" value="" required="required"/>
                   <span class="required">Required</span>
-                [% ELSE %]
-                  <label for="code">Code:</label>
-                  <input type="hidden" id="code" name="code" value="[% code %]" />[% code %]
-                [% END %]
+              [% ELSE %]
+                  <span class="label">Code:</span>
+                  <input type="hidden" id="code" name="code" value="[% code %]" />
+                  [% code %]
+              [% END %]
             </li>
-        <li>
-            <label for="name" class="required">Name:</label>
-            <input type="text" id="name" name="name" size="60" value="[% letter_name %]" required="required" />
-            <span class="required">Required</span>
-        </li>
-
+            <li>
+              <label for="name" class="required">Name:</label>
+              <input type="text" id="name" name="name" size="60" value="[% letter_name %]" required="required" />
+              <span class="required">Required</span>
+            </li>
+        </ol>
+    </fieldset>
+        <div id="transport-types" style="clear:both">
         [% FOREACH letter IN letters %]
-          <li>
-            <fieldset class="rows mtt" id="[% letter.message_transport_type %]">
-              <legend>
+            <h3>
                 [% SWITCH letter.message_transport_type %]
                 [% CASE 'email' %]
-                  email
+                  Email
                 [% CASE 'print' %]
-                  print
+                  Print
                 [% CASE 'sms' %]
-                  sms
+                  SMS
                 [% CASE 'feed' %]
-                  feed
+                  Feed
                 [% CASE 'phone' %]
-                  phone
+                  Phone
                 [% CASE %]
                   [% letter.message_transport_type %]
                 [% END %]
-              </legend>
+            </h3>
+            [% IF letter.message_transport_type == "sms" and not Koha.Preference("SMSSendDriver") %]
+              <fieldset class="rows mtt" id="[% letter.message_transport_type %]" disabled="disabled">
+                <div class="dialog message">You should enable the SMSSendDriver preference to use the SMS templates.</div>
+            [% ELSIF letter.message_transport_type == "phone" and not Koha.Preference("TalkingTechItivaPhoneNotification") %]
+              <fieldset class="rows mtt" id="[% letter.message_transport_type %]" disabled="disabled">
+                <div class="dialog message">You should enable the TalkingTechItivaPhoneNotification preference to use the phone templates.</div>
+            [% ELSE %]
+              <fieldset class="rows mtt" id="[% letter.message_transport_type %]">
+            [% END %]
               <ol>
                 <li>
                   <input type="hidden" name="message_transport_type" value="[% letter.message_transport_type %]" />
@@ -338,78 +398,80 @@ $(document).ready(function() {
                   [% END %]
                 </li>
                 <li>
-                  <label for="title">Message subject:</label><input type="text" id="title" name="title" size="60" value="[% letter.title %]" />
+                  <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 %]" />
                 </li>
                 <li>
-                  <label for="SQLfieldname">Message body: [% IF letter.message_transport_type == 'sms' %]<span id="sms_counter">[% letter.content.length %]/160</span>[% END %]</label>
+                  <label for="SQLfieldname_[% letter.message_transport_type %]">Message body:</label>
+                  [% IF letter.message_transport_type == 'sms' %]
+                    <span id="sms_counter">[% IF letter.content && letter.content.length > 0 %][% letter.content.length %][% ELSE %]0[% END %]/160 characters</span>
+                  [% END %]
                   <table>
                     <tr>
                       <td>
-                        <select name="SQLfieldname" multiple="multiple" size="9">
-                          [% FOREACH SQLfieldnam IN SQLfieldname %]
-                            <option value="[% SQLfieldnam.value %]">[% SQLfieldnam.text %]</option>
+                        <select name="SQLfieldname" id="SQLfieldname_[% letter.message_transport_type %]" multiple="multiple" size="9">
+                          [% FOREACH SQLfieldname IN SQLfieldnames %]
+                            <option value="[% SQLfieldname.value %]">[% SQLfieldname.text %]</option>
                           [% END %]
                         </select>
                       </td>
-                      <td><input type="button" name="insert" value="&gt;&gt;" onclick="insertValueQuery('[% letter.message_transport_type %]')" title="Insert" /></td>
+                        <td class="actions">
+                            <button type="button" data-containerid="[% letter.message_transport_type %]" class="btn btn-small insert">Insert <i class="fa fa-long-arrow-right"></i></button>
+                        </td>
                       <td><textarea name="content" id="content_[% letter.message_transport_type %]" cols="80" rows="15">[% letter.content %]</textarea></td>
                     </tr>
                   </table>
                 </li>
               </ol>
             </fieldset>
-          </li>
         [% END %]
-        </ol>
+        </div> <!-- / #transport-types -->
 
         [% 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 %]
-        </fieldset>
-        <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>
+        <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>
       <input type="hidden" name="searchfield" value="[% searchfield %]" />
     </form>
 [% END %]
 
-[% IF ( add_validate ) %]
+[% IF ( add_validate or copy_validate) %]
        Data recorded
        <form action="[% action %]" method="post">
        <input type="submit" value="OK" />
        </form>
 [% END %]
-       
-[% IF ( delete_confirm ) %]
-    <div class="dialog alert"><h3>Delete notice?</h3>
-       <table>
-        <thead>
-               <tr>
-                       <th>Library</th>
-                       <th>Module</th>
-                       <th>Code</th>
-                       <th>Name</th>
-               </tr>
-        </thead>
-               <tr>
-                       <td>[% branchname %]</td>
-                       <td>[% module %]</td>
-            <td>[% code %]</td>
-                       <td>[% name %]</td>
-               </tr>
-       </table>
-               <form action="[% action %]" method="post">
-               <input type="hidden" name="op" value="delete_confirmed">
-               <input type="hidden" name="branchcode" value="[% branchcode %]" />
-               <input type="hidden" name="code" value="[% code %]" />
-               <input type="hidden" name="module" value="[% module %]" />
-        <input type="hidden" name="message_transport_type" value="*" />
-                <input type="submit" value="Yes, delete" class="approve" />
-                               </form>
 
-                               <form action="[% action %]" method="get">
-                    <input type="submit" value="No, do not delete" class="deny" />
-                               </form>
-               </div>
+[% IF ( delete_confirm ) %]
+    <div class="dialog alert">
+        <h3>Delete notice?</h3>
+        <table>
+            <thead>
+            <tr>
+                <th>Library</th>
+                <th>Module</th>
+                <th>Code</th>
+                <th>Name</th>
+            </tr>
+            </thead>
+            <tr>
+                <td>[% IF letter.branchcode %][% Branches.GetName( letter.branchcode ) %][% ELSE %](All libraries)[% END %]</td>
+                <td>[% letter.module %]</td>
+                <td>[% letter.code %]</td>
+                <td>[% letter.name %]</td>
+            </tr>
+        </table>
+            <form action="[% action %]" method="post">
+            <input type="hidden" name="op" value="delete_confirmed">
+            <input type="hidden" name="branchcode" value="[% letter.branchcode %]" />
+            <input type="hidden" name="code" value="[% letter.code %]" />
+            <input type="hidden" name="module" value="[% letter.module %]" />
+            <button type="submit" class="approve"><i class="fa fa-check"></i> Yes, delete</button>
+        </form>
 
+        <form action="[% action %]" method="get">
+            <button type="submit" class="deny"><i class="fa fa-times"></i> No, do not delete</button>
+        </form>
+    </div>
 [% END %]
-       
+
 [% IF ( delete_confirmed ) %]
        Data deleted
        <form action="[% action %]" method="post">
@@ -419,7 +481,7 @@ $(document).ready(function() {
 
 </div>
 </div>
-[% UNLESS ( add_form ) %]
+[% UNLESS add_form or copy_form %]
     <div class="yui-b noprint">
         [% INCLUDE 'tools-menu.inc' %]
     </div>