Bug 19804: Add the new column to the circ rules interface
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / admin / smart-rules.tt
index 9e87404..03a8bdc 100644 (file)
 [% USE Branches %]
+[% SET footerjs = 1 %]
 [% INCLUDE 'doc-head-open.inc' %]
 <title>Koha &rsaquo; Administration &rsaquo; Circulation and fine rules</title>
 [% INCLUDE 'doc-head-close.inc' %]
-[% INCLUDE 'calendar.inc' %]
-<script type="text/javascript">
-//<![CDATA[
-
-function clear_edit(){
-    var cancel = confirm(_("Are you sure you want to cancel your changes?"));
-    if ( !cancel ) return;
-    $('#default-circulation-rules td').removeClass('highlighted-row');
-    var edit_row = $("#edit_row");
-    $(edit_row).find("input").each(function(){
-        var type = $(this).attr("type");
-        if (type != "button" && type != "submit" ) {
-            $(this).val("");
-            $(this).prop('disabled', false);
-        }
-        if ( type == "checkbox" ) {
-            $(this).prop('checked', false);
-        }
-    });
-    $(edit_row).find("select").prop('disabled', false);
-    $(edit_row).find("select option:first").attr("selected", "selected");
-    $(edit_row).find("td:last input[name='clear']").remove();
-}
-
-var MSG_CONFIRM_DELETE = _("Are you sure you want to delete this rule? This cannot be undone.");
-
-$(document).ready(function() {
-    $(".delete").on("click",function(){
-        return confirmDelete(MSG_CONFIRM_DELETE);
-    });
-
-        $('#cap_fine_to_replacement_price').on('change', function(){
-            $('#overduefinescap').prop('disabled', $(this).is(':checked') );
-        });
-        $('#selectlibrary').find("input:submit").hide();
-        $('#branch').change(function() {
-                $('#selectlibrary').submit();
-        });
-        $(".editrule").click(function(){
-            if ( $(edit_row).find("input[type='text'][value!='']").length > 0 ) {
-                var edit = confirm(_("Are you sure you want to edit another rule?"));
-                if (!edit) return false;
-            }
-            $('#default-circulation-rules td').removeClass('highlighted-row');
-            $(this).parent().parent().find("td").each(function (i) {
-                $(this).addClass('highlighted-row');
-                itm = $(this).text();
-                itm = itm.replace(/^\s*|\s*$/g,'');
-                var current_column = $("#edit_row td:eq("+i+")");
-                if ( i == 6 ) {
-                    // specific processing for the Hard due date column
-                    var select_value = $(this).find("input[type='hidden'][name='hardduedatecomparebackup']").val();
-                    var input_value = '';
-                    if (typeof select_value === 'undefined'){
-                        select_value = '-1';
-                    }else {
-                        input_value = itm.split(' ')[1];
-                    }
-                    $(current_column).find("input[type='text']").val(input_value);
-                    $(current_column).find("select").val(select_value);
-                } else if ( i == 12 ) {
-                    // specific processing for cap_fine_to_replacement_price
-                    var cap_fine_to_replacement_price = $(this).find("input[type='checkbox']");
-                    $('#cap_fine_to_replacement_price').prop('checked', cap_fine_to_replacement_price.is(':checked') );
-                    $('#overduefinescap').prop('disabled', cap_fine_to_replacement_price.is(':checked') );
-                } else {
-                    $(current_column).find("input[type='text']").val(itm);
-                    // select the corresponding option
-                    $(current_column).find("select option").each(function(){
-                        opt = $(this).text().toLowerCase();
-                        opt = opt.replace(/^\s*|\s*$/g,'');
-                        if ( opt == itm.toLowerCase() ) {
-                            $(this).attr('selected', 'selected');
-                        }
-                    });
-                    if ( i == 0 || i == 1 ) {
-                        // Disable the 2 first columns, we cannot update them.
-                        var val = $(current_column).find("select option:selected").val();
-                        var name = "categorycode";
-                        if ( i == 1 ) {
-                            name="itemtype";
-                        }
-                        // Remove potential previous input added
-                        $(current_column).find("input").remove();
-                        $(current_column).append("<input type='hidden' name='"+name+"' value='"+val+"' />");
-                    } else if ( i == 2 || i == 3 ) {
-                        // If the value is not an integer for "Current checkouts allowed" or "Current on-site checkouts allowed"
-                        // The value is "Unlimited" (or an equivalent translated string)
-                        // an it should be set to an empty string
-                        if( !((parseFloat(itm) == parseInt(itm)) && !isNaN(itm)) ) {
-                            $(current_column).find("input[type='text']").val("");
-                        }
-                    }
-                }
-            });
-            $("#default-circulation-rules tr:last td:eq(0) select").prop('disabled', true);
-            $("#default-circulation-rules tr:last td:eq(1) select").prop('disabled', true);
-            return false;
-        });
-        $(".clear_edit").on("click",function(e){
-            e.preventDefault();
-            clear_edit();
-        });
-});
-//]]>
-</script>
 </head>
