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

(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementLicenses.vue (-2 / +10 lines)
Lines 101-107 Link Here
101
</template>
101
</template>
102
102
103
<script>
103
<script>
104
import { fetchLicenses } from "../../fetch/erm.js"
104
import { APIClient } from "../../fetch/api-client.js"
105
105
export default {
106
export default {
106
    name: "AgreementLicenses",
107
    name: "AgreementLicenses",
107
    data() {
108
    data() {
Lines 115-121 export default { Link Here
115
        agreement_licenses: Array,
116
        agreement_licenses: Array,
116
    },
117
    },
117
    beforeCreate() {
118
    beforeCreate() {
118
        fetchLicenses().then(licenses => (this.licenses = licenses))
119
        const client = APIClient.erm
120
        client.licenses.getAll.then(
121
            licenses => {
122
                this.licenses = licenses
123
                this.initialized = true
124
            },
125
            error => {}
126
        )
119
    },
127
    },
120
    methods: {
128
    methods: {
121
        addLicense() {
129
        addLicense() {
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/LicensesFormAdd.vue (-32 / +24 lines)
Lines 149-156 import { inject } from "vue" Link Here
149
import flatPickr from "vue-flatpickr-component"
149
import flatPickr from "vue-flatpickr-component"
150
import UserRoles from "./UserRoles.vue"
150
import UserRoles from "./UserRoles.vue"
151
import Documents from "./Documents.vue"
151
import Documents from "./Documents.vue"
152
import { setMessage, setError, setWarning } from "../../messages"
152
import { setMessage, setWarning } from "../../messages"
153
import { fetchLicense, checkError } from "../../fetch/erm.js"
153
import { APIClient } from "../../fetch/api-client.js"
154
import { storeToRefs } from "pinia"
154
import { storeToRefs } from "pinia"
155
155
156
export default {
156
export default {
Lines 199-207 export default { Link Here
199
    },
199
    },
200
    methods: {
200
    methods: {
201
        async getLicense(license_id) {
201
        async getLicense(license_id) {
202
            const license = await fetchLicense(license_id)
202
            const client = APIClient.erm
203
            this.license = license
203
            client.licenses.get(license_id).then(license => {
204
            this.initialized = true
204
                this.license = license
205
                this.initialized = true
206
            })
205
        },
207
        },
206
        checkForm(license) {
208
        checkForm(license) {
207
            let errors = []
209
            let errors = []
Lines 229-234 export default { Link Here
229
            e.preventDefault()
231
            e.preventDefault()
230
232
231
            let license = JSON.parse(JSON.stringify(this.license)) // copy
233
            let license = JSON.parse(JSON.stringify(this.license)) // copy
234
            let license_id = license.license_id
232
235
233
            if (!this.checkForm(license)) {
236
            if (!this.checkForm(license)) {
234
                return false
237
                return false
Lines 256-290 export default { Link Here
256
                ({ file_type, uploaded_on, ...keepAttrs }) => keepAttrs
259
                ({ file_type, uploaded_on, ...keepAttrs }) => keepAttrs
257
            )
260
            )
258
261
259
            const options = {
262
            const client = APIClient.erm
260
                method: method,
263
            if (license_id) {
261
                body: JSON.stringify(license),
264
                client.licenses.update(license, license_id).then(
262
                headers: {
265
                    success => {
263
                    "Content-Type": "application/json;charset=utf-8",
266
                        setMessage(this.$__("License updated"))
264
                },
267
                        this.$router.push("/cgi-bin/koha/erm/licenses")
265
            }
266
267
            fetch(apiUrl, options)
268
                .then(response => checkError(response, 1))
269
                .then(
270
                    response => {
271
                        if (response.status == 200) {
272
                            this.$router.push("/cgi-bin/koha/erm/licenses")
273
                            setMessage(this.$__("License updated"))
274
                        } else if (response.status == 201) {
275
                            this.$router.push("/cgi-bin/koha/erm/licenses")
276
                            setMessage(this.$__("License created"))
277
                        } else {
278
                            setError(response.message || response.statusText)
279
                        }
280
                    },
268
                    },
281
                    error => {
269
                    error => {}
282
                        setError(error)
283
                    }
284
                )
270
                )
285
                .catch(e => {
271
            } else {
286
                    console.log(e)
272
                client.licenses.create(license).then(
287
                })
273
                    success => {
274
                        setMessage(this.$__("License created"))
275
                        this.$router.push("/cgi-bin/koha/erm/licenses")
276
                    },
277
                    error => {}
278
                )
279
            }
288
        },
280
        },
289
    },
281
    },
290
    components: {
282
    components: {
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/LicensesFormConfirmDelete.vue (-26 / +14 lines)
Lines 35-42 Link Here
35
</template>
35
</template>
36
36
37
<script>
37
<script>
38
import { fetchLicense, checkError } from "../../fetch/erm.js"
38
import { APIClient } from "../../fetch/api-client.js"
39
import { setMessage, setError } from "../../messages"
39
import { setMessage } from "../../messages"
40
40
41
export default {
41
export default {
42
    data() {
42
    data() {
Lines 53-87 export default { Link Here
53
    },
53
    },
54
    methods: {
54
    methods: {
55
        async getLicense(license_id) {
55
        async getLicense(license_id) {
56
            const license = await fetchLicense(license_id)
56
            const client = APIClient.erm
57
            this.license = license
57
            client.licenses.get(license_id).then(data => {
58
            this.initialized = true
58
                this.license = data
59
                this.initialized = true
60
            })
59
        },
61
        },
60
        onSubmit(e) {
62
        onSubmit(e) {
61
            e.preventDefault()
63
            e.preventDefault()
62
64
63
            let apiUrl = "/api/v1/erm/licenses/" + this.license.license_id
65
            const client = APIClient.erm
64
66
            client.licenses.delete(this.license.license_id).then(
65
            const options = {
67
                success => {
66
                method: "DELETE",
68
                    setMessage(this.$__("License deleted"))
67
                headers: {
69
                    this.$router.push("/cgi-bin/koha/erm/licenses")
68
                    "Content-Type": "application/json;charset=utf-8",
69
                },
70
                },
70
            }
71
                error => {}
71
72
            )
72
            fetch(apiUrl, options)
73
                .then(response => checkError(response, 1))
74
                .then(response => {
75
                    if (response.status == 204) {
76
                        this.$router.push("/cgi-bin/koha/erm/licenses")
77
                        setMessage(this.$__("License deleted"))
78
                    } else {
79
                        setError(response.message || response.statusText)
80
                    }
81
                })
82
                .catch(error => {
83
                    setError(error)
84
                })
85
        },
73
        },
86
    },
74
    },
87
    name: "LicensesFormConfirmDelete",
75
    name: "LicensesFormConfirmDelete",
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/LicensesList.vue (-4 / +9 lines)
Lines 15-21 Link Here
15
import Toolbar from "./LicensesToolbar.vue"
15
import Toolbar from "./LicensesToolbar.vue"
16
import { inject, createVNode, render } from "vue"
16
import { inject, createVNode, render } from "vue"
17
import { storeToRefs } from "pinia"
17
import { storeToRefs } from "pinia"
18
import { fetchLicenses } from "../../fetch/erm.js"
18
import { APIClient } from "../../fetch/api-client.js"
19
import { useDataTable } from "../../composables/datatables"
19
import { useDataTable } from "../../composables/datatables"
20
20
21
export default {
21
export default {
Lines 49-57 export default { Link Here
49
    },
49
    },
50
    methods: {
50
    methods: {
51
        async getLicenses() {
51
        async getLicenses() {
52
            const licenses = await fetchLicenses()
52
            const client = APIClient.erm
53
            this.licenses = licenses
53
            await client.licenses.getAll().then(
54
            this.initialized = true
54
                licenses => {
55
                    this.licenses = licenses
56
                    this.initialized = true
57
                },
58
                error => {}
59
            )
55
        },
60
        },
56
        show_license: function (license_id) {
61
        show_license: function (license_id) {
57
            this.$router.push("/cgi-bin/koha/erm/licenses/" + license_id)
62
            this.$router.push("/cgi-bin/koha/erm/licenses/" + license_id)
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/LicensesShow.vue (-4 / +9 lines)
Lines 145-151 Link Here
145
145
146
<script>
146
<script>
147
import { inject } from "vue"
147
import { inject } from "vue"
148
import { fetchLicense } from "../../fetch/erm.js"
148
import { APIClient } from "../../fetch/api-client.js"
149
149
150
export default {
150
export default {
151
    setup() {
151
    setup() {
Lines 185-193 export default { Link Here
185
    },
185
    },
186
    methods: {
186
    methods: {
187
        async getLicense(license_id) {
187
        async getLicense(license_id) {
188
            const license = await fetchLicense(license_id)
188
            const client = APIClient.erm
189
            this.license = license
189
            client.licenses.get(license_id).then(
190
            this.initialized = true
190
                license => {
191
                    this.license = license
192
                    this.initialized = true
193
                },
194
                error => {}
195
            )
191
        },
196
        },
192
    },
197
    },
193
    components: {},
198
    components: {},
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/erm-api-client.js (+34 lines)
Lines 38-43 export class ERMAPIClient extends HttpClient { Link Here
38
            //count: () => this.count("agreements"), //TODO: Implement count method
38
            //count: () => this.count("agreements"), //TODO: Implement count method
39
        };
39
        };
40
    }
40
    }
41
42
    get licenses() {
43
        return {
44
            get: (id) =>
45
                this.get({
46
                    endpoint: "licenses/" + id,
47
                    headers: {
48
                        "x-koha-embed":
49
                        "user_roles,user_roles.patron,vendor,documents"
50
                    },
51
                }),
52
            getAll: (query) =>
53
                this.get({
54
                    endpoint: "licenses?" + (query || "_per_page=-1"),
55
                    headers: {
56
                        "x-koha-embed": "vendor.name",
57
                    },
58
                }),
59
            delete: (id) =>
60
                this.delete({
61
                    endpoint: "licenses/" + id,
62
                }),
63
            create: (license) =>
64
                this.post({
65
                    endpoint: "licenses",
66
                    body: license,
67
                }),
68
            update: (license, id) =>
69
                this.put({
70
                    endpoint: "licenses/" + id,
71
                    body: license,
72
                }),
73
        };
74
    }
41
}
75
}
42
76
43
export default ERMAPIClient;
77
export default ERMAPIClient;
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/erm.js (-20 lines)
Lines 2-26 import { setError } from "../messages"; Link Here
2
2
3
//TODO: all of these functions should be deleted and reimplemented in the components using ERMAPIClient
3
//TODO: all of these functions should be deleted and reimplemented in the components using ERMAPIClient
4
4
5
export const fetchLicense = function (license_id) {
6
    if (!license_id) return;
7
    const apiUrl = "/api/v1/erm/licenses/" + license_id;
8
    return myFetch(apiUrl, {
9
        headers: {
10
            "x-koha-embed": "user_roles,user_roles.patron,vendor,documents",
11
        },
12
    });
13
};
14
15
export const fetchLicenses = function () {
16
    const apiUrl = "/api/v1/erm/licenses?_per_page=-1";
17
    return myFetch(apiUrl, {
18
        headers: {
19
            "x-koha-embed": "vendor.name",
20
        },
21
    });
22
};
23
24
export const fetchPatron = function (patron_id) {
5
export const fetchPatron = function (patron_id) {
25
    if (!patron_id) return;
6
    if (!patron_id) return;
26
    const apiUrl = "/api/v1/patrons/" + patron_id;
7
    const apiUrl = "/api/v1/patrons/" + patron_id;
27
- 

Return to bug 32939