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 47-53 Link Here
47
                :searchable_av_options="searchable_av_options"
47
                :searchable_av_options="searchable_av_options"
48
                @show="goToResourceShow"
48
                @show="goToResourceShow"
49
                @edit="goToResourceEdit"
49
                @edit="goToResourceEdit"
50
                @delete="doDelete"
50
                @delete="doResourceDelete"
51
                @select="doSelect"
51
                @select="doSelect"
52
            ></KohaTable>
52
            ></KohaTable>
53
        </div>
53
        </div>
Lines 222-254 export default { Link Here
222
                    })
222
                    })
223
                })
223
                })
224
        },
224
        },
225
        doDelete: function (agreement, dt, event) {
226
            this.setConfirmationDialog(
227
                {
228
                    title: this.$__(
229
                        "Are you sure you want to remove this agreement?"
230
                    ),
231
                    message: agreement.name,
232
                    accept_label: this.$__("Yes, delete"),
233
                    cancel_label: this.$__("No, do not delete"),
234
                },
235
                () => {
236
                    const client = APIClient.erm
237
                    client.agreements.delete(agreement.agreement_id).then(
238
                        success => {
239
                            this.setMessage(
240
                                this.$__("Agreement %s deleted").format(
241
                                    agreement.name
242
                                ),
243
                                true
244
                            )
245
                            dt.draw()
246
                        },
247
                        error => {}
248
                    )
249
                }
250
            )
251
        },
252
        doSelect: function (agreement, dt, event) {
225
        doSelect: function (agreement, dt, event) {
253
            this.$emit("select-agreement", agreement.agreement_id)
226
            this.$emit("select-agreement", agreement.agreement_id)
254
            this.$emit("close")
227
            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 398-433 export default { Link Here
398
                error => {}
398
                error => {}
399
            )
399
            )
400
        },
400
        },
401
        delete_agreement: function () {
402
            let agreement_id = this.agreement.agreement_id
403
            let agreement_name = this.agreement.name
404
405
            this.setConfirmationDialog(
406
                {
407
                    title: this.$__(
408
                        "Are you sure you want to remove this agreement?"
409
                    ),
410
                    message: agreement_name,
411
                    accept_label: this.$__("Yes, delete"),
412
                    cancel_label: this.$__("No, do not delete"),
413
                },
414
                () => {
415
                    const client = APIClient.erm
416
                    client.agreements.delete(agreement_id).then(
417
                        success => {
418
                            this.setMessage(
419
                                this.$__("Agreement %s deleted").format(
420
                                    agreement_name
421
                                ),
422
                                true
423
                            )
424
                            this.$router.push({ name: "AgreementsList" })
425
                        },
426
                        error => {}
427
                    )
428
                }
429
            )
430
        },
431
    },
401
    },
432
    components: { Toolbar, ToolbarButton, AdditionalFieldsDisplay },
402
    components: { Toolbar, ToolbarButton, AdditionalFieldsDisplay },
433
    name: "AgreementsShow",
403
    name: "AgreementsShow",
434
- 

Return to bug 37301