Line 0
Link Here
|
|
|
1 |
<template> |
2 |
<div v-if="!initialized">{{ $__("Loading") }}</div> |
3 |
<div v-else id="record_sources_list"> |
4 |
<Toolbar> |
5 |
<ToolbarButton |
6 |
:to="{ name: 'RecordSourcesFormAdd' }" |
7 |
icon="plus" |
8 |
:title="$__('New record source')" |
9 |
/> |
10 |
</Toolbar> |
11 |
<h1>{{ title }}</h1> |
12 |
<div v-if="record_sources_count > 0" class="page-section"> |
13 |
<KohaTable |
14 |
ref="table" |
15 |
v-bind="tableOptions" |
16 |
@edit="doEdit" |
17 |
@delete="doDelete" |
18 |
></KohaTable> |
19 |
</div> |
20 |
<div v-else class="dialog message"> |
21 |
{{ $__("There are no record sources defined") }} |
22 |
</div> |
23 |
</div> |
24 |
</template> |
25 |
|
26 |
<script> |
27 |
import Toolbar from "../../Toolbar.vue" |
28 |
import ToolbarButton from "../../ToolbarButton.vue" |
29 |
import { inject } from "vue" |
30 |
import { APIClient } from "../../../fetch/api-client.js" |
31 |
import KohaTable from "../../KohaTable.vue" |
32 |
|
33 |
export default { |
34 |
data() { |
35 |
return { |
36 |
title: this.$__("Record sources"), |
37 |
tableOptions: { |
38 |
columns: [ |
39 |
{ |
40 |
title: this.$__("ID"), |
41 |
data: "record_source_id", |
42 |
searchable: true, |
43 |
}, |
44 |
{ |
45 |
title: this.$__("Name"), |
46 |
data: "name", |
47 |
searchable: true, |
48 |
}, |
49 |
{ |
50 |
title: __("Can be edited"), |
51 |
data: "can_be_edited", |
52 |
searchable: true, |
53 |
orderable: true, |
54 |
render: function (data, type, row, meta) { |
55 |
return escape_str( |
56 |
row.can_be_edited ? __("Yes") : __("No") |
57 |
) |
58 |
}, |
59 |
}, |
60 |
], |
61 |
actions: { |
62 |
"-1": ["edit", "delete"], |
63 |
}, |
64 |
url: "/api/v1/record_sources", |
65 |
}, |
66 |
initialized: false, |
67 |
record_sources_count: 0, |
68 |
} |
69 |
}, |
70 |
setup() { |
71 |
const { setWarning, setMessage, setError, setConfirmationDialog } = |
72 |
inject("mainStore") |
73 |
return { |
74 |
setWarning, |
75 |
setMessage, |
76 |
setError, |
77 |
setConfirmationDialog, |
78 |
} |
79 |
}, |
80 |
beforeRouteEnter(to, from, next) { |
81 |
next(vm => { |
82 |
vm.getRecordSourcesCount().then(() => (vm.initialized = true)) |
83 |
}) |
84 |
}, |
85 |
methods: { |
86 |
async getRecordSourcesCount() { |
87 |
const client = APIClient.record_sources |
88 |
await client.record_sources.count().then( |
89 |
count => { |
90 |
this.record_sources_count = count |
91 |
}, |
92 |
error => {} |
93 |
) |
94 |
}, |
95 |
newRecordSource() { |
96 |
this.$router.push({ name: "RecordSourcesFormAdd" }) |
97 |
}, |
98 |
doEdit: function ({ record_source_id }, dt, event) { |
99 |
this.$router.push({ |
100 |
name: "RecordSourcesFormAddEdit", |
101 |
params: { record_source_id }, |
102 |
}) |
103 |
}, |
104 |
doDelete: function (record_source, dt, event) { |
105 |
this.setConfirmationDialog( |
106 |
{ |
107 |
title: this.$__( |
108 |
"Are you sure you want to remove this record source?" |
109 |
), |
110 |
message: record_source.name, |
111 |
accept_label: this.$__("Yes, delete"), |
112 |
cancel_label: this.$__("No, do not delete"), |
113 |
}, |
114 |
() => { |
115 |
const client = APIClient.record_sources |
116 |
client.record_sources |
117 |
.delete(record_source.record_source_id) |
118 |
.then( |
119 |
success => { |
120 |
this.setMessage( |
121 |
this.$__("Record source %s deleted").format( |
122 |
record_source.name |
123 |
), |
124 |
true |
125 |
) |
126 |
dt.draw() |
127 |
}, |
128 |
error => {} |
129 |
) |
130 |
} |
131 |
) |
132 |
}, |
133 |
}, |
134 |
components: { |
135 |
KohaTable, |
136 |
Toolbar, |
137 |
ToolbarButton, |
138 |
}, |
139 |
} |
140 |
</script> |