Bug 14866: Make high holds work with different item types
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / admin / smart-rules.tt
1 [% USE raw %]
2 [% USE Asset %]
3 [% USE Koha %]
4 [% USE KohaDates %]
5 [% USE Branches %]
6 [% USE Categories %]
7 [% USE ItemTypes %]
8 [% USE CirculationRules %]
9 [% SET footerjs = 1 %]
10
11 [% SET branchcode = humanbranch || undef %]
12
13 [% SET categorycodes = [] %]
14 [% FOREACH pc IN patron_categories %]
15     [% categorycodes.push( pc.id ) %]
16 [% END %]
17 [% categorycodes.push(undef) %]
18
19 [% SET itemtypes = [] %]
20 [% FOREACH i IN itemtypeloop %]
21     [% itemtypes.push( i.itemtype ) %]
22 [% END %]
23 [% itemtypes.push(undef) %]
24
25 [% INCLUDE 'doc-head-open.inc' %]
26 <title>Koha &rsaquo; Administration &rsaquo; Circulation and fine rules</title>
27 [% INCLUDE 'doc-head-close.inc' %]
28 </head>
29
30 <body id="admin_smart-rules" class="admin">
31 [% INCLUDE 'header.inc' %]
32 [% INCLUDE 'prefs-admin-search.inc' %]
33
34 <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>
35
36 <div class="main container-fluid">
37     <div class="row">
38         <div class="col-sm-10 col-sm-push-2">
39             <main>
40
41     <h1 class="parameters">
42         [% IF humanbranch %]
43             Defining circulation and fine rules for "[% Branches.GetName( humanbranch ) | html %]"
44         [% ELSE %]
45             Defining circulation and fine rules for all libraries
46         [% END %]
47     </h1>
48     <div class="help">
49         <p>The rules are applied from most specific to less specific, using the first found in this order:</p>
50         <ul>
51             <li>same library, same patron category, same item type</li>
52             <li>same library, same patron category, all item types</li>
53             <li>same library, all patron categories, same item type</li>
54             <li>same library, all patron categories, all item types</li>
55             <li>default (all libraries), same patron category, same item type</li>
56             <li>default (all libraries), same patron category, all item types</li>
57             <li>default (all libraries), all patron categories, same item type</li>
58             <li>default (all libraries), all patron categories, all item types</li>
59         </ul>
60
61         <p>Where an itemtype has a parent, the rule will display as "Parent->Child" and the number of
62         current checkouts allowed will be limited to either the maximum for the parent (counting sibling types)
63         or the specific rule's type, whichever is less.</p>
64         <p>To modify a rule, create a new one with the same patron category and item type.</p>
65     </div>
66     <div>
67         [% UNLESS restricted_to_own_library %]
68             <form method="get" action="/cgi-bin/koha/admin/smart-rules.pl" id="selectlibrary">
69             Select a library :
70                 <select name="branch" id="branch" style="width:20em;">
71                     <option value="*">Standard rules for all libraries</option>
72                     [% PROCESS options_for_libraries libraries => Branches.all( selected => current_branch, unfiltered => 1 ) %]
73                 </select>
74             </form>
75             [% IF ( definedbranch ) %]
76                 <form action="/cgi-bin/koha/admin/clone-rules.pl" method="post">
77                     <label for="tobranch"><strong>Clone these rules to:</strong></label>
78                     <input type="hidden" name="frombranch" value="[% current_branch | html %]" />
79                     <select name="tobranch" id="tobranch">
80                         [% PROCESS options_for_libraries libraries => Branches.all( unfiltered => 1 ) %]
81                     </select>
82                     <input type="submit" id="clone_rules" value="Clone" />
83                 </form>
84             [% END %]
85         [% END %]
86
87         <form method="post" action="/cgi-bin/koha/admin/smart-rules.pl">
88             <input type="hidden" name="op" value="add" />
89             <input type="hidden" name="branch" value="[% current_branch | html %]"/>
90             <table id="default-circulation-rules">
91             <thead>
92             <tr>
93                 <th>&nbsp;</th>
94                 <th class="fixed_sort">Patron category</th>
95                 <th>&nbsp;</th>
96                 <th class="fixed_sort">Item type</th>
97                 <th>Actions</th>
98                 <th>Note</th>
99                 <th>Current checkouts allowed</th>
100                 <th>Current on-site checkouts allowed</th>
101                 <th>Loan period</th>
102                 <th>Days mode</th>
103                 <th>Unit</th>
104                 <th>Hard due date</th>
105                 <th>Decreased loan period for high holds (day)</th>
106                 <th>Fine amount</th>
107                 <th>Fine charging interval</th>
108                 <th>When to charge</th>
109                 <th>Fine grace period</th>
110                 <th>Overdue fines cap (amount)</th>
111                 <th>Cap fine at replacement price</th>
112                 <th>Suspension in days (day)</th>
113                 <th>Max. suspension duration (day)</th>
114                 <th>Suspension charging interval</th>
115                 <th>Renewals allowed (count)</th>
116                 <th>Renewal period</th>
117                 <th>No renewal before</th>
118                 <th>Automatic renewal</th>
119                 <th>No automatic renewal after</th>
120                 <th>No automatic renewal after (hard limit)</th>
121                 <th>Holds allowed (total)</th>
122                 <th>Holds allowed (daily)</th>
123                 <th>Holds per record (count)</th>
124                 <th>On shelf holds allowed</th>
125                 <th>OPAC item level holds</th>
126                 <th>Article requests</th>
127                 <th>Rental discount (%)</th>
128                 <th>Actions</th>
129             </tr>
130             </thead>
131             <tbody>
132                 [% SET row_count = 0 %]
133                 [% FOREACH c IN categorycodes %]
134                     [% SET c = '' UNLESS c.defined %]
135                     [% FOREACH i IN itemtypes %]
136                         [% SET i = '' UNLESS i.defined %]
137                         [% SET note = all_rules.$c.$i.note %]
138                         [% SET maxissueqty = all_rules.$c.$i.maxissueqty %]
139                         [% SET maxonsiteissueqty = all_rules.$c.$i.maxonsiteissueqty %]
140                         [% SET issuelength = all_rules.$c.$i.issuelength %]
141                         [% SET daysmode = all_rules.$c.$i.daysmode %]
142                         [% SET lengthunit = all_rules.$c.$i.lengthunit %]
143                         [% SET hardduedate = all_rules.$c.$i.hardduedate %]
144                         [% SET hardduedatecompare = all_rules.$c.$i.hardduedatecompare %]
145                         [% SET fine = all_rules.$c.$i.fine %]
146                         [% SET chargeperiod = all_rules.$c.$i.chargeperiod %]
147                         [% SET chargeperiod_charge_at = all_rules.$c.$i.chargeperiod_charge_at %]
148                         [% SET firstremind = all_rules.$c.$i.firstremind %]
149                         [% SET overduefinescap = all_rules.$c.$i.overduefinescap %]
150                         [% SET cap_fine_to_replacement_price = all_rules.$c.$i.cap_fine_to_replacement_price %]
151                         [% SET finedays = all_rules.$c.$i.finedays %]
152                         [% SET maxsuspensiondays = all_rules.$c.$i.maxsuspensiondays %]
153                         [% SET suspension_chargeperiod = all_rules.$c.$i.suspension_chargeperiod %]
154                         [% SET renewalsallowed = all_rules.$c.$i.renewalsallowed %]
155                         [% SET renewalperiod = all_rules.$c.$i.renewalperiod %]
156                         [% SET norenewalbefore = all_rules.$c.$i.norenewalbefore %]
157                         [% SET auto_renew = all_rules.$c.$i.auto_renew %]
158                         [% SET no_auto_renewal_after = all_rules.$c.$i.no_auto_renewal_after %]
159                         [% SET no_auto_renewal_after_hard_limit = all_rules.$c.$i.no_auto_renewal_after_hard_limit %]
160                         [% SET reservesallowed = all_rules.$c.$i.reservesallowed %]
161                         [% SET holds_per_day = all_rules.$c.$i.holds_per_day %]
162                         [% SET holds_per_record = all_rules.$c.$i.holds_per_record %]
163                         [% SET onshelfholds = all_rules.$c.$i.onshelfholds %]
164                         [% SET opacitemholds = all_rules.$c.$i.opacitemholds %]
165                         [% SET article_requests = all_rules.$c.$i.article_requests %]
166                         [% SET rentaldiscount = all_rules.$c.$i.rentaldiscount %]
167                         [% SET decreaseloanholds = all_rules.$c.$i.decreaseloanholds %]
168
169                         [% SET show_rule = note || maxissueqty || maxonsiteissueqty || issuelength || daysmode || lengthunit || hardduedate || hardduedatecompare || fine || chargeperiod || chargeperiod_charge_at || firstremind || overduefinescap || cap_fine_to_replacement_price || finedays || maxsuspensiondays || suspension_chargeperiod || renewalsallowed || renewalperiod || norenewalbefore || auto_renew || no_auto_renewal_after || no_auto_renewal_after_hard_limit || reservesallowed || holds_per_day || holds_per_record || onshelfholds || opacitemholds || article_requests || rentaldiscount || decreaseloanholds %]
170                         [% IF show_rule %]
171                             [% SET row_count = row_count + 1 %]
172                             <tr row_countd="row_[% row_count | html %]">
173                                     <td>[% IF ( c == undef ) %]1[% ELSE %]0[% END %]</td>
174                                     <td>
175                                         [% IF c == undef %]
176                                             <em>All</em>
177                                         [% ELSE %]
178                                             [% Categories.GetName(c) | html %]
179                                         [% END %]
180                                     </td>
181                                     <td>[% IF ( i == undef ) %]1[% ELSE %]0[% END %]</td>
182                                     <td>
183                                         [% IF i == undef %]
184                                             <em>All</em>
185                                         [% ELSE %]
186                                             [% ItemTypes.GetDescription(i,1) | html %]
187                                         [% END %]
188                                     </td>
189                                     <td class="actions">
190                                       <a href="#" class="editrule btn btn-default btn-xs"><i class="fa fa-pencil"></i> Edit</a>
191                                       <a class="btn btn-default btn-xs delete" href="/cgi-bin/koha/admin/smart-rules.pl?op=delete&amp;itemtype=[% i || '*' | html %]&amp;categorycode=[% c || '*' | html %]&amp;branch=[% current_branch | html %]"><i class="fa fa-trash"></i> Delete</a>
192                                     </td>
193                                     <td>
194                                         [% IF note.defined && note != '' %]
195                                             <a name="viewnote" data-toggle="popover" title="Note" data-content="[% note | html %]" data-placement="top" data-trigger="hover">View note</a>
196                                         [% ELSE %]<span>&nbsp;</span>[% END %]
197                                     </td>
198                                     <td>
199                                         [% IF maxissueqty.defined && maxissueqty != '' %]
200                                             [% maxissueqty | html %]
201                                         [% ELSE %]
202                                             <span>Unlimited</span>
203                                         [% END %]
204                                     </td>
205                                     <td>
206                                         [% IF maxonsiteissueqty.defined && maxonsiteissueqty != ''  %]
207                                             [% maxonsiteissueqty | html %]
208                                         [% ELSE %]
209                                             <span>Unlimited</span>
210                                         [% END %]
211                                     </td>
212                                     <td>[% issuelength | html %]</td>
213                                     <td>
214                                         [% SWITCH daysmode %]
215                                         [% CASE 'Calendar' %]<span title="Use the calendar to skip days the library is closed">Calendar</span>
216                                         [% CASE 'Datedue' %]<span title="Use the calendar to push the due date to the next open day">Datedue</span>
217                                         [% CASE 'Days' %]<span title="Ignore the calendar">Days</span>
218                                         [% CASE 'Dayweek' %]<span title="Use the calendar to push the due date to the next open matching weekday for weekly loan periods, or the next open day otherwise">Dayweek</span>
219                                         [% CASE %]<span title="Use the system preference 'useDaysMode' as a default value">Default</span>
220                                         [% END %]
221                                     </td>
222                                     <td>
223                                         [% IF ( lengthunit == 'days' ) %]
224                                             Days
225                                         [% ELSIF ( lengthunit == 'hours') %]
226                                             Hours
227                                         [% ELSE %]
228                                             Undefined
229                                         [% END %]
230                                     </td>
231                                     <td>
232                                       [% IF ( hardduedate ) %]
233                                         [% IF ( hardduedatecompare == '-1' ) %]
234                                           before [% hardduedate | $KohaDates %]
235                                           <input type="hidden" name="hardduedatecomparebackup" value="-1" />
236                                         [% ELSIF ( hardduedatecompare == '0' ) %]
237                                           on [% hardduedate | $KohaDates %]
238                                           <input type="hidden" name="hardduedatecomparebackup" value="0" />
239                                         [% ELSIF ( hardduedatecompare == '1' ) %]
240                                           after [% hardduedate | $KohaDates %]
241                                           <input type="hidden" name="hardduedatecomparebackup" value="1" />
242                                         [% END %]
243                                       [% ELSE %]
244                                         <span>None defined</span>
245                                       [% END %]
246                                     </td>
247                                     <td>[% decreaseloanholds | html %]</td>
248                                     <td>[% fine | html %]</td>
249                                     <td>[% chargeperiod | html %]</td>
250                                     <td>[% IF chargeperiod_charge_at %]Start of interval[% ELSE %]End of interval[% END %]</td>
251                                     <td>[% firstremind | html %]</td>
252                                     <td>[% overduefinescap FILTER format("%.2f") %]</td>
253                                     <td>
254                                         [% IF cap_fine_to_replacement_price %]
255                                             <input type="checkbox" checked="checked" disabled="disabled" />
256                                         [% ELSE %]
257                                             <input type="checkbox" disabled="disabled" />
258                                         [% END %]
259                                     </td>
260                                     <td>[% finedays | html %]</td>
261                                     <td>[% maxsuspensiondays | html %]</td>
262                                     <td>[% suspension_chargeperiod | html %]</td>
263                                     <td>[% renewalsallowed | html %]</td>
264                                     <td>[% renewalperiod | html %]</td>
265                                     <td>[% norenewalbefore | html %]</td>
266                                     <td>
267                                         [% IF auto_renew %]
268                                             <span>Yes</span>
269                                         [% ELSE %]
270                                             <span>No</span>
271                                         [% END %]
272                                     </td>
273                                     <td>[% no_auto_renewal_after | html %]</td>
274                                     <td>[% no_auto_renewal_after_hard_limit | $KohaDates %]</td>
275                                     <td>
276                                         [% IF reservesallowed.defined && reservesallowed != '' %]
277                                             [% reservesallowed | html %]
278                                         [% ELSE %]
279                                             <span>Unlimited</span>
280                                         [% END %]
281                                     </td>
282                                     <td>
283                                         [% IF holds_per_day.defined && holds_per_day != '' %]
284                                             [% holds_per_day | html %]
285                                         [% ELSE %]
286                                             <span>Unlimited</span>
287                                         [% END %]
288                                     </td>
289                                     <td>
290                                         [% IF holds_per_record.defined && holds_per_record != '' %]
291                                             [% holds_per_record | html %]
292                                         [% ELSE %]
293                                             <span>Unlimited</span>
294                                         [% END %]
295                                     </td>
296                                     <td>
297                                         [% IF onshelfholds == 1 %]
298                                             <span>Yes</span>
299                                         [% ELSIF onshelfholds == 2 %]
300                                             <span>If all unavailable</span>
301                                         [% ELSE %]
302                                             <span>If any unavailable</span>
303                                         [% END %]
304                                     </td>
305                                     <td>
306                                         [% IF opacitemholds == 'F'%]
307                                             <span>Force</span>
308                                         [% ELSIF opacitemholds == 'Y'%]
309                                             <span>Allow</span>
310                                         [% ELSE %]
311                                             <span>Don't allow</span>
312                                         [% END %]
313                                     </td>
314                                     <td>
315                                         [% IF article_requests == 'no' %]
316                                             <span>No</span>
317                                         [% ELSIF article_requests == 'yes' %]
318                                             <span>Yes</span>
319                                         [% ELSIF article_requests == 'bib_only' %]
320                                             <span>Record only</span>
321                                         [% ELSIF article_requests == 'item_only' %]
322                                             <span>Item only</span>
323                                         [% END %]
324                                     </td>
325                                     <td>[% rentaldiscount | html %]</td>
326                                     <td class="actions">
327                                       <a href="#" class="editrule btn btn-default btn-xs"><i class="fa fa-pencil"></i> Edit</a>
328                                       <a class="btn btn-default btn-xs delete" href="/cgi-bin/koha/admin/smart-rules.pl?op=delete&amp;itemtype=[% i || '*' | uri %]&amp;categorycode=[% c || '*' | uri %]&amp;branch=[% current_branch | uri %]"><i class="fa fa-trash"></i> Delete</a>
329                                     </td>
330                             </tr>
331                         [% END %]
332                     [% END %]
333                 [% END %]
334                 <tr id="edit_row">
335                     <td>2</td>
336                     <td>
337                         <select name="categorycode" id="categorycode">
338                             <option value="*">All</option>
339                         [% FOREACH patron_category IN patron_categories%]
340                             <option value="[% patron_category.categorycode | html %]">[% patron_category.description | html %]</option>
341                         [% END %]
342                         </select>
343                     </td>
344                     <td>0</td>
345                     <td>
346                         <select name="itemtype" id="matrixitemtype" style="width:13em;">
347                             <option value="*">All</option>
348                             [% FOREACH itemtypeloo IN itemtypeloop %]
349                                 [% NEXT IF itemtypeloo.parent_type %]
350                                 [% SET children = itemtypeloo.children_with_localization %]
351                                 [% IF children %]
352                                     <optgroup label="[% itemtypeloo.translated_description | html %]">
353                                         <option value="[% itemtypeloo.itemtype | html %]">[% itemtypeloo.translated_description | html %] (All)</option>
354                                         [% FOREACH child IN children %]
355                                             <option value="[% child.itemtype | html %]">[% child.translated_description | html %]</option>
356                                         [% END %]
357                                     </optgroup>
358                                 [% ELSE %]
359                                     <option value="[% itemtypeloo.itemtype | html %]">[% itemtypeloo.translated_description | html %]</option>
360                                 [% END %]
361                             [% END %]
362                         </select>
363                     </td>
364                     <td class="actions">
365                         <input type="hidden" name="branch" value="[% current_branch | html %]"/>
366                         <button type="submit" class="btn btn-default btn-xs"><i class="fa fa-save"></i> Save</button>
367                         <button name="cancel" class="clear_edit btn btn-default btn-xs"><i class="fa fa-undo"></i> Clear</button>
368                     </td>
369                     <td><input type="text" name="note" id="note" size="15" value="" maxlength="100"></td>
370                     <td><input type="text" name="maxissueqty" id="maxissueqty" size="3" /></td>
371                     <td><input type="text" name="maxonsiteissueqty" id="maxonsiteissueqty" size="3" /></td>
372                     <td><input type="text" name="issuelength" id="issuelength" size="3" /> </td>
373                     <td>
374                         <select name="daysmode" id="daysmode">
375                             <option value="">Default</option>
376                             <option value="Calendar">Calendar</option>
377                             <option value="Datedue">Datedue</option>
378                             <option value="Days">Days</option>
379                             <option value="Dayweek">Dayweek</option>
380                         </select>
381                     </td>
382                     <td>
383                       <select name="lengthunit" id="lengthunit">
384                         <option value="days" selected="selected">Days</option>
385                         <option value="hours">Hours</option>
386                       </select>
387                     </td>
388                     <td>
389                         <select name="hardduedatecompare" id="hardduedatecompare">
390                            <option value="-1">Before</option>
391                            <option value="0">Exactly on</option>
392                            <option value="1">After</option>
393                         </select>
394                         <input type="text" size="10" id="hardduedate" name="hardduedate" value="[% hardduedate | html %]" class="datepicker" />
395                         <div class="hint">[% INCLUDE 'date-format.inc' %]</div>
396                     </td>
397                     <td><input type="text" name="decreaseloanholds" id="decreaseloanholds" size="2" /></td>
398                     <td><input type="text" name="fine" id="fine" size="4" /></td>
399                     <td><input type="text" name="chargeperiod" id="chargeperiod" size="2" /></td>
400                     <td>
401                         <select name="chargeperiod_charge_at" id="chargeperiod_charge_at">
402                            <option value="0">End of interval</option>
403                            <option value="1">Start of interval</option>
404                         </select>
405                     </td>
406                     <td><input type="text" name="firstremind" id="firstremind" size="2" /> </td>
407                     <td><input type="text" name="overduefinescap" id="overduefinescap" size="6" /> </td>
408                     <td><input type="checkbox" name="cap_fine_to_replacement_price" id="cap_fine_to_replacement_price" /></td>
409                     <td><input type="text" name="finedays" id="fined" size="3" /> </td>
410                     <td><input type="text" name="maxsuspensiondays" id="maxsuspensiondays" size="3" /> </td>
411                     <td><input type="text" name="suspension_chargeperiod" id="suspension_chargeperiod" size="3" /> </td>
412                     <td><input type="text" name="renewalsallowed" id="renewalsallowed" size="2" /></td>
413                     <td><input type="text" name="renewalperiod" id="renewalperiod" size="3" /></td>
414                     <td><input type="text" name="norenewalbefore" id="norenewalbefore" size="3" /></td>
415                     <td>
416                         <select name="auto_renew" id="auto_renew">
417                             <option value="no" selected>No</option>
418                             <option value="yes">Yes</option>
419                         </select>
420                     </td>
421                     <td><input type="text" name="no_auto_renewal_after" id="no_auto_renewal_after" size="3" /></td>
422                     <td>
423                         <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 | html %]" class="datepicker"/>
424                         <div class="hint">[% INCLUDE 'date-format.inc' %]</div>
425                     </td>
426                     <td><input type="text" name="reservesallowed"  id="reservesallowed"  size="2" /></td>
427                     <td><input type="text" name="holds_per_day"    id="holds_per_day"    size="2" /></td>
428                     <td><input type="text" name="holds_per_record" id="holds_per_record" size="2" /></td>
429                     <td>
430                         <select name="onshelfholds" id="onshelfholds">
431                             <option value="1">Yes</option>
432                             <option value="0">If any unavailable</option>
433                             <option value="2">If all unavailable</option>
434                         </select>
435                     </td>
436                     <td>
437                         <select id="opacitemholds" name="opacitemholds">
438                             <option value="N">Don't allow</option>
439                             <option value="Y">Allow</option>
440                             <option value="F">Force</option>
441                         </select>
442                     </td>
443                     <td>
444                         <select id="article_requests" name="article_requests">
445                             <option value="no">No</option>
446                             <option value="yes">Yes</option>
447                             <option value="bib_only">Record only</option>
448                             <option value="item_only">Item only</option>
449                         </select>
450                     </td>
451                     <td><input type="text" name="rentaldiscount" id="rentaldiscount" size="2" /></td>
452                     <td class="actions">
453                         <input type="hidden" name="branch" value="[% current_branch | html %]"/>
454                         <button type="submit" class="btn btn-default btn-xs"><i class="fa fa-save"></i> Save</button>
455                         <button name="cancel" class="clear_edit btn btn-default btn-xs"><i class="fa fa-undo"></i> Clear</button>
456                     </td>
457                 </tr>
458                 <tfoot>
459                     <tr>
460                       <th>&nbsp;</th>
461                       <th>Patron category</th>
462                       <th>&nbsp;</th>
463                       <th>Item type</th>
464                       <th>&nbsp;</th>
465                       <th>Note</th>
466                       <th>Current checkouts allowed</th>
467                       <th>Current on-site checkouts allowed</th>
468                       <th>Loan period</th>
469                       <th>Days mode</th>
470                       <th>Unit</th>
471                       <th>Hard due date</th>
472                       <th>Decreased loan period for high holds (day)</th>
473                       <th>Fine amount</th>
474                       <th>Fine charging interval</th>
475                       <th>Charge when?</th>
476                       <th>Fine grace period</th>
477                       <th>Overdue fines cap (amount)</th>
478                       <th>Cap fine at replacement price</th>
479                       <th>Suspension in days (day)</th>
480                       <th>Max. suspension duration (day)</th>
481                       <th>Suspension charging interval</th>
482                       <th>Renewals allowed (count)</th>
483                       <th>Renewal period</th>
484                       <th>No renewal before</th>
485                       <th>Automatic renewal</th>
486                       <th>No automatic renewal after</th>
487                       <th>No automatic renewal after (hard limit)</th>
488                       <th>Holds allowed (total)</th>
489                       <th>Holds allowed (daily)</th>
490                       <th>Holds per record (count)</th>
491                       <th>On shelf holds allowed</th>
492                       <th>OPAC item level holds</th>
493                       <th>Article requests</th>
494                       <th>Rental discount (%)</th>
495                       <th>&nbsp;</th>
496                     </tr>
497                   </tfoot>
498                 </tbody>
499             </table>
500         </form>
501     </div>
502     <div id="defaults-for-this-library" class="container">
503     <h3>Default checkout, hold and return policy[% IF humanbranch %] for [% Branches.GetName( humanbranch ) | html %][% END %]</h3>
504         <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>
505         <form method="post" action="/cgi-bin/koha/admin/smart-rules.pl">
506             <input type="hidden" name="op" value="set-branch-defaults" />
507             <input type="hidden" name="branch" value="[% current_branch | html %]"/>
508             <table>
509                 <tr>
510                     <th>&nbsp;</th>
511                     <th>Total current checkouts allowed</th>
512                     <th>Total current on-site checkouts allowed</th>
513                     <th>Maximum total holds allowed (count)</th>
514                     <th>Hold policy</th>
515                     <th>Hold pickup library match</th>
516                     <th>Return policy</th>
517                     <th>Actions</th>
518                 </tr>
519                 <tr>
520                     <td><em>Defaults</em></td>
521                     <td>
522                         [% SET patron_maxissueqty = CirculationRules.Search( current_branch, undef, undef, 'patron_maxissueqty' ) %]
523                         <input type="text" name="patron_maxissueqty" size="3" value="[% patron_maxissueqty | html %]"/>
524                     </td>
525                     <td>
526                         [% SET patron_maxonsiteissueqty = CirculationRules.Search( current_branch, undef, undef, 'patron_maxonsiteissueqty' ) %]
527                         <input type="text" name="patron_maxonsiteissueqty" size="3" value="[% patron_maxonsiteissueqty | html %]"/>
528                     </td>
529                     <td>
530                         [% SET rule_value = CirculationRules.Search( current_branch, undef , undef, 'max_holds' ) %]
531                         <input name="max_holds" size="3" value="[% rule_value | html %]" />
532                     </td>
533                     <td>
534                         <select name="holdallowed">
535                             [% SET holdallowed = CirculationRules.Search( current_branch, undef, undef, 'holdallowed' ) %]
536                             <option value="">
537                                 Not set
538                             </option>
539
540                             [% IF holdallowed == 2 %]
541                                 <option value="2" selected="selected">
542                             [% ELSE %]
543                                 <option value="2">
544                             [% END %]
545                                 From any library
546                             </option>
547
548                             [% IF holdallowed == 3 %]
549                             <option value="3" selected="selected">
550                             [% ELSE %]
551                             <option value="3">
552                             [% END %]
553                                 From local hold group
554                             </option>
555
556                             [% IF holdallowed == 1 %]
557                                 <option value="1" selected="selected">
558                             [% ELSE %]
559                                 <option value="1">
560                             [% END %]
561                                 From home library
562                             </option>
563
564                             [% IF holdallowed == 0 %]
565                                 <option value="0" selected="selected">
566                             [% ELSE %]
567                                 <option value="0">
568                             [% END %]
569                                 No holds allowed
570                             </option>
571                         </select>
572                     </td>
573                     <td>
574                         <select name="hold_fulfillment_policy">
575                             [% SET hold_fulfillment_policy = CirculationRules.Search( current_branch, undef, undef, 'hold_fulfillment_policy' ) %]
576
577                             <option value="">
578                                 Not set
579                             </option>
580
581                             [% IF hold_fulfillment_policy == 'any' %]
582                                 <option value="any" selected="selected">
583                                     any library
584                                 </option>
585                             [% ELSE %]
586                                 <option value="any">
587                                     any library
588                                 </option>
589                             [% END %]
590
591                             [% IF hold_fulfillment_policy == 'holdgroup' %]
592                                 <option value="holdgroup" selected="selected">
593                                     item's hold group
594                                 </option>
595                             [% ELSE %]
596                                 <option value="holdgroup">
597                                     item's hold group
598                                 </option>
599                             [% END %]
600
601                             [% IF hold_fulfillment_policy == 'patrongroup' %]
602                                 <option value="patrongroup" selected="selected">
603                                     patron's hold group
604                                 </option>
605                             [% ELSE %]
606                                 <option value="patrongroup">
607                                     patron's hold group
608                                 </option>
609                             [% END %]
610
611                             [% IF hold_fulfillment_policy == 'homebranch' %]
612                                 <option value="homebranch" selected="selected">
613                                     item's home library
614                                 </option>
615                             [% ELSE %]
616                                 <option value="homebranch">
617                                     item's home library
618                                 </option>
619                             [% END %]
620
621                             [% IF hold_fulfillment_policy == 'holdingbranch' %]
622                                 <option value="holdingbranch" selected="selected">
623                                     item's holding library
624                                 </option>
625                             [% ELSE %]
626                                 <option value="holdingbranch">
627                                     item's holding library
628                                 </option>
629                             [% END %]
630                         </select>
631                     </td>
632                     <td>
633                         <select name="returnbranch">
634                             [% SET returnbranch = CirculationRules.Search( current_branch, undef, undef, 'returnbranch' ) %]
635
636                             <option value="">
637                                 Not set
638                             </option>
639
640                             [% IF returnbranch == 'homebranch' %]
641                             <option value="homebranch" selected="selected">
642                             [% ELSE %]
643                             <option value="homebranch">
644                             [% END %]
645                                 Item returns home
646                             </option>
647                             [% IF returnbranch == 'holdingbranch' %]
648                             <option value="holdingbranch" selected="selected">
649                             [% ELSE %]
650                             <option value="holdingbranch">
651                             [% END %]
652                                 Item returns to issuing library
653                             </option>
654                             [% IF returnbranch == 'noreturn' %]
655                             <option value="noreturn" selected="selected">
656                             [% ELSE %]
657                             <option value="noreturn">
658                             [% END %]
659                                 Item floats
660                             </option>
661                         </select>
662                     </td>
663                     <td class="actions">
664                         <button type="submit" class="btn btn-default btn-xs"><i class="fa fa-save"></i> Save</button>
665                         <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 | html %]" id="unset"><i class="fa fa-undo"></i> Unset</a>
666                     </td>
667                 </tr>
668             </table>
669         </form>
670     </div>
671     [% IF ( show_branch_cat_rule_form ) %]
672     <div id="holds-policy-by-patron-category" class="container">
673     <h3>[% IF humanbranch %]Checkout, hold policy by patron category for [% Branches.GetName( humanbranch ) | html %][% ELSE %]Default checkout, hold policy by patron category[% END %]</h3>
674         <p>For this library, you can specify the maximum number of loans that
675             a patron of a given category can make, regardless of the item type.
676         </p>
677         <p>If the total amount loanable for a given patron category is left blank,
678            no limit applies, except possibly for a limit you define for a specific item type.
679         </p>
680         <form method="post" action="/cgi-bin/koha/admin/smart-rules.pl">
681             <input type="hidden" name="op" value="add-branch-cat" />
682             <input type="hidden" name="branch" value="[% current_branch | html %]"/>
683             <table>
684                 <tr>
685                     <th>Patron category</th>
686                     <th>Total current checkouts allowed</th>
687                     <th>Total current on-site checkouts allowed</th>
688                     <th>Total holds allowed</th>
689                     <th>&nbsp;</th>
690                 </tr>
691                 [% FOREACH c IN categorycodes %]
692                     [% NEXT UNLESS c %]
693                     [% SET patron_maxissueqty = CirculationRules.Search( branchcode, c, undef, 'patron_maxissueqty' ) %]
694                     [% SET patron_maxonsiteissueqty = CirculationRules.Search( branchcode, c, undef, 'patron_maxonsiteissueqty' ) %]
695                     [% SET max_holds = CirculationRules.Search( branchcode, c, undef, 'max_holds' ) %]
696
697                     [% IF  ( patron_maxissueqty.defined && patron_maxissueqty != '' ) || ( patron_maxonsiteissueqty.defined && patron_maxonsiteissueqty != '' ) || ( max_holds.defined && max_holds != '' ) %]
698                     <tr>
699                         <td>
700                             [% IF c == undef %]
701                                 <em>Default</em>
702                             [% ELSE %]
703                                 [% Categories.GetName(c) | html %]
704                             [% END %]
705                         </td>
706                         <td>
707                             [% IF patron_maxissueqty.defined && patron_maxissueqty != '' %]
708                                 [% patron_maxissueqty | html %]
709                             [% ELSE %]
710                                 <span>Unlimited</span>
711                             [% END %]
712                         </td>
713                         <td>
714                             [% IF patron_maxonsiteissueqty.defined && patron_maxonsiteissueqty != '' %]
715                                 [% patron_maxonsiteissueqty | html %]
716                             [% ELSE %]
717                                 <span>Unlimited</span>
718                             [% END %]
719                         </td>
720                         <td>
721                             [% IF max_holds.defined && max_holds != '' %]
722                                 [% max_holds | html %]
723                             [% ELSE %]
724                                 <span>Unlimited</span>
725                             [% END %]
726                         </td>
727
728                         <td class="actions">
729                             <a class="btn btn-default btn-xs delete" href="/cgi-bin/koha/admin/smart-rules.pl?op=delete-branch-cat&amp;categorycode=[% c | html %]&amp;branch=[% current_branch | html %]"><i class="fa fa-trash"></i> Delete</a>
730                         </td>
731                     </tr>
732                     [% END %]
733                 [% END %]
734                 <tr>
735                     <td>
736                         <select name="categorycode">
737                         [% FOREACH patron_category IN patron_categories%]
738                             <option value="[% patron_category.categorycode | html %]">[% patron_category.description | html %]</option>
739                         [% END %]
740                         </select>
741                     </td>
742                     <td><input name="patron_maxissueqty" size="3" type="text" /></td>
743                     <td><input name="patron_maxonsiteissueqty" size="3" type="text" /></td>
744                     <td><input name="max_holds" size="3" type="text" /></td>
745                     <td class="actions"><button type="submit" class="btn btn-default btn-xs"><i class="fa fa-plus"></i> Add</td>
746                 </tr>
747             </table>
748         </form>
749     </div>
750     [% END %]
751
752     <div id="refund-lost-item-fee-on-return" class="container">
753         [% IF current_branch == '*' %]
754             <h3>Default lost item fee refund on return policy</h3>
755         [% ELSE %]
756             <h3>Lost item fee refund on return policy for [% Branches.GetName(current_branch) | html %]</h3>
757         [% END %]
758         <p>Specify the default policy for lost item fees on return.
759         </p>
760         <form method="post" action="/cgi-bin/koha/admin/smart-rules.pl">
761             <input type="hidden" name="op" value="mod-refund-lost-item-fee-rule" />
762             <input type="hidden" name="branch" value="[% current_branch | html %]" />
763             <table>
764                 <tr>
765                     <th>Refund lost item fee</th>
766                     <th>&nbsp;</th>
767                 </tr>
768                 <tr>
769                     <td>
770                         <select name="lostreturn">
771                           [%# Default branch %]
772                           [% IF ( current_branch == '*' ) %]
773                             [% IF ( defaultRefundRule == 'refund' ) %]
774                             <option value="refund" selected="selected">Refund lost item charge</option>
775                             <option value="charge">Refund lost item charge and charge new overdue fine</option>
776                             <option value="restore">Refund lost item charge and restore overdue fine</option>
777                             <option value="0">Leave lost item charge</option>
778                             [% ELSIF ( defaultRefundRule == 'charge' ) %]
779                             <option value="refund">Refund lost item charge</option>
780                             <option value="charge" selected="selected">Refund lost item charge and charge new overdue fine</option>
781                             <option value="restore">Refund lost item charge and restore overdue fine</option>
782                             <option value="0">Leave lost item charge</option>
783                             [% ELSIF ( defaultRefundRule == 'restore' ) %]
784                             <option value="refund">Refund lost item charge</option>
785                             <option value="charge">Refund lost item charge and charge new overdue fine</option>
786                             <option value="restore" selected="selected">Refund lost item charge and restore overdue fine</option>
787                             <option value="0">Leave lost item charge</option>
788                             [% ELSIF ( defaultRefundRule == 0 ) %]
789                             <option value="refund">Refund lost item charge</option>
790                             <option value="charge">Refund lost item charge and charge new overdue fine</option>
791                             <option value="restore">Refund lost item charge and restore overdue fine</option>
792                             <option value="0" selected="selected">Leave lost item charge</option>
793                             [% ELSE %]
794                             <option value="refund">Refund lost item charge</option>
795                             <option value="charge">Refund lost item charge and charge new overdue fine</option>
796                             <option value="restore">Refund lost item charge and restore overdue fine</option>
797                             <option value="0">Leave lost item charge</option>
798                             [% END %]
799                           [% ELSE %]
800                           [%# Branch-specific %]
801                             [% IF ( not refundLostItemFeeRule ) %]
802                                 <option value="*" selected="selected">
803                             [% ELSE %]
804                                 <option value="*">
805                             [% END %]
806                               [% IF defaultRefundRule == 'refund' %]
807                                 Use default (Refund lost item charge)
808                               [% ELSIF defaultRefundRule == 'charge' %]
809                                 Use default (Refund lost item charge and restore overdue fine)
810                               [% ELSIF defaultRefundRule == 'restore' %]
811                                 Use default (Refund lost item charge and charge new overdue fine)
812                               [% ELSE %]
813                                 Use default (Leave lost item charge)
814                               [% END %]
815                                 </option>
816                             [% IF ( not refundLostItemFeeRule ) %]
817                                 <option value="refund">Refund lost item charge</option>
818                                 <option value="charge">Refund lost item charge and charge new overdue fine</option>
819                                 <option value="restore">Refund lost item charge and restore overdue fine</option>
820                                 <option value="0">Leave lost item charge</option>
821                             [% ELSE %]
822                                 [% IF ( refundLostItemFeeRule.rule_value == 'refund' ) %]
823                                 <option value="refund" selected="selected">Refund lost item charge</option>
824                                 <option value="charge">Refund lost item charge and charge new overdue fine</option>
825                                 <option value="restore">Refund lost item charge and restore overdue fine</option>
826                                 <option value="0">Leave lost item charge</option>
827                                 [% ELSIF ( refundLostItemFeeRule.rule_value == 'charge' ) %]
828                                 <option value="refund">Refund lost item charge</option>
829                                 <option value="charge" selected="selected">Refund lost item charge and charge new overdue fine</option>
830                                 <option value="restore">Refund lost item charge and restore overdue fine</option>
831                                 <option value="0">Leave lost item charge</option>
832                                 [% ELSIF ( refundLostItemFeeRule.rule_value == 'restore' ) %]
833                                 <option value="refund">Refund lost item charge</option>
834                                 <option value="charge">Refund lost item charge and charge new overdue fine</option>
835                                 <option value="restore" selected="selected">Refund lost item charge and restore overdue fine</option>
836                                 <option value="0">Leave lost item charge</option>
837                                 [% ELSIF ( refundLostItemFeeRule.rule_value == 0 ) %]
838                                 <option value="refund">Refund lost item charge</option>
839                                 <option value="charge">Refund lost item charge and charge new overdue fine</option>
840                                 <option value="restore">Refund lost item charge and restore overdue fine</option>
841                                 <option value="0" selected="selected">Leave lost item charge</option>
842                                 [% END %]
843                             [% END %]
844                           [% END %]
845                         </select>
846                     </td>
847                     <td class="actions">
848                         <button type="submit" class="btn btn-default btn-xs"><i class="fa fa-save"></i> Save</button>
849                     </td>
850                     </td>
851                 </tr>
852             </table>
853         </form>
854     </div>
855
856     <div id="holds-policy-by-item-type" class="container">
857     <h3>[% IF humanbranch %]Holds policy by item type for [% Branches.GetName( humanbranch ) | html %][% ELSE %]Default holds policy by item type[% END %]</h3>
858         <p>
859             For this library, you can edit rules for given itemtypes, regardless
860             of the patron's category.
861         </p>
862         <p>
863             Currently, this means hold policies.
864             The various policies have the following effects:
865         </p>
866         <ul>
867             <li><strong>From any library:</strong> Patrons from any library may put this item on hold. <cite>(default if none is defined)</cite></li>
868             <li><strong>From local hold group:</strong> Only patrons from libraries in the same item's home library hold groups may put this book on hold.</li>
869             <li><strong>From home library:</strong> Only patrons from the item's home library may put this book on hold.</li>
870             <li><strong>No holds allowed:</strong> No patron may put this book on hold.</li>
871         </ul>
872         <p><strong>Note: </strong>If the system preference 'AllowHoldPolicyOverride' is enabled, these policies can be overridden by your circulation staff.</br />
873             <strong>Important: </strong>The policies are applied based on the ReservesControlBranch system preference which is set to <a href="/cgi-bin/koha/admin/preferences.pl?op=search&searchfield=ReservesControlBranch">[% Koha.Preference('ReservesControlBranch') | html %]</a>.
874         </p>
875
876         <form method="post" action="/cgi-bin/koha/admin/smart-rules.pl">
877             <input type="hidden" name="op" value="add-branch-item" />
878             <input type="hidden" name="branch" value="[% current_branch | html %]"/>
879             <table>
880                 <tr>
881                     <th>Item type</th>
882                     <th>Hold policy</th>
883                     <th>Hold pickup library match</th>
884                     <th>Return policy</th>
885                     <th>&nbsp;</th>
886                 </tr>
887                 [% FOREACH i IN itemtypeloop %]
888                     [% SET holdallowed = CirculationRules.Search( branchcode, undef, i.itemtype, 'holdallowed' ) %]
889                     [% SET hold_fulfillment_policy = CirculationRules.Search( branchcode, undef, i.itemtype, 'hold_fulfillment_policy' ) %]
890                     [% SET returnbranch = CirculationRules.Search( branchcode, undef, i.itemtype, 'returnbranch' ) %]
891
892                     [% IF holdallowed || hold_fulfillment_policy || returnbranch %]
893                         <tr>
894                             <td>
895                                 [% i.translated_description | html %]
896                             </td>
897                             <td>
898                                 [% IF holdallowed == 2 %]
899                                     <span>From any library</span>
900                                 [% ELSIF holdallowed == 3 %]
901                                     <span>From local hold group</span>
902                                 [% ELSIF holdallowed == 1 %]
903                                     <span>From home library</span>
904                                 [% ELSE %]
905                                     <span>No holds allowed</span>
906                                 [% END %]
907                             </td>
908                             <td>
909                                 [% IF hold_fulfillment_policy == 'any' %]
910                                     <span>any library</span>
911                                 [% ELSIF hold_fulfillment_policy == 'homebranch' %]
912                                     <span>item's home library</span>
913                                 [% ELSIF hold_fulfillment_policy == 'holdgroup' %]
914                                     <span>item's hold group</span>
915                                 [% ELSIF hold_fulfillment_policy == 'patrongroup' %]
916                                     <span>patron's hold group</span>
917                                 [% ELSIF hold_fulfillment_policy == 'holdingbranch' %]
918                                     <span>item's holding library</span>
919                                 [% END %]
920                             </td>
921                             <td>
922                                 [% IF returnbranch == 'homebranch' %]
923                                     <span>Item returns home</span>
924                                 [% ELSIF returnbranch == 'holdingbranch' %]
925                                     <span>Item returns to issuing branch</span>
926                                 [% ELSIF returnbranch == 'noreturn' %]
927                                     <span>Item floats</span>
928                                 [% END %]
929                             </td>
930                             <td class="actions">
931                                 <a class="btn btn-default btn-xs delete" href="/cgi-bin/koha/admin/smart-rules.pl?op=delete-branch-item&amp;itemtype=[% i.itemtype | uri %]&amp;branch=[% current_branch | uri %]"><i class="fa fa-trash"></i> Delete</a>
932                             </td>
933                         </tr>
934                     [% END %]
935                 [% END %]
936                 <tr>
937                     <td>
938                         <select name="itemtype">
939                         [% FOREACH itemtypeloo IN itemtypeloop %]
940                             <option value="[% itemtypeloo.itemtype | html %]">[% itemtypeloo.translated_description | html %]</option>
941                         [% END %]
942                         </select>
943                     </td>
944                     <td>
945                         <select name="holdallowed">
946                             <option value="2">From any library</option>
947                             <option value="3">From local hold group</option>
948                             <option value="1">From home library</option>
949                             <option value="0">No holds allowed</option>
950                         </select>
951                     </td>
952                     <td>
953                         <select name="hold_fulfillment_policy">
954                             <option value="any">
955                                 any library
956                             </option>
957
958                             <option value="holdgroup">
959                                 item's hold group
960                             </option>
961
962                             <option value="patrongroup">
963                                 patron's hold group
964                             </option>
965
966                             <option value="homebranch">
967                                 item's home library
968                             </option>
969
970                             <option value="holdingbranch">
971                                 item's holding library
972                             </option>
973                         </select>
974                     </td>
975                     <td>
976                         <select name="returnbranch">
977                             <option value="homebranch">Item returns home</option>
978                             <option value="holdingbranch">Item returns to issuing library</option>
979                             <option value="noreturn">Item floats</option>
980                         </select>
981                     </td>
982                     <td class="actions"><button type="submit" class="btn btn-default btn-xs"><i class="fa fa-plus"></i> Add</button></td>
983                 </tr>
984             </table>
985         </form>
986     </div>
987             </main>
988         </div> <!-- /.col-sm-10.col-sm-push-2 -->
989
990         <div class="col-sm-2 col-sm-pull-10">
991             <aside>
992                 [% INCLUDE 'admin-menu.inc' %]
993             </aside>
994         </div> <!-- /.col-sm-2.col-sm-pull-10 -->
995      </div> <!-- /.row -->
996
997 [% MACRO jsinclude BLOCK %]
998     [% Asset.js("js/admin-menu.js") | $raw %]
999     [% INCLUDE 'datatables.inc' %]
1000     [% INCLUDE 'calendar.inc' %]
1001     <script>
1002          $(document).ready(function() {
1003             $("#default-circulation-rules").dataTable($.extend(true,{},dataTablesDefaults, {
1004                 "aoColumnDefs": [
1005                     { "bVisible": false, "aTargets": [ 0,2 ] },
1006                     { "bSortable": false, "aTargets": ["_all"] }
1007                 ],
1008                 "aaSortingFixed": [ [0,'asc'], [1,'asc'], [2,'asc'], [3,'asc'] ],
1009                 "bPaginate": false,
1010                 "bAutoWidth": false
1011             }));
1012         });
1013
1014         function clear_edit(){
1015             var cancel = confirm(_("Are you sure you want to cancel your changes?"));
1016             if ( !cancel ) return;
1017             $('#default-circulation-rules td').removeClass('highlighted-row');
1018             var edit_row = $("#edit_row");
1019             $(edit_row).find("input").each(function(){
1020                 var type = $(this).attr("type");
1021                 if (type != "button" && type != "submit" ) {
1022                     $(this).val("");
1023                     $(this).prop('disabled', false);
1024                 }
1025                 if ( type == "checkbox" ) {
1026                     $(this).prop('checked', false);
1027                 }
1028             });
1029             $(edit_row).find("select").prop('disabled', false);
1030             $(edit_row).find("select option:first-child").attr("selected", "selected");
1031             $(edit_row).find("td:last input[name='clear']").remove();
1032         }
1033
1034         var MSG_CONFIRM_DELETE = _("Are you sure you want to delete this rule? This cannot be undone.");
1035
1036         $(document).ready(function() {
1037             $('[data-toggle="popover"]').popover();
1038
1039             $(".delete").on("click",function(){
1040                 return confirmDelete(MSG_CONFIRM_DELETE);
1041             });
1042
1043             $("#clone_rules").on("click",function(){
1044                 var library_dropdown = document.getElementById("branch");
1045                 var selected_library = library_dropdown.options[library_dropdown.selectedIndex].value;
1046                 var selected_library_text = $("#branch option:selected").text();
1047                 var to_library = $("#tobranch option:selected").text();
1048                 var MSG_CONFIRM_CLONE;
1049                 if (selected_library === "*") {
1050                     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);
1051                     return confirmClone(MSG_CONFIRM_CLONE);
1052                 } else {
1053                     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);
1054                     return confirmClone(MSG_CONFIRM_CLONE);
1055                 }
1056             });
1057
1058             $('#selectlibrary').find("input:submit").hide();
1059             $('#branch').change(function() {
1060                     $('#selectlibrary').submit();
1061             });
1062             $(".editrule").click(function(){
1063                 if ( $("#edit_row").find("input[type='text']").filter(function(){return this.value.length > 0 }).length > 0 ) {
1064                     var edit = confirm(_("Are you sure you want to edit another rule?"));
1065                     if (!edit) return false;
1066                 }
1067                 $('#default-circulation-rules td').removeClass('highlighted-row');
1068                 $(this).parent().parent().find("td").each(function (i) {
1069                     $(this).addClass('highlighted-row');
1070                     itm = $(this).text();
1071                     itm = itm.replace(/^\s*|\s*$/g,'');
1072                     var current_column = $("#edit_row td:eq("+i+")");
1073                     if ( i == 3 ) {
1074                         // specific processing for the Note column
1075                         var note = $(this).find("a[name='viewnote']").data("content");
1076                         $(current_column).find("input[type='text']").val(note);
1077                     } else if ( i == 9 ) {
1078                         // specific processing for the Hard due date column
1079                         var select_value = $(this).find("input[type='hidden'][name='hardduedatecomparebackup']").val();
1080                         var input_value = '';
1081                         if (typeof select_value === 'undefined'){
1082                             select_value = '-1';
1083                         }else {
1084                             input_value = itm.split(' ')[1];
1085                         }
1086                         $(current_column).find("input[type='text']").val(input_value);
1087                         $(current_column).find("select").val(select_value);
1088                     } else if ( i == 15 ) {
1089                         // specific processing for cap_fine_to_replacement_price
1090                         var cap_fine_to_replacement_price = $(this).find("input[type='checkbox']");
1091                         $('#cap_fine_to_replacement_price').prop('checked', cap_fine_to_replacement_price.is(':checked') );
1092                         $('#overduefinescap').prop('disabled', cap_fine_to_replacement_price.is(':checked') );
1093                     } else {
1094                         $(current_column).find("input[type='text']").val(itm);
1095                         // select the corresponding option
1096                         $(current_column).find("select option").each(function(){
1097                             opt = $(this).text().toLowerCase();
1098                             itm = itm.replace(/.*->(.*)/,"$1"); //If item type is part of a group we need to clear the parent description
1099                             opt = opt.replace(/^\s*|\s*$/g,'');
1100                             if ( opt == itm.toLowerCase() ) {
1101                                 $(this).attr('selected', 'selected');
1102                             }
1103                         });
1104                         if ( i == 0 || i == 1 ) {
1105                             // Disable the 2 first columns, we cannot update them.
1106                             var val = $(current_column).find("select option:selected").val();
1107                             var name = "categorycode";
1108                             if ( i == 1 ) {
1109                                 name="itemtype";
1110                             }
1111                             // Remove potential previous input added
1112                             $(current_column).find("input").remove();
1113                             $(current_column).append("<input type='hidden' name='"+name+"' value='"+val+"' />");
1114                         } else if ( i == 5 || i == 6 || i == 25 || i == 26 || i == 27 ) {
1115                             // If the value is not an integer for
1116                             //     - "Current checkouts allowed"
1117                             //     - "Current on-site checkouts allowed"
1118                             //     - "Holds allowed (total)"
1119                             //     - "Holds allowed (daily)"
1120                             //     - "Holds per record (count)"
1121                             // The value is "Unlimited" (or an equivalent translated string)
1122                             // an it should be set to an empty string
1123                             if( !((parseFloat(itm) == parseInt(itm)) && !isNaN(itm)) ) {
1124                                 $(current_column).find("input[type='text']").val("");
1125                             }
1126                         }
1127                     }
1128                 });
1129                 $("#default-circulation-rules tr:last td:eq(0) select").prop('disabled', true);
1130                 $("#default-circulation-rules tr:last td:eq(1) select").prop('disabled', true);
1131                 return false;
1132             });
1133             $(".clear_edit").on("click",function(e){
1134                 e.preventDefault();
1135                 clear_edit();
1136             });
1137         });
1138     </script>
1139 [% END %]
1140 [% INCLUDE 'intranet-bottom.inc' %]