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' %]
125 const branchTransferLimitsType = "[% BranchTransferLimitsType | html %]";
126 const val_type = branchTransferLimitsType == "itemtype" ? "item_type" : "collection_code";
127 const branches = [% To.json(branches) | $raw %];
129 $('#loading_limits').hide();
130 $('.spinner').hide();
132 $(document).ready(function() {
133 $("#check-all").click(function() {
134 const val = $('#value_selector').val();
136 $('.limit-action').addClass('disabled');
137 $('#value_selector').prop('disabled',true);
140 $(".limit-checkboxes").each(function() {
141 const checkbox = $(this);
142 if (checkbox.data('limit_id')) {
143 checkboxes.push(checkbox);
145 $(`#spinner-${checkbox.attr('id')}`).show();
149 del_limits( checkboxes, val );
154 $("#uncheck-all").click(function() {
155 const val = $('#value_selector').val();
157 $('.limit-action').addClass('disabled');
158 $('#value_selector').prop('disabled',true);
161 $(".limit-checkboxes").each(function() {
162 const checkbox = $(this);
163 if (!checkbox.data('limit_id')) {
164 checkboxes.push(checkbox);
166 $(`#spinner-${checkbox.attr('id')}`).show();
170 add_limits( checkboxes, val );
174 $('.check-all-col').click(function() {
176 const to = $(this).data('to');
177 const val = $('#value_selector').val();
179 $('.limit-action').addClass('disabled');
180 $('#value_selector').prop('disabled',true);
182 $(`.to-${to}`).each(function() {
183 const checkbox = $(this);
184 if (checkbox.data('limit_id')) {
185 checkboxes.push(checkbox);
187 $(`#spinner-${checkbox.attr('id')}`).show();
191 del_limits( checkboxes, val, to );
195 $('.uncheck-all-col').click(function() {
197 const to = $(this).data('to');
198 const val = $('#value_selector').val();
200 $('.limit-action').addClass('disabled');
201 $('#value_selector').prop('disabled',true);
203 $(`.to-${to}`).each(function() {
204 const checkbox = $(this);
205 if (!checkbox.data('limit_id')) {
207 $(`#spinner-${checkbox.attr('id')}`).show();
211 add_limits( checkboxes, val, to );
215 $('.check-all-row').click(function() {
217 const from = $(this).data('from');
218 const val = $('#value_selector').val();
220 $('.limit-action').addClass('disabled');
221 $('#value_selector').prop('disabled',true);
223 $(`.from-${from}`).each(function() {
224 const checkbox = $(this);
225 if (checkbox.data('limit_id')) {
226 checkboxes.push(checkbox);
228 $(`#spinner-${checkbox.attr('id')}`).show();
232 del_limits( checkboxes, val, null, from );
237 $('.uncheck-all-row').click(function() {
239 const from = $(this).data('from');
240 const val = $('#value_selector').val();
242 $('.limit-action').addClass('disabled');
243 $('#value_selector').prop('disabled',true);
245 $(`.from-${from}`).each(function() {
246 const checkbox = $(this);
247 if (!checkbox.data('limit_id')) {
249 $(`#spinner-${checkbox.attr('id')}`).show();
253 add_limits( checkboxes, val, null, from );
257 $(".checkbox-cell").click(function(e) {
258 var checkbox = $(this).find(".limit-checkboxes").get(0);
259 if (checkbox && !checkbox.disabled) {
260 if (e.target != checkbox) {
261 checkbox.checked = !checkbox.checked;
262 $(checkbox).change();
267 $("#value_selector").on('change', function() {
268 updateTransferLimitsTable();
271 $(".limit-checkboxes").on('change', function() {
272 const checkbox = $(this);
273 const id = checkbox.attr('id');
276 $(`#spinner-${id}`).show();
278 const limit_id = checkbox.data('limit_id');
280 if (limit_id) { // limit id exists, so limit needs to be deleted
282 } else { // limit does not exist, needs to be created
287 updateTransferLimitsTable();
290 function delLimit(checkbox) {
291 const id = checkbox.attr('id');
292 const limit_id = checkbox.data('limit_id');
295 url: `/api/v1/transfer_limits/${limit_id}`,
297 success: function(result) {
298 checkbox.data('limit_id', null);
299 checkbox.attr('checked', true);
300 $(`#spinner-${id}`).hide();
303 error: function(xhr, status, error) {
304 var errorMessage = xhr.status + ': ' + xhr.statusText
305 alert('Error - ' + errorMessage);
310 function addLimit(checkbox) {
311 const id = checkbox.attr('id');
312 const parts = id.split('-');
313 const from = parts[1];
316 const val = $('#value_selector').val();
320 from_library_id: from,
322 data[val_type] = val;
324 url: `/api/v1/transfer_limits`,
326 data: JSON.stringify(data),
328 success: function(result) {
329 checkbox.data('limit_id', result.limit_id);
330 checkbox.attr('checked', false);
331 $(`#spinner-${id}`).hide();
334 error: function(xhr, status, error) {
335 var errorMessage = xhr.status + ': ' + xhr.statusText
336 alert('Error - ' + errorMessage);
341 function add_limits( checkboxes, val, to, from ){
343 data[val_type] = val;
344 if (to) data["to_library_id"] = to;
345 if (from) data["from_library_id"] = from;
348 url: `/api/v1/transfer_limits/batch`,
350 data: JSON.stringify(data),
352 success: function(result) {
353 for ( i = 0; i < result.length; i++ ) {
355 let checkbox = $(`#limit-${r.from_library_id}-${r.to_library_id}`);
356 const id = checkbox.attr('id');
357 checkbox.data('limit_id', r.limit_id);
358 checkbox.attr('checked', false);
359 $(`#spinner-${id}`).hide();
363 complete: function() {
364 $('.limit-action').removeClass('disabled');
365 $('#value_selector').prop('disabled',false);
367 error: function(xhr, status, error) {
368 var errorMessage = xhr.status + ': ' + xhr.statusText
369 alert('Error - ' + errorMessage);
374 function del_limits( checkboxes, val, to, from ){
376 data[val_type] = val;
377 if (to) data["to_library_id"] = to;
378 if (from) data["from_library_id"] = from;
381 url: `/api/v1/transfer_limits/batch`,
383 data: JSON.stringify(data),
385 success: function(result) {
386 for ( i = 0; i < checkboxes.length; i++ ) {
387 const checkbox = checkboxes[i];
388 const id = checkbox.attr('id');
389 checkbox.data('limit_id', '');
390 checkbox.attr('checked', true);
391 $(`#spinner-${id}`).hide();
395 complete: function() {
396 $('.limit-action').removeClass('disabled');
397 $('#value_selector').prop('disabled',false);
399 error: function(xhr, status, error) {
400 var errorMessage = xhr.status + ': ' + xhr.statusText
401 alert('Error - ' + errorMessage);
406 function updateTransferLimitsTable() {
407 const val = $('#value_selector').val();
408 const url = `/api/v1/transfer_limits?_per_page=-1&q={"${val_type}": "${val}"}`;
411 $('#transfer_limits').show();
413 $('#transfer_limits').hide();
416 $(".limit-checkboxes").attr("disabled", true);
417 $(".limit-checkboxes").attr("checked", false);
420 $('#loading_limits').show();
422 $.getJSON(url, function(data) {
423 $(".limit-checkboxes").attr("disabled", false);
424 $(".limit-checkboxes").attr("checked", true);
425 $(".limit-checkboxes").data('limit_id', null);
427 for (var i = 0; i < data.length; i++) {
429 let checkbox = $(`#limit-${limit.from_library_id}-${limit.to_library_id}`);
430 checkbox.attr('checked', false);
431 checkbox.data('limit_id', limit.limit_id);
434 $('#loading_limits').hide();
440 [% INCLUDE 'intranet-bottom.inc' %]