|
Lines 1-4
Link Here
|
| 1 |
(function () { |
1 |
(function () { |
|
|
2 |
// Bail if there aren't any metadata enrichment plugins installed |
| 3 |
if (typeof metadata_enrichment_services === 'undefined') { |
| 4 |
console.log('No metadata enrichment plugins found.') |
| 5 |
return; |
| 6 |
} |
| 7 |
|
| 2 |
window.addEventListener('load', onload); |
8 |
window.addEventListener('load', onload); |
| 3 |
|
9 |
|
| 4 |
// Delay between API requests |
10 |
// Delay between API requests |
|
Lines 7-13
Link Here
|
| 7 |
// Elements we work frequently with |
13 |
// Elements we work frequently with |
| 8 |
var textarea = document.getElementById("identifiers_input"); |
14 |
var textarea = document.getElementById("identifiers_input"); |
| 9 |
var nameInput = document.getElementById("name"); |
15 |
var nameInput = document.getElementById("name"); |
| 10 |
var cardnumberInput = document.getElementById("cardnumber"); |
16 |
var cardnumberInput = document.getElementById("batchcardnumber"); |
| 11 |
var branchcodeSelect = document.getElementById("branchcode"); |
17 |
var branchcodeSelect = document.getElementById("branchcode"); |
| 12 |
var processButton = document.getElementById("process_button"); |
18 |
var processButton = document.getElementById("process_button"); |
| 13 |
var createButton = document.getElementById("button_create_batch"); |
19 |
var createButton = document.getElementById("button_create_batch"); |
|
Lines 20-26
Link Here
|
| 20 |
var identifierTable = document.getElementById('identifier-table'); |
26 |
var identifierTable = document.getElementById('identifier-table'); |
| 21 |
var createRequestsButton = document.getElementById('create-requests-button'); |
27 |
var createRequestsButton = document.getElementById('create-requests-button'); |
| 22 |
var statusesSelect = document.getElementById('statuscode'); |
28 |
var statusesSelect = document.getElementById('statuscode'); |
| 23 |
|
29 |
var cancelButton = document.getElementById('lhs').querySelector('button'); |
|
|
30 |
var cancelButtonOriginalText = cancelButton.innerHTML; |
| 24 |
|
31 |
|
| 25 |
// We need a data structure keyed on identifier type, which tells us how to parse that |
32 |
// We need a data structure keyed on identifier type, which tells us how to parse that |
| 26 |
// identifier type and what services can get its metadata. We receive an array of |
33 |
// identifier type and what services can get its metadata. We receive an array of |
|
Lines 58-64
Link Here
|
| 58 |
obj[prop] = value; |
65 |
obj[prop] = value; |
| 59 |
manageBatchItemsDisplay(); |
66 |
manageBatchItemsDisplay(); |
| 60 |
updateBatchInputs(); |
67 |
updateBatchInputs(); |
| 61 |
setFinishButton(); |
|
|
| 62 |
disableCardnumberInput(); |
68 |
disableCardnumberInput(); |
| 63 |
displayPatronName(); |
69 |
displayPatronName(); |
| 64 |
updateStatusesSelect(); |
70 |
updateStatusesSelect(); |
|
Lines 149-154
Link Here
|
| 149 |
}); |
155 |
}); |
| 150 |
$('#ill-batch-modal').on('hidden.bs.modal', function () { |
156 |
$('#ill-batch-modal').on('hidden.bs.modal', function () { |
| 151 |
// Reset our state when we close the modal |
157 |
// Reset our state when we close the modal |
|
|
158 |
// TODO: need to also reset progress bar and already processed identifiers |
| 152 |
delete idEl.dataset.batchId; |
159 |
delete idEl.dataset.batchId; |
| 153 |
delete idEl.dataset.backend; |
160 |
delete idEl.dataset.backend; |
| 154 |
batchId = null; |
161 |
batchId = null; |
|
Lines 161-166
Link Here
|
| 161 |
}; |
168 |
}; |
| 162 |
textarea.value = ''; |
169 |
textarea.value = ''; |
| 163 |
batch.data = {}; |
170 |
batch.data = {}; |
|
|
171 |
cancelButton.innerHTML = cancelButtonOriginalText; |
| 164 |
// Remove event listeners we created |
172 |
// Remove event listeners we created |
| 165 |
removeEventListeners(); |
173 |
removeEventListeners(); |
| 166 |
}); |
174 |
}); |
|
Lines 194-199
Link Here
|
| 194 |
|
202 |
|
| 195 |
function initPostCreate() { |
203 |
function initPostCreate() { |
| 196 |
disableCreateButton(); |
204 |
disableCreateButton(); |
|
|
205 |
cancelButton.innerHTML = ill_batch_create_cancel_button; |
| 197 |
}; |
206 |
}; |
| 198 |
|
207 |
|
| 199 |
function setFinishButton() { |
208 |
function setFinishButton() { |
|
Lines 211-216
Link Here
|
| 211 |
// created, and do so |
220 |
// created, and do so |
| 212 |
function requestRequestable() { |
221 |
function requestRequestable() { |
| 213 |
createRequestsButton.setAttribute('disabled', true); |
222 |
createRequestsButton.setAttribute('disabled', true); |
|
|
223 |
createRequestsButton.setAttribute('aria-disabled', true); |
| 224 |
setFinishButton(); |
| 214 |
var toCheck = tableContent.data; |
225 |
var toCheck = tableContent.data; |
| 215 |
toCheck.forEach(function (row) { |
226 |
toCheck.forEach(function (row) { |
| 216 |
if ( |
227 |
if ( |
|
Lines 299-304
Link Here
|
| 299 |
tableContent.data = tableContent.data.map(function (row) { |
310 |
tableContent.data = tableContent.data.map(function (row) { |
| 300 |
if (row.value === identifier) { |
311 |
if (row.value === identifier) { |
| 301 |
row.requestId = data.illrequest_id; |
312 |
row.requestId = data.illrequest_id; |
|
|
313 |
row.requestStatus = data.status; |
| 302 |
} |
314 |
} |
| 303 |
return row; |
315 |
return row; |
| 304 |
}); |
316 |
}); |
|
Lines 421-436
Link Here
|
| 421 |
function processButtonState() { |
433 |
function processButtonState() { |
| 422 |
if (textarea.value.length > 0) { |
434 |
if (textarea.value.length > 0) { |
| 423 |
processButton.removeAttribute('disabled'); |
435 |
processButton.removeAttribute('disabled'); |
|
|
436 |
processButton.removeAttribute('aria-disabled'); |
| 424 |
} else { |
437 |
} else { |
| 425 |
processButton.setAttribute('disabled', 1); |
438 |
processButton.setAttribute('disabled', true); |
|
|
439 |
processButton.setAttribute('aria-disabled', true); |
| 426 |
} |
440 |
} |
| 427 |
}; |
441 |
}; |
| 428 |
|
442 |
|
| 429 |
function disableCardnumberInput() { |
443 |
function disableCardnumberInput() { |
| 430 |
if (batch.data.patron) { |
444 |
if (batch.data.patron) { |
| 431 |
cardnumberInput.setAttribute('disabled', true); |
445 |
cardnumberInput.setAttribute('disabled', true); |
|
|
446 |
cardnumberInput.setAttribute('aria-disabled', true); |
| 432 |
} else { |
447 |
} else { |
| 433 |
cardnumberInput.removeAttribute('disabled'); |
448 |
cardnumberInput.removeAttribute('disabled'); |
|
|
449 |
cardnumberInput.removeAttribute('aria-disabled'); |
| 434 |
} |
450 |
} |
| 435 |
}; |
451 |
}; |
| 436 |
|
452 |
|
|
Lines 512-518
Link Here
|
| 512 |
}) |
528 |
}) |
| 513 |
}) |
529 |
}) |
| 514 |
.then(function (response) { |
530 |
.then(function (response) { |
| 515 |
return response.json(); |
531 |
if ( response.ok ) { |
|
|
532 |
return response.json(); |
| 533 |
} |
| 534 |
return Promise.reject(response); |
| 516 |
}) |
535 |
}) |
| 517 |
.then(function (body) { |
536 |
.then(function (body) { |
| 518 |
batchId = body.id; |
537 |
batchId = body.id; |
|
Lines 528-535
Link Here
|
| 528 |
}; |
547 |
}; |
| 529 |
initPostCreate(); |
548 |
initPostCreate(); |
| 530 |
}) |
549 |
}) |
| 531 |
.catch(function () { |
550 |
.catch(function (response) { |
| 532 |
handleApiError(ill_batch_create_api_fail); |
551 |
response.json().then((json) => { |
|
|
552 |
if( json.error ) { |
| 553 |
handleApiError(json.error); |
| 554 |
} else { |
| 555 |
handleApiError(ill_batch_create_api_fail); |
| 556 |
} |
| 557 |
}) |
| 533 |
}); |
558 |
}); |
| 534 |
}; |
559 |
}; |
| 535 |
|
560 |
|
|
Lines 706-722
Link Here
|
| 706 |
|
731 |
|
| 707 |
function disableProcessButton() { |
732 |
function disableProcessButton() { |
| 708 |
processButton.setAttribute('disabled', true); |
733 |
processButton.setAttribute('disabled', true); |
|
|
734 |
processButton.setAttribute('aria-disabled', true); |
| 709 |
} |
735 |
} |
| 710 |
|
736 |
|
| 711 |
function disableCreateButton() { |
737 |
function disableCreateButton() { |
| 712 |
createButton.setAttribute('disabled', true); |
738 |
createButton.setAttribute('disabled', true); |
| 713 |
} |
739 |
createButton.setAttribute('aria-disabled', true); |
| 714 |
|
|
|
| 715 |
function disableRemoveRowButtons() { |
| 716 |
var buttons = document.getElementsByClassName('remove-row'); |
| 717 |
for (var button of buttons) { |
| 718 |
button.setAttribute('disabled', true); |
| 719 |
} |
| 720 |
} |
740 |
} |
| 721 |
|
741 |
|
| 722 |
async function populateMetadata(identifier) { |
742 |
async function populateMetadata(identifier) { |
|
Lines 893-898
Link Here
|
| 893 |
return data.requestId || '-'; |
913 |
return data.requestId || '-'; |
| 894 |
} |
914 |
} |
| 895 |
|
915 |
|
|
|
916 |
function createRequestStatus(x, y, data) { |
| 917 |
return data.requestStatus || '-'; |
| 918 |
} |
| 919 |
|
| 896 |
function buildTable(identifiers) { |
920 |
function buildTable(identifiers) { |
| 897 |
table = KohaTable('identifier-table', { |
921 |
table = KohaTable('identifier-table', { |
| 898 |
processing: true, |
922 |
processing: true, |
|
Lines 918-926
Link Here
|
| 918 |
}, |
942 |
}, |
| 919 |
{ |
943 |
{ |
| 920 |
data: 'requestId', |
944 |
data: 'requestId', |
| 921 |
width: '13%', |
945 |
width: '6.5%', |
| 922 |
render: createRequestId |
946 |
render: createRequestId |
| 923 |
}, |
947 |
}, |
|
|
948 |
{ |
| 949 |
data: 'requestStatus', |
| 950 |
width: '6.5%', |
| 951 |
render: createRequestStatus |
| 952 |
}, |
| 924 |
{ |
953 |
{ |
| 925 |
width: '18%', |
954 |
width: '18%', |
| 926 |
render: createActions, |
955 |
render: createActions, |
|
Lines 936-942
Link Here
|
| 936 |
} |
965 |
} |
| 937 |
|
966 |
|
| 938 |
function createActions(x, y, data) { |
967 |
function createActions(x, y, data) { |
| 939 |
return '<button type="button"' + (data.requestId ? ' disabled' : '') + ' class="btn btn-xs btn-danger remove-row">' + ill_button_remove + '</button>'; |
968 |
return '<button type="button" aria-label='+ ill_button_remove + (data.requestId ? ' disabled aria-disabled="true"' : '') + ' class="btn btn-xs btn-danger remove-row">' + ill_button_remove + '</button>'; |
| 940 |
} |
969 |
} |
| 941 |
|
970 |
|
| 942 |
// Redraw the table |
971 |
// Redraw the table |
|
Lines 1021-1043
Link Here
|
| 1021 |
} |
1050 |
} |
| 1022 |
|
1051 |
|
| 1023 |
function patronAutocomplete() { |
1052 |
function patronAutocomplete() { |
| 1024 |
// Add autocomplete for patron selection |
1053 |
patron_autocomplete( |
| 1025 |
$('#batch-form #cardnumber').autocomplete({ |
1054 |
$('#batch-form #batchcardnumber'), |
| 1026 |
appendTo: '#batch-form', |
1055 |
{ |
| 1027 |
source: "/cgi-bin/koha/circ/ysearch.pl", |
1056 |
'on-select-callback': function( event, ui ) { |
| 1028 |
minLength: 3, |
1057 |
$("#batch-form #batchcardnumber").val( ui.item.cardnumber ); |
| 1029 |
select: function (event, ui) { |
|
|
| 1030 |
var field = ui.item.cardnumber; |
| 1031 |
$('#batch-form #cardnumber').val(field) |
| 1032 |
return false; |
1058 |
return false; |
|
|
1059 |
} |
| 1033 |
} |
1060 |
} |
| 1034 |
}) |
1061 |
); |
| 1035 |
.data("ui-autocomplete")._renderItem = function (ul, item) { |
|
|
| 1036 |
return $("<li></li>") |
| 1037 |
.data("ui-autocomplete-item", item) |
| 1038 |
.append("<a>" + item.surname + ", " + item.firstname + " (" + item.cardnumber + ") <small>" + item.address + " " + item.city + " " + item.zipcode + " " + item.country + "</small></a>") |
| 1039 |
.appendTo(ul); |
| 1040 |
}; |
| 1041 |
}; |
1062 |
}; |
| 1042 |
|
1063 |
|
| 1043 |
function createPatronLink() { |
1064 |
function createPatronLink() { |