Bug 19680: Move JS to the footer: Patron and circulation tools
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / tools / modborrowers.tt
index 8d50d70..53b5c0d 100644 (file)
+[% USE Koha %]
 [% USE KohaDates %]
-[% INCLUDE 'doc-head-open.inc'%]
+[% USE Branches %]
+[% SET footerjs = 1 %]
+[% INCLUDE 'doc-head-open.inc' %]
 <title>Koha &rsaquo; Tools &rsaquo; Batch patron modification</title>
 [% INCLUDE 'doc-head-close.inc' %]
-[% INCLUDE 'calendar.inc' %]
 <link rel="stylesheet" type="text/css" href="[% interface %]/[% theme %]/css/datatables.css" />
-[% INCLUDE 'datatables.inc' %]
-<script type="text/javascript">
-//<![CDATA[
-        var patron_attributes_lib = new Array();
-        var patron_attributes_values = new Array();
-        $(document).ready(function() {
-            [% IF borrowers %]
-                $("#borrowerst").dataTable($.extend(true, {}, dataTablesDefaults, {
-                    "sDom": 't',
-                    [% IF ( op == 'show_results' ) %]
-                        "aoColumnDefs": [
-                            { 'sType': "title-string", 'aTargets' : [ 'title-string'] }
-                        ],
-                    [% ELSE %]
-                        "aoColumnDefs": [
-                            { "aTargets": [ 0 ], "bSortable": false, "bSearchable": false },
-                            { 'sType': "title-string", 'aTargets' : [ 'title-string'] }
-                        ],
-                    [% END %]
-                    "bPaginate": false
-                }));
-                $("#selectallbutton").click(function() {
-                    $("#borrowerst").find("input:checkbox").each(function() {
-                        $(this).prop("checked", true);
-                    });
-                    return false;
-                });
-                $("#clearallbutton").click(function() {
-                    $("#borrowerst").find("input:checkbox").each(function() {
-                        $(this).prop("checked", false);
-                    });
-                    return false;
-                });
-            [% END %]
-
-            var values = new Array();
-            var lib = new Array();
-            [% FOREACH pav IN patron_attributes_values %]
-                values = new Array();
-                lib = new Array();
-                [% FOREACH option IN pav.options %]
-                    values.push("[% option.lib %]");
-                    lib.push("[% option.authorised_value %]");
-                [% END %]
-                patron_attributes_lib["[% pav.attribute_code %]"] = values;
-                patron_attributes_values["[% pav.attribute_code %]"] = lib;
-            [% END %]
-
-            $('select[name="patron_attributes"]').change(function() {
-                updateAttrValues(this);
-            } );
-
-            $('select[name="patron_attributes"]').change();
-
-        } );
-
-        function updateAttrValues (select_attr) {
-            var attr_code = $(select_attr).val();
-            var type = $(select_attr).find("option:selected").attr('data-type');
-            var category = $(select_attr).find("option:selected").attr('data-category');
-            var span = $(select_attr).parent().parent().find('span.patron_attributes_value');
-            var information_category_node = $(select_attr).parent().parent().find('span.information_category');
-            information_category_node.html("");
-            if ( category.length > 0 ) {
-                information_category_node.html(_("This attribute will be only applied to the patron's category %s").format(category));
-            }
-            if ( type == 'select' ) {
-                var options = '<option value = ""></option>';
-                for ( var i = 0 ; i < patron_attributes_values[attr_code].length ; i++ ) {
-                    options += '<option value="'+patron_attributes_values[attr_code][i]+'">'+patron_attributes_lib[attr_code][i]+'</option>';
-                }
-                span.html('<select name="patron_attributes_value">' + options + '</select>');
-            } else {
-                span.html('<input type="text" name="patron_attributes_value"/>')
-            }
-        }
-
-        function add_attributes() {
-            var li_node = $("li.attributes:last");
-            var li_clone = $(li_node).clone();
-            if ( $(li_clone).find("a.delete").length == 0 ) {
-                $(li_clone).append('<a href="#" title="Delete" class="delete" onclick="del_attributes(this);return false;"><i class="fa fa-fw fa-trash"></i> Delete</a>');
-            }
-            $(li_clone).find('select[name="patron_attributes"]').change(function() {
-                updateAttrValues(this);
-            } );
-
-            $(li_clone).find('select[name="patron_attributes"]').change();
-
-            $("#fields_list>ol").append(li_clone);
-            update_attr_values();
-        }
-
-        function del_attributes(a_node) {
-            $(a_node).parent('li').remove();
-            update_attr_values();
-        }
-
-        function update_attr_values() {
-            $("li.attributes").each(function(i) {
-                $(this).find("input:checkbox").val("attr"+i+"_value");
-            });
-        }
-        function clearDate(nodeid) {
-            $("#"+nodeid).val("");
-        }
-
-//]]>
-</script>
 </head>
+
 <body id="tools_modborrowers" class="tools">
 [% INCLUDE 'header.inc' %]
 [% INCLUDE 'cat-search.inc' %]
                 </form>
                 [% END %]
 
