2 <transition name="modal">
3 <div v-if="show_modal" class="modal">
4 <h2>{{ $__("Copy item to the following train") }}</h2>
5 <form @submit="copyItem($event)">
6 <div class="page-section">
7 <fieldset class="rows">
10 <label class="required" for="train_list"
11 >{{ $__("Select a train") }}:</label
14 v-model="train_id_selected_for_copy"
17 :reduce="t => t.train_id"
19 <template #search="{ attributes, events }">
22 !train_id_selected_for_copy
30 <span class="required">{{
36 <fieldset class="action">
37 <input type="submit" value="Copy" />
40 @click="show_modal = false"
48 <div v-if="!initialized">{{ $__("Loading") }}</div>
49 <div v-else id="trains_show">
50 <div id="toolbar" class="btn-toolbar">
52 :to="`/cgi-bin/koha/preservation/trains/${train.train_id}/items/add`"
53 class="btn btn-default"
54 ><font-awesome-icon icon="plus" />
55 {{ $__("Add items") }}</router-link
58 :to="`/cgi-bin/koha/preservation/trains/edit/${train.train_id}`"
59 class="btn btn-default"
60 ><font-awesome-icon icon="pencil" />
61 {{ $__("Edit") }}</router-link
63 <a @click="deleteTrain(train)" class="btn btn-default"
64 ><font-awesome-icon icon="trash" /> {{ $__("Delete") }}</a
67 v-if="!train.closed_on"
68 class="btn btn-default"
70 ><font-awesome-icon icon="remove" /> {{ $__("Close") }}</a
73 v-else-if="!train.sent_on"
74 class="btn btn-default"
76 ><font-awesome-icon icon="paper-plane" /> {{ $__("Send") }}</a
79 v-else-if="!train.received_on"
80 class="btn btn-default"
82 ><font-awesome-icon icon="inbox" /> {{ $__("Receive") }}</a
86 {{ $__("Train #%s").format(train.train_id) }}
89 <fieldset class="rows">
92 <label>{{ $__("Name") }}:</label>
98 <label>{{ $__("Description") }}:</label>
100 {{ train.description }}
103 <li v-if="train.closed_on">
104 <label>{{ $__("Closed on") }}:</label>
106 {{ format_date(train.closed_on) }}
109 <li v-if="train.sent_on">
110 <label>{{ $__("Sent on") }}:</label>
112 {{ format_date(train.sent_on) }}
115 <li v-if="train.received_on">
116 <label>{{ $__("Received on") }}:</label>
118 {{ format_date(train.received_on) }}
124 $__("Status for item added to this train")
128 get_lib_from_av("av_notforloan", train.not_for_loan)
132 <label>{{ $__("Default processing") }}:</label>
134 {{ train.default_processing.name }}
139 <fieldset v-if="train.items.length" class="rows">
140 <legend>{{ $__("Items") }}</legend>
141 <table v-if="item_table.display" :id="table_id"></table>
144 :id="`item_${counter}`"
146 v-for="(item, counter) in train.items"
150 >{{ item.user_train_item_id }}
151 <span class="action_links">
153 :to="`/cgi-bin/koha/preservation/trains/${train.train_id}/items/edit/${item.train_item_id}`"
155 ><i class="fa fa-pencil"></i></router-link
158 <div class="attributes_values">
160 :id="`attribute_${counter_attribute}`"
161 class="attribute_value"
163 attribute, counter_attribute
164 ) in item.attributes"
165 v-bind:key="counter_attribute"
167 <!-- FIXME We need to display the description of the AV here -->
168 {{ attribute.processing_attribute.name }}={{
176 <fieldset class="action">
178 to="/cgi-bin/koha/preservation/trains"
181 >{{ $__("Close") }}</router-link
189 import { inject, createVNode, render } from "vue"
190 import { APIClient } from "../../fetch/api-client"
191 import { useDataTable } from "../../composables/datatables"
195 const format_date = $date
197 const AVStore = inject("AVStore")
198 const { get_lib_from_av } = AVStore
200 const { setConfirmationDialog, setMessage } = inject("mainStore")
202 const table_id = "item_list"
203 useDataTable(table_id)
209 setConfirmationDialog,
228 train_id_selected_for_copy: null,
229 train_item_id_to_copy: null,
232 beforeRouteEnter(to, from, next) {
234 vm.getTrain(to.params.train_id).then(() => vm.build_datatable())
239 async getTrain(train_id) {
240 const client = APIClient.preservation
241 await client.trains.get(train_id).then(
244 let display = this.train.items.every(
246 item.processing_id ==
247 this.train.default_processing_id
250 this.item_table.data = []
251 this.train.items.forEach(item => {
253 this.train.default_processing.attributes.forEach(
256 if (item.attributes.length >= 0) {
257 let a = item.attributes.find(
259 a.processing_attribute_id ==
260 attribute.processing_attribute_id
268 attribute.processing_attribute_id
273 this.item_table.data.push(item_row)
275 this.item_table.columns = []
276 this.item_table.columns.push({
278 title: this.$__("ID"),
279 data: "item.user_train_item_id",
281 train.default_processing.attributes.forEach(a =>
282 this.item_table.columns.push({
285 data: a.processing_attribute_id,
288 this.item_table.columns.push({
290 className: "actions noExport",
291 title: this.$__("Actions"),
294 render: (data, type, row) => {
299 this.initialized = true
300 this.item_table.display = display
305 getTrainList: function () {
306 const client = APIClient.preservation
307 let q = { "me.closed_on": null }
308 client.trains.getAll(q).then(
309 trains => (this.train_list = trains),
313 deleteTrain: function (train) {
314 this.setConfirmationDialog(
317 "Are you sure you want to remove this train?"
320 accept_label: this.$__("Yes, delete"),
321 cancel_label: this.$__("No, do not delete"),
324 const client = APIClient.preservation
325 client.trains.delete(train.train_id).then(
328 this.$__("Train %s deleted").format(train.name),
337 async updateTrainDate(attribute) {
338 let train = JSON.parse(JSON.stringify(this.train))
339 let train_id = train.train_id
340 delete train.train_id
342 delete train.default_processing
343 train[attribute] = new Date()
344 const client = APIClient.preservation
347 .update(train, train_id)
348 .then(() => this.getTrain(this.train.train_id))
352 .then(() => this.getTrain(this.train.train_id))
356 this.updateTrainDate("closed_on")
359 this.updateTrainDate("sent_on")
362 this.updateTrainDate("received_on").then(
364 // Rebuild the table to show the "copy" button
365 $("#" + this.table_id)
368 this.build_datatable()
373 editItem(train_item_id) {
375 `/cgi-bin/koha/preservation/trains/${this.train.train_id}/items/edit/${train_item_id}`
378 removeItem(train_item_id) {
379 this.setConfirmationDialog(
382 "Are you sure you want to remove this item?"
384 accept_label: this.$__("Yes, remove"),
385 cancel_label: this.$__("No, do not remove"),
388 const client = APIClient.preservation
390 .delete(this.train.train_id, train_item_id)
393 this.setMessage(this.$__("Item removed"), true)
394 this.getTrain(this.train.train_id).then(() => {
395 $("#" + this.table_id)
398 this.build_datatable()
406 selectTrainForCopy(train_item_id) {
407 this.show_modal = true
408 this.train_item_id_to_copy = train_item_id
411 event.preventDefault()
412 const client = APIClient.preservation
415 this.train_id_selected_for_copy,
417 this.train_item_id_to_copy
421 this.setMessage(this.$__("Item copied successfully."))
422 this.show_modal = false
427 build_datatable: function () {
428 let table_id = this.table_id
429 let item_table = this.item_table
430 let removeItem = this.removeItem
431 let editItem = this.editItem
432 let selectTrainForCopy = this.selectTrainForCopy
433 let train = this.train
435 let table = KohaTable(table_id, {
436 data: item_table.data,
439 columns: item_table.columns,
440 drawCallback: function (settings) {
441 var api = new $.fn.dataTable.Api(settings)
442 $.each($(this).find("td.actions"), function (index, e) {
443 let tr = $(this).parent()
444 let train_item_id = api.row(tr).data()
447 let editButton = createVNode(
450 class: "btn btn-default btn-xs",
453 editItem(train_item_id)
458 class: "fa fa-pencil",
459 "aria-hidden": "true",
465 let removeButton = createVNode(
468 class: "btn btn-default btn-xs",
471 removeItem(train_item_id)
476 class: "fa fa-trash",
477 "aria-hidden": "true",
482 let buttons = [editButton, "", removeButton]
484 if (train.received_on !== null) {
490 class: "btn btn-default btn-xs",
493 selectTrainForCopy(train_item_id)
499 "aria-hidden": "true",
507 let n = createVNode("span", {}, buttons)
535 background-color: rgba(0, 0, 0, 0.5);
537 transition: opacity 0.3s ease;
540 background-color: #fff;
542 box-shadow: 0 2px 8px rgba(0, 0, 0, 0.33);
543 transition: all 0.3s ease;