Bug 5786 - Move AllowOnShelfHolds and OPACItemHolds system prefs to the Circulation...
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / admin / smart-rules.tt
index d2f314f..2f7ec7e 100644 (file)
@@ -1,29 +1,97 @@
 [% INCLUDE 'doc-head-open.inc' %]
-<title>Koha &rsaquo; Administration &rsaquo; Circulation and Fine Rules</title>
+<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).removeAttr("disabled");
+        }
+    });
+    $(edit_row).find("select").removeAttr("disabled");
+    $(edit_row).find("select option:first").attr("selected", "selected");
+    $(edit_row).find("td:last input[name='clear']").remove();
+}
+
 $(document).ready(function() {
         $('#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 != 5 ) {
+                    $(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 ) {
+                        // If the value is not an integer for "Current 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("");
+                        }
+                    }
+                } else {
+                    // 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);
+                }
+            });
+            $("#default-circulation-rules tr:last td:eq(0) select").attr('disabled', 'disabled');
+            $("#default-circulation-rules tr:last td:eq(1) select").attr('disabled', 'disabled');
+            return false;
+        });
 });
 //]]>
 </script>
-<!-- Enable Calendar system -->
-<link rel="stylesheet" type="text/css" href="[% themelang %]/lib/calendar/calendar-system.css" />
-<script type="text/javascript" src="[% themelang %]/lib/calendar/calendar.js"></script>
-<script type="text/javascript" src="[% themelang %]/lib/calendar/calendar-en.js"></script>
-<script type="text/javascript" src="[% themelang %]/lib/calendar/calendar-setup.js"></script>
-<!-- End Calendar system additions -->
 </head>
