2 <h2 v-if="license.license_id">Edit license</h2>
3 <h2 v-else>New license</h2>
5 <form @submit="onSubmit($event)">
6 <fieldset class="rows">
9 <label class="required" for="license_name"
14 v-model="license.name"
15 placeholder="License name"
18 <span class="required">Required</span>
21 <label for="license_description">Description: </label>
23 id="license_description"
24 v-model="license.description"
25 placeholder="Description"
30 <span class="required">Required</span>
33 <label for="license_type">Type: </label>
36 v-model="license.type"
39 <option value=""></option>
41 v-for="type in av_license_types"
42 :key="type.authorised_values"
43 :value="type.authorised_value"
45 type.authorised_value == license.type
53 <span class="required">Required</span>
56 <label for="license_status">Status: </label>
59 v-model="license.status"
62 <option value=""></option>
64 v-for="status in av_license_statuses"
65 :key="status.authorised_values"
66 :value="status.authorised_value"
68 status.authorised_value == license.status
76 <span class="required">Required</span>
79 <label for="started_on">Start date: </label>
82 v-model="license.started_on"
84 data-date_to="ended_on"
88 <label for="ended_on">End date: </label>
91 v-model="license.ended_on"
97 <fieldset class="action">
98 <input type="submit" value="Submit" />
100 to="/cgi-bin/koha/erm/licenses"
111 import flatPickr from 'vue-flatpickr-component'
112 import { useAVStore } from "../../stores/authorised_values"
113 import { useMainStore } from "../../stores/main"
114 import { fetchLicense } from '../../fetch'
115 import { storeToRefs } from "pinia"
120 const AVStore = useAVStore()
124 } = storeToRefs(AVStore)
126 const mainStore = useMainStore()
127 const { setMessage, setError, resetMessages } = mainStore
132 setMessage, setError, resetMessages,
137 fp_config: flatpickr_defaults, dates_fixed: 0,
145 started_on: undefined,
151 if (!this.dates_fixed) {
152 this.license.started_on = $date(this.license.started_on)
153 this.license.ended_on = $date(this.license.ended_on)
157 beforeRouteEnter(to, from, next) {
158 if (to.params.license_id) {
160 vm.license = vm.getLicense(to.params.license_id)
167 async getLicense(license_id) {
168 const license = await fetchLicense(license_id)
169 this.license = license
174 let license = JSON.parse(JSON.stringify(this.license)) // copy
175 let apiUrl = '/api/v1/erm/licenses'
178 if (license.license_id) {
180 apiUrl += '/' + license.license_id
182 delete license.license_id
184 license.started_on = license.started_on ? $date_to_rfc3339(license.started_on) : null
185 license.ended_on = license.ended_on ? $date_to_rfc3339(license.ended_on) : null
189 body: JSON.stringify(license),
191 'Content-Type': 'application/json;charset=utf-8'
195 fetch(apiUrl, options)
197 if (response.status == 200) {
198 this.$router.push("/cgi-bin/koha/erm/licenses")
199 this.setMessage('License updated')
200 } else if (response.status == 201) {
201 this.$router.push("/cgi-bin/koha/erm/licenses")
202 this.setMessage('License created')
204 this.setError(response.message || response.statusText)
208 }).catch(e => { console.log(e) })
217 name: "LicensesFormAdd",