@@ -, +, @@
---
.../prog/en/modules/catalogue/detail.tt | 287 +++++++++++++++++++++
1 file changed, 287 insertions(+)
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt
+++ a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt
@@ -184,6 +184,7 @@
Holdings ([% itemloop.size() || 0 | html %])
[% END %]
+[% IF Koha.Preference('EnableVolumes') %]
[% IF ( Koha.Preference('NovelistSelectStaffEnabled') && Koha.Preference('NovelistSelectStaffProfile') && Koha.Preference('NovelistSelectStaffView') == 'above' ) %]
@@ -899,6 +917,88 @@ Note that permanent location is a code, and location may be an authval.
[% END %]
+
+
+
+
+
+
+
+
+
+ Are you sure you want to delete this volume?
+
+
+
+
+
+
[% MACRO jsinclude BLOCK %]
[% INCLUDE 'catalog-strings.inc' %]
[% Asset.js("js/catalog.js") | $raw %]
@@ -1162,6 +1262,193 @@ Note that permanent location is a code, and location may be an authval.
}));
[% END %]
});
+
+ [% IF Koha.Preference('EnableVolumes') %]
+ // Load volumes table
+ var volumesTable = KohaTable("volumes-table", {
+ "bAutoWidth": false,
+ 'sDom': '<"top pager"ilp>t<"bottom pager"ip>r',
+ "aoColumns": [
+ {
+ "mDataProp": function( oObj ) {
+ return oObj.display_order;
+ },
+ },
+ {
+ "mDataProp": function( oObj ) {
+ return oObj.description;
+ },
+ },
+ {
+ "mDataProp": function( oObj ) {
+ return `
+ ${_('Edit')}
+ `
+ + ' '
+ + `
+ ${('Delete')}
+ `;
+ },
+ },
+ ],
+ "bPaginate": false,
+ "bProcessing": true,
+ "bServerSide": false,
+ "sAjaxSource": `/api/v1/biblios/${biblionumber}/volumes`,
+ "sAjaxDataProp": "",
+ "fnServerData": function ( sSource, aoData, fnCallback ) {
+ $.getJSON( sSource, aoData, function (json) {
+ fnCallback(json)
+ } );
+ },
+ });
+
+ // Create new volumes
+ $('.volume-create').on('click', function(){
+ $('#modal-volume-create-form-description').val("");
+ $('#modal-volume-create-submit').removeAttr('disabled');
+ $('#modal-volume-create').modal('show');
+ });
+
+ $("#modal-volume-create-form").validate({
+ submitHandler: function(form) {
+ $.ajax({
+ url: `/api/v1/biblios/${biblionumber}/volumes`,
+ headers: { "x-koha-embed": "items" },
+ success: function(volumes){
+ $('#modal-volume-create-submit').attr('disabled', 'disabled');
+
+ var settings = {
+ "url": `/api/v1/biblios/${biblionumber}/volumes`,
+ "method": "POST",
+ "headers": {
+ "Content-Type": "application/json"
+ },
+ "data": JSON.stringify(
+ {
+ "description": $("#modal-volume-create-form-description").val(),
+ "display_order": $("#modal-volume-create-form-display_order").val(),
+ }
+ ),
+ };
+
+ $.ajax(settings)
+ .done(function (response) {
+ $('#volume-add-form-select').append($('
', {
+ value: response.volume_id,
+ text: response.description
+ }));
+
+ $('#modal-volume-create').modal('hide');
+ if ( volumes.length == 0 ) {
+ // This bib has no previous volumes, reload the page
+ window.location.replace(`/cgi-bin/koha/catalogue/detail.pl?biblionumber=${biblionumber}`);
+ } else {
+ // Has other volumes, just reload the table
+ volumesTable.api().ajax.reload();
+ }
+ })
+ .fail(function(err) {
+ var message = err.responseJSON.error;
+ alert(message);
+ });
+ }
+ });
+ }
+ });
+
+ $('#modal-volume-create').on('shown.bs.modal', function () {
+ $('#modal-volume-create-form-description').focus();
+ })
+
+ // Edit existing volumes
+ $('body').on( 'click', '.volume-edit', function(){
+ const volume_id = $(this).data('volume-id');
+ const url = `/api/v1/biblios/${biblionumber}/volumes/${volume_id}`;
+ $.get( url, function( data ) {
+ $('#modal-volume-edit-form-description').val( data.description );
+ $('#modal-volume-edit-form-display_order').val( data.display_order );
+ $('#modal-volume-edit-submit').data('volume-id', volume_id );
+ $('#modal-volume-edit-submit').removeAttr('disabled');
+ $('#modal-volume-edit').modal('show');
+ });
+ });
+
+ $("#modal-volume-edit-form").validate({
+ submitHandler: function(form) {
+ $('#modal-volume-edit-submit').attr('disabled', 'disabled');
+
+ const volume_id = $('#modal-volume-edit-submit').data('volume-id');
+ const url = `/api/v1/biblios/${biblionumber}/volumes/${volume_id}`;
+
+ var settings = {
+ "url": url,
+ "method": "PUT",
+ "headers": {
+ "Content-Type": "application/json"
+ },
+ "data": JSON.stringify(
+ {
+ "description": $("#modal-volume-edit-form-description").val(),
+ "display_order": $("#modal-volume-edit-form-display_order").val(),
+ }
+ ),
+ };
+
+ $.ajax(settings)
+ .done(function (response) {
+ $('#modal-volume-edit').modal('hide');
+ volumesTable.api().ajax.reload();
+ })
+ .fail(function(err) {
+ var message = err.responseJSON.error;
+ alert(message);
+ });
+ }
+ });
+
+ $('#modal-volume-edit').on('shown.bs.modal', function () {
+ $('#modal-volume-edit-form-description').focus();
+ })
+
+ // Delete existing volumes
+ $('body').on( 'click', '.volume-delete', function(){
+ const volume_id = $(this).data('volume-id');
+ $('#modal-volume-delete-submit').data('volume-id', volume_id );
+ $('#modal-volume-delete-submit').removeAttr('disabled');
+ $('#modal-volume-delete').modal('show');
+ });
+ $("#modal-volume-delete-submit").on('click', function(){
+ $('#modal-volume-delete-submit').attr('disabled', 'disabled');
+ const volume_id = $("#modal-volume-delete-submit").data('volume-id');
+
+ $.ajax({
+ url: `/api/v1/biblios/${biblionumber}/volumes/${volume_id}`,
+ headers: { "x-koha-embed": "items" },
+ success: function(volume_data){
+ $.ajax({
+ "url": `/api/v1/biblios/${biblionumber}/volumes/${volume_id}`,
+ "method": "DELETE",
+ })
+ .done(function (response) {
+ $('#modal-volume-delete').modal('hide');
+ $(`#volume-add-form-select option[value='${volume_id}']`).remove();
+ if ( volume_data.items === null ) {
+ // No items for this volume, we can just refresh the table
+ volumesTable.api().ajax.reload();
+ } else {
+ // This volume had items attached to it, we need to reload the page
+ window.location.replace(`/cgi-bin/koha/catalogue/detail.pl?biblionumber=${biblionumber}`);
+ }
+ })
+ .fail(function(err) {
+ var message = err.responseJSON.error;
+ alert(message);
+ });
+ }
+ });
+ });
+ [% END %]
[% END %]
[% INCLUDE 'intranet-bottom.inc' %]
--