+
 <body id="admin_smart-rules" class="admin">
 [% INCLUDE 'header.inc' %]
-[% INCLUDE 'cat-search.inc' %]
+[% INCLUDE 'prefs-admin-search.inc' %]
 
 <div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a> &rsaquo; Circulation and fine rules</div>
 
@@ -130,22 +26,22 @@ $(document).ready(function() {
     <div class="help">
         <p>The rules are applied from most specific to less specific, using the first found in this order:</p>
         <ul>
-            <li>same library, same patron type, same item type</li>
-            <li>same library, same patron type, all item types</li>
-            <li>same library, all patron types, same item type</li>
-            <li>same library, all patron types, all item types</li>
-            <li>default (all libraries), same patron type, same item type</li>
-            <li>default (all libraries), same patron type, all item types</li>
-            <li>default (all libraries), all patron types, same item type</li>
-            <li>default (all libraries), all patron types, all item types</li>
+            <li>same library, same patron category, same item type</li>
+            <li>same library, same patron category, all item types</li>
+            <li>same library, all patron categories, same item type</li>
+            <li>same library, all patron categories, all item types</li>
+            <li>default (all libraries), same patron category, same item type</li>
+            <li>default (all libraries), same patron category, all item types</li>
+            <li>default (all libraries), all patron categories, same item type</li>
+            <li>default (all libraries), all patron categories, all item types</li>
         </ul>
-        <p>To modify a rule, create a new one with the same patron type and item type.</p>
+        <p>To modify a rule, create a new one with the same patron category and item type.</p>
     </div>
     <div>
         <form method="get" action="/cgi-bin/koha/admin/smart-rules.pl" id="selectlibrary">
         Select a library :
             <select name="branch" id="branch" style="width:20em;">
-                <option value="*">All libraries</option>
+                <option value="*">Standard rules for all libraries</option>
                 [% PROCESS options_for_libraries libraries => Branches.all( selected => current_branch, unfiltered => 1 ) %]
             </select>
         </form>
@@ -156,7 +52,7 @@ $(document).ready(function() {
                 <select name="tobranch" id="tobranch">
                     [% PROCESS options_for_libraries libraries => Branches.all( unfiltered => 1 ) %]
                 </select>
-                <input type="submit" value="Clone" />
+                <input type="submit" id="clone_rules" value="Clone" />
             </form>
         [% END %]
 
@@ -168,6 +64,7 @@ $(document).ready(function() {
             <tr>
                 <th>Patron category</th>
                 <th>Item type</th>
+                <th>Actions</th>
                 <th>Current checkouts allowed</th>
                 <th>Current on-site checkouts allowed</th>
                 <th>Loan period</th>
@@ -181,14 +78,18 @@ $(document).ready(function() {
                 <th>Cap fine at replacement price</th>
                 <th>Suspension in days (day)</th>
                 <th>Max. suspension duration (day)</th>
+                <th>Fine day charging interval</th>
                 <th>Renewals allowed (count)</th>
                 <th>Renewal period</th>
                 <th>No renewal before</th>
                 <th>Automatic renewal</th>
+                <th>No automatic renewal after</th>
+                <th>No automatic renewal after (hard limit)</th>
                 <th>Holds allowed (count)</th>
                 <th>Holds per record (count)</th>
                 <th>On shelf holds allowed</th>
                 <th>Item level holds</th>
+                <th>Article requests</th>
                 <th>Rental discount (%)</th>
                 <th>Actions</th>
             </tr>
@@ -208,14 +109,19 @@ $(document).ready(function() {
                                                                        [% rule.translated_description %]
                                                                [% END %]
                                                        </td>
+                                                        <td class="actions">
+                                                          <a href="#" class="editrule btn btn-default btn-xs"><i class="fa fa-pencil"></i> Edit</a>
+                                                          <a class="btn btn-default btn-xs delete" href="/cgi-bin/koha/admin/smart-rules.pl?op=delete&amp;itemtype=[% rule.itemtype %]&amp;categorycode=[% rule.categorycode %]&amp;branch=[% rule.current_branch %]"><i class="fa fa-trash"></i> Delete</a>
+                                                        </td>
+
                                                        <td>[% IF ( rule.unlimited_maxissueqty ) %]
-                                                                       Unlimited
+                                                                       <span>Unlimited</span>
                                                                [% ELSE %]
                                                                        [% rule.maxissueqty %]
                                                                [% END %]
                                                        </td>
                             <td>[% IF rule.unlimited_maxonsiteissueqty %]
-                                    Unlimited
+                                    <span>Unlimited</span>
                                 [% ELSE %]
                                     [% rule.maxonsiteissueqty %]
                                 [% END %]
@@ -237,12 +143,18 @@ $(document).ready(function() {
                                   <input type="hidden" name="hardduedatecomparebackup" value="1" />
                                 [% END %]
                               [% ELSE %]
-                                None defined
+                                <span>None defined</span>
                               [% END %]
                             </td>
                                                        <td>[% rule.fine %]</td>
                                                        <td>[% rule.chargeperiod %]</td>
-                <td>[% IF rule.chargeperiod_charge_at %]Start of interval[% ELSE %]End of interval[% END %]</td>
+                            <td>
+                                [% IF rule.chargeperiod_charge_at %]
+                                    <span>Start of interval</span>
+                                [% ELSE %]
+                                    <span>End of interval</span>
+                                [% END %]
+                            </td>
                                                        <td>[% rule.firstremind %]</td>
                             <td>[% rule.overduefinescap FILTER format("%.2f") %]</td>
                             <td>
@@ -254,32 +166,56 @@ $(document).ready(function() {
                             </td>
                                                        <td>[% rule.finedays %]</td>
                             <td>[% rule.maxsuspensiondays %]</td>
+                            <td>[% rule.suspension_chargeperiod %]</td>
                                                        <td>[% rule.renewalsallowed %]</td>
                             <td>[% rule.renewalperiod %]</td>
                             <td>[% rule.norenewalbefore %]</td>
                             <td>
                                 [% IF ( rule.auto_renew ) %]
-                                Yes
+                                    <span>Yes</span>
                                 [% ELSE %]
-                                No
+                                    <span>No</span>
                                 [% END %]
                             </td>
+                            <td>[% rule.no_auto_renewal_after %]</td>
+                            <td>[% rule.no_auto_renewal_after_hard_limit %]</td>
                                                        <td>[% rule.reservesallowed %]</td>
                                                         <td>[% rule.holds_per_record %]</td>
                                                         <td>
                                                             [% IF rule.onshelfholds == 1 %]
-                                                                Yes
+                                                                <span>Yes</span>
                                                             [% ELSIF rule.onshelfholds == 2 %]
-                                                                If all unavailable
+                                                                <span>If all unavailable</span>
                                                             [% ELSE %]
-                                                                If any unavailable
-                                                            [% END %]</td>
-                                                        <td>[% IF rule.opacitemholds == 'F'%]Force[% ELSIF rule.opacitemholds == 'Y'%]Allow[% ELSE %]Don't allow[% END %]</td>
+                                                                <span>If any unavailable</span>
+                                                            [% END %]
+                                                        </td>
+                                                        <td>
+                                                            [% IF rule.opacitemholds == 'F'%]
+                                                                <span>Force</span>
+                                                            [% ELSIF rule.opacitemholds == 'Y'%]
+                                                                <span>Allow</span>
+                                                            [% ELSE %]
+                                                                <span>Don't allow</span>
+                                                            [% END %]
+                                                        </td>
+                                                        <td>
+                                                            [% IF rule.article_requests == 'no' %]
+                                                                <span>No</span>
+                                                            [% ELSIF rule.article_requests == 'yes' %]
+                                                                <span>Yes</span>
+                                                            [% ELSIF rule.article_requests == 'bib_only' %]
+                                                                <span>Record only</span>
+                                                            [% ELSIF rule.article_requests == 'item_only' %]
+                                                                <span>Item only</span>
+                                                            [% END %]
+                                                        </td>
                                                        <td>[% rule.rentaldiscount %]</td>
                                                         <td class="actions">
-                                                          <a href="#" class="editrule btn btn-mini"><i class="fa fa-pencil"></i> Edit</a>
-                                                          <a class="btn btn-mini delete" href="/cgi-bin/koha/admin/smart-rules.pl?op=delete&amp;itemtype=[% rule.itemtype %]&amp;categorycode=[% rule.categorycode %]&amp;branch=[% rule.current_branch %]"><i class="fa fa-trash"></i> Delete</a>
-                                                       </td>
+                                                          <a href="#" class="editrule btn btn-default btn-xs"><i class="fa fa-pencil"></i> Edit</a>
+                                                          <a class="btn btn-default btn-xs delete" href="/cgi-bin/koha/admin/smart-rules.pl?op=delete&amp;itemtype=[% rule.itemtype %]&amp;categorycode=[% rule.categorycode %]&amp;branch=[% rule.current_branch %]"><i class="fa fa-trash"></i> Delete</a>
+                                                        </td>
+
                        </tr>
                [% END %]
                 <tr id="edit_row">
@@ -299,6 +235,11 @@ $(document).ready(function() {
                         [% END %]
                         </select>
                     </td>
+                    <td class="actions">
+                        <input type="hidden" name="branch" value="[% current_branch %]"/>
+                        <button type="submit" class="btn btn-default btn-xs"><i class="fa fa-save"></i> Save</button>
+                        <button name="cancel" class="clear_edit btn btn-default btn-xs"><i class="fa fa-undo"></i> Clear</button>
+                    </td>
                     <td><input type="text" name="maxissueqty" id="maxissueqty" size="3" /></td>
                     <td><input type="text" name="maxonsiteissueqty" id="maxonsiteissueqty" size="3" /></td>
                     <td><input type="text" name="issuelength" id="issuelength" size="3" /> </td>
@@ -330,6 +271,7 @@ $(document).ready(function() {
                     <td><input type="checkbox" name="cap_fine_to_replacement_price" id="cap_fine_to_replacement_price" /></td>
                     <td><input type="text" name="finedays" id="fined" size="3" /> </td>
                     <td><input type="text" name="maxsuspensiondays" id="maxsuspensiondays" size="3" /> </td>
+                    <td><input type="text" name="suspension_chargeperiod" id="suspension_chargeperiod" size="3" /> </td>
                     <td><input type="text" name="renewalsallowed" id="renewalsallowed" size="2" /></td>
                     <td><input type="text" name="renewalperiod" id="renewalperiod" size="3" /></td>
                     <td><input type="text" name="norenewalbefore" id="norenewalbefore" size="3" /></td>
@@ -339,6 +281,11 @@ $(document).ready(function() {
                             <option value="yes">Yes</option>
                         </select>
                     </td>
+                    <td><input type="text" name="no_auto_renewal_after" id="no_auto_renewal_after" size="3" /></td>
+                    <td>
+                        <input type="text" size="10" name="no_auto_renewal_after_hard_limit" id="no_auto_renewal_after_hard_limit" value="[% no_auto_renewal_after_hard_limit %]" class="datepicker"/>
+                        <div class="hint">[% INCLUDE 'date-format.inc' %]</div>
+                    </td>
                     <td><input type="text" name="reservesallowed" id="reservesallowed" size="2" /></td>
                     <td><input type="text" name="holds_per_record" id="holds_per_record" size="2" /></td>
                     <td>
@@ -355,17 +302,26 @@ $(document).ready(function() {
                             <option value="F">Force</option>
                         </select>
                     </td>
+                    <td>
+                        <select id="article_requests" name="article_requests">
+                            <option value="no">No</option>
+                            <option value="yes">Yes</option>
+                            <option value="bib_only">Record only</option>
+                            <option value="item_only">Item only</option>
+                        </select>
+                    </td>
                     <td><input type="text" name="rentaldiscount" id="rentaldiscount" size="2" /></td>
                     <td class="actions">
                         <input type="hidden" name="branch" value="[% current_branch %]"/>
-                        <button type="submit" class="btn btn-mini"><i class="fa fa-save"></i> Save</button>
-                        <button name="cancel" class="clear_edit btn btn-mini"><i class="fa fa-undo"></i> Clear</button>
+                        <button type="submit" class="btn btn-default btn-xs"><i class="fa fa-save"></i> Save</button>
+                        <button name="cancel" class="clear_edit btn btn-default btn-xs"><i class="fa fa-undo"></i> Clear</button>
                     </td>
                 </tr>
                 <tfoot>
                     <tr>
                       <th>Patron category</th>
                       <th>Item type</th>
+                      <th>&nbsp;</th>
                       <th>Current checkouts allowed</th>
                       <th>Current on-site checkouts allowed</th>
                       <th>Loan period</th>
@@ -378,17 +334,21 @@ $(document).ready(function() {
                       <th>Overdue fines cap (amount)</th>
                       <th>Cap fine at replacement price</th>
                       <th>Suspension in days (day)</th>
+                      <th>Fine day charging interval</th>
                       <th>Max. suspension duration (day)</th>
                       <th>Renewals allowed (count)</th>
                       <th>Renewal period</th>
                       <th>No renewal before</th>
                       <th>Automatic renewal</th>
+                      <th>No automatic renewal after</th>
+                       <th>No automatic renewal after (hard limit)</th>
                       <th>Holds allowed (count)</th>
                       <th>Holds per record (count)</th>
                       <th>On shelf holds allowed</th>
                       <th>Item level holds</th>
+                      <th>Article requests</th>
                       <th>Rental discount (%)</th>
-                      <th colspan="2">&nbsp;</th>
+                      <th>&nbsp;</th>
                     </tr>
                   </tfoot>
                 </tbody>
@@ -499,8 +459,8 @@ $(document).ready(function() {
                         </select>
                     </td>
                     <td class="actions">
-                        <button type="submit" class="btn btn-mini"><i class="fa fa-save"></i> Save</button>
-                        <a class="btn btn-mini delete" href="/cgi-bin/koha/admin/smart-rules.pl?op=delete-branch-cat&amp;categorycode=*&amp;branch=[% current_branch %]" id="unset"><i class="fa fa-undo"></i> Unset</a>
+                        <button type="submit" class="btn btn-default btn-xs"><i class="fa fa-save"></i> Save</button>
+                        <a class="btn btn-default btn-xs delete" href="/cgi-bin/koha/admin/smart-rules.pl?op=delete-branch-cat&amp;categorycode=*&amp;branch=[% current_branch %]" id="unset"><i class="fa fa-undo"></i> Unset</a>
                     </td>
                 </tr>
             </table>
@@ -538,20 +498,20 @@ $(document).ready(function() {
                             [% END %]
                         </td>
                         <td>[% IF ( branch_cat_rule_loo.unlimited_maxissueqty ) %]
-                                Unlimited
+                                <span>Unlimited</span>
                             [% ELSE %]
                                 [% branch_cat_rule_loo.maxissueqty %]
                             [% END %]
                         </td>
                         <td>[% IF ( branch_cat_rule_loo.unlimited_maxonsiteissueqty ) %]
-                                Unlimited
+                                <span>Unlimited</span>
                             [% ELSE %]
                                 [% branch_cat_rule_loo.maxonsiteissueqty %]
                             [% END %]
                         </td>
 
                         <td class="actions">
-                            <a class="btn btn-mini delete" href="/cgi-bin/koha/admin/smart-rules.pl?op=delete-branch-cat&amp;categorycode=[% branch_cat_rule_loo.categorycode %]&amp;branch=[% current_branch %]"><i class="fa fa-trash"></i> Delete</a>
+                            <a class="btn btn-default btn-xs delete" href="/cgi-bin/koha/admin/smart-rules.pl?op=delete-branch-cat&amp;categorycode=[% branch_cat_rule_loo.categorycode %]&amp;branch=[% current_branch %]"><i class="fa fa-trash"></i> Delete</a>
                         </td>
                     </tr>
                 [% END %]
@@ -565,7 +525,7 @@ $(document).ready(function() {
                     </td>
                     <td><input name="maxissueqty" size="3" /></td>
                     <td><input name="maxonsiteissueqty" size="3" /></td>
-                    <td class="actions"><button type="submit" class="btn btn-mini"><i class="fa fa-plus"></i> Add</td>
+                    <td class="actions"><button type="submit" class="btn btn-default btn-xs"><i class="fa fa-plus"></i> Add</td>
                 </tr>
             </table>
         </form>
@@ -643,7 +603,7 @@ $(document).ready(function() {
                         </select>
                     </td>
                     <td class="actions">
-                        <button type="submit" class="btn btn-mini"><i class="fa fa-save"></i> Save</button>
+                        <button type="submit" class="btn btn-default btn-xs"><i class="fa fa-save"></i> Save</button>
                     </td>
                     </td>
                 </tr>
@@ -694,33 +654,33 @@ $(document).ready(function() {
                             [% END %]
                         </td>
                         <td>[% IF ( branch_item_rule_loo.holdallowed_any ) %]
-                                From any library
+                                <span>From any library</span>
                             [% ELSIF ( branch_item_rule_loo.holdallowed_same ) %]
-                                From home library
+                                <span>From home library</span>
                             [% ELSE %]
-                                No holds allowed
+                                <span>No holds allowed</span>
                             [% END %]
                         </td>
                         <td>[% IF ( branch_item_rule_loo.hold_fulfillment_policy == 'any' ) %]
-                                any library
+                                <span>any library</span>
                             [% ELSIF ( branch_item_rule_loo.hold_fulfillment_policy == 'homebranch' ) %]
-                                item's home library
+                                <span>item's home library</span>
                             [% ELSIF ( branch_item_rule_loo.hold_fulfillment_policy == 'holdingbranch' ) %]
-                                item's holding library
+                                <span>item's holding library</span>
                             [% END %]
                         </td>
                         <td>[% IF ( branch_item_rule_loo.returnbranch == 'homebranch' ) %]
-                                Item returns home
+                                <span>Item returns home</span>
                             [% ELSIF ( branch_item_rule_loo.returnbranch == 'holdingbranch' ) %]
-                                Item returns to issuing branch
+                                <span>Item returns to issuing branch</span>
                             [% ELSIF ( branch_item_rule_loo.returnbranch == 'noreturn' ) %]
-                                Item floats
+                                <span>Item floats</span>
                             [% ELSE %]
-                                Error - unknown option
+                                <span>Error - unknown option</span>
                             [% END %]
                         </td>
                         <td class="actions">
-                            <a class="btn btn-mini delete" href="/cgi-bin/koha/admin/smart-rules.pl?op=delete-branch-item&amp;itemtype=[% branch_item_rule_loo.itemtype %]&amp;branch=[% current_branch %]"><i class="fa fa-trash"></i> Delete</a>
+                            <a class="btn btn-default btn-xs delete" href="/cgi-bin/koha/admin/smart-rules.pl?op=delete-branch-item&amp;itemtype=[% branch_item_rule_loo.itemtype %]&amp;branch=[% current_branch %]"><i class="fa fa-trash"></i> Delete</a>
                         </td>
                     </tr>
                 [% END %]
@@ -761,7 +721,7 @@ $(document).ready(function() {
                             <option value="noreturn">Item floats</option>
                         </select>
                     </td>
-                    <td class="actions"><button type="submit" class="btn btn-mini"><i class="fa fa-plus"></i> Add</button></td>
+                    <td class="actions"><button type="submit" class="btn btn-default btn-xs"><i class="fa fa-plus"></i> Add</button></td>
                 </tr>
             </table>
         </form>
@@ -773,4 +733,127 @@ $(document).ready(function() {
 [% INCLUDE 'admin-menu.inc' %]
 </div>
 </div>
+
+[% MACRO jsinclude BLOCK %]
+    <script type="text/javascript" src="[% interface %]/[% theme %]/js/admin-menu_[% KOHA_VERSION %].js"></script>
+    [% INCLUDE 'calendar.inc' %]
+    <script type="text/javascript">
+
+        function clear_edit(){
+            var cancel = confirm(_("Are you sure you want to cancel your changes?"));
+            if ( !cancel ) return;
+            $('#default-circulation-rules td').removeClass('highlighted-row');
+            var edit_row = $("#edit_row");
+            $(edit_row).find("input").each(function(){
+                var type = $(this).attr("type");
+                if (type != "button" && type != "submit" ) {
+                    $(this).val("");
+                    $(this).prop('disabled', false);
+                }
+                if ( type == "checkbox" ) {
+                    $(this).prop('checked', false);
+                }
+            });
+            $(edit_row).find("select").prop('disabled', false);
+            $(edit_row).find("select option:first").attr("selected", "selected");
+            $(edit_row).find("td:last input[name='clear']").remove();
+        }
+
+        var MSG_CONFIRM_DELETE = _("Are you sure you want to delete this rule? This cannot be undone.");
+
+        $(document).ready(function() {
+            $(".delete").on("click",function(){
+                return confirmDelete(MSG_CONFIRM_DELETE);
+            });
+
+            $("#clone_rules").on("click",function(){
+                var library_dropdown = document.getElementById("branch");
+                var selected_library = library_dropdown.options[library_dropdown.selectedIndex].value;
+                var selected_library_text = $("#branch option:selected").text();
+                var to_library = $("#tobranch option:selected").text();
+                var MSG_CONFIRM_CLONE;
+                if (selected_library === "*") {
+                    MSG_CONFIRM_CLONE = _("Are you sure you want to clone this standard rule to %s library? This will override the existing rules in this library.").format(to_library);
+                    return confirmClone(MSG_CONFIRM_CLONE);
+                } else {
+                    MSG_CONFIRM_CLONE = _("Are you sure you want to clone this circulation and fine rule from %s to %s library? This will override the existing rules in this library.").format(selected_library_text, to_library);
+                    return confirmClone(MSG_CONFIRM_CLONE);
+                }
+            });
+
+            $('#cap_fine_to_replacement_price').on('change', function(){
+                $('#overduefinescap').prop('disabled', $(this).is(':checked') );
+            });
+            $('#selectlibrary').find("input:submit").hide();
+            $('#branch').change(function() {
+                    $('#selectlibrary').submit();
+            });
+            $(".editrule").click(function(){
+                if ( $("#edit_row").find("input[type='text']").filter(function(){return this.value.length > 0 }).length > 0 ) {
+                    var edit = confirm(_("Are you sure you want to edit another rule?"));
+                    if (!edit) return false;
+                }
+                $('#default-circulation-rules td').removeClass('highlighted-row');
+                $(this).parent().parent().find("td").each(function (i) {
+                    $(this).addClass('highlighted-row');
+                    itm = $(this).text();
+                    itm = itm.replace(/^\s*|\s*$/g,'');
+                    var current_column = $("#edit_row td:eq("+i+")");
+                    if ( i == 7 ) {
+                        // specific processing for the Hard due date column
+                        var select_value = $(this).find("input[type='hidden'][name='hardduedatecomparebackup']").val();
+                        var input_value = '';
+                        if (typeof select_value === 'undefined'){
+                            select_value = '-1';
+                        }else {
+                            input_value = itm.split(' ')[1];
+                        }
+                        $(current_column).find("input[type='text']").val(input_value);
+                        $(current_column).find("select").val(select_value);
+                    } else if ( i == 13 ) {
+                        // specific processing for cap_fine_to_replacement_price
+                        var cap_fine_to_replacement_price = $(this).find("input[type='checkbox']");
+                        $('#cap_fine_to_replacement_price').prop('checked', cap_fine_to_replacement_price.is(':checked') );
+                        $('#overduefinescap').prop('disabled', cap_fine_to_replacement_price.is(':checked') );
+                    } else {
+                        $(current_column).find("input[type='text']").val(itm);
+                        // select the corresponding option
+                        $(current_column).find("select option").each(function(){
+                            opt = $(this).text().toLowerCase();
+                            opt = opt.replace(/^\s*|\s*$/g,'');
+                            if ( opt == itm.toLowerCase() ) {
+                                $(this).attr('selected', 'selected');
+                            }
+                        });
+                        if ( i == 0 || i == 1 ) {
+                            // Disable the 2 first columns, we cannot update them.
+                            var val = $(current_column).find("select option:selected").val();
+                            var name = "categorycode";
+                            if ( i == 1 ) {
+                                name="itemtype";
+                            }
+                            // Remove potential previous input added
+                            $(current_column).find("input").remove();
+                            $(current_column).append("<input type='hidden' name='"+name+"' value='"+val+"' />");
+                        } else if ( i == 3 || i == 4 ) {
+                            // If the value is not an integer for "Current checkouts allowed" or "Current on-site checkouts allowed"
+                            // The value is "Unlimited" (or an equivalent translated string)
+                            // an it should be set to an empty string
+                            if( !((parseFloat(itm) == parseInt(itm)) && !isNaN(itm)) ) {
+                                $(current_column).find("input[type='text']").val("");
+                            }
+                        }
+                    }
+                });
+                $("#default-circulation-rules tr:last td:eq(0) select").prop('disabled', true);
+                $("#default-circulation-rules tr:last td:eq(1) select").prop('disabled', true);
+                return false;
+            });
+            $(".clear_edit").on("click",function(e){
+                e.preventDefault();
+                clear_edit();
+            });
+        });
+    </script>
+[% END %]
 [% INCLUDE 'intranet-bottom.inc' %]