Bug 32030: Add lib for agreement's relationships values
[koha.git] / koha-tmpl / intranet-tmpl / prog / js / vue / stores / authorised_values.js
1 import { defineStore } from "pinia";
2
3 export const useAVStore = defineStore("authorised_values", {
4     state: () => ({
5         av_agreement_statuses: [],
6         av_agreement_closure_reasons: [],
7         av_agreement_renewal_priorities: [],
8         av_user_roles: [],
9         av_license_types: [],
10         av_license_statuses: [],
11         av_agreement_license_statuses: [],
12         av_agreement_license_location: [],
13         av_agreement_relationships: [
14             { authorised_value: "supersedes", lib: __("supersedes") },
15             { authorised_value: "is-superseded-by", lib: __("is superseded by") },
16             {
17                 authorised_value: "provides_post-cancellation_access_for",
18                 lib: __("provides post-cancellation access for"),
19             },
20             {
21                 authorised_value: "has-post-cancellation-access-in",
22                 lib: __("has post-cancellation access in"),
23             },
24             {
25                 authorised_value: "tracks_demand-driven_acquisitions_for",
26                 lib: __("tracks demand-driven acquisitions for"),
27             },
28             {
29                 authorised_value: "has-demand-driven-acquisitions-in",
30                 lib: __("has demand-driven acquisitions in"),
31             },
32             { authorised_value: "has_backfile_in", lib: __("has backfile in") },
33             { authorised_value: "has_frontfile_in", lib: __("has frontfile in") },
34             { authorised_value: "related_to", lib: __("related to") },
35         ],
36         av_package_types: [],
37         av_package_content_types: [],
38         av_title_publication_types: [],
39     }),
40     actions: {
41         get_lib_from_av(arr_name, av) {
42             if (this[arr_name] === undefined) {
43                 console.warn(
44                     "The authorised value category for '%s' is not defined.".format(
45                         arr_name
46                     )
47                 );
48                 return;
49             }
50             let o = this[arr_name].find((e) => e.authorised_value == av);
51             return o ? o.lib : av;
52         },
53         map_av_dt_filter(arr_name) {
54             return this[arr_name].map((e) => {
55                 e["_id"] = e["authorised_value"];
56                 e["_str"] = e["lib"];
57                 return e;
58             });
59         },
60     },
61 });