From 2950523e0822e3c0e4feff87de9729b1a90e05a1 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 20 Jul 2022 10:50:47 +0200 Subject: [PATCH] Bug 32030: Unique - Prevent same package for local titles Signed-off-by: Jonathan Field Signed-off-by: Martin Renvoize Signed-off-by: Kyle M Hall Signed-off-by: Tomas Cohen Arazi --- .../ERM/EHoldingsLocalTitlesFormAdd.vue | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalTitlesFormAdd.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalTitlesFormAdd.vue index 0fdb5cbdab..1a9d5ffd9e 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalTitlesFormAdd.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalTitlesFormAdd.vue @@ -394,7 +394,7 @@ import { useVendorStore } from "../../stores/vendors" import { useAVStore } from "../../stores/authorised_values" import EHoldingsTitlesFormAddResources from "./EHoldingsLocalTitlesFormAddResources.vue" -import { setMessage, setError } from "../../messages" +import { setMessage, setError, setWarning } from "../../messages" import { fetchLocalTitle } from '../../fetch' import { storeToRefs } from "pinia" @@ -462,10 +462,30 @@ export default { this.title = title this.initialized = true }, + checkForm(title) { + let errors = [] + + let resources = title.resources + const package_ids = resources.map(al => al.package_id) + const duplicate_package_ids = package_ids.filter((id, i) => package_ids.indexOf(id) !== i) + + if (duplicate_package_ids.length) { + errors.push(this.$t("A package is used several times")) + } + + errors.forEach(function (e) { + setWarning(e) + }) + return !errors.length + }, onSubmit(e) { e.preventDefault() let title = JSON.parse(JSON.stringify(this.title)) // copy + + if (!this.checkForm(title)) { + return false + } let apiUrl = '/api/v1/erm/eholdings/local/titles' let method = 'POST' -- 2.39.5