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

(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/components/Preservation/TrainResource.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: "train",
11
                name_attr: "name",
12
                id_attr: "train_id",
13
                show_component: "TrainsShow",
14
                list_component: "TrainsList",
15
                add_component: "TrainsFormAdd",
16
                edit_component: "TrainsFormAddEdit",
17
                api_client: APIClient.preservation.trains,
18
                resource_table_url: APIClient.preservation._baseURL + "trains",
19
                i18n: {
20
                    display_name: __("Train"),
21
                },
22
            }),
23
            //TrainResource specific setup here
24
        }
25
    },
26
    methods: {},
27
    name: "TrainResource",
28
}
29
</script>
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/components/Preservation/TrainsList.vue (-51 / +15 lines)
Lines 3-10 Link Here
3
    <div v-else id="trains_list">
3
    <div v-else id="trains_list">
4
        <Toolbar>
4
        <Toolbar>
5
            <ToolbarButton
5
            <ToolbarButton
6
                :to="{ name: 'TrainsFormAdd' }"
6
                action="add"
7
                icon="plus"
7
                @go-to-add-resource="goToResourceAdd"
8
                :title="$__('New train')"
8
                :title="$__('New train')"
9
            />
9
            />
10
        </Toolbar>
10
        </Toolbar>
Lines 45-53 Link Here
45
            <KohaTable
45
            <KohaTable
46
                ref="table"
46
                ref="table"
47
                v-bind="tableOptions"
47
                v-bind="tableOptions"
48
                @show="doShow"
48
                @show="goToResourceShow"
49
                @edit="doEdit"
49
                @edit="goToResourceEdit"
50
                @delete="doDelete"
50
                @delete="doResourceDelete"
51
                @addItems="doAddItems"
51
                @addItems="doAddItems"
52
            ></KohaTable>
52
            ></KohaTable>
53
        </div>
53
        </div>
