Koha/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/LicensesFormConfirmDelete.vue
Jonathan Druart 1edd4d4589
Bug 32806: Move Vue files for reusability
Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de>
Signed-off-by: Pedro Amorim <pedro.amorim@ptfs-europe.com>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
2023-02-27 11:11:58 -03:00

89 lines
2.7 KiB
Vue

<template>
<div v-if="!initialized">{{ $__("Loading") }}</div>
<div v-else id="licenses_confirm_delete">
<h2>{{ $__("Delete license") }}</h2>
<div>
<form @submit="onSubmit($event)">
<fieldset class="rows">
<ol>
<li>
{{ $__("License name") }}:
{{ license.name }}
</li>
<li>
{{ $__("Description") }}:
{{ license.description }}
</li>
</ol>
</fieldset>
<fieldset class="action">
<input
type="submit"
variant="primary"
:value="$__('Yes, delete')"
/>
<router-link
to="/cgi-bin/koha/erm/licenses"
role="button"
class="cancel"
>{{ $__("No, do not delete") }}</router-link
>
</fieldset>
</form>
</div>
</div>
</template>
<script>
import { fetchLicense, checkError } from "../../fetch/erm.js"
import { setMessage, setError } from "../../messages"
export default {
data() {
return {
license: {},
initialized: false,
}
},
beforeRouteEnter(to, from, next) {
next(vm => {
vm.license = vm.getLicense(to.params.license_id)
vm.initialized = true
})
},
methods: {
async getLicense(license_id) {
const license = await fetchLicense(license_id)
this.license = license
this.initialized = true
},
onSubmit(e) {
e.preventDefault()
let apiUrl = "/api/v1/erm/licenses/" + this.license.license_id
const options = {
method: "DELETE",
headers: {
"Content-Type": "application/json;charset=utf-8",
},
}
fetch(apiUrl, options)
.then(response => checkError(response, 1))
.then(response => {
if (response.status == 204) {
this.$router.push("/cgi-bin/koha/erm/licenses")
setMessage(this.$__("License deleted"))
} else {
setError(response.message || response.statusText)
}
})
.catch(error => {
setError(error)
})
},
},
name: "LicensesFormConfirmDelete",
}
</script>