|
Lines 216-222
Link Here
|
| 216 |
} |
216 |
} |
| 217 |
}, 100); |
217 |
}, 100); |
| 218 |
|
218 |
|
| 219 |
function buildApiUrl(baseUrl) { |
219 |
function buildApiUrl(baseUrl, dateField) { |
| 220 |
var from = $("#from").val(); |
220 |
var from = $("#from").val(); |
| 221 |
var to = $("#to").val(); |
221 |
var to = $("#to").val(); |
| 222 |
|
222 |
|
|
Lines 226-240
Link Here
|
| 226 |
|
226 |
|
| 227 |
var query = {}; |
227 |
var query = {}; |
| 228 |
if (from && to) { |
228 |
if (from && to) { |
| 229 |
query["me.timestamp"] = { |
229 |
query[dateField] = { |
| 230 |
"-between": [from + "T00:00:00Z", to + "T23:59:59Z"], |
230 |
"-between": [from + "T00:00:00Z", to + "T23:59:59Z"], |
| 231 |
}; |
231 |
}; |
| 232 |
} else if (from) { |
232 |
} else if (from) { |
| 233 |
query["me.timestamp"] = { |
233 |
query[dateField] = { |
| 234 |
">=": from + "T00:00:00Z", |
234 |
">=": from + "T00:00:00Z", |
| 235 |
}; |
235 |
}; |
| 236 |
} else if (to) { |
236 |
} else if (to) { |
| 237 |
query["me.timestamp"] = { |
237 |
query[dateField] = { |
| 238 |
"<=": to + "T23:59:59Z", |
238 |
"<=": to + "T23:59:59Z", |
| 239 |
}; |
239 |
}; |
| 240 |
} |
240 |
} |
|
Lines 245-251
Link Here
|
| 245 |
// Deleted biblios DataTable |
245 |
// Deleted biblios DataTable |
| 246 |
var biblios_table = $("#deleted_biblios_table").kohaTable({ |
246 |
var biblios_table = $("#deleted_biblios_table").kohaTable({ |
| 247 |
ajax: { |
247 |
ajax: { |
| 248 |
url: buildApiUrl("/api/v1/deleted/biblios"), |
248 |
url: buildApiUrl("/api/v1/deleted/biblios", "me.timestamp"), |
| 249 |
}, |
249 |
}, |
| 250 |
embed: "items", |
250 |
embed: "items", |
| 251 |
order: [[3, "desc"]], |
251 |
order: [[3, "desc"]], |
|
Lines 313-319
Link Here
|
| 313 |
// Deleted items DataTable |
313 |
// Deleted items DataTable |
| 314 |
var items_table = $("#deleted_items_table").kohaTable({ |
314 |
var items_table = $("#deleted_items_table").kohaTable({ |
| 315 |
ajax: { |
315 |
ajax: { |
| 316 |
url: buildApiUrl("/api/v1/deleted/items"), |
316 |
url: buildApiUrl("/api/v1/deleted/items", "me.deleted_on"), |
| 317 |
}, |
317 |
}, |
| 318 |
embed: "biblio", |
318 |
embed: "biblio", |
| 319 |
order: [[5, "desc"]], |
319 |
order: [[5, "desc"]], |
|
Lines 405-434
Link Here
|
| 405 |
var modal_items_table = null; |
405 |
var modal_items_table = null; |
| 406 |
var modal_items_table_api = null; |
406 |
var modal_items_table_api = null; |
| 407 |
|
407 |
|
| 408 |
// Restore biblio handler |
408 |
// Populate and show the restore biblio modal. |
| 409 |
$("#deleted_biblios_table").on("click", ".restore-biblio", function (e) { |
409 |
// preselectedItemId: optional item_id to pre-check in the items list. |
| 410 |
e.preventDefault(); |
410 |
function showRestoreBiblioModal(biblio_id, title, author, items, preselectedItemId) { |
| 411 |
var button = $(this); |
|
|
| 412 |
var biblio_id = button.data("biblio-id"); |
| 413 |
var title = button.data("title"); |
| 414 |
var row = biblios_table_api.row(button.closest("tr")).data(); |
| 415 |
|
| 416 |
// Populate modal with biblio info |
| 417 |
$("#restore-modal-biblio-id").text(biblio_id); |
411 |
$("#restore-modal-biblio-id").text(biblio_id); |
| 418 |
$("#restore-modal-biblio-title").text(title || _("(No title)")); |
412 |
$("#restore-modal-biblio-title").text(title || _("(No title)")); |
| 419 |
$("#restore-modal-biblio-author").text(row.author || _("(No author)")); |
413 |
$("#restore-modal-biblio-author").text(author || _("(No author)")); |
| 420 |
|
414 |
|
| 421 |
// Check if there are deleted items |
|
|
| 422 |
var items = row.items || []; |
| 423 |
if (items.length > 0) { |
415 |
if (items.length > 0) { |
| 424 |
$("#items-section").show(); |
416 |
$("#items-section").show(); |
| 425 |
|
417 |
|
| 426 |
// Destroy existing DataTable if it exists |
|
|
| 427 |
if (modal_items_table_api) { |
418 |
if (modal_items_table_api) { |
| 428 |
modal_items_table_api.destroy(); |
419 |
modal_items_table_api.destroy(); |
| 429 |
} |
420 |
} |
| 430 |
|
421 |
|
| 431 |
// Initialize kohaTable with the items data |
|
|
| 432 |
modal_items_table = $("#deleted-items-list").kohaTable({ |
422 |
modal_items_table = $("#deleted-items-list").kohaTable({ |
| 433 |
data: items, |
423 |
data: items, |
| 434 |
paging: false, |
424 |
paging: false, |
|
Lines 439-445
Link Here
|
| 439 |
if (type === "display") { |
429 |
if (type === "display") { |
| 440 |
var canEdit = canEditItem(row.home_library_id); |
430 |
var canEdit = canEditItem(row.home_library_id); |
| 441 |
var disabled = canEdit ? '' : ' disabled'; |
431 |
var disabled = canEdit ? '' : ' disabled'; |
| 442 |
var checkbox = '<input type="checkbox" class="item-checkbox" data-item-id="' + row.item_id + '"' + disabled + '>'; |
432 |
var preselected = (preselectedItemId && row.item_id == preselectedItemId && canEdit) ? ' checked' : ''; |
|
|
433 |
var checkbox = '<input type="checkbox" class="item-checkbox" data-item-id="' + row.item_id + '"' + disabled + preselected + '>'; |
| 443 |
|
434 |
|
| 444 |
if (!canEdit) { |
435 |
if (!canEdit) { |
| 445 |
return '<span title="' + _("You do not have permission to restore items from this library") + '">' + checkbox + '</span>'; |
436 |
return '<span title="' + _("You do not have permission to restore items from this library") + '">' + checkbox + '</span>'; |
|
Lines 501-512
Link Here
|
| 501 |
$("#items-section").hide(); |
492 |
$("#items-section").hide(); |
| 502 |
} |
493 |
} |
| 503 |
|
494 |
|
| 504 |
// Store biblio data |
|
|
| 505 |
$("#restore-biblio-with-items-button").data("biblio-id", biblio_id); |
495 |
$("#restore-biblio-with-items-button").data("biblio-id", biblio_id); |
| 506 |
$("#restore-biblio-with-items-button").data("restore-button", button); |
|
|
| 507 |
|
496 |
|
| 508 |
var modal = new bootstrap.Modal(document.getElementById("restoreBiblioModal")); |
497 |
var modal = new bootstrap.Modal(document.getElementById("restoreBiblioModal")); |
| 509 |
modal.show(); |
498 |
modal.show(); |
|
|
499 |
} |
| 500 |
|
| 501 |
// Restore biblio handler (from deleted biblios table) |
| 502 |
$("#deleted_biblios_table").on("click", ".restore-biblio", function (e) { |
| 503 |
e.preventDefault(); |
| 504 |
var button = $(this); |
| 505 |
var biblio_id = button.data("biblio-id"); |
| 506 |
var row = biblios_table_api.row(button.closest("tr")).data(); |
| 507 |
|
| 508 |
$("#restore-biblio-with-items-button").data("restore-button", button); |
| 509 |
showRestoreBiblioModal(biblio_id, row.title, row.author, row.items || []); |
| 510 |
}); |
510 |
}); |
| 511 |
|
511 |
|
| 512 |
// Restore item handler |
512 |
// Restore item handler |
|
Lines 561-590
Link Here
|
| 561 |
}); |
561 |
}); |
| 562 |
}); |
562 |
}); |
| 563 |
|
563 |
|
| 564 |
// Restore biblio from modal |
564 |
// "Restore bibliographic record" button in the deleted-bib warning modal: |
|
|
565 |
// fetch the biblio (with items) and open the full restore modal with the |
| 566 |
// originally clicked item pre-selected. |
| 565 |
$("#restore-biblio-button").on("click", function () { |
567 |
$("#restore-biblio-button").on("click", function () { |
| 566 |
var button = $(this); |
568 |
var button = $(this); |
| 567 |
var biblio_id = button.data("biblio-id"); |
569 |
var biblio_id = button.data("biblio-id"); |
| 568 |
var item_id = button.data("item-id"); |
570 |
var original_item_id = button.data("item-id"); |
| 569 |
var item_button = button.data("item-button"); |
571 |
var item_button = button.data("item-button"); |
| 570 |
|
572 |
|
| 571 |
button.prop("disabled", true); |
573 |
button.prop("disabled", true); |
| 572 |
|
574 |
|
| 573 |
$.ajax({ |
575 |
$.ajax({ |
| 574 |
url: "/api/v1/deleted/biblios/" + biblio_id, |
576 |
url: "/api/v1/deleted/biblios/" + biblio_id, |
| 575 |
type: "PUT", |
577 |
type: "GET", |
| 576 |
headers: { |
578 |
headers: { |
| 577 |
"x-koha-request-id": Math.random(), |
579 |
"x-koha-embed": "items", |
| 578 |
}, |
580 |
}, |
| 579 |
success: function (data) { |
581 |
success: function (biblio) { |
| 580 |
showMessage(_("Bibliographic record %s restored successfully").format(biblio_id), "success"); |
|
|
| 581 |
bootstrap.Modal.getInstance(document.getElementById("deletedBiblioModal")).hide(); |
582 |
bootstrap.Modal.getInstance(document.getElementById("deletedBiblioModal")).hide(); |
| 582 |
biblios_table_api.ajax.reload(); |
583 |
$("#restore-biblio-with-items-button").data("restore-button", item_button); |
| 583 |
items_table_api.ajax.reload(); |
584 |
showRestoreBiblioModal( |
|
|
585 |
biblio.biblio_id, |
| 586 |
biblio.title, |
| 587 |
biblio.author, |
| 588 |
biblio.items || [], |
| 589 |
original_item_id |
| 590 |
); |
| 584 |
button.prop("disabled", false); |
591 |
button.prop("disabled", false); |
| 585 |
}, |
592 |
}, |
| 586 |
error: function (xhr) { |
593 |
error: function (xhr) { |
| 587 |
var error_msg = _("Error restoring bibliographic record %s").format(biblio_id); |
594 |
var error_msg = _("Error loading bibliographic record %s").format(biblio_id); |
| 588 |
if (xhr.responseJSON && xhr.responseJSON.error) { |
595 |
if (xhr.responseJSON && xhr.responseJSON.error) { |
| 589 |
error_msg += ": " + xhr.responseJSON.error; |
596 |
error_msg += ": " + xhr.responseJSON.error; |
| 590 |
} |
597 |
} |
|
Lines 678-685
Link Here
|
| 678 |
}); |
685 |
}); |
| 679 |
|
686 |
|
| 680 |
$("#filter_table").on("click", function () { |
687 |
$("#filter_table").on("click", function () { |
| 681 |
biblios_table_api.ajax.url(buildApiUrl("/api/v1/deleted/biblios")).load(); |
688 |
biblios_table_api.ajax.url(buildApiUrl("/api/v1/deleted/biblios", "me.timestamp")).load(); |
| 682 |
items_table_api.ajax.url(buildApiUrl("/api/v1/deleted/items")).load(); |
689 |
items_table_api.ajax.url(buildApiUrl("/api/v1/deleted/items", "me.deleted_on")).load(); |
| 683 |
}); |
690 |
}); |
| 684 |
|
691 |
|
| 685 |
$("#clear_filters").on("click", function () { |
692 |
$("#clear_filters").on("click", function () { |
| 686 |
- |
|
|