Lines 66-86 import { inject, ref, reactive } from "vue" Link Here
66
import { APIClient } from "../../fetch/api-client"
66
import { APIClient } from "../../fetch/api-client"
67
import { build_url } from "../../composables/datatables"
67
import { build_url } from "../../composables/datatables"
68
import KohaTable from "../KohaTable.vue"
68
import KohaTable from "../KohaTable.vue"
69
import TrainResource from "./TrainResource.vue"
69
70
70
export default {
71
export default {
72
    extends: TrainResource,
71
    setup() {
73
    setup() {
72
        const AVStore = inject("AVStore")
74
        const AVStore = inject("AVStore")
73
        const { get_lib_from_av, map_av_dt_filter } = AVStore
75
        const { get_lib_from_av, map_av_dt_filter } = AVStore
74
        const { setConfirmationDialog, setMessage, setWarning } =
75
            inject("mainStore")
76
        const table = ref()
76
        const table = ref()
77
        const filters = reactive({ status: "" })
77
        const filters = reactive({ status: "" })
78
        return {
78
        return {
79
            ...TrainResource.setup(),
79
            get_lib_from_av,
80
            get_lib_from_av,
80
            map_av_dt_filter,
81
            map_av_dt_filter,
81
            setConfirmationDialog,
82
            escape_str,
82
            setMessage,
83
            setWarning,
84
            table,
83
            table,
85
            filters,
84
            filters,
86
        }
85
        }
Lines 136-179 export default { Link Here
136
                error => {}
135
                error => {}
137
            )
136
            )
138
        },
137
        },
139
        doShow: function (train, dt, event) {
140
            event.preventDefault()
141
            this.$router.push({
142
                name: "TrainsShow",
143
                params: { train_id: train.train_id },
144
            })
145
        },
146
        doEdit: function (train, dt, event) {
147
            this.$router.push({
148
                name: "TrainsFormEdit",
149
                params: { train_id: train.train_id },
150
            })
151
        },
152
        doDelete: function (train, dt, event) {
153
            this.setConfirmationDialog(
154
                {
155
                    title: this.$__(
156
                        "Are you sure you want to remove this train?"
157
                    ),
158
                    message: train.name,
159
                    accept_label: this.$__("Yes, delete"),
160
                    cancel_label: this.$__("No, do not delete"),
161
                },
162
                () => {
163
                    const client = APIClient.preservation
164
                    client.trains.delete(train.train_id).then(
165
                        success => {
166
                            this.setMessage(
167
                                this.$__("Train %s deleted").format(train.name),
168
                                true
169
                            )
170
                            dt.draw()
171
                        },
172
                        error => {}
173
                    )
174
                }
175
            )
176
        },
177
        doAddItems: function (train, dt, event) {
138
        doAddItems: function (train, dt, event) {
178
            if (train.closed_on != null) {
139
            if (train.closed_on != null) {
179
                this.setWarning(this.$__("Cannot add items to a closed train"))
140
                this.setWarning(this.$__("Cannot add items to a closed train"))
Lines 185-191 export default { Link Here
185
            }
146
            }
186
        },
147
        },
187
        table_url() {
148
        table_url() {
188
            let url = "/api/v1/preservation/trains"
149
            let url = this.getResourceTableUrl()
189
            let q
150
            let q
190
            if (this.filters.status == "closed") {
151
            if (this.filters.status == "closed") {
191
                q = {
152
                q = {
Lines 231-237 export default { Link Here
231
                    searchable: true,
192
                    searchable: true,
232
                    orderable: true,
193
                    orderable: true,
233
                    render: function (data, type, row, meta) {
194
                    render: function (data, type, row, meta) {
234
                        return `<a href="/cgi-bin/koha/preservation/trains/${row.train_id}" class="show">${row.name} (#${row.train_id})</a>`
195
                        return (
196
                            '<a role="button" class="show">' +
197
                            escape_str(`${row.name} (#${row.train_id})`)
198
                        )
235
                    },
199
                    },
236
                },
200
                },
237
                {
201
                {
Lines 274-280 export default { Link Here
274
        },
238
        },
275
    },
239
    },
276
    components: { flatPickr, Toolbar, ToolbarButton, KohaTable },
240
    components: { flatPickr, Toolbar, ToolbarButton, KohaTable },
277
    name: "trainsList",
241
    name: "TrainsList",
278
    emits: ["select-train", "close"],
242
    emits: ["select-train", "close"],
279
}
243
}
280
</script>
244
</script>
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/components/Preservation/TrainsShow.vue (-41 / +9 lines)
Lines 92-108 Link Here
92
                <font-awesome-icon icon="plus" /> {{ $__("Add items") }}
92
                <font-awesome-icon icon="plus" /> {{ $__("Add items") }}
93
            </span>
93
            </span>
94
            <ToolbarButton
94
            <ToolbarButton
95
                :to="{
95
                action="edit"
96
                    name: 'TrainsFormEdit',
96
                @go-to-edit-resource="goToResourceEdit"
97
                    params: { train_id: train.train_id },
97
            />
98
                }"
98
            <ToolbarButton
99
                class="btn btn-default"
99
                action="delete"
100
                icon="pencil"
100
                @delete-resource="doResourceDelete"
101
                :title="$__('Edit')"
102
            />
101
            />
103
            <a @click="deleteTrain(train)" class="btn btn-default"
104
                ><font-awesome-icon icon="trash" /> {{ $__("Delete") }}</a
105
            >
106
            <a
102
            <a
107
                v-if="!train.closed_on"
103
                v-if="!train.closed_on"
108
                class="btn btn-default"
104
                class="btn btn-default"
Lines 288-314 import { APIClient } from "../../fetch/api-client" Link Here
288
import { useDataTable } from "../../composables/datatables"
284
import { useDataTable } from "../../composables/datatables"
289
import Toolbar from "../Toolbar.vue"
285
import Toolbar from "../Toolbar.vue"
290
import ToolbarButton from "../ToolbarButton.vue"
286
import ToolbarButton from "../ToolbarButton.vue"
287
import TrainResource from "./TrainResource.vue"
291
288
292
export default {
289
export default {
290
    extends: TrainResource,
293
    setup() {
291
    setup() {
294
        const format_date = $date
292
        const format_date = $date
295
293
296
        const AVStore = inject("AVStore")
294
        const AVStore = inject("AVStore")
297
        const { get_lib_from_av } = AVStore
295
        const { get_lib_from_av } = AVStore
298
296
299
        const { setConfirmationDialog, setMessage, setWarning } =
300
            inject("mainStore")
301
302
        const table_id = "item_list"
297
        const table_id = "item_list"
303
        useDataTable(table_id)
298
        useDataTable(table_id)
304
299
305
        return {
300
        return {
301
            ...TrainResource.setup(),
306
            format_date,
302
            format_date,
307
            get_lib_from_av,
303
            get_lib_from_av,
308
            table_id,
304
            table_id,
309
            setConfirmationDialog,
310
            setMessage,
311
            setWarning,
312
        }
305
        }
313
    },
306
    },
314
    data() {
307
    data() {
Lines 419-449 export default { Link Here
419
                error => {}
412
                error => {}
420
            )
413
            )
421
        },
414
        },
422
        deleteTrain: function (train) {
423
            this.setConfirmationDialog(
424
                {
425
                    title: this.$__(
426
                        "Are you sure you want to remove this train?"
427
                    ),
428
                    message: train.name,
429
                    accept_label: this.$__("Yes, delete"),
430
                    cancel_label: this.$__("No, do not delete"),
431
                },
432
                () => {
433
                    const client = APIClient.preservation
434
                    client.trains.delete(train.train_id).then(
435
                        success => {
436
                            this.setMessage(
437
                                this.$__("Train %s deleted").format(train.name),
438
                                true
439
                            )
440
                            this.$router.push({ name: "TrainsList" })
441
                        },
442
                        error => {}
443
                    )
444
                }
445
            )
446
        },
447
        async updateTrainDate(attribute) {
415
        async updateTrainDate(attribute) {
448
            let train = JSON.parse(JSON.stringify(this.train))
416
            let train = JSON.parse(JSON.stringify(this.train))
449
            let train_id = train.train_id
417
            let train_id = train.train_id
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/routes/preservation.js (-2 / +1 lines)
Lines 89-95 export const routes = [ Link Here
89
                    },
89
                    },
90
                    {
90
                    {
91
                        path: "edit/:train_id",
91
                        path: "edit/:train_id",
92
                        name: "TrainsFormEdit",
92
                        name: "TrainsFormAddEdit",
93
                        component: markRaw(TrainsFormAdd),
93
                        component: markRaw(TrainsFormAdd),
94
                        title: $__("Edit train"),
94
                        title: $__("Edit train"),
95
                    },
95
                    },
96
- 

Return to bug 37301