diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/FormRelationshipSelect.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/FormRelationshipSelect.vue index d83e613f9a..6968e70cc6 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/FormRelationshipSelect.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/FormRelationshipSelect.vue @@ -38,6 +38,10 @@ export default { relationshipRequiredKey: String | null, disabled: Boolean | false, required: Boolean | false, + query: { + type: Object, + default: {}, + }, }, data() { return { @@ -47,7 +51,7 @@ export default { }, created() { const relatedResources = this.relationshipAPIClient; - relatedResources.getAll().then( + relatedResources.getAll(this.query).then( relatedResources => { this.relatedResources = relatedResources; this.relatedResourcesLoaded = true; diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/Preservation/TrainItemsTable.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/Preservation/TrainItemsTable.vue index f7d9863ece..8916165fa1 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/Preservation/TrainItemsTable.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/Preservation/TrainItemsTable.vue @@ -190,8 +190,33 @@ export default { ); }, selectTrainForCopy(train_item_id) { - $("#copy_item_to_train").modal("show"); this.train_item_id_to_copy = train_item_id; + let copyItem = this.copyItem; + + this.setConfirmationDialog( + { + title: this.$__("Copy item to the following train"), + message: null, + accept_label: this.$__("Save"), + cancel_label: this.$__("Cancel"), + inputs: [ + { + name: "train_id", + type: "relationshipSelect", + label: __("Select a train"), + required: true, + relationshipAPIClient: + APIClient.preservation.trains, + relationshipOptionLabelAttr: "name", + relationshipRequiredKey: "train_id", + query: { + "me.closed_on": null, + }, + }, + ], + }, + copyItem + ); }, clearAll() { this.selected_items = []; @@ -235,6 +260,27 @@ export default { ); } }, + copyItem(result, trainToCopy) { + const client = APIClient.preservation; + client.train_items + .copy( + trainToCopy.train_id, + this.train.train_id, + this.train_item_id_to_copy + ) + .then( + success => { + this.setMessage(this.$__("Item copied successfully.")); + }, + error => { + this.setWarning( + this.$__( + "Item cannot be copied to a train, it is already in a non-received train." + ) + ); + } + ); + }, build_datatable() { let table_id = this.table_id; let item_table = this.item_table; @@ -244,6 +290,7 @@ export default { let selectTrainForCopy = this.selectTrainForCopy; let train = this.train; let updateSelectedItems = this.updateSelectedItems; + let copyItem = this.copyItem; let table = $("#" + table_id).kohaTable({ data: item_table.data, diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/Preservation/TrainResource.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/Preservation/TrainResource.vue index d3e63001e5..2716da4f54 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/Preservation/TrainResource.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/Preservation/TrainResource.vue @@ -194,16 +194,7 @@ export default { this.updateTrainDate(resource, "sent_on"); }, receiveTrain(resource) { - this.updateTrainDate(resource, "received_on").then( - success => { - // Rebuild the table to show the "copy" button - $("#" + this.table_id) - .DataTable() - .destroy(); - this.build_datatable(); - }, - error => {} - ); + this.updateTrainDate(resource, "received_on"); }, onSubmit(e, trainToSave) { e.preventDefault();