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 } 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 => { this.agreement = data; this.initialized = true; } ); |
|
|
259 |
} catch (err) { |
260 |
setError(err.message || err.statusText) |
261 |
} |
259 |
}, |
262 |
}, |
260 |
checkForm(agreement) { |
263 |
checkForm(agreement) { |
261 |
let errors = [] |
264 |
let errors = [] |
Lines 326-343
export default {
Link Here
|
326 |
|
329 |
|
327 |
//let agreement= Object.assign( {} ,this.agreement); // copy |
330 |
//let agreement= Object.assign( {} ,this.agreement); // copy |
328 |
let agreement = JSON.parse(JSON.stringify(this.agreement)) // copy |
331 |
let agreement = JSON.parse(JSON.stringify(this.agreement)) // copy |
|
|
332 |
let agreement_id = agreement.agreement_id; |
329 |
|
333 |
|
330 |
if (!this.checkForm(agreement)) { |
334 |
if (!this.checkForm(agreement)) { |
331 |
return false |
335 |
return false |
332 |
} |
336 |
} |
333 |
|
337 |
|
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 |
338 |
delete agreement.agreement_id |
342 |
delete agreement.vendor |
339 |
delete agreement.vendor |
343 |
agreement.is_perpetual = agreement.is_perpetual ? true : false |
340 |
agreement.is_perpetual = agreement.is_perpetual ? true : false |
Lines 375-403
export default {
Link Here
|
375 |
|
372 |
|
376 |
delete agreement.agreement_packages |
373 |
delete agreement.agreement_packages |
377 |
|
374 |
|
378 |
const options = { |
375 |
const client = new ERMAPIClient(); |
379 |
method: method, |
376 |
(async () => { |
380 |
body: JSON.stringify(agreement), |
377 |
try { |
381 |
headers: { |
378 |
if ( agreement_id ) { |
382 |
"Content-Type": "application/json;charset=utf-8", |
379 |
await client.agreements.update(agreement, agreement_id).then(setMessage(this.$__("Agreement updated"))); |
383 |
}, |
380 |
}else{ |
384 |
} |
381 |
await client.agreements.create(agreement).then(setMessage(this.$__("Agreement created"))); |
385 |
|
|
|
386 |
fetch(apiUrl, options) |
387 |
.then(response => { |
388 |
if (response.status == 200) { |
389 |
this.$router.push("/cgi-bin/koha/erm/agreements") |
390 |
setMessage(this.$__("Agreement updated")) |
391 |
} else if (response.status == 201) { |
392 |
this.$router.push("/cgi-bin/koha/erm/agreements") |
393 |
setMessage(this.$__("Agreement created")) |
394 |
} else { |
395 |
setError(response.message || response.statusText) |
396 |
} |
382 |
} |
397 |
}) |
383 |
this.$router.push("/cgi-bin/koha/erm/agreements") |
398 |
.catch(error => { |
384 |
} catch (err) { |
399 |
setError(error) |
385 |
setError(err.message || err.statusText) |
400 |
}) |
386 |
} |
|
|
387 |
})(); |
388 |
|
401 |
}, |
389 |
}, |
402 |
onStatusChanged(e) { |
390 |
onStatusChanged(e) { |
403 |
if (e.authorised_value != "closed") { |
391 |
if (e.authorised_value != "closed") { |