Lines 149-156
import { inject } from "vue"
Link Here
|
149 |
import flatPickr from "vue-flatpickr-component" |
149 |
import flatPickr from "vue-flatpickr-component" |
150 |
import UserRoles from "./UserRoles.vue" |
150 |
import UserRoles from "./UserRoles.vue" |
151 |
import Documents from "./Documents.vue" |
151 |
import Documents from "./Documents.vue" |
152 |
import { setMessage, setError, setWarning } from "../../messages" |
152 |
import { setMessage, setWarning } from "../../messages" |
153 |
import { fetchLicense, checkError } from "../../fetch/erm.js" |
153 |
import { APIClient } from "../../fetch/api-client.js" |
154 |
import { storeToRefs } from "pinia" |
154 |
import { storeToRefs } from "pinia" |
155 |
|
155 |
|
156 |
export default { |
156 |
export default { |
Lines 199-207
export default {
Link Here
|
199 |
}, |
199 |
}, |
200 |
methods: { |
200 |
methods: { |
201 |
async getLicense(license_id) { |
201 |
async getLicense(license_id) { |
202 |
const license = await fetchLicense(license_id) |
202 |
const client = APIClient.erm |
203 |
this.license = license |
203 |
client.licenses.get(license_id).then(license => { |
204 |
this.initialized = true |
204 |
this.license = license |
|
|
205 |
this.initialized = true |
206 |
}) |
205 |
}, |
207 |
}, |
206 |
checkForm(license) { |
208 |
checkForm(license) { |
207 |
let errors = [] |
209 |
let errors = [] |
Lines 229-234
export default {
Link Here
|
229 |
e.preventDefault() |
231 |
e.preventDefault() |
230 |
|
232 |
|
231 |
let license = JSON.parse(JSON.stringify(this.license)) // copy |
233 |
let license = JSON.parse(JSON.stringify(this.license)) // copy |
|
|
234 |
let license_id = license.license_id |
232 |
|
235 |
|
233 |
if (!this.checkForm(license)) { |
236 |
if (!this.checkForm(license)) { |
234 |
return false |
237 |
return false |
Lines 256-290
export default {
Link Here
|
256 |
({ file_type, uploaded_on, ...keepAttrs }) => keepAttrs |
259 |
({ file_type, uploaded_on, ...keepAttrs }) => keepAttrs |
257 |
) |
260 |
) |
258 |
|
261 |
|
259 |
const options = { |
262 |
const client = APIClient.erm |
260 |
method: method, |
263 |
if (license_id) { |
261 |
body: JSON.stringify(license), |
264 |
client.licenses.update(license, license_id).then( |
262 |
headers: { |
265 |
success => { |
263 |
"Content-Type": "application/json;charset=utf-8", |
266 |
setMessage(this.$__("License updated")) |
264 |
}, |
267 |
this.$router.push("/cgi-bin/koha/erm/licenses") |
265 |
} |
|
|
266 |
|
267 |
fetch(apiUrl, options) |
268 |
.then(response => checkError(response, 1)) |
269 |
.then( |
270 |
response => { |
271 |
if (response.status == 200) { |
272 |
this.$router.push("/cgi-bin/koha/erm/licenses") |
273 |
setMessage(this.$__("License updated")) |
274 |
} else if (response.status == 201) { |
275 |
this.$router.push("/cgi-bin/koha/erm/licenses") |
276 |
setMessage(this.$__("License created")) |
277 |
} else { |
278 |
setError(response.message || response.statusText) |
279 |
} |
280 |
}, |
268 |
}, |
281 |
error => { |
269 |
error => {} |
282 |
setError(error) |
|
|
283 |
} |
284 |
) |
270 |
) |
285 |
.catch(e => { |
271 |
} else { |
286 |
console.log(e) |
272 |
client.licenses.create(license).then( |
287 |
}) |
273 |
success => { |
|
|
274 |
setMessage(this.$__("License created")) |
275 |
this.$router.push("/cgi-bin/koha/erm/licenses") |
276 |
}, |
277 |
error => {} |
278 |
) |
279 |
} |
288 |
}, |
280 |
}, |
289 |
}, |
281 |
}, |
290 |
components: { |
282 |
components: { |