Lines 1768-2084
Link Here
|
1768 |
[% END # /IF bundlesEnabled %] |
1768 |
[% END # /IF bundlesEnabled %] |
1769 |
}); |
1769 |
}); |
1770 |
|
1770 |
|
1771 |
$(document).ready(function() { |
1771 |
[% IF bundlesEnabled %] // Bundle handling |
1772 |
[% IF bundlesEnabled %] // Bundle handling |
1772 |
function createChild ( row, itemnumber, duedate ) { |
1773 |
function createChild ( row, itemnumber, duedate ) { |
|
|
1774 |
// Toolbar |
1775 |
var bundle_toolbar = $('<div id="toolbar" class="btn-toolbar"></div>'); |
1776 |
bundle_toolbar.append('<a class="btn btn-default" data-bs-toggle="modal" data-bs-target="#addToBundleModal" data-item="' + itemnumber + '"><i class="fa fa-plus"></i> ' + _("Add to bundle") + '</a>'); |
1777 |
bundle_toolbar.append('<a class="btn btn-default" data-bs-toggle="modal" data-bs-target="#removeFromBundleModal" data-item="' + itemnumber + '"><i class="fa fa-minus"></i> ' + _("Remove from bundle") + '</a>'); |
1778 |
|
1779 |
// Toolbar |
1773 |
// Toolbar |
1780 |
var bundle_toolbar = $('<div id="toolbar" class="btn-toolbar"></div>'); |
1774 |
var bundle_toolbar = $('<div id="toolbar" class="btn-toolbar"></div>'); |
1781 |
bundle_toolbar.append('<a class="btn btn-default" data-bs-toggle="modal" data-bs-target="#addToBundleModal" data-item="' + itemnumber + '"><i class="fa fa-plus"></i> ' + _("Add to bundle") + '</a>'); |
1775 |
bundle_toolbar.append('<a class="btn btn-default" data-bs-toggle="modal" data-bs-target="#addToBundleModal" data-item="' + itemnumber + '"><i class="fa fa-plus"></i> ' + _("Add to bundle") + '</a>'); |
1782 |
bundle_toolbar.append('<a class="btn btn-default" data-bs-toggle="modal" data-bs-target="#removeFromBundleModal" data-item="' + itemnumber + '"><i class="fa fa-minus"></i> ' + _("Remove from bundle") + '</a>'); |
1776 |
bundle_toolbar.append('<a class="btn btn-default" data-bs-toggle="modal" data-bs-target="#removeFromBundleModal" data-item="' + itemnumber + '"><i class="fa fa-minus"></i> ' + _("Remove from bundle") + '</a>'); |
1783 |
|
1777 |
|
1784 |
// This is the table we'll convert into a DataTable |
1778 |
// Toolbar |
1785 |
var bundles_table = $('<table class="display tbundle" data-itemnumber="'+itemnumber+'" id="bundle_table_'+itemnumber+'" width="100%"/>'); |
1779 |
var bundle_toolbar = $('<div id="toolbar" class="btn-toolbar"></div>'); |
|
|
1780 |
bundle_toolbar.append('<a class="btn btn-default" data-bs-toggle="modal" data-bs-target="#addToBundleModal" data-item="' + itemnumber + '"><i class="fa fa-plus"></i> ' + _("Add to bundle") + '</a>'); |
1781 |
bundle_toolbar.append('<a class="btn btn-default" data-bs-toggle="modal" data-bs-target="#removeFromBundleModal" data-item="' + itemnumber + '"><i class="fa fa-minus"></i> ' + _("Remove from bundle") + '</a>'); |
1786 |
|
1782 |
|
1787 |
// Display it the child row |
1783 |
// This is the table we'll convert into a DataTable |
1788 |
row.child( bundle_toolbar.add(bundles_table), 'bundle' ).show(); |
1784 |
var bundles_table = $('<table class="display tbundle" data-itemnumber="'+itemnumber+'" id="bundle_table_'+itemnumber+'" width="100%"/>'); |
1789 |
|
1785 |
|
1790 |
// Initialise as a DataTable |
1786 |
// Display it the child row |
1791 |
var bundle_table_url = "/api/v1/items/" + itemnumber + "/bundled_items?"; |
1787 |
row.child( bundle_toolbar.add(bundles_table), 'bundle' ).show(); |
1792 |
var bundle_table = bundles_table.kohaTable({ |
1788 |
|
1793 |
"ajax": { |
1789 |
// Initialise as a DataTable |
1794 |
"url": bundle_table_url |
1790 |
var bundle_table_url = "/api/v1/items/" + itemnumber + "/bundled_items?"; |
|
|
1791 |
var bundle_table = bundles_table.kohaTable({ |
1792 |
"ajax": { |
1793 |
"url": bundle_table_url |
1794 |
}, |
1795 |
"embed": [ |
1796 |
"biblio", |
1797 |
"return_claim.patron" |
1798 |
], |
1799 |
"order": [[ 1, "asc" ]], |
1800 |
"columnDefs": [ { |
1801 |
"targets": [0,1,2,3], |
1802 |
"render": function (data, type, row, meta) { |
1803 |
if ( data && type == 'display' ) { |
1804 |
return data.escapeHtml(); |
1805 |
} |
1806 |
return data; |
1807 |
} |
1808 |
} ], |
1809 |
"columns": [ |
1810 |
{ |
1811 |
"data": "biblio.title:biblio.subtitle:biblio.medium", |
1812 |
"title": _("Title"), |
1813 |
"searchable": true, |
1814 |
"orderable": true, |
1815 |
"render": function(data, type, row, meta) { |
1816 |
return $biblio_to_html(row.biblio, { link: 1 }); |
1817 |
} |
1795 |
}, |
1818 |
}, |
1796 |
"embed": [ |
1819 |
{ |
1797 |
"biblio", |
1820 |
"data": "biblio.author", |
1798 |
"return_claim.patron" |
1821 |
"title": _("Author"), |
1799 |
], |
1822 |
"searchable": true, |
1800 |
"order": [[ 1, "asc" ]], |
1823 |
"orderable": true, |
1801 |
"columnDefs": [ { |
1824 |
}, |
1802 |
"targets": [0,1,2,3], |
1825 |
{ |
1803 |
"render": function (data, type, row, meta) { |
1826 |
"data": "copy_number", |
1804 |
if ( data && type == 'display' ) { |
1827 |
"title": _("Copy number"), |
1805 |
return data.escapeHtml(); |
1828 |
"searchable": true, |
|
|
1829 |
"orderable": true, |
1830 |
}, |
1831 |
{ |
1832 |
"data": "callnumber", |
1833 |
"title": _("Callnumber"), |
1834 |
"searchable": true, |
1835 |
"orderable": true, |
1836 |
}, |
1837 |
{ |
1838 |
"data": "external_id", |
1839 |
"title": _("Barcode"), |
1840 |
"searchable": true, |
1841 |
"orderable": true, |
1842 |
}, |
1843 |
{ |
1844 |
"data": "lost_status:last_seen_date:return_claim.patron", |
1845 |
"title": _("Status"), |
1846 |
"searchable": false, |
1847 |
"orderable": false, |
1848 |
"render": function(data, type, row, meta) { |
1849 |
if ( row.lost_status == bundle_lost_value ) { |
1850 |
let out = '<span class="lost">' + _("Last seen") + ': ' + $date(row.last_seen_date) + '</span>'; |
1851 |
if ( row.return_claim ) { |
1852 |
out = out + '<span class="claims_return">' + _("Claims returned by") + ': ' + $patron_to_html( row.return_claim.patron, { display_cardnumber: false, url: true } ) + '</span>'; |
1853 |
} |
1854 |
return out; |
1806 |
} |
1855 |
} |
1807 |
return data; |
1856 |
else if ( row.lost_status !== 0 ) { |
1808 |
} |
1857 |
return '<span class="lost">' + _("Lost") + ': ' + row.lost_status + '</span>'; |
1809 |
} ], |
|
|
1810 |
"columns": [ |
1811 |
{ |
1812 |
"data": "biblio.title:biblio.subtitle:biblio.medium", |
1813 |
"title": _("Title"), |
1814 |
"searchable": true, |
1815 |
"orderable": true, |
1816 |
"render": function(data, type, row, meta) { |
1817 |
return $biblio_to_html(row.biblio, { link: 1 }); |
1818 |
} |
1858 |
} |
1819 |
}, |
1859 |
return '<span class="available">' + _("Present") + '</span>'; |
1820 |
{ |
1860 |
} |
1821 |
"data": "biblio.author", |
1861 |
}, |
1822 |
"title": _("Author"), |
1862 |
{ |
1823 |
"searchable": true, |
1863 |
"data": function( row, type, val, meta ) { |
1824 |
"orderable": true, |
1864 |
var result; |
1825 |
}, |
1865 |
if (duedate) { |
1826 |
{ |
1866 |
result = '<button class="btn btn-default btn-xs remove disabled" role="button" data-itemnumber="'+row.item_id+'" title="%s"><i class="fa fa-minus" aria-hidden="true"></i> %s</button>\n'.format(_("This bundle is checked out, it cannot be modified"), _("Remove")); |
1827 |
"data": "copy_number", |
1867 |
} else { |
1828 |
"title": _("Copy number"), |
1868 |
result = '<button class="btn btn-default btn-xs remove" role="button" data-itemnumber="'+row.item_id+'"><i class="fa fa-minus" aria-hidden="true"></i> '+_("Remove")+'</button>\n'; |
1829 |
"searchable": true, |
|
|
1830 |
"orderable": true, |
1831 |
}, |
1832 |
{ |
1833 |
"data": "callnumber", |
1834 |
"title": _("Callnumber"), |
1835 |
"searchable": true, |
1836 |
"orderable": true, |
1837 |
}, |
1838 |
{ |
1839 |
"data": "external_id", |
1840 |
"title": _("Barcode"), |
1841 |
"searchable": true, |
1842 |
"orderable": true, |
1843 |
}, |
1844 |
{ |
1845 |
"data": "lost_status:last_seen_date:return_claim.patron", |
1846 |
"title": _("Status"), |
1847 |
"searchable": false, |
1848 |
"orderable": false, |
1849 |
"render": function(data, type, row, meta) { |
1850 |
if ( row.lost_status == bundle_lost_value ) { |
1851 |
let out = '<span class="lost">' + _("Last seen") + ': ' + $date(row.last_seen_date) + '</span>'; |
1852 |
if ( row.return_claim ) { |
1853 |
out = out + '<span class="claims_return">' + _("Claims returned by") + ': ' + $patron_to_html( row.return_claim.patron, { display_cardnumber: false, url: true } ) + '</span>'; |
1854 |
} |
1855 |
return out; |
1856 |
} |
1857 |
else if ( row.lost_status !== 0 ) { |
1858 |
return '<span class="lost">' + _("Lost") + ': ' + row.lost_status + '</span>'; |
1859 |
} |
1860 |
return '<span class="available">' + _("Present") + '</span>'; |
1861 |
} |
1869 |
} |
|
|
1870 |
return result; |
1862 |
}, |
1871 |
}, |
1863 |
{ |
1872 |
"title": _("Actions"), |
1864 |
"data": function( row, type, val, meta ) { |
1873 |
"searchable": false, |
1865 |
var result; |
1874 |
"orderable": false, |
1866 |
if (duedate) { |
1875 |
"class": "no-export" |
1867 |
result = '<button class="btn btn-default btn-xs remove disabled" role="button" data-itemnumber="'+row.item_id+'" title="%s"><i class="fa fa-minus" aria-hidden="true"></i> %s</button>\n'.format(_("This bundle is checked out, it cannot be modified"), _("Remove")); |
1876 |
} |
1868 |
} else { |
1877 |
] |
1869 |
result = '<button class="btn btn-default btn-xs remove" role="button" data-itemnumber="'+row.item_id+'"><i class="fa fa-minus" aria-hidden="true"></i> '+_("Remove")+'</button>\n'; |
1878 |
}, bundle_settings, 1); |
1870 |
} |
1879 |
$(".tbundle").on("click", ".remove:not(.disabled)", function(){ |
1871 |
return result; |
1880 |
var bundle_table = $(this).closest('table'); |
1872 |
}, |
1881 |
var host_itemnumber = bundle_table.data('itemnumber'); |
1873 |
"title": _("Actions"), |
1882 |
var component_itemnumber = $(this).data('itemnumber'); |
1874 |
"searchable": false, |
1883 |
var unlink_item_url = "/api/v1/items/" + host_itemnumber + "/bundled_items/" + component_itemnumber; |
1875 |
"orderable": false, |
1884 |
$.ajax({ |
1876 |
"class": "no-export" |
1885 |
type: "DELETE", |
1877 |
} |
1886 |
url: unlink_item_url, |
1878 |
] |
1887 |
success: function(){ |
1879 |
}, bundle_settings, 1); |
1888 |
bundle_table.DataTable({ 'retrieve': true }).draw(false); |
1880 |
$(".tbundle").on("click", ".remove:not(.disabled)", function(){ |
1889 |
} |
1881 |
var bundle_table = $(this).closest('table'); |
|
|
1882 |
var host_itemnumber = bundle_table.data('itemnumber'); |
1883 |
var component_itemnumber = $(this).data('itemnumber'); |
1884 |
var unlink_item_url = "/api/v1/items/" + host_itemnumber + "/bundled_items/" + component_itemnumber; |
1885 |
$.ajax({ |
1886 |
type: "DELETE", |
1887 |
url: unlink_item_url, |
1888 |
success: function(){ |
1889 |
bundle_table.DataTable({ 'retrieve': true }).draw(false); |
1890 |
} |
1891 |
}); |
1892 |
}); |
1890 |
}); |
|
|
1891 |
}); |
1893 |
|
1892 |
|
1894 |
return; |
1893 |
return; |
1895 |
} |
1894 |
} |
1896 |
|
1895 |
|
1897 |
var bundle_changed; |
1896 |
var bundle_changed; |
1898 |
var bundle_form_active; |
1897 |
var bundle_form_active; |
1899 |
$("#addToBundleModal").on("shown.bs.modal", function(e){ |
1898 |
$("#addToBundleModal").on("shown.bs.modal", function(e){ |
1900 |
var button = $(e.relatedTarget); |
1899 |
var button = $(e.relatedTarget); |
1901 |
var item_id = button.data('item'); |
1900 |
var item_id = button.data('item'); |
1902 |
$("#addResult").replaceWith('<div id="addResult"></div>'); |
1901 |
$("#addResult").replaceWith('<div id="addResult"></div>'); |
1903 |
$("#addToBundleForm").attr('action', '/api/v1/items/' + item_id + '/bundled_items'); |
1902 |
$("#addToBundleForm").attr('action', '/api/v1/items/' + item_id + '/bundled_items'); |
1904 |
$("#external_id").focus(); |
1903 |
$("#external_id").focus(); |
1905 |
bundle_changed = 0; |
1904 |
bundle_changed = 0; |
1906 |
bundle_form_active = item_id; |
1905 |
bundle_form_active = item_id; |
1907 |
}); |
1906 |
}); |
1908 |
|
1907 |
|
1909 |
function addToBundle (url, data) { |
1908 |
function addToBundle (url, data) { |
1910 |
/* Send the data using post with external_id */ |
1909 |
/* Send the data using post with external_id */ |
1911 |
var posting = $.post({ |
1910 |
var posting = $.post({ |
1912 |
url: url, |
1911 |
url: url, |
1913 |
data: JSON.stringify(data), |
1912 |
data: JSON.stringify(data), |
1914 |
contentType: "application/json; charset=utf-8", |
1913 |
contentType: "application/json; charset=utf-8", |
1915 |
dataType: "json" |
1914 |
dataType: "json" |
1916 |
}); |
1915 |
}); |
1917 |
|
1916 |
|
1918 |
const barcode = data.external_id; |
1917 |
const barcode = data.external_id; |
1919 |
const marc_link = data.marc_link; |
1918 |
const marc_link = data.marc_link; |
1920 |
|
1919 |
|
1921 |
/* Report the results */ |
1920 |
/* Report the results */ |
1922 |
posting.done(function(data) { |
1921 |
posting.done(function(data) { |
1923 |
$('#addResult').replaceWith('<div id="addResult" class="alert alert-success">'+_("Success: Added '%s'").format(barcode)+'</div>'); |
1922 |
$('#addResult').replaceWith('<div id="addResult" class="alert alert-success">'+_("Success: Added '%s'").format(barcode)+'</div>'); |
1924 |
$('#external_id').val('').focus(); |
1923 |
$('#external_id').val('').focus(); |
1925 |
bundle_changed = 1; |
1924 |
bundle_changed = 1; |
1926 |
}); |
1925 |
}); |
1927 |
posting.fail(function(data) { |
1926 |
posting.fail(function(data) { |
1928 |
if ( data.status === 409 ) { |
1927 |
if ( data.status === 409 ) { |
1929 |
var response = data.responseJSON; |
1928 |
var response = data.responseJSON; |
1930 |
if ( response.error_code === 'already_bundled' ) { |
1929 |
if ( response.error_code === 'already_bundled' ) { |
1931 |
$('#addResult').replaceWith('<div id="addResult" class="alert alert-warning">'+_("Warning: Item '%s' already attached").format(barcode)+'</div>'); |
1930 |
$('#addResult').replaceWith('<div id="addResult" class="alert alert-warning">'+_("Warning: Item '%s' already attached").format(barcode)+'</div>'); |
1932 |
} else if (response.error_code === 'bundle_checkout_out') { |
1931 |
} else if (response.error_code === 'bundle_checkout_out') { |
1933 |
$('#addResult').replaceWith('<div id="addResult" class="alert alert-danger">'+_("Failure: Bundle is currently checked out")+'</div>'); |
1932 |
$('#addResult').replaceWith('<div id="addResult" class="alert alert-danger">'+_("Failure: Bundle is currently checked out")+'</div>'); |
1934 |
} else if (response.error_code === 'checked_out') { |
1933 |
} else if (response.error_code === 'checked_out') { |
1935 |
const button = $('<button type="button">') |
1934 |
const button = $('<button type="button">') |
1936 |
.addClass('btn btn-xs') |
1935 |
.addClass('btn btn-xs') |
1937 |
.text(_("Check in and add to bundle")) |
1936 |
.text(_("Check in and add to bundle")) |
1938 |
.on('click', function () { |
1937 |
.on('click', function () { |
1939 |
addToBundle(url, { external_id: barcode, force_checkin: true, marc_link: marc_link }); |
1938 |
addToBundle(url, { external_id: barcode, force_checkin: true, marc_link: marc_link }); |
1940 |
}); |
1939 |
}); |
1941 |
$('#addResult') |
1940 |
$('#addResult') |
1942 |
.empty() |
1941 |
.empty() |
1943 |
.attr('class', 'alert alert-warning') |
1942 |
.attr('class', 'alert alert-warning') |
1944 |
.append(__x('Warning: Item {barcode} is checked out', { barcode })) |
1943 |
.append(__x('Warning: Item {barcode} is checked out', { barcode })) |
1945 |
.append(' ', button); |
1944 |
.append(' ', button); |
1946 |
} else if (response.error_code === 'failed_checkin') { |
1945 |
} else if (response.error_code === 'failed_checkin') { |
1947 |
$('#addResult') |
1946 |
$('#addResult') |
1948 |
.empty() |
1947 |
.empty() |
1949 |
.attr('class', 'alert alert-danger') |
1948 |
.attr('class', 'alert alert-danger') |
1950 |
.append(__x('Failure: Item {barcode} cannot be checked in', { barcode })) |
1949 |
.append(__x('Failure: Item {barcode} cannot be checked in', { barcode })) |
1951 |
} else if (response.error_code === 'reserved') { |
1950 |
} else if (response.error_code === 'reserved') { |
1952 |
const button = $('<button type="button">') |
1951 |
const button = $('<button type="button">') |
1953 |
.addClass('btn btn-xs') |
1952 |
.addClass('btn btn-xs') |
1954 |
.text(_("Ignore holds and add to bundle")) |
1953 |
.text(_("Ignore holds and add to bundle")) |
1955 |
.on('click', function () { |
1954 |
.on('click', function () { |
1956 |
addToBundle(url, { external_id: barcode, ignore_holds: true, marc_link: marc_link }); |
1955 |
addToBundle(url, { external_id: barcode, ignore_holds: true, marc_link: marc_link }); |
1957 |
}); |
1956 |
}); |
1958 |
$('#addResult') |
1957 |
$('#addResult') |
1959 |
.empty() |
1958 |
.empty() |
1960 |
.attr('class', 'alert alert-warning') |
1959 |
.attr('class', 'alert alert-warning') |
1961 |
.append(__x('Warning: Item {barcode} is on hold', { barcode })) |
1960 |
.append(__x('Warning: Item {barcode} is on hold', { barcode })) |
1962 |
.append(' ', button); |
1961 |
.append(' ', button); |
1963 |
} else { |
1962 |
} else { |
1964 |
$('#addResult').replaceWith('<div id="addResult" class="alert alert-danger">'+_("Failure: Item '%s' belongs to another bundle").format(barcode)+'</div>'); |
1963 |
$('#addResult').replaceWith('<div id="addResult" class="alert alert-danger">'+_("Failure: Item '%s' belongs to another bundle").format(barcode)+'</div>'); |
1965 |
} |
1964 |
} |
1966 |
} else if ( data.status === 404 ) { |
1965 |
} else if ( data.status === 404 ) { |
1967 |
$('#addResult').replaceWith('<div id="addResult" class="alert alert-danger">'+_("Failure: Item '%s' not found").format(barcode)+'</div>'); |
1966 |
$('#addResult').replaceWith('<div id="addResult" class="alert alert-danger">'+_("Failure: Item '%s' not found").format(barcode)+'</div>'); |
1968 |
} else if ( data.status === 400 ) { |
1967 |
} else if ( data.status === 400 ) { |
1969 |
var response = data.responseJSON; |
1968 |
var response = data.responseJSON; |
1970 |
if ( response.error_code === "failed_nesting" ) { |
1969 |
if ( response.error_code === "failed_nesting" ) { |
1971 |
$('#addResult').replaceWith('<div id="addResult" class="alert alert-danger">'+_("Failure: Item '%s' is a bundle and bundles cannot be nested").format(barcode)+'</div>'); |
1970 |
$('#addResult').replaceWith('<div id="addResult" class="alert alert-danger">'+_("Failure: Item '%s' is a bundle and bundles cannot be nested").format(barcode)+'</div>'); |
1972 |
} else { |
|
|
1973 |
$('#addResult').replaceWith('<div id="addResult" class="alert alert-danger">'+_("Failure: Check the logs for details.")+'</div>'); |
1974 |
} |
1975 |
} else { |
1971 |
} else { |
1976 |
$('#addResult').replaceWith('<div id="addResult" class="alert alert-danger">'+_("Failure: Check the logs for details.")+'</div>'); |
1972 |
$('#addResult').replaceWith('<div id="addResult" class="alert alert-danger">'+_("Failure: Check the logs for details.")+'</div>'); |
1977 |
} |
1973 |
} |
1978 |
$('#external_id').val('').focus(); |
1974 |
} else { |
1979 |
}); |
1975 |
$('#addResult').replaceWith('<div id="addResult" class="alert alert-danger">'+_("Failure: Check the logs for details.")+'</div>'); |
1980 |
} |
1976 |
} |
|
|
1977 |
$('#external_id').val('').focus(); |
1978 |
}); |
1979 |
} |
1981 |
|
1980 |
|
1982 |
$("#addToBundleForm").submit(function(event) { |
1981 |
$("#addToBundleForm").submit(function(event) { |
1983 |
/* stop form from submitting normally */ |
1982 |
/* stop form from submitting normally */ |
1984 |
event.preventDefault(); |
1983 |
event.preventDefault(); |
1985 |
|
1984 |
|
1986 |
const url = this.action; |
1985 |
const url = this.action; |
1987 |
const data = { external_id: this.elements.external_id.value, marc_link: this.elements.bundle_link.checked }; |
1986 |
const data = { external_id: this.elements.external_id.value, marc_link: this.elements.bundle_link.checked }; |
1988 |
|
1987 |
|
1989 |
addToBundle(url, data); |
1988 |
addToBundle(url, data); |
1990 |
}); |
1989 |
}); |
1991 |
|
1990 |
|
1992 |
$("#addToBundleModal").on("hidden.bs.modal", function(e){ |
1991 |
$("#addToBundleModal").on("hidden.bs.modal", function(e){ |
1993 |
if ( bundle_changed ) { |
1992 |
if ( bundle_changed ) { |
1994 |
$('#bundle_table_'+bundle_form_active).DataTable({ 'retrieve': true }).ajax.reload(); |
1993 |
$('#bundle_table_'+bundle_form_active).DataTable({ 'retrieve': true }).ajax.reload(); |
1995 |
} |
1994 |
} |
1996 |
bundle_form_active = 0; |
1995 |
bundle_form_active = 0; |
1997 |
bundle_changed = 0; |
1996 |
bundle_changed = 0; |
1998 |
}); |
1997 |
}); |
1999 |
|
1998 |
|
2000 |
$("#removeFromBundleModal").on("shown.bs.modal", function(e){ |
1999 |
$("#removeFromBundleModal").on("shown.bs.modal", function(e){ |
2001 |
var button = $(e.relatedTarget); |
2000 |
var button = $(e.relatedTarget); |
2002 |
var item_id = button.data('item'); |
2001 |
var item_id = button.data('item'); |
2003 |
$("#removeResult").replaceWith('<div id="removeResult"></div>'); |
2002 |
$("#removeResult").replaceWith('<div id="removeResult"></div>'); |
2004 |
$("#removeFromBundleForm").attr('action', '/api/v1/items/' + item_id + '/bundled_items/'); |
2003 |
$("#removeFromBundleForm").attr('action', '/api/v1/items/' + item_id + '/bundled_items/'); |
2005 |
$("#rm_external_id").focus(); |
2004 |
$("#rm_external_id").focus(); |
2006 |
bundle_changed = 0; |
2005 |
bundle_changed = 0; |
2007 |
bundle_form_active = item_id; |
2006 |
bundle_form_active = item_id; |
2008 |
}); |
2007 |
}); |
2009 |
|
2008 |
|
2010 |
$("#removeFromBundleForm").submit(function(event) { |
2009 |
$("#removeFromBundleForm").submit(function(event) { |
2011 |
|
2010 |
|
2012 |
/* stop form from submitting normally */ |
2011 |
/* stop form from submitting normally */ |
2013 |
event.preventDefault(); |
2012 |
event.preventDefault(); |
2014 |
|
2013 |
|
2015 |
/* get the action attribute from the <form action=""> element */ |
2014 |
/* get the action attribute from the <form action=""> element */ |
2016 |
var $form = $(this), |
2015 |
var $form = $(this), |
2017 |
url = $form.attr('action'); |
2016 |
url = $form.attr('action'); |
2018 |
|
2017 |
|
2019 |
var barcode = $('#rm_external_id').val(); |
2018 |
var barcode = $('#rm_external_id').val(); |
2020 |
|
2019 |
|
2021 |
/* Fetch itemnumber using rm_external_id */ |
2020 |
/* Fetch itemnumber using rm_external_id */ |
2022 |
var itemReq = $.get('/api/v1/items', { q: JSON.stringify({ |
2021 |
var itemReq = $.get('/api/v1/items', { q: JSON.stringify({ |
2023 |
external_id: barcode |
2022 |
external_id: barcode |
2024 |
}) }, null, "json"); |
2023 |
}) }, null, "json"); |
2025 |
|
2024 |
|
2026 |
var itemnumber; |
2025 |
var itemnumber; |
2027 |
itemReq.done(function(data) { |
2026 |
itemReq.done(function(data) { |
2028 |
if (data.length === 1) { |
2027 |
if (data.length === 1) { |
2029 |
itemnumber = data[0].item_id; |
2028 |
itemnumber = data[0].item_id; |
2030 |
|
2029 |
|
2031 |
/* Remove link using fetch itemnumber */ |
2030 |
/* Remove link using fetch itemnumber */ |
2032 |
var deleteReq = $.ajax( url + itemnumber, { |
2031 |
var deleteReq = $.ajax( url + itemnumber, { |
2033 |
type : 'DELETE' |
2032 |
type : 'DELETE' |
2034 |
}); |
2033 |
}); |
2035 |
|
2034 |
|
2036 |
/* Report the results */ |
2035 |
/* Report the results */ |
2037 |
deleteReq.done(function(data) { |
2036 |
deleteReq.done(function(data) { |
2038 |
var barcode = $('#rm_external_id').val(); |
2037 |
var barcode = $('#rm_external_id').val(); |
2039 |
$('#removeResult').replaceWith('<div id="removeResult" class="alert alert-success">'+_("Success: Removed '%s'").format(barcode)+'</div>'); |
2038 |
$('#removeResult').replaceWith('<div id="removeResult" class="alert alert-success">'+_("Success: Removed '%s'").format(barcode)+'</div>'); |
2040 |
$('#rm_external_id').val('').focus(); |
2039 |
$('#rm_external_id').val('').focus(); |
2041 |
bundle_changed = 1; |
2040 |
bundle_changed = 1; |
2042 |
}); |
2041 |
}); |
2043 |
deleteReq.fail(function(data) { |
2042 |
deleteReq.fail(function(data) { |
2044 |
var barcode = $('#rm_external_id').val(); |
2043 |
var barcode = $('#rm_external_id').val(); |
2045 |
if ( data.status === 409 ) { |
2044 |
if ( data.status === 409 ) { |
2046 |
var response = data.responseJSON; |
2045 |
var response = data.responseJSON; |
2047 |
if (response.error_code === 'bundle_checkout_out') { |
2046 |
if (response.error_code === 'bundle_checkout_out') { |
2048 |
$('#removeResult').replaceWith('<div id="removeResult" class="alert alert-danger">'+_("Failure: Bundle is currently checked out")+'</div>'); |
2047 |
$('#removeResult').replaceWith('<div id="removeResult" class="alert alert-danger">'+_("Failure: Bundle is currently checked out")+'</div>'); |
2049 |
} else if ( response.key === "PRIMARY" ) { |
2048 |
} else if ( response.key === "PRIMARY" ) { |
2050 |
$('#removeResult').replaceWith('<div id="removeResult" class="alert alert-warning">'+_("Warning: Item '%s' already attached").format(barcode)+'</div>'); |
2049 |
$('#removeResult').replaceWith('<div id="removeResult" class="alert alert-warning">'+_("Warning: Item '%s' already attached").format(barcode)+'</div>'); |
2051 |
} else { |
|
|
2052 |
$('#removeResult').replaceWith('<div id="removeResult" class="alert alert-danger">'+_("Failure: Item '%s' belongs to another bundle").format(barcode)+'</div>'); |
2053 |
} |
2054 |
} else if ( data.status === 404 ) { |
2055 |
$('#addResult').replaceWith('<div id="addResult" class="alert alert-danger">'+_("Failure: Item '%s' not found").format(barcode)+'</div>'); |
2056 |
} else { |
2050 |
} else { |
2057 |
$('#removeResult').replaceWith('<div id="removeResult" class="alert alert-danger">'+_("Failure: Check the logs for details")+'</div>'); |
2051 |
$('#removeResult').replaceWith('<div id="removeResult" class="alert alert-danger">'+_("Failure: Item '%s' belongs to another bundle").format(barcode)+'</div>'); |
2058 |
} |
2052 |
} |
2059 |
$('#rm_external_id').val('').focus(); |
2053 |
} else if ( data.status === 404 ) { |
2060 |
}); |
2054 |
$('#addResult').replaceWith('<div id="addResult" class="alert alert-danger">'+_("Failure: Item '%s' not found").format(barcode)+'</div>'); |
2061 |
} else { |
2055 |
} else { |
2062 |
$('#removeResult').replaceWith('<div id="removeResult" class="alert alert-danger">'+_("Failed: Barcode matched more than one item '%s'").format(barcode)+'</div>'); |
2056 |
$('#removeResult').replaceWith('<div id="removeResult" class="alert alert-danger">'+_("Failure: Check the logs for details")+'</div>'); |
2063 |
} |
2057 |
} |
2064 |
}); |
2058 |
$('#rm_external_id').val('').focus(); |
2065 |
itemReq.fail(function(data) { |
2059 |
}); |
2066 |
$('#removeResult').replaceWith('<div id="removeResult" class="alert alert-danger">'+_("Failed: Item not found '%s'").format(barcode)+'</div>'); |
2060 |
} else { |
2067 |
$('#rm_external_id').val('').focus(); |
2061 |
$('#removeResult').replaceWith('<div id="removeResult" class="alert alert-danger">'+_("Failed: Barcode matched more than one item '%s'").format(barcode)+'</div>'); |
2068 |
|
2062 |
} |
2069 |
}); |
|
|
2070 |
}); |
2063 |
}); |
|
|
2064 |
itemReq.fail(function(data) { |
2065 |
$('#removeResult').replaceWith('<div id="removeResult" class="alert alert-danger">'+_("Failed: Item not found '%s'").format(barcode)+'</div>'); |
2066 |
$('#rm_external_id').val('').focus(); |
2071 |
|
2067 |
|
2072 |
$("#removeFromBundleModal").on("hidden.bs.modal", function(e){ |
|
|
2073 |
if ( bundle_changed ) { |
2074 |
$('#bundle_table_'+bundle_form_active).DataTable({ 'retrieve': true }).ajax.reload(); |
2075 |
} |
2076 |
bundle_form_active = 0; |
2077 |
bundle_changed = 0; |
2078 |
}); |
2068 |
}); |
2079 |
// End bundle handling |
2069 |
}); |
2080 |
[% END # /IF bundlesEnabled %] |
|
|
2081 |
|
2070 |
|
|
|
2071 |
$("#removeFromBundleModal").on("hidden.bs.modal", function(e){ |
2072 |
if ( bundle_changed ) { |
2073 |
$('#bundle_table_'+bundle_form_active).DataTable({ 'retrieve': true }).ajax.reload(); |
2074 |
} |
2075 |
bundle_form_active = 0; |
2076 |
bundle_changed = 0; |
2077 |
}); |
2078 |
// End bundle handling |
2079 |
[% END # /IF bundlesEnabled %] |
2080 |
|
2081 |
$(document).ready(function() { |
2082 |
[% IF Koha.Preference('AcquisitionDetails') %] |
2082 |
[% IF Koha.Preference('AcquisitionDetails') %] |
2083 |
var table_settings = [% TablesSettings.GetTableSettings('catalogue', 'detail', 'acquisitiondetails-table', 'json') | $raw %]; |
2083 |
var table_settings = [% TablesSettings.GetTableSettings('catalogue', 'detail', 'acquisitiondetails-table', 'json') | $raw %]; |
2084 |
var acquisitiondetails_table = $("#orders").kohaTable( |
2084 |
var acquisitiondetails_table = $("#orders").kohaTable( |
2085 |
- |
|
|