Line 0
Link Here
|
|
|
1 |
<template> |
2 |
<div v-if="!initialized">{{ $__("Loading") }}</div> |
3 |
<div v-else id="vendors_list"> |
4 |
<Toolbar> |
5 |
<ToolbarButton |
6 |
:to="{ name: 'VendorList' }" |
7 |
icon="plus" |
8 |
:title="$__('New vendor')" |
9 |
/> |
10 |
</Toolbar> |
11 |
<div v-if="vendor_count > 0" class="page-section"> |
12 |
<KohaTable |
13 |
ref="table" |
14 |
v-bind="tableOptions" |
15 |
@show="doShow" |
16 |
@edit="doEdit" |
17 |
@delete="doDelete" |
18 |
@select="doSelect" |
19 |
></KohaTable> |
20 |
</div> |
21 |
<div v-else class="alert alert-info"> |
22 |
{{ $__("There are no vendors defined") }} |
23 |
</div> |
24 |
</div> |
25 |
</template> |
26 |
|
27 |
<script> |
28 |
import flatPickr from "vue-flatpickr-component" |
29 |
import Toolbar from "../Toolbar.vue" |
30 |
import ToolbarButton from "../ToolbarButton.vue" |
31 |
import { inject, ref, reactive } from "vue" |
32 |
import { APIClient } from "../../fetch/api-client.js" |
33 |
import { storeToRefs } from "pinia" |
34 |
import { build_url } from "../../composables/datatables" |
35 |
import KohaTable from "../KohaTable.vue" |
36 |
|
37 |
export default { |
38 |
setup() { |
39 |
const vendorStore = inject("vendorStore") |
40 |
const { vendors } = storeToRefs(vendorStore) |
41 |
|
42 |
const { setConfirmationDialog, setMessage } = inject("mainStore") |
43 |
|
44 |
const { get_lib_from_av, map_av_dt_filter } = inject("AVStore") |
45 |
|
46 |
const table = ref() |
47 |
|
48 |
// const filters = reactive({ |
49 |
// by_expired: false, |
50 |
// max_expiration_date: "", |
51 |
// by_mine: false, |
52 |
// }) |
53 |
return { |
54 |
vendors, |
55 |
get_lib_from_av, |
56 |
map_av_dt_filter, |
57 |
table, |
58 |
setConfirmationDialog, |
59 |
setMessage, |
60 |
escape_str, |
61 |
// filters, |
62 |
} |
63 |
}, |
64 |
data() { |
65 |
return { |
66 |
fp_config: flatpickr_defaults, |
67 |
vendor_count: 0, |
68 |
initialized: false, |
69 |
tableOptions: { |
70 |
columns: this.getTableColumns(), |
71 |
options: { embed: "aliases,baskets,subscriptions" }, |
72 |
url: () => this.table_url(), |
73 |
add_filters: true, |
74 |
filters_options: { |
75 |
1: [ |
76 |
{ _id: 0, _str: this.$__("Inactive") }, |
77 |
{ _id: 1, _str: this.$__("Active") }, |
78 |
], |
79 |
...(this.map_av_dt_filter("av_vendor_types").length && { |
80 |
2: () => this.map_av_dt_filter("av_vendor_types"), |
81 |
}), |
82 |
}, |
83 |
actions: { |
84 |
0: ["show"], |
85 |
"-1": ["edit", "delete"], |
86 |
}, |
87 |
}, |
88 |
before_route_entered: false, |
89 |
building_table: false, |
90 |
} |
91 |
}, |
92 |
beforeRouteEnter(to, from, next) { |
93 |
next(vm => { |
94 |
vm.getVendorCount().then(() => (vm.initialized = true)) |
95 |
}) |
96 |
}, |
97 |
methods: { |
98 |
async getVendorCount() { |
99 |
const client = APIClient.acquisition |
100 |
await client.vendors.count().then( |
101 |
count => { |
102 |
this.vendor_count = count |
103 |
}, |
104 |
error => {} |
105 |
) |
106 |
}, |
107 |
doShow: function ({ id }, dt, event) { |
108 |
event.preventDefault() |
109 |
this.$router.push({ |
110 |
name: "VendorShow", |
111 |
params: { vendor_id: id }, |
112 |
}) |
113 |
}, |
114 |
doEdit: function ({ id }, dt, event) { |
115 |
this.$router.push({ |
116 |
name: "Home", |
117 |
}) |
118 |
}, |
119 |
doDelete: function (vendor, dt, event) { |
120 |
this.setConfirmationDialog( |
121 |
{ |
122 |
title: this.$__( |
123 |
"Are you sure you want to remove this vendor?" |
124 |
), |
125 |
message: vendor.name, |
126 |
accept_label: this.$__("Yes, delete"), |
127 |
cancel_label: this.$__("No, do not delete"), |
128 |
}, |
129 |
() => { |
130 |
const client = APIClient.erm |
131 |
client.vendors.delete(vendor.id).then( |
132 |
success => { |
133 |
this.setMessage( |
134 |
this.$__("Vendor %s deleted").format( |
135 |
vendor.name |
136 |
), |
137 |
true |
138 |
) |
139 |
dt.draw() |
140 |
}, |
141 |
error => {} |
142 |
) |
143 |
} |
144 |
) |
145 |
}, |
146 |
doSelect: function (vendor, dt, event) { |
147 |
this.$emit("select-vendor", vendor.id) |
148 |
this.$emit("close") |
149 |
}, |
150 |
table_url: function () { |
151 |
let url = "/api/v1/acquisitions/vendors" |
152 |
return url |
153 |
}, |
154 |
getTableColumns: function () { |
155 |
const escape_str = this.escape_str |
156 |
const get_lib_from_av = this.get_lib_from_av |
157 |
|
158 |
return [ |
159 |
{ |
160 |
title: __("Name"), |
161 |
data: "me.name:me.id", |
162 |
searchable: true, |
163 |
orderable: true, |
164 |
render: function (data, type, row, meta) { |
165 |
return ( |
166 |
'<a href="/cgi-bin/koha/vendors/' + |
167 |
row.id + |
168 |
'" class="show">' + |
169 |
escape_str(`${row.name} (#${row.id})`) + |
170 |
"</a>" |
171 |
) |
172 |
}, |
173 |
}, |
174 |
{ |
175 |
title: __("Status"), |
176 |
data: "active", |
177 |
searchable: true, |
178 |
orderable: true, |
179 |
render: function (data, type, row, meta) { |
180 |
return escape_str( |
181 |
row.active ? __("Active") : __("Inactive") |
182 |
) |
183 |
}, |
184 |
}, |
185 |
{ |
186 |
title: __("Type"), |
187 |
data: "type", |
188 |
searchable: true, |
189 |
orderable: true, |
190 |
render(data, type, row, meta) { |
191 |
return get_lib_from_av("av_vendor_types", row.type) |
192 |
}, |
193 |
}, |
194 |
{ |
195 |
title: __("Currency"), |
196 |
data: "invoice_currency", |
197 |
searchable: true, |
198 |
orderable: true, |
199 |
}, |
200 |
{ |
201 |
title: __("Baskets"), |
202 |
data: "baskets", |
203 |
searchable: false, |
204 |
orderable: true, |
205 |
render: function (data, type, row, meta) { |
206 |
return row.baskets.length |
207 |
? '<a href="/cgi-bin/koha/vendors/' + |
208 |
row.id + |
209 |
'" class="show">' + |
210 |
escape_str( |
211 |
`${row.baskets.length} basket(s)` |
212 |
) + |
213 |
"</a>" |
214 |
: escape_str(__("No baskets")) |
215 |
}, |
216 |
}, |
217 |
{ |
218 |
title: __("Subscriptions"), |
219 |
data: "subscriptions", |
220 |
searchable: false, |
221 |
orderable: true, |
222 |
render: function (data, type, row, meta) { |
223 |
return row.subscriptions.length |
224 |
? '<a href="/cgi-bin/koha/serials/serials-search.pl?bookseller_filter=' + |
225 |
row.name + |
226 |
"&searched=1" + |
227 |
'" class="show">' + |
228 |
escape_str( |
229 |
`${row.subscriptions.length} subscription(s)` |
230 |
) + |
231 |
"</a>" |
232 |
: escape_str(__("No subscriptions")) |
233 |
}, |
234 |
}, |
235 |
] |
236 |
}, |
237 |
}, |
238 |
components: { flatPickr, Toolbar, ToolbarButton, KohaTable }, |
239 |
name: "VendorList", |
240 |
emits: ["select-vendor", "close"], |
241 |
} |
242 |
</script> |
243 |
|
244 |
<style scoped> |
245 |
.filters > label[for="by_mine_filter"], |
246 |
.filters > input[type="checkbox"], |
247 |
.filters > input[type="button"] { |
248 |
margin-left: 1rem; |
249 |
} |
250 |
</style> |