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

(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/components/BaseResource.vue (+67 lines)
Lines 48-53 export default { Link Here
48
                name: this.add_component,
48
                name: this.add_component,
49
            })
49
            })
50
        },
50
        },
51
        /**
52
         * Navigates to the list page of the given resource.
53
         *
54
         * @return {void}
55
         */
56
        goToResourceList: function () {
57
            this.$router.push({
58
                name: this.list_component,
59
            })
60
        },
61
        /**
62
         * Resource deletion handler.
63
         * Accepts an optional callback function to run after deletion.
64
         * If no callback is provided, does the following:
65
         * - If deleting from show component, navigates to resource list component.
66
         * - If deleting from resource list component, redraws the table.
67
         *
68
         * @param {Object} resource - The resource to delete (optional)
69
         * @param {Object} callback - Callback to call after deletion (optional)
70
         * @return {void}
71
         */
72
        doResourceDelete: function (resource, callback) {
73
            let resource_id = resource
74
                ? resource[this.id_attr]
75
                : this[this.resource_name][this.id_attr]
76
            let resource_name = resource
77
                ? resource[this.name_attr]
78
                : this[this.resource_name][this.name_attr]
79
80
            this.setConfirmationDialog(
81
                {
82
                    title: this.$__(
83
                        "Are you sure you want to remove this %s?"
84
                    ).format(this.i18n.display_name.toLowerCase()),
85
                    message: resource_name,
86
                    accept_label: this.$__("Yes, delete"),
87
                    cancel_label: this.$__("No, do not delete"),
88
                },
89
                () => {
90
                    this.api_client.delete(resource_id).then(
91
                        success => {
92
                            this.setMessage(
93
                                this.$__("%s %s deleted").format(
94
                                    this.i18n.display_name,
95
                                    resource_name
96
                                ),
97
                                true
98
                            )
99
                            if (typeof callback === "function") {
100
                                callback()
101
                            } else {
102
                                if (
103
                                    this.$options.name === this.list_component
104
                                ) {
105
                                    this.$refs.table.redraw(this.table_url())
106
                                } else if (
107
                                    this.$options.name === this.show_component
108
                                ) {
109
                                    this.goToResourceList()
110
                                }
111
                            }
112
                        },
113
                        error => {}
114
                    )
115
                }
116
            )
117
        },
51
    },
118
    },
52
    name: "BaseResource",
119
    name: "BaseResource",
53
    props: {
120
    props: {
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementResource.vue (+7 lines)
Lines 1-5 Link Here
1
<script>
1
<script>
2
import BaseResource from "../BaseResource.vue"
2
import BaseResource from "../BaseResource.vue"
3
import { APIClient } from "../../fetch/api-client.js"
3
4
4
export default {
5
export default {
5
    extends: BaseResource,
6
    extends: BaseResource,
Lines 7-16 export default { Link Here
7
        return {
8
        return {
8
            ...BaseResource.setup({
9
            ...BaseResource.setup({
9
                resource_name: "agreement",
10
                resource_name: "agreement",
11
                name_attr: "name",
10
                id_attr: "agreement_id",
12
                id_attr: "agreement_id",
11
                show_component: "AgreementsShow",
13
                show_component: "AgreementsShow",
14
                list_component: "AgreementsList",
12
                add_component: "AgreementsFormAdd",
15
                add_component: "AgreementsFormAdd",
13
                edit_component: "AgreementsFormAddEdit",
16
                edit_component: "AgreementsFormAddEdit",
17
                api_client: APIClient.erm.agreements,
18
                i18n: {
19
                    display_name: __("Agreement"),
20
                },
14
            }),
21
            }),
15
            //AgreementResource specific setup here
22
            //AgreementResource specific setup here
16
        }
23
        }
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsList.vue (-28 / +1 lines)
Lines 45-51 Link Here
45
                v-bind="tableOptions"
45
                v-bind="tableOptions"
46
                @show="goToResourceShow"
46
                @show="goToResourceShow"
47
                @edit="goToResourceEdit"
47
                @edit="goToResourceEdit"
48
                @delete="doDelete"
48
                @delete="doResourceDelete"
49
                @select="doSelect"
49
                @select="doSelect"
50
            ></KohaTable>
50
            ></KohaTable>
51
        </div>
51
        </div>
Lines 173-205 export default { Link Here
173
                error => {}
173
                error => {}
174
            )
174
            )
175
        },
175
        },
176
        doDelete: function (agreement, dt, event) {
177
            this.setConfirmationDialog(
178
                {
179
                    title: this.$__(
180
                        "Are you sure you want to remove this agreement?"
181
                    ),
182
                    message: agreement.name,
183
                    accept_label: this.$__("Yes, delete"),
184
                    cancel_label: this.$__("No, do not delete"),
185
                },
186
                () => {
187
                    const client = APIClient.erm
188
                    client.agreements.delete(agreement.agreement_id).then(
189
                        success => {
190
                            this.setMessage(
191
                                this.$__("Agreement %s deleted").format(
192
                                    agreement.name
193
                                ),
194
                                true
195
                            )
196
                            dt.draw()
197
                        },
198
                        error => {}
199
                    )
200
                }
201
            )
202
        },
203
        doSelect: function (agreement, dt, event) {
176
        doSelect: function (agreement, dt, event) {
204
            this.$emit("select-agreement", agreement.agreement_id)
177
            this.$emit("select-agreement", agreement.agreement_id)
205
            this.$emit("close")
178
            this.$emit("close")
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsShow.vue (-32 / +1 lines)
Lines 8-14 Link Here
8
            />
8
            />
9
            <ToolbarButton
9
            <ToolbarButton
10
                action="delete"
10
                action="delete"
11
                @delete_resource="delete_agreement"
11
                @delete-resource="doResourceDelete"
12
            />
12
            />
13
        </Toolbar>
13
        </Toolbar>
14
14
Lines 388-423 export default { Link Here
388
                error => {}
388
                error => {}
389
            )
389
            )
390
        },
390
        },
391
        delete_agreement: function () {
392
            let agreement_id = this.agreement.agreement_id
393
            let agreement_name = this.agreement.name
394
395
            this.setConfirmationDialog(
396
                {
397
                    title: this.$__(
398
                        "Are you sure you want to remove this agreement?"
399
                    ),
400
                    message: agreement_name,
401
                    accept_label: this.$__("Yes, delete"),
402
                    cancel_label: this.$__("No, do not delete"),
403
                },
404
                () => {
405
                    const client = APIClient.erm
406
                    client.agreements.delete(agreement_id).then(
407
                        success => {
408
                            this.setMessage(
409
                                this.$__("Agreement %s deleted").format(
410
                                    agreement_name
411
                                ),
412
                                true
413
                            )
414
                            this.$router.push({ name: "AgreementsList" })
415
                        },
416
                        error => {}
417
                    )
418
                }
419
            )
420
        },
421
    },
391
    },
422
    components: { Toolbar, ToolbarButton },
392
    components: { Toolbar, ToolbarButton },
423
    name: "AgreementsShow",
393
    name: "AgreementsShow",
424
- 

Return to bug 37301