+                [% IF ( op == 'show') && (!borrowers) && (!notfoundcardnumbers) # Alert if no patrons given%]
+                    [% op = 'noshow' # Change op to prevent display in code below %]
+                    <h1>Batch patrons modification</h1>
+                    <div class="dialog alert">
+                        <p>No patron card numbers given.</p>
+                        <form action="/cgi-bin/koha/tools/modborrowers.pl" method="get">
+                         <button type="submit" class="approve"><i class="fa fa-fw fa-check"></i> OK</button>
+                        </form>
+                    </div>
+                [% END #Alert if no patrons %]
+
                 [% IF ( op == 'show' or op == 'show_results' ) %]
                     [% IF ( op == 'show' ) %]
                         <h1>Batch patrons modification</h1>
                     <form name="f" action="modborrowers.pl" method="post">
                         <input type="hidden" name="op" value="do" />
                         [% IF ( borrowers ) %]
-                            <div id="toolbar"><a id="selectallbutton" href="#">Select all</a> | <a id="clearallbutton" href="#">Clear all</a></div>
+                            <div id="toolbar"><a id="selectallbutton" href="#"><i class="fa fa-check"></i> Select all</a> | <a id="clearallbutton" href="#"><i class="fa fa-remove"></i> Clear all</a></div>
                         [% END %]
                     [% END %]
                         [% IF borrowers %]
                                                 <th>Country</th>
                                                 <th class="title-string">Registration date</th>
                                                 <th class="title-string">Expiry date</th>
+                                                <th>Circulation note</th>
+                                                <th>Opac Note</th>
                                                 [% FOREACH attrh IN attributes_header %]
                                                     <th>[% attrh.attribute %]</th>
                                                 [% END %]
                                                     <td><a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% borrower.borrowernumber %]">[% borrower.cardnumber %]</a></td>
                                                     <td>[% borrower.surname %]</td>
                                                     <td>[% borrower.firstname %]</td>
-                                                    <td>[% borrower.branchname %]</td>
-                                                    <td>[% borrower.categorycode %]</td>
+                                                    <td>[% Branches.GetName( borrower.branchcode ) %]</td>
+                                                    <td>[% borrower.category_description %]</td>
                                                     <td>[% borrower.city %]</td>
                                                     <td>[% borrower.state %]</td>
                                                     <td>[% borrower.zipcode %]</td>
                                                     <td>[% borrower.country %]</td>
                                                     <td><span title="[% borrower.dateenrolled %]">[% borrower.dateenrolled | $KohaDates %]</span></td>
                                                     <td><span title="[% borrower.dateexpiry %]">[% borrower.dateexpiry | $KohaDates %]</span></td>
+                                                    <td>[% borrower.borrowernotes %]</td>
+                                                    <td>[% borrower.opacnote %]</td>
                                                     [% FOREACH pa IN borrower.patron_attributes %]
                                                         [% IF ( pa.code ) %]
                                                             <td>[% pa.code %]=[% pa.value %]</td>
                                                 Expiry date:
                                                 [% CASE 'borrowernotes' %]
                                                 Circulation note:
+                                                [% CASE 'opacnote' %]
+                                                OPAC note:
                                             [% END %]
                                             </label>
-                                            [% IF field.mandatory %]
-                                                <input type="checkbox" title="This field is mandatory" name="disable_input" value="[% field.name %]" readonly="readonly" onclick="return false;" />
-                                            [% ELSE %]
-                                                <input type="checkbox" title="Check to delete this field" name="disable_input" value="[% field.name %]" />
-                                            [% END %]
                                             [% IF ( field.type == 'text' ) %]
                                                 <input type="text" name="[% field.name %]" value="" />
                                             [% END %]
                                                 [% END %]
                                             [% END %]
                                             [% IF ( field.type == 'date' ) %]
-                                                <input type="text" name="[% field.name %]" id="[% field.name %]" value="" size="10" maxlength="10" readonly="readonly" class="datepicker" />
-                                                <a href="#" onclick="clearDate('[% field.name %]');return false;"><i class="fa fa-fw fa-trash"></i> Clear</a>
+                                                <input type="text" name="[% field.name %]" id="[% field.name %]" value="" size="10" maxlength="10" class="datepicker" />
+                                                <a href="#"  class="clear-date" id="clear-date-[% field.name %]" ><i class="fa fa-fw fa-trash"></i> Clear</a>
                                             [% END %]
                                             [% IF field.mandatory %]
+                                                <input type="checkbox" title="This field is mandatory" name="disable_input" value="[% field.name %]" disabled="disabled" readonly="readonly" />
                                                 <span class="required">Required fields cannot be cleared</span>
+                                            [% ELSE %]
+                                                <input type="checkbox" title="Check to delete this field" name="disable_input" value="[% field.name %]" />
                                             [% END %]
                                         </li>
                                         [% END %]
                                                 </label>
                                                 <input type="checkbox" title="check to delete this field" name="disable_input" value="attr0_value" />
                                                 <span class="patron_attributes_value"></span>
-                                                <a href="#" title="Add an attribute" onclick="add_attributes(); return false;"><i class="fa fa-fw fa-plus"></i> New</a>
+                                                <a href="#" class="add_attributes" title="Add an attribute"><i class="fa fa-fw fa-plus"></i> New</a>
                                                 <span class="information_category hint" style="width:25%;float:right;"></span>
                                             </li>
                                         [% END %]
                 [% INCLUDE 'tools-menu.inc' %]
             </div>
         </div>
+
+[% MACRO jsinclude BLOCK %]
+    [% INCLUDE 'calendar.inc' %]
+    [% INCLUDE 'datatables.inc' %]
+    <script type="text/javascript" src="[% interface %]/[% theme %]/js/tools-menu.js"></script>
+    <script type="text/javascript">
+        var patron_attributes_lib = new Array();
+        var patron_attributes_values = new Array();
+        $(document).ready(function() {
+            [% IF borrowers %]
+                $("#borrowerst").dataTable($.extend(true, {}, dataTablesDefaults, {
+                    "sDom": 't',
+                    [% IF ( op == 'show_results' ) %]
+                        "aoColumnDefs": [
+                            { 'sType': "title-string", 'aTargets' : [ 'title-string'] }
+                        ],
+                    [% ELSE %]
+                        "aoColumnDefs": [
+                            { "aTargets": [ 0 ], "bSortable": false, "bSearchable": false },
+                            { 'sType': "title-string", 'aTargets' : [ 'title-string'] }
+                        ],
+                    [% END %]
+                    "bPaginate": false
+                }));
+                $("#selectallbutton").click(function() {
+                    $("#borrowerst").find("input:checkbox").each(function() {
+                        $(this).prop("checked", true);
+                    });
+                    return false;
+                });
+                $("#clearallbutton").click(function() {
+                    $("#borrowerst").find("input:checkbox").each(function() {
+                        $(this).prop("checked", false);
+                    });
+                    return false;
+                });
+            [% END %]
+
+            var values = new Array();
+            var lib = new Array();
+            [% FOREACH pav IN patron_attributes_values %]
+                values = new Array();
+                lib = new Array();
+                [% FOREACH option IN pav.options %]
+                    values.push("[% option.lib %]");
+                    lib.push("[% option.authorised_value %]");
+                [% END %]
+                patron_attributes_lib["[% pav.attribute_code %]"] = values;
+                patron_attributes_values["[% pav.attribute_code %]"] = lib;
+            [% END %]
+
+            $('select[name="patron_attributes"]').change(function() {
+                updateAttrValues(this);
+            } );
+
+            $('select[name="patron_attributes"]').change();
+
+            $(".clear-date").on("click",function(e){
+                e.preventDefault();
+                var fieldID = this.id.replace("clear-date-","");
+                $("#" + fieldID).val("");
+            });
+            $("#cataloguing_additem_newitem").on("click",".add_attributes",function(e){
+                e.preventDefault();
+                add_attributes();
+            });
+            $("#cataloguing_additem_newitem").on("click",".del_attributes",function(e){
+                e.preventDefault();
+                del_attributes(this);
+            });
+        });
+
+        function updateAttrValues (select_attr) {
+            var attr_code = $(select_attr).val();
+            var type = $(select_attr).find("option:selected").attr('data-type');
+            var category = $(select_attr).find("option:selected").attr('data-category');
+            var span = $(select_attr).parent().parent().find('span.patron_attributes_value');
+            var information_category_node = $(select_attr).parent().parent().find('span.information_category');
+            information_category_node.html("");
+            if ( category.length > 0 ) {
+                information_category_node.html(_("This attribute will be only applied to the patron's category %s").format(category));
+            }
+            if ( type == 'select' ) {
+                var options = '<option value = ""></option>';
+                for ( var i = 0 ; i < patron_attributes_values[attr_code].length ; i++ ) {
+                    options += '<option value="'+patron_attributes_values[attr_code][i]+'">'+patron_attributes_lib[attr_code][i]+'</option>';
+                }
+                span.html('<select name="patron_attributes_value">' + options + '</select>');
+            } else {
+                span.html('<input type="text" name="patron_attributes_value"/>')
+            }
+        }
+
+        function add_attributes() {
+            var li_node = $("li.attributes:last");
+            var li_clone = $(li_node).clone();
+            if ( $(li_clone).find("a.del_attributes").length == 0 ) {
+                $(li_clone).append('<a href="#" title="Delete" class="del_attributes"><i class="fa fa-fw fa-trash"></i> Delete</a>');
+            }
+            $(li_clone).find('select[name="patron_attributes"]').change(function() {
+                updateAttrValues(this);
+            } );
+
+            $(li_clone).find('select[name="patron_attributes"]').change();
+
+            $("#fields_list>ol").append(li_clone);
+            update_attr_values();
+        }
+
+        function del_attributes(a_node) {
+            $(a_node).parent('li').remove();
+            update_attr_values();
+        }
+
+        function update_attr_values() {
+            $("li.attributes").each(function(i) {
+                $(this).find("input:checkbox").val("attr"+i+"_value");
+            });
+        }
+        function clearDate(nodeid) {
+            $("#"+nodeid).val("");
+        }
+    </script>
+[% END %]
+
 [% INCLUDE 'intranet-bottom.inc' %]