Lines 190-196
import AgreementLicenses from "./AgreementLicenses.vue"
Link Here
|
190 |
import AgreementRelationships from "./AgreementRelationships.vue" |
190 |
import AgreementRelationships from "./AgreementRelationships.vue" |
191 |
import Documents from "./Documents.vue" |
191 |
import Documents from "./Documents.vue" |
192 |
import { setMessage, setError, setWarning } from "../../messages" |
192 |
import { setMessage, setError, setWarning } from "../../messages" |
193 |
import { fetchAgreement, checkError } from "../../fetch/erm.js" |
193 |
import { ERMAPIClient } from "../../fetch/erm-api-client.js" |
194 |
import { storeToRefs } from "pinia" |
194 |
import { storeToRefs } from "pinia" |
195 |
|
195 |
|
196 |
export default { |
196 |
export default { |
Lines 245-251
export default {
Link Here
|
245 |
beforeRouteEnter(to, from, next) { |
245 |
beforeRouteEnter(to, from, next) { |
246 |
next(vm => { |
246 |
next(vm => { |
247 |
if (to.params.agreement_id) { |
247 |
if (to.params.agreement_id) { |
248 |
vm.agreement = vm.getAgreement(to.params.agreement_id) |
248 |
vm.getAgreement(to.params.agreement_id) |
249 |
} else { |
249 |
} else { |
250 |
vm.initialized = true |
250 |
vm.initialized = true |
251 |
} |
251 |
} |
Lines 253-261
export default {
Link Here
|
253 |
}, |
253 |
}, |
254 |
methods: { |
254 |
methods: { |
255 |
async getAgreement(agreement_id) { |
255 |
async getAgreement(agreement_id) { |
256 |
const agreement = await fetchAgreement(agreement_id) |
256 |
const client = new ERMAPIClient() |
257 |
this.agreement = agreement |
257 |
try { |
258 |
this.initialized = true |
258 |
await client.agreements.get(agreement_id).then(data => { |
|
|
259 |
this.agreement = data |
260 |
this.initialized = true |
261 |
}) |
262 |
} catch (err) { |
263 |
setError(err.message || err.statusText) |
264 |
} |
259 |
}, |
265 |
}, |
260 |
checkForm(agreement) { |
266 |
checkForm(agreement) { |
261 |
let errors = [] |
267 |
let errors = [] |
Lines 326-343
export default {
Link Here
|
326 |
|
332 |
|
327 |
//let agreement= Object.assign( {} ,this.agreement); // copy |
333 |
//let agreement= Object.assign( {} ,this.agreement); // copy |
328 |
let agreement = JSON.parse(JSON.stringify(this.agreement)) // copy |
334 |
let agreement = JSON.parse(JSON.stringify(this.agreement)) // copy |
|
|
335 |
let agreement_id = agreement.agreement_id |
329 |
|
336 |
|
330 |
if (!this.checkForm(agreement)) { |
337 |
if (!this.checkForm(agreement)) { |
331 |
return false |
338 |
return false |
332 |
} |
339 |
} |
333 |
|
340 |
|
334 |
let apiUrl = "/api/v1/erm/agreements" |
|
|
335 |
|
336 |
let method = "POST" |
337 |
if (agreement.agreement_id) { |
338 |
method = "PUT" |
339 |
apiUrl += "/" + agreement.agreement_id |
340 |
} |
341 |
delete agreement.agreement_id |
341 |
delete agreement.agreement_id |
342 |
delete agreement.vendor |
342 |
delete agreement.vendor |
343 |
agreement.is_perpetual = agreement.is_perpetual ? true : false |
343 |
agreement.is_perpetual = agreement.is_perpetual ? true : false |
Lines 375-404
export default {
Link Here
|
375 |
|
375 |
|
376 |
delete agreement.agreement_packages |
376 |
delete agreement.agreement_packages |
377 |
|
377 |
|
378 |
const options = { |
378 |
const client = new ERMAPIClient() |
379 |
method: method, |
379 |
;(async () => { |
380 |
body: JSON.stringify(agreement), |
380 |
try { |
381 |
headers: { |
381 |
if (agreement_id) { |
382 |
"Content-Type": "application/json;charset=utf-8", |
382 |
await client.agreements |
383 |
}, |
383 |
.update(agreement, agreement_id) |
384 |
} |
384 |
.then(setMessage(this.$__("Agreement updated"))) |
385 |
|
|
|
386 |
fetch(apiUrl, options) |
387 |
.then(response => checkError(response, 1)) |
388 |
.then(response => { |
389 |
if (response.status == 200) { |
390 |
this.$router.push("/cgi-bin/koha/erm/agreements") |
391 |
setMessage(this.$__("Agreement updated")) |
392 |
} else if (response.status == 201) { |
393 |
this.$router.push("/cgi-bin/koha/erm/agreements") |
394 |
setMessage(this.$__("Agreement created")) |
395 |
} else { |
385 |
} else { |
396 |
setError(response.message || response.statusText) |
386 |
await client.agreements |
|
|
387 |
.create(agreement) |
388 |
.then(setMessage(this.$__("Agreement created"))) |
397 |
} |
389 |
} |
398 |
}) |
390 |
this.$router.push("/cgi-bin/koha/erm/agreements") |
399 |
.catch(error => { |
391 |
} catch (err) { |
400 |
setError(error) |
392 |
setError(err.message || err.statusText) |
401 |
}) |
393 |
} |
|
|
394 |
})() |
402 |
}, |
395 |
}, |
403 |
onStatusChanged(e) { |
396 |
onStatusChanged(e) { |
404 |
if (e.authorised_value != "closed") { |
397 |
if (e.authorised_value != "closed") { |