Koha/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsFormConfirmDelete.vue
Jonathan Druart 545e568b9f
Bug 32939: Uniformize api calls
We want to make the call easier and without less errors possible.
Here, no need to async keyword, try-catch, etc.
Only call the method and use the common then with the 2 success and
error Promise arguments.

We will certainly want to add later a parameter to prevent the display
of the error in fetchJSON, in case the failure does not require a message
for the end user.

Signed-off-by: Matt Blenkinsop <matt.blenkinsop@ptfs-europe.com>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
2023-02-27 11:13:10 -03:00

77 lines
2.4 KiB
Vue

<template>
<div v-if="!initialized">{{ $__("Loading") }}</div>
<div v-else id="agreements_confirm_delete">
<h2>{{ $__("Delete agreement") }}</h2>
<div>
<form @submit="onSubmit($event)">
<fieldset class="rows">
<ol>
<li>
{{ $__("Agreement name") }}:
{{ agreement.name }}
</li>
<li>{{ $__("Vendor") }}: {{ agreement.vendor_id }}</li>
<li>
{{ $__("Description") }}:
{{ agreement.description }}
</li>
</ol>
</fieldset>
<fieldset class="action">
<input
type="submit"
variant="primary"
:value="$__('Yes, delete')"
/>
<router-link
to="/cgi-bin/koha/erm/agreements"
role="button"
class="cancel"
>{{ $__("No, do not delete") }}</router-link
>
</fieldset>
</form>
</div>
</div>
</template>
<script>
import { APIClient } from "../../fetch/api-client.js"
import { setMessage } from "../../messages"
export default {
data() {
return {
agreement: {},
initialized: false,
}
},
beforeRouteEnter(to, from, next) {
next(vm => {
vm.getAgreement(to.params.agreement_id)
})
},
methods: {
async getAgreement(agreement_id) {
const client = APIClient.erm
client.agreements.get(agreement_id).then(data => {
this.agreement = data
this.initialized = true
})
},
onSubmit(e) {
e.preventDefault()
const client = APIClient.erm
client.agreements.delete(this.agreement.agreement_id).then(
success => {
setMessage(this.$__("Agreement deleted"))
this.$router.push("/cgi-bin/koha/erm/agreements")
},
error => {}
)
},
},
name: "AgreementsFormConfirmDelete",
}
</script>