-<body>
+<body id="admin_smart-rules" class="admin">
 [% INCLUDE 'header.inc' %]
 [% INCLUDE 'cat-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>
+<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>
 
 <div id="doc3" class="yui-t1">
 
@@ -44,10 +112,10 @@ $(document).ready(function() {
             <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>all libraries, same patron type, same item type</li>
-            <li>all libraries, same patron type, all item types</li>
-            <li>all libraries, all patron types, same item type</li>
-            <li>all libraries, 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>
         </ul>
         <p>To modify a rule, create a new one with the same patron type and item type.</p>
     </div>
@@ -63,32 +131,40 @@ $(document).ready(function() {
         </form>
 [% IF ( definedbranch ) %]<form action="/cgi-bin/koha/admin/clone-rules.pl" method="post"><label 
 for="tobranch"><strong>Clone these rules to:</strong></label> <input type="hidden" name="frombranch" value="[% current_branch %]" />
-            <select name="tobranch" id="tobranch">[% FOREACH branchloo IN branchloop %]<option value="[% branchloo.value %]">[% branchloo.branchname %]</option>[% END %]</select> <input type="submit" value="Clone" /></form>[% END %]</fieldset>
+            <select name="tobranch" id="tobranch">[% FOREACH branchloo IN branchloop %]<option value="[% branchloo.value %]">[% branchloo.branchname %]</option>[% END %]</select> <input type="submit" value="Clone" /></form>[% END %]
 
         <form method="post" action="/cgi-bin/koha/admin/smart-rules.pl">
             <input type="hidden" name="op" value="add" />
-            <table>
+            <input type="hidden" name="branch" value="[% current_branch %]"/>
+            <table id="default-circulation-rules">
+            <thead>
             <tr>
-                <th>Patron Category</th>
-                <th>Item Type</th>
-                <th>Current Checkouts Allowed</th>
-                <th>Loan Period (day)</th>
-                <th>Hard Due Date</th>
-                <th>Fine Amount</th>
-                <th>Fine Charging Interval</th>
-                <th>Fine Grace period (day)</th>
-                <th>Suspension in Days (day)</th>
-                <th>Renewals Allowed (count)</th>
-                <th>Holds Allowed (count)</th>
-                       <th>Rental Discount (%)</th>
-                               <th>&nbsp;</th>
+                <th>Patron category</th>
+                <th>Item type</th>
+                <th>Current checkouts allowed</th>
+                <th>Loan period</th>
+                <th>Unit</th>
+                <th>Hard due date</th>
+                <th>Fine amount</th>
+                <th>Fine charging interval</th>
+                <th>Fine grace period (day)</th>
+                <th>Overdue fines cap (amount)</th>
+                <th>Suspension in days (day)</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>Holds allowed (count)</th>
+                <th>On shelf holds allowed</th>
+                <th>Item level holds</th>
+                <th>Rental discount (%)</th>
+                <th colspan="2">&nbsp;</th>
             </tr>
+            </thead>
+            <tbody>
                                [% FOREACH rule IN rules %]
-                                       [% UNLESS ( loop.odd ) %]
-                                       <tr class="highlight">
-                                       [% ELSE %]
-                                       <tr>
-                                       [% END %]
+                                       <tr id="row_[% loop.count %]">
                                                        <td>[% IF ( rule.default_humancategorycode ) %]
                                                                        <em>All</em>
                                                                [% ELSE %]
@@ -108,28 +184,54 @@ for="tobranch"><strong>Clone these rules to:</strong></label> <input type="hidde
                                                                [% END %]
                                                        </td>
                                                        <td>[% rule.issuelength %]</td>
-                                                        <td>[% IF ( rule.hardduedate ) %]
-                                                               [% IF ( rule.hardduedatebefore ) %]before [% rule.hardduedate %]</td>
-                                                               [% ELSE %][% IF ( rule.hardduedateexact ) %]on [% rule.hardduedate %]</td>
-                                                                                 [% ELSE %][% IF ( rule.hardduedateafter ) %]after [% rule.hardduedate %]</td>[% END %]
-                                                                                 [% END %]
-                                                               [% END %]
-                                                            [% ELSE %]None defined[% END %]   
+                                                       <td>
+                                                           [% rule.lengthunit %]
+                                                       </td>
+                            <td>
+                              [% IF ( rule.hardduedate ) %]
+                                [% IF ( rule.hardduedatebefore ) %]
+                                  before [% rule.hardduedate %]
+                                  <input type="hidden" name="hardduedatecomparebackup" value="-1" />
+                                [% ELSIF ( rule.hardduedateexact ) %]
+                                  on [% rule.hardduedate %]
+                                  <input type="hidden" name="hardduedatecomparebackup" value="0" />
+                                [% ELSIF ( rule.hardduedateafter ) %]
+                                  after [% rule.hardduedate %]
+                                  <input type="hidden" name="hardduedatecomparebackup" value="1" />
+                                [% END %]
+                              [% ELSE %]
+                                None defined
+                              [% END %]
+                            </td>
                                                        <td>[% rule.fine %]</td>
                                                        <td>[% rule.chargeperiod %]</td>
                                                        <td>[% rule.firstremind %]</td>
+                            <td>[% rule.overduefinescap FILTER format("%.2f") %]</td>
                                                        <td>[% rule.finedays %]</td>
+                            <td>[% rule.maxsuspensiondays %]</td>
                                                        <td>[% rule.renewalsallowed %]</td>
+                            <td>[% rule.renewalperiod %]</td>
+                            <td>[% rule.norenewalbefore %]</td>
+                            <td>
+                                [% IF ( rule.auto_renew ) %]
+                                Yes
+                                [% ELSE %]
+                                No
+                                [% END %]
+                            </td>
                                                        <td>[% rule.reservesallowed %]</td>
+                                                        <td>[% IF rule.onshelfholds %]Yes[% ELSE %]No[% END %]</td>
+                                                        <td>[% IF rule.opacitemholds == 'F'%]Enforce[% ELSIF rule.opacitemholds == 'Y'%]Allow[% ELSE %]Don't allow[% END %]</td>
                                                        <td>[% rule.rentaldiscount %]</td>
+                            <td><a href="#" class="editrule">Edit</a></td>
                                                        <td>
                                                                <a class="button" href="/cgi-bin/koha/admin/smart-rules.pl?op=delete&amp;itemtype=[% rule.itemtype %]&amp;categorycode=[% rule.categorycode %]&amp;branch=[% rule.current_branch %]">Delete</a>
                                                        </td>
                        </tr>
                [% END %]
-                <tr>
+                <tr id="edit_row">
                     <td>
-                        <select name="categorycode">
+                        <select name="categorycode" id="categorycode">
                             <option value="*">All</option>
                         [% FOREACH categoryloo IN categoryloop %]
                             <option value="[% categoryloo.categorycode %]">[% categoryloo.description %]</option>
@@ -137,61 +239,82 @@ for="tobranch"><strong>Clone these rules to:</strong></label> <input type="hidde
                         </select>
                     </td>
                     <td>
-                        <select name="itemtype" style="width:13em;">
+                        <select name="itemtype" id="matrixitemtype" style="width:13em;">
                             <option value="*">All</option>
                         [% FOREACH itemtypeloo IN itemtypeloop %]
                             <option value="[% itemtypeloo.itemtype %]">[% itemtypeloo.description %]</option>
                         [% END %]
                         </select>
                     </td>
-                    <td><input name="maxissueqty" size="3" /></td>
-                    <td><input name="issuelength" size="3" /> </td>
-                    <td><select name="hardduedatecompare">
+                    <td><input type="text" name="maxissueqty" id="maxissueqty" size="3" /></td>
+                    <td><input type="text" name="issuelength" id="issuelength" size="3" /> </td>
+                    <td>
+                      <select name="lengthunit" id="lengthunit">
+                        <option value="days" selected="selected">Days</option>
+                        <option value="hours">Hours</option>
+                      </select>
+                    </td>
+                    <td>
+                        <select name="hardduedatecompare" id="hardduedatecompare">
                            <option value="-1">Before</option>
                            <option value="0">Exactly on</option>
                            <option value="1">After</option>
                         </select>
-                        <input type="text" size="10" id="hardduedate" name="hardduedate" value="[% hardduedate %]" />
-                        [% INCLUDE 'date-format.inc' %]
-                        <img src="[% themelang %]/lib/calendar/cal.gif" alt="Show Calendar"  border="0" id="CalendarDueDate" style="cursor: pointer;"/>
-                        <script language="JavaScript" type="text/javascript">
-                             function refocus(calendar) {
-                                 document.getElementById('hardduedate').focus();
-                                 calendar.hide();
-                             };
-                             Calendar.setup(
-                             {
-                             inputField : "hardduedate",
-                             ifFormat : "%m/%d/%Y",
-                             button : "CalendarDueDate",
-                             onClose: refocus
-                             }
-                             );
-                 </script>
+                        <input type="text" size="10" id="hardduedate" name="hardduedate" value="[% hardduedate %]" class="datepicker" />
+                        <div class="hint">[% INCLUDE 'date-format.inc' %]</div>
+                    </td>
+                    <td><input type="text" name="fine" id="fine" size="4" /></td>
+                    <td><input type="text" name="chargeperiod" id="chargeperiod" size="2" /></td>
+                    <td><input type="text" name="firstremind" id="firstremind" size="2" /> </td>
+                    <td><input type="text" name="overduefinescap" id="overduefinescap" size="6" /> </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="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>
+                    <td>
+                        <select name="auto_renew" id="auto_renew">
+                            <option value="no" selected>No</option>
+                            <option value="yes">Yes</option>
+                        </select>
+                    </td>
+                    <td><input type="text" name="reservesallowed" id="reservesallowed" size="2" /></td>
+                    <td>
+                        <select name="onshelfholds" id="onshelfholds">
+                            <option value="0" selected>No</option>
+                            <option value="1">Yes</option>
+                        </select>
+                    </td>
+                    <td>
+                        <select id="opacitemholds" name="opacitemholds">
+                            <option value="N">Don't allow</option>
+                            <option value="Y">Allow</option>
+                            <option value="F">Enforce</option>
+                        </select>
+                    </td>
+                    <td><input type="text" name="rentaldiscount" id="rentaldiscount" size="2" /></td>
+                    <td colspan="2">
+                        <input type="hidden" name="branch" value="[% current_branch %]"/>
+                        <input type="submit" value="Save" class="submit" />
+                        <input type="button" name="cancel" value="Clear" onclick="clear_edit();return false;" />
                     </td>
-                    <td><input name="fine" size="4" /></td>
-                    <td><input name="chargeperiod" size="2" /></td>
-                    <td><input name="firstremind" size="2" /> </td>
-                    <td><input name="finedays" size="3" /> </td>
-                    <td><input name="renewalsallowed" size="2" /></td>
-                    <td><input name="reservesallowed" size="2" /></td>
-                   <td><input name="rentaldiscount" size="2" /></td>
-                    <td><input type="hidden" name="branch" value="[% current_branch %]"/><input type="submit" value="Add" class="submit" /></td>
                 </tr>
+                </tbody>
             </table>
         </form>
     </div>
     <div id="defaults-for-this-library" class="container">
-    <h3>Default checkout and hold policy for [% IF ( humanbranch ) %][% humanbranch %][% ELSE %]all libraries[% END %]</h3>
-        <p>You can set a default maximum number of checkouts and hold policy that will be used if none is defined below for a particular item type or category.</p>
+    <h3>Default checkout, hold and return policy[% IF ( humanbranch ) %] for [% humanbranch %][% END %]</h3>
+        <p>You can set a default maximum number of checkouts, hold policy and return policy that will be used if none is defined below for a particular item type or category.</p>
         <form method="post" action="/cgi-bin/koha/admin/smart-rules.pl">
             <input type="hidden" name="op" value="set-branch-defaults" />
             <input type="hidden" name="branch" value="[% current_branch %]"/>
             <table>
                 <tr>
                     <th>&nbsp;</th>
-                    <th>Total Current Checkouts Allowed</th>
-                    <th>Hold Policy</th>
+                    <th>Total current checkouts allowed</th>
+                    <th>Hold policy</th>
+                    <th>Return policy</th>
                     <th>&nbsp;</th>
                     <th>&nbsp;</th>
                 </tr>
@@ -205,21 +328,46 @@ for="tobranch"><strong>Clone these rules to:</strong></label> <input type="hidde
                             [% ELSE %]
                             <option value="2">
                             [% END %]
-                                From Any Library
+                                From any library
                             </option>
                             [% IF ( default_holdallowed_same ) %]
                             <option value="1" selected="selected">
                             [% ELSE %]
                             <option value="1">
                             [% END %]
-                                From Home Library
+                                From home library
                             </option>
                             [% IF ( default_holdallowed_none ) %]
                             <option value="0" selected="selected">
                             [% ELSE %]
                             <option value="0">
                             [% END %]
-                                No Holds Allowed
+                                No holds allowed
+                            </option>
+                        </select>
+                    </td>
+                    <td>
+                        <select name="returnbranch">
+                            [% IF ( default_returnbranch == 'homebranch' ) %]
+                            <option value="homebranch" selected="selected">
+                            [% ELSE %]
+                            <option value="homebranch">
+                            [% END %]
+                                Item returns home
+                            </option>
+                            [% IF ( default_returnbranch == 'holdingbranch' ) %]
+                            <option value="holdingbranch" selected="selected">
+                            [% ELSE %]
+                            <option value="holdingbranch">
+                            [% END %]
+                                Item returns to issuing library
+                            </option>
+                            [% IF ( default_returnbranch == 'noreturn' ) %]
+                            <option value="noreturn" selected="selected">
+                            [% ELSE %]
+                            <option value="noreturn">
+                            [% END %]
+                                Item floats
                             </option>
                         </select>
                     </td>
@@ -233,7 +381,7 @@ for="tobranch"><strong>Clone these rules to:</strong></label> <input type="hidde
     </div>
     [% IF ( show_branch_cat_rule_form ) %]
     <div id="holds-policy-by-patron-category" class="container">
-    <h3>Checkout limit by patron category for [% IF ( humanbranch ) %][% humanbranch %][% ELSE %]all libraries[% END %]</h3>
+    <h3>[% IF humanbranch %]Checkout limit by patron category for [% humanbranch %][% ELSE %]Default checkout limit by patron category[% END %]</h3>
         <p>For this library, you can specify the maximum number of loans that
             a patron of a given category can make, regardless of the item type.
         </p>
@@ -245,8 +393,8 @@ for="tobranch"><strong>Clone these rules to:</strong></label> <input type="hidde
             <input type="hidden" name="branch" value="[% current_branch %]"/>
             <table>
                 <tr>
-                    <th>Patron Category</th>
-                    <th>Total Current Checkouts Allowed</th>
+                    <th>Patron category</th>
+                    <th>Total current checkouts allowed</th>
                     <th>&nbsp;</th>
                 </tr>
                 [% FOREACH branch_cat_rule_loo IN branch_cat_rule_loop %]
@@ -288,7 +436,7 @@ for="tobranch"><strong>Clone these rules to:</strong></label> <input type="hidde
     </div>
     [% END %]
     <div id="holds-policy-by-item-type" class="container">
-    <h3>Holds policy by item type for [% IF ( humanbranch ) %][% humanbranch %][% ELSE %]all libraries[% END %]</h3>
+    <h3>[% IF humanbranch %]Holds policy by item type for [% humanbranch %][% ELSE %]Default holds policy by item type[% END %]</h3>
         <p>
             For this library, you can edit rules for given itemtypes, regardless
             of the patron's category.
@@ -298,9 +446,9 @@ for="tobranch"><strong>Clone these rules to:</strong></label> <input type="hidde
             The various policies have the following effects:
         </p>
         <ul>
-            <li><strong>From Any Library:</strong> Patrons from any library may put this item on hold. <cite>(default if none is defined)</cite></li>
-            <li><strong>From Home Library:</strong> Only patrons from the item's home library may put this book on hold.</li>
-            <li><strong>No Holds Allowed:</strong> No patron may put this book on hold.</li>
+            <li><strong>From any library:</strong> Patrons from any library may put this item on hold. <cite>(default if none is defined)</cite></li>
+            <li><strong>From home library:</strong> Only patrons from the item's home library may put this book on hold.</li>
+            <li><strong>No holds allowed:</strong> No patron may put this book on hold.</li>
         </ul>
         <p>
             Note that if the system preference
@@ -314,8 +462,9 @@ for="tobranch"><strong>Clone these rules to:</strong></label> <input type="hidde
             <input type="hidden" name="branch" value="[% current_branch %]"/>
             <table>
                 <tr>
-                    <th>Item Type</th>
-                    <th>Hold Policy</th>
+                    <th>Item type</th>
+                    <th>Hold policy</th>
+                    <th>Return policy</th>
                     <th>&nbsp;</th>
                 </tr>
                 [% FOREACH branch_item_rule_loo IN branch_item_rule_loop %]
@@ -331,11 +480,21 @@ for="tobranch"><strong>Clone these rules to:</strong></label> <input type="hidde
                             [% END %]
                         </td>
                         <td>[% IF ( branch_item_rule_loo.holdallowed_any ) %]
-                                From Any Library
+                                From any library
                             [% ELSIF ( branch_item_rule_loo.holdallowed_same ) %]
-                                From Home Library
+                                From home library
+                            [% ELSE %]
+                                No holds allowed
+                            [% END %]
+                        </td>
+                        <td>[% IF ( branch_item_rule_loo.returnbranch == 'homebranch' ) %]
+                                Item returns home
+                            [% ELSIF ( branch_item_rule_loo.returnbranch == 'holdingbranch' ) %]
+                                Item returns to issuing branch
+                            [% ELSIF ( branch_item_rule_loo.returnbranch == 'noreturn' ) %]
+                                Item floats
                             [% ELSE %]
-                                No Holds Allowed
+                                Error - unknown option
                             [% END %]
                         </td>
                         <td>
@@ -353,9 +512,16 @@ for="tobranch"><strong>Clone these rules to:</strong></label> <input type="hidde
                     </td>
                     <td>
                         <select name="holdallowed">
-                            <option value="2">From Any Library</option>
-                            <option value="1">From Home Library</option>
-                            <option value="0">No Holds Allowed</option>
+                            <option value="2">From any library</option>
+                            <option value="1">From home library</option>
+                            <option value="0">No holds allowed</option>
+                        </select>
+                    </td>
+                    <td>
+                        <select name="returnbranch">
+                            <option value="homebranch">Item returns home</option>
+                            <option value="holdingbranch">Item returns to issuing library</option>
+                            <option value="noreturn">Item floats</option>
                         </select>
                     </td>
                     <td><input type="submit" value="Add" class="submit" /></td>