View | Details | Raw Unified | Return to bug 37930
Collapse All | Expand All

(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/composables/authorisedValues.js (-3 / +23 lines)
Lines 1-6 Link Here
1
import { APIClient } from "../fetch/api-client.js";
1
import { APIClient } from "../fetch/api-client.js";
2
2
3
export const get_lib_from_av_handler = (arr_name, av, store) => {
3
const get_lib_from_av_handler = (arr_name, av, store) => {
4
    if (store.authorisedValues[arr_name] === undefined) {
4
    if (store.authorisedValues[arr_name] === undefined) {
5
        console.warn(
5
        console.warn(
6
            "The authorised value category for '%s' is not defined.".format(
6
            "The authorised value category for '%s' is not defined.".format(
Lines 12-25 export const get_lib_from_av_handler = (arr_name, av, store) => { Link Here
12
    let o = store.authorisedValues[arr_name].find(e => e.value == av);
12
    let o = store.authorisedValues[arr_name].find(e => e.value == av);
13
    return o ? o.description : av;
13
    return o ? o.description : av;
14
};
14
};
15
export const map_av_dt_filter_handler = (arr_name, store) => {
15
const map_av_dt_filter_handler = (arr_name, store) => {
16
    return store.authorisedValues[arr_name].map(e => {
16
    return store.authorisedValues[arr_name].map(e => {
17
        e["_id"] = e["value"];
17
        e["_id"] = e["value"];
18
        e["_str"] = e["description"];
18
        e["_str"] = e["description"];
19
        return e;
19
        return e;
20
    });
20
    });
21
};
21
};
22
export const loadAuthorisedValues = async (authorisedValues, targetStore) => {
22
const load_authorised_values_handler = async (
23
    authorisedValues,
24
    targetStore
25
) => {
23
    const AVsToFetch = Object.keys(authorisedValues).reduce((acc, avKey) => {
26
    const AVsToFetch = Object.keys(authorisedValues).reduce((acc, avKey) => {
24
        if (Array.isArray(authorisedValues[avKey])) return acc;
27
        if (Array.isArray(authorisedValues[avKey])) return acc;
25
        acc[avKey] = authorisedValues[avKey];
28
        acc[avKey] = authorisedValues[avKey];
Lines 48-50 export const loadAuthorisedValues = async (authorisedValues, targetStore) => { Link Here
48
51
49
    return Promise.all(promises);
52
    return Promise.all(promises);
50
};
53
};
54
55
export function withAuthorisedValueActions(store) {
56
    return {
57
        loadAuthorisedValues(authorisedValues, targetStore) {
58
            return load_authorised_values_handler(
59
                authorisedValues,
60
                targetStore
61
            );
62
        },
63
        get_lib_from_av(arr_name, av) {
64
            return get_lib_from_av_handler(arr_name, av, store);
65
        },
66
        map_av_dt_filter(arr_name) {
67
            return map_av_dt_filter_handler(arr_name, store);
68
        },
69
    };
70
}
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/stores/erm.js (-13 / +3 lines)
Lines 1-9 Link Here
1
import { defineStore } from "pinia";
1
import { defineStore } from "pinia";
2
import {
2
3
    loadAuthorisedValues,
3
import { withAuthorisedValueActions } from "../composables/authorisedValues";
4
    get_lib_from_av_handler,
5
    map_av_dt_filter_handler,
6
} from "../composables/authorisedValues";
7
4
8
export const useERMStore = defineStore("erm", {
5
export const useERMStore = defineStore("erm", {
9
    state: () => ({
6
    state: () => ({
Lines 65-76 export const useERMStore = defineStore("erm", { Link Here
65
        },
62
        },
66
    }),
63
    }),
67
    actions: {
64
    actions: {
68
        loadAuthorisedValues,
65
        ...withAuthorisedValueActions(this),
69
        get_lib_from_av(arr_name, av) {
70
            return get_lib_from_av_handler(arr_name, av, this);
71
        },
72
        map_av_dt_filter(arr_name) {
73
            return map_av_dt_filter_handler(arr_name, this);
74
        },
75
    },
66
    },
76
});
67
});
77
- 

Return to bug 37930