7 [% USE AuthorisedValues %]
9 [% INCLUDE 'doc-head-open.inc' %]
10 <title>Koha › Administration › Library checkin and transfer policy</title>
11 [% INCLUDE 'doc-head-close.inc' %]
12 <style>td { text-align: center; } .sorted { min-width: 50%; }</style>
15 [% SET BranchTransferLimitsType = Koha.Preference('BranchTransferLimitsType') %]
16 [% SET branches = Branches.all %]
18 <body id="admin_branch_transfer_limits" class="admin">
19 [% INCLUDE 'header.inc' %]
20 [% INCLUDE 'prefs-admin-search.inc' %]
22 <div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> › <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a> › Set library checkin and transfer policy</div>
24 <div class="main container-fluid">
26 <div class="col-sm-10 col-sm-push-2">
28 <h1>Checkin and transfer policy</h1>
31 [% IF BranchTransferLimitsType == "itemtype" %]
32 <label for="value_selector">Select an item type:</label>
33 <select id="value_selector">
34 <option value="" selected></option>
35 [% SET itemtypes = ItemTypes.Get %]
36 [% FOREACH i IN itemtypes %]
37 <option value="[% i.itemtype | html %]">[% i.description | html %]</option>
40 [% ELSE #BranchTransferLimitsType == "ccode" %]
41 <label for="value_selector">Select a collection:</label>
42 <select id="value_selector">
43 <option value="" selected></option>
44 [% SET ccodes = AuthorisedValues.Get('CCODE') %]
45 [% FOREACH c IN ccodes %]
46 <option value="[% c.authorised_value | html %]">[% c.lib | html %]</option>
51 <span id="loading_limits">
52 <i class="fa fa-spinner fa-pulse fa-fw"></i>
53 <span>Loading...</span>
57 <p class="help">Check the boxes for the libraries you allow your items to be transferred to.</p>
59 <a id="check-all" class="limit-action" href="#"><i class="fa fa-check"></i> Check all</a>
61 <a id="uncheck-all" class="limit-action" href="#"><i class="fa fa-remove"></i> Uncheck all</a>
63 <a href="/cgi-bin/koha/admin/branch_transfer_limits.pl">Switch to basic editor</a>
66 <table id="transfer_limits" class="table table-striped table-bordered table-hover table-condensed">
72 [% FOREACH to IN branches %]
74 <p><a class="btn btn-default btn-xs check-all-col limit-action" data-to="[% to.branchcode | html %]" href="#"><i class="fa fa-check"></i> Check</a></p>
75 <p><a class="btn btn-default btn-xs uncheck-all-col limit-action" data-to="[% to.branchcode | html %]" href="#"><i class="fa fa-remove"></i> Uncheck</a></p>
83 [% FOREACH b IN branches %]
84 <th style="word-break: break-all !important" title="[% b.branchname | html %]">[% b.branchname | html %]</th>
90 [% FOREACH from IN branches %]
93 <p><a class="btn btn-default btn-xs check-all-row limit-action" data-from="[% from.branchcode | html %]" href="#"><i class="fa fa-check"></i> Check</a></p>
94 <p><a class="btn btn-default btn-xs uncheck-all-row limit-action" data-from="[% from.branchcode | html %]" href="#"><i class="fa fa-remove"></i> Uncheck</a></p>
96 <th>[% from.branchname | html %]</th>
97 [% FOREACH to IN branches %]
98 <td class="checkbox-cell">
99 [% IF to.branchcode == from.branchcode %]
102 <input class="limit-checkboxes from-[% from.branchcode | html %] to-[% to.branchcode | html %]" id="limit-[% from.branchcode | html %]-[% to.branchcode | html %]" type="checkbox" title="From: [% from.branchname | html %], To: [% to.branchname | html %]" checked/>
103 <i id="spinner-limit-[% from.branchcode | html %]-[% to.branchcode | html %]" class="spinner fa fa-spinner fa-pulse fa-fw"></i>
112 </div> <!-- /.col-sm-10.col-sm-push-2 -->
114 <div class="col-sm-2 col-sm-pull-10">
116 [% INCLUDE 'admin-menu.inc' %]
118 </div> <!-- /.col-sm-2.col-sm-pull-10 -->
119 </div> <!-- /.row -->
121 [% MACRO jsinclude BLOCK %]
122 [% Asset.js("js/admin-menu.js") | $raw %]
123 [% INCLUDE 'datatables.inc' %]
124 [% Asset.js("lib/jquery/plugins/jquery.checkboxes.min.js") | $raw %]
126 const branchTransferLimitsType = "[% BranchTransferLimitsType | html %]";
127 const val_type = branchTransferLimitsType == "itemtype" ? "item_type" : "collection_code";
128 const branches = [% To.json(branches) | $raw %];
130 $('#loading_limits').hide();
131 $('.spinner').hide();
133 $(document).ready(function() {
134 $("#check-all").click(function() {
135 const val = $('#value_selector').val();
137 $('.limit-action').addClass('disabled');
138 $('#value_selector').prop('disabled',true);
141 $(".limit-checkboxes").each(function() {
142 const checkbox = $(this);
143 if (checkbox.data('limit_id')) {
144 checkboxes.push(checkbox);
146 $(`#spinner-${checkbox.attr('id')}`).show();
150 del_limits( checkboxes, val );
155 $("#uncheck-all").click(function() {
156 const val = $('#value_selector').val();
158 $('.limit-action').addClass('disabled');
159 $('#value_selector').prop('disabled',true);
162 $(".limit-checkboxes").each(function() {
163 const checkbox = $(this);
164 if (!checkbox.data('limit_id')) {
165 checkboxes.push(checkbox);
167 $(`#spinner-${checkbox.attr('id')}`).show();
171 add_limits( checkboxes, val );
175 $('.check-all-col').click(function() {
177 const to = $(this).data('to');
178 const val = $('#value_selector').val();
180 $('.limit-action').addClass('disabled');
181 $('#value_selector').prop('disabled',true);
183 $(`.to-${to}`).each(function() {
184 const checkbox = $(this);
185 if (checkbox.data('limit_id')) {
186 checkboxes.push(checkbox);
188 $(`#spinner-${checkbox.attr('id')}`).show();
192 del_limits( checkboxes, val, to );
196 $('.uncheck-all-col').click(function() {
198 const to = $(this).data('to');
199 const val = $('#value_selector').val();
201 $('.limit-action').addClass('disabled');
202 $('#value_selector').prop('disabled',true);
204 $(`.to-${to}`).each(function() {
205 const checkbox = $(this);
206 if (!checkbox.data('limit_id')) {
208 $(`#spinner-${checkbox.attr('id')}`).show();
212 add_limits( checkboxes, val, to );
216 $('.check-all-row').click(function() {
218 const from = $(this).data('from');
219 const val = $('#value_selector').val();
221 $('.limit-action').addClass('disabled');
222 $('#value_selector').prop('disabled',true);
224 $(`.from-${from}`).each(function() {
225 const checkbox = $(this);
226 if (checkbox.data('limit_id')) {
227 checkboxes.push(checkbox);
229 $(`#spinner-${checkbox.attr('id')}`).show();
233 del_limits( checkboxes, val, null, from );
238 $('.uncheck-all-row').click(function() {
240 const from = $(this).data('from');
241 const val = $('#value_selector').val();
243 $('.limit-action').addClass('disabled');
244 $('#value_selector').prop('disabled',true);
246 $(`.from-${from}`).each(function() {
247 const checkbox = $(this);
248 if (!checkbox.data('limit_id')) {
250 $(`#spinner-${checkbox.attr('id')}`).show();
254 add_limits( checkboxes, val, null, from );
258 $(".checkbox-cell").click(function(e) {
259 var checkbox = $(this).find(".limit-checkboxes").get(0);
260 if (checkbox && !checkbox.disabled) {
261 if (e.target != checkbox) {
262 checkbox.checked = !checkbox.checked;
263 $(checkbox).change();
268 $("#value_selector").on('change', function() {
269 updateTransferLimitsTable();
272 $(".limit-checkboxes").on('change', function() {
273 const checkbox = $(this);
274 const id = checkbox.attr('id');
277 $(`#spinner-${id}`).show();
279 const limit_id = checkbox.data('limit_id');
281 if (limit_id) { // limit id exists, so limit needs to be deleted
283 } else { // limit does not exist, needs to be created
288 updateTransferLimitsTable();
291 function delLimit(checkbox) {
292 const id = checkbox.attr('id');
293 const limit_id = checkbox.data('limit_id');
296 url: `/api/v1/transfer_limits/${limit_id}`,
298 success: function(result) {
299 checkbox.data('limit_id', null);
300 checkbox.attr('checked', true);
301 $(`#spinner-${id}`).hide();
304 error: function(xhr, status, error) {
305 var errorMessage = xhr.status + ': ' + xhr.statusText
306 alert('Error - ' + errorMessage);
311 function addLimit(checkbox) {
312 const id = checkbox.attr('id');
313 const parts = id.split('-');
314 const from = parts[1];
317 const val = $('#value_selector').val();
321 from_library_id: from,
323 data[val_type] = val;
325 url: `/api/v1/transfer_limits`,
327 data: JSON.stringify(data),
329 success: function(result) {
330 checkbox.data('limit_id', result.limit_id);
331 checkbox.attr('checked', false);
332 $(`#spinner-${id}`).hide();
335 error: function(xhr, status, error) {
336 var errorMessage = xhr.status + ': ' + xhr.statusText
337 alert('Error - ' + errorMessage);
342 function add_limits( checkboxes, val, to, from ){
344 data[val_type] = val;
345 if (to) data["to_library_id"] = to;
346 if (from) data["from_library_id"] = from;
349 url: `/api/v1/transfer_limits/batch`,
351 data: JSON.stringify(data),
353 success: function(result) {
354 for ( i = 0; i < result.length; i++ ) {
356 let checkbox = $(`#limit-${r.from_library_id}-${r.to_library_id}`);
357 const id = checkbox.attr('id');
358 checkbox.data('limit_id', r.limit_id);
359 checkbox.attr('checked', false);
360 $(`#spinner-${id}`).hide();
364 complete: function() {
365 $('.limit-action').removeClass('disabled');
366 $('#value_selector').prop('disabled',false);
368 error: function(xhr, status, error) {
369 var errorMessage = xhr.status + ': ' + xhr.statusText
370 alert('Error - ' + errorMessage);
375 function del_limits( checkboxes, val, to, from ){
377 data[val_type] = val;
378 if (to) data["to_library_id"] = to;
379 if (from) data["from_library_id"] = from;
382 url: `/api/v1/transfer_limits/batch`,
384 data: JSON.stringify(data),
386 success: function(result) {
387 for ( i = 0; i < checkboxes.length; i++ ) {
388 const checkbox = checkboxes[i];
389 const id = checkbox.attr('id');
390 checkbox.data('limit_id', '');
391 checkbox.attr('checked', true);
392 $(`#spinner-${id}`).hide();
396 complete: function() {
397 $('.limit-action').removeClass('disabled');
398 $('#value_selector').prop('disabled',false);
400 error: function(xhr, status, error) {
401 var errorMessage = xhr.status + ': ' + xhr.statusText
402 alert('Error - ' + errorMessage);
407 function updateTransferLimitsTable() {
408 const val = $('#value_selector').val();
409 const url = `/api/v1/transfer_limits?_per_page=-1&q={"${val_type}": "${val}"}`;
412 $('#transfer_limits').show();
414 $('#transfer_limits').hide();
417 $(".limit-checkboxes").attr("disabled", true);
418 $(".limit-checkboxes").attr("checked", false);
421 $('#loading_limits').show();
423 $.getJSON(url, function(data) {
424 $(".limit-checkboxes").attr("disabled", false);
425 $(".limit-checkboxes").attr("checked", true);
426 $(".limit-checkboxes").data('limit_id', null);
428 for (var i = 0; i < data.length; i++) {
430 let checkbox = $(`#limit-${limit.from_library_id}-${limit.to_library_id}`);
431 checkbox.attr('checked', false);
432 checkbox.data('limit_id', limit.limit_id);
435 $('#loading_limits').hide();
441 [% INCLUDE 'intranet-bottom.inc' %]