Bug 32728: Fix warning
[koha.git] / koha-tmpl / intranet-tmpl / prog / js / vue / modules / erm.ts
1 import { createApp } from "vue";
2 import { createWebHistory, createRouter } from "vue-router";
3 import { createPinia } from "pinia";
4
5 import { library } from "@fortawesome/fontawesome-svg-core";
6 import {
7     faPlus,
8     faMinus,
9     faPencil,
10     faTrash,
11     faSpinner,
12 } from "@fortawesome/free-solid-svg-icons";
13 import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
14 import vSelect from "vue-select";
15
16 library.add(faPlus, faMinus, faPencil, faTrash, faSpinner);
17
18 import App from "../components/ERM/Main.vue";
19
20 import { routes } from "../routes/erm";
21
22 const router = createRouter({
23     history: createWebHistory(),
24     linkExactActiveClass: "current",
25     routes,
26 });
27
28 import { useMainStore } from "../stores/main";
29 import { useVendorStore } from "../stores/vendors";
30 import { useAVStore } from "../stores/authorised_values";
31
32 const pinia = createPinia();
33
34 const i18n = {
35     install: (app, options) => {
36         app.config.globalProperties.$__ = (key) => {
37             return window["__"](key);
38         };
39     },
40 };
41
42 const app = createApp(App);
43
44 const rootComponent = app
45     .use(i18n)
46     .use(pinia)
47     .use(router)
48     .component("font-awesome-icon", FontAwesomeIcon)
49     .component("v-select", vSelect);
50
51 app.config.unwrapInjectedRef = true;
52 app.provide("vendorStore", useVendorStore(pinia));
53 const mainStore = useMainStore(pinia);
54 app.provide("mainStore", mainStore);
55 app.provide("AVStore", useAVStore(pinia));
56
57 app.mount("#erm");
58
59 const { removeMessages } = mainStore;
60 router.beforeEach((to, from) => {
61     removeMessages(); // This will actually flag the messages as displayed already
62 });
63 router.afterEach((to, from) => {
64     let tab_id = 1; // Agreements
65     if (to.path.match(/\/erm\/eholdings\/local\/packages/)) {
66         tab_id = 2;
67     } else if (to.path.match(/\/erm\/eholdings\/local\/titles/)) {
68         tab_id = 3;
69     }
70     let node = document.getElementById("ui-id-" + tab_id);
71     if (node) {
72         node.click();
73     }
74 });