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

(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/LicenseResource.vue (+29 lines)
Line 0 Link Here
1
<script>
2
import BaseResource from "../BaseResource.vue"
3
import { APIClient } from "../../fetch/api-client.js"
4
5
export default {
6
    extends: BaseResource,
7
    setup(props) {
8
        return {
9
            ...BaseResource.setup({
10
                resource_name: "license",
11
                name_attr: "name",
12
                id_attr: "license_id",
13
                show_component: "LicensesShow",
14
                list_component: "LicensesList",
15
                add_component: "LicensesFormAdd",
16
                edit_component: "LicensesFormAddEdit",
17
                api_client: APIClient.erm.licenses,
18
                resource_table_url: APIClient.erm._baseURL + "licenses",
19
                i18n: {
20
                    display_name: __("License"),
21
                },
22
            }),
23
            //LicenseResource specific setup here
24
        }
25
    },
26
    methods: {},
27
    name: "LicenseResource",
28
}
29
</script>
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/LicensesList.vue (-50 / +10 lines)
Lines 3-10 Link Here
3
    <div v-else id="licenses_list">
3
    <div v-else id="licenses_list">
4
        <Toolbar>
4
        <Toolbar>
5
            <ToolbarButton
5
            <ToolbarButton
6
                :to="{ name: 'LicensesFormAdd' }"
6
                action="add"
7
                icon="plus"
7
                @go-to-add-resource="goToResourceAdd"
8
                :title="$__('New license')"
8
                :title="$__('New license')"
9
            />
9
            />
10
        </Toolbar>
10
        </Toolbar>
Lines 12-20 Link Here
12
            <KohaTable
12
            <KohaTable
13
                ref="table"
13
                ref="table"
14
                v-bind="tableOptions"
14
                v-bind="tableOptions"
15
                @show="doShow"
15
                @show="goToResourceShow"
16
                @edit="doEdit"
16
                @edit="goToResourceEdit"
17
                @delete="doDelete"
17
                @delete="doResourceDelete"
18
            ></KohaTable>
18
            ></KohaTable>
19
        </div>
19
        </div>
20
        <div v-else class="alert alert-info">
20
        <div v-else class="alert alert-info">
Lines 30-37 import { inject, ref } from "vue" Link Here
30
import { storeToRefs } from "pinia"
30
import { storeToRefs } from "pinia"
31
import { APIClient } from "../../fetch/api-client.js"
31
import { APIClient } from "../../fetch/api-client.js"
32
import KohaTable from "../KohaTable.vue"
32
import KohaTable from "../KohaTable.vue"
33
import LicenseResource from "./LicenseResource.vue"
33
34
34
export default {
35
export default {
36
    extends: LicenseResource,
35
    setup() {
37
    setup() {
36
        const vendorStore = inject("vendorStore")
38
        const vendorStore = inject("vendorStore")
37
        const { vendors } = storeToRefs(vendorStore)
39
        const { vendors } = storeToRefs(vendorStore)
Lines 39-55 export default { Link Here
39
        const AVStore = inject("AVStore")
41
        const AVStore = inject("AVStore")
40
        const { get_lib_from_av, map_av_dt_filter } = AVStore
42
        const { get_lib_from_av, map_av_dt_filter } = AVStore
41
43
42
        const { setConfirmationDialog, setMessage } = inject("mainStore")
43
44
        const table = ref()
44
        const table = ref()
45
45
46
        return {
46
        return {
47
            ...LicenseResource.setup(),
47
            vendors,
48
            vendors,
48
            get_lib_from_av,
49
            get_lib_from_av,
49
            map_av_dt_filter,
50
            map_av_dt_filter,
50
            table,
51
            table,
51
            setConfirmationDialog,
52
            setMessage,
53
            license_table_settings,
52
            license_table_settings,
54
        }
53
        }
55
    },
54
    },
Lines 66-72 export default { Link Here
66
            ],
65
            ],
67
            tableOptions: {
66
            tableOptions: {
68
                columns: this.getTableColumns(),
67
                columns: this.getTableColumns(),
69
                url: "/api/v1/erm/licenses",
68
                url: this.getResourceTableUrl(),
70
                options: { embed: "vendor" },
69
                options: { embed: "vendor" },
71
                table_settings: this.license_table_settings,
70
                table_settings: this.license_table_settings,
72
                add_filters: true,
71
                add_filters: true,
Lines 102-144 export default { Link Here
102
                error => {}
101
                error => {}
103
            )
102
            )
104
        },
103
        },
105
        doShow: function ({ license_id }, dt, event) {
106
            event.preventDefault()
107
            this.$router.push({ name: "LicensesShow", params: { license_id } })
108
        },
109
        doEdit: function ({ license_id }, dt, event) {
110
            this.$router.push({
111
                name: "LicensesFormAddEdit",
112
                params: { license_id },
113
            })
114
        },
115
        doDelete: function (license, dt, event) {
116
            this.setConfirmationDialog(
117
                {
118
                    title: this.$__(
119
                        "Are you sure you want to remove this license?"
120
                    ),
121
                    message: license.name,
122
                    accept_label: this.$__("Yes, delete"),
123
                    cancel_label: this.$__("No, do not delete"),
124
                },
125
                () => {
126
                    const client = APIClient.erm
127
                    client.licenses.delete(license.license_id).then(
128
                        success => {
129
                            this.setMessage(
130
                                this.$__("License %s deleted").format(
131
                                    license.name
132
                                ),
133
                                true
134
                            )
135
                            dt.draw()
136
                        },
137
                        error => {}
138
                    )
139
                }
140
            )
141
        },
142
        getTableColumns: function () {
104
        getTableColumns: function () {
143
            let get_lib_from_av = this.get_lib_from_av
105
            let get_lib_from_av = this.get_lib_from_av
144
106
Lines 150-158 export default { Link Here
150
                    orderable: true,
112
                    orderable: true,
151
                    render: function (data, type, row, meta) {
113
                    render: function (data, type, row, meta) {
152
                        return (
114
                        return (
153
                            '<a href="/cgi-bin/koha/erm/licenses/' +
115
                            '<a role="button" class="show">' +
154
                            row.license_id +
155
                            '" class="show">' +
156
                            escape_str(`${row.name} (#${row.license_id})`) +
116
                            escape_str(`${row.name} (#${row.license_id})`) +
157
                            "</a>"
117
                            "</a>"
158
                        )
118
                        )
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/LicensesShow.vue (-44 / +9 lines)
Lines 3-21 Link Here
3
    <div v-else id="licenses_show">
3
    <div v-else id="licenses_show">
4
        <Toolbar>
4
        <Toolbar>
5
            <ToolbarButton
5
            <ToolbarButton
6
                :to="{
6
                action="edit"
7
                    name: 'LicensesFormAddEdit',
7
                @go-to-edit-resource="goToResourceEdit"
8
                    params: { license_id: license.license_id },
8
            />
9
                }"
9
            <ToolbarButton
10
                class="btn btn-default"
10
                action="delete"
11
                icon="pencil"
11
                @delete-resource="doResourceDelete"
12
                :title="$__('Edit')"
13
            />
12
            />
14
            <a
15
                @click="delete_license(license.license_id, license.name)"
16
                class="btn btn-default"
17
                ><font-awesome-icon icon="trash" /> {{ $__("Delete") }}</a
18
            >
19
        </Toolbar>
13
        </Toolbar>
20
14
21
        <h2>
15
        <h2>
Lines 153-175 import { inject } from "vue" Link Here
153
import { APIClient } from "../../fetch/api-client.js"
147
import { APIClient } from "../../fetch/api-client.js"
154
import Toolbar from "../Toolbar.vue"
148
import Toolbar from "../Toolbar.vue"
155
import ToolbarButton from "../ToolbarButton.vue"
149
import ToolbarButton from "../ToolbarButton.vue"
150
import LicenseResource from "./LicenseResource.vue"
156
151
157
export default {
152
export default {
153
    extends: LicenseResource,
158
    setup() {
154
    setup() {
159
        const format_date = $date
155
        const format_date = $date
160
        const patron_to_html = $patron_to_html
156
        const patron_to_html = $patron_to_html
161
157
162
        const { setConfirmationDialog, setMessage } = inject("mainStore")
163
164
        const AVStore = inject("AVStore")
158
        const AVStore = inject("AVStore")
165
        const { get_lib_from_av } = AVStore
159
        const { get_lib_from_av } = AVStore
166
160
167
        return {
161
        return {
162
            ...LicenseResource.setup(),
168
            format_date,
163
            format_date,
169
            patron_to_html,
164
            patron_to_html,
170
            get_lib_from_av,
165
            get_lib_from_av,
171
            setConfirmationDialog,
172
            setMessage,
173
        }
166
        }
174
    },
167
    },
175
    data() {
168
    data() {
Lines 205-237 export default { Link Here
205
                error => {}
198
                error => {}
206
            )
199
            )
207
        },
200
        },
208
        delete_license: function (license_id, license_name) {
209
            this.setConfirmationDialog(
210
                {
211
                    title: this.$__(
212
                        "Are you sure you want to remove this license?"
213
                    ),
214
                    message: license_name,
215
                    accept_label: this.$__("Yes, delete"),
216
                    cancel_label: this.$__("No, do not delete"),
217
                },
218
                () => {
219
                    const client = APIClient.erm
220
                    client.licenses.delete(license_id).then(
221
                        success => {
222
                            this.setMessage(
223
                                this.$__("License %s deleted").format(
224
                                    license_name
225
                                ),
226
                                true
227
                            )
228
                            this.$router.push({ name: "LicensesList" })
229
                        },
230
                        error => {}
231
                    )
232
                }
233
            )
234
        },
235
    },
201
    },
236
    components: { Toolbar, ToolbarButton },
202
    components: { Toolbar, ToolbarButton },
237
    name: "LicensesShow",
203
    name: "LicensesShow",
238
- 

Return to bug 37301