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">
52 v-if="train.closed_on == null"
54 name: 'TrainsFormAddItem',
55 params: { train_id: train.train_id },
57 class="btn btn-default"
59 :title="$__('Add items')"
63 class="btn btn-default"
65 :title="$__('Cannot add items to a closed train')"
67 <font-awesome-icon icon="plus" /> {{ $__("Add items") }}
71 name: 'TrainsFormEdit',
72 params: { train_id: train.train_id },
74 class="btn btn-default"
78 <a @click="deleteTrain(train)" class="btn btn-default"
79 ><font-awesome-icon icon="trash" /> {{ $__("Delete") }}</a
82 v-if="!train.closed_on"
83 class="btn btn-default"
85 ><font-awesome-icon icon="remove" /> {{ $__("Close") }}</a
88 v-else-if="!train.sent_on"
89 class="btn btn-default"
91 ><font-awesome-icon icon="paper-plane" /> {{ $__("Send") }}</a
94 v-else-if="!train.received_on"
95 class="btn btn-default"
97 ><font-awesome-icon icon="inbox" /> {{ $__("Receive") }}</a
101 {{ $__("Train #%s").format(train.train_id) }}
104 <fieldset class="rows">
107 <label>{{ $__("Name") }}:</label>
113 <label>{{ $__("Description") }}:</label>
115 {{ train.description }}
118 <li v-if="train.closed_on">
119 <label>{{ $__("Closed on") }}:</label>
121 {{ format_date(train.closed_on) }}
124 <li v-if="train.sent_on">
125 <label>{{ $__("Sent on") }}:</label>
127 {{ format_date(train.sent_on) }}
130 <li v-if="train.received_on">
131 <label>{{ $__("Received on") }}:</label>
133 {{ format_date(train.received_on) }}
139 $__("Status for item added to this train")
143 get_lib_from_av("av_notforloan", train.not_for_loan)
147 <label>{{ $__("Default processing") }}:</label>
149 {{ train.default_processing.name }}
154 <fieldset v-if="train.items.length" class="rows">
155 <legend>{{ $__("Items") }}</legend>
156 <table v-if="item_table.display" :id="table_id"></table>
159 :id="`item_${counter}`"
161 v-for="(item, counter) in train.items"
165 >{{ item.user_train_item_id }}
166 <span class="action_links">
169 @click="editItem(item.train_item_id)"
171 ><i class="fa fa-pencil"></i
175 @click="removeItem(item.train_item_id)"
176 :title="$__('Remove')"
177 ><i class="fa fa-trash"></i
180 v-if="train.received_on !== null"
183 selectTrainForCopy(item.train_item_id)
186 ><i class="fa fa-copy"></i
189 v-if="item.processing.letter_code !== null"
191 @click="printSlip(item.train_item_id)"
192 :title="$__('Print')"
193 ><i class="fa fa-print"></i></a
196 <div class="attributes_values">
198 :id="`attribute_${counter_attribute}`"
199 class="attribute_value"
201 attribute, counter_attribute
202 ) in item.attributes"
203 v-bind:key="counter_attribute"
205 {{ attribute.processing_attribute.name }}={{
206 attribute._strings.value.str
213 <fieldset class="action">
215 :to="{ name: 'TrainsList' }"
218 >{{ $__("Close") }}</router-link
226 import { inject, createVNode, render } from "vue"
227 import { APIClient } from "../../fetch/api-client"
228 import { useDataTable } from "../../composables/datatables"
229 import Toolbar from "../Toolbar.vue"
230 import ToolbarButton from "../ToolbarButton.vue"
234 const format_date = $date
236 const AVStore = inject("AVStore")
237 const { get_lib_from_av } = AVStore
239 const { setConfirmationDialog, setMessage, setWarning } =
242 const table_id = "item_list"
243 useDataTable(table_id)
249 setConfirmationDialog,
269 train_id_selected_for_copy: null,
270 train_item_id_to_copy: null,
274 beforeRouteEnter(to, from, next) {
276 vm.getTrain(to.params.train_id).then(() => vm.build_datatable())
281 async getTrain(train_id) {
282 const client = APIClient.preservation
283 await client.trains.get(train_id).then(
286 let display_table = this.train.items.every(
288 item.processing_id ==
289 this.train.default_processing_id
292 this.item_table.data = []
293 this.train.items.forEach(item => {
295 this.train.default_processing.attributes.forEach(
298 attribute.processing_attribute_id
302 a.processing_attribute_id ==
303 attribute.processing_attribute_id
305 .map(a => a._strings.value.str)
309 this.item_table.data.push(item_row)
311 this.item_table.columns = []
312 this.item_table.columns.push({
314 title: this.$__("ID"),
315 data: "item.user_train_item_id",
317 train.default_processing.attributes.forEach(a =>
318 this.item_table.columns.push({
321 data: a.processing_attribute_id,
322 render: (data, type, row) => {
323 return data.join("<br/>")
327 this.item_table.columns.push({
329 className: "actions noExport",
330 title: this.$__("Actions"),
333 render: (data, type, row) => {
338 this.initialized = true
339 this.item_table.display = display_table
344 getTrainList: function () {
345 const client = APIClient.preservation
346 let q = { "me.closed_on": null }
347 client.trains.getAll(q).then(
348 trains => (this.train_list = trains),
352 deleteTrain: function (train) {
353 this.setConfirmationDialog(
356 "Are you sure you want to remove this train?"
359 accept_label: this.$__("Yes, delete"),
360 cancel_label: this.$__("No, do not delete"),
363 const client = APIClient.preservation
364 client.trains.delete(train.train_id).then(
367 this.$__("Train %s deleted").format(train.name),
370 this.$router.push({ name: "TrainsList" })
377 async updateTrainDate(attribute) {
378 let train = JSON.parse(JSON.stringify(this.train))
379 let train_id = train.train_id
380 delete train.train_id
382 delete train.default_processing
383 train[attribute] = new Date()
384 const client = APIClient.preservation
387 .update(train, train_id)
388 .then(() => this.getTrain(this.train.train_id))
392 .then(() => this.getTrain(this.train.train_id))
396 this.updateTrainDate("closed_on")
399 this.updateTrainDate("sent_on")
402 this.updateTrainDate("received_on").then(
404 // Rebuild the table to show the "copy" button
405 $("#" + this.table_id)
408 this.build_datatable()
413 editItem(train_item_id) {
415 name: "TrainsFormEditItem",
416 params: { train_id: this.train.train_id, train_item_id },
419 removeItem(train_item_id) {
420 this.setConfirmationDialog(
423 "Are you sure you want to remove this item?"
425 accept_label: this.$__("Yes, remove"),
426 cancel_label: this.$__("No, do not remove"),
429 const client = APIClient.preservation
431 .delete(this.train.train_id, train_item_id)
434 this.setMessage(this.$__("Item removed"), true)
435 this.getTrain(this.train.train_id).then(() => {
436 $("#" + this.table_id)
439 this.build_datatable()
447 printSlip(train_item_id) {
449 "/cgi-bin/koha/preservation/print_slip.pl?train_item_id=" +
454 selectTrainForCopy(train_item_id) {
455 this.show_modal = true
456 this.train_item_id_to_copy = train_item_id
459 event.preventDefault()
460 const client = APIClient.preservation
463 this.train_id_selected_for_copy,
465 this.train_item_id_to_copy
469 this.setMessage(this.$__("Item copied successfully."))
470 this.show_modal = false
475 "Item cannot be copied to a train, it is already in a non-received train."
481 build_datatable: function () {
482 let table_id = this.table_id
483 let item_table = this.item_table
484 let removeItem = this.removeItem
485 let editItem = this.editItem
486 let printSlip = this.printSlip
487 let selectTrainForCopy = this.selectTrainForCopy
488 let train = this.train
490 let table = KohaTable(table_id, {
491 data: item_table.data,
494 columns: item_table.columns,
495 drawCallback: function (settings) {
496 var api = new $.fn.dataTable.Api(settings)
497 $.each($(this).find("td.actions"), function (index, e) {
498 let tr = $(this).parent()
499 let train_item = api.row(tr).data().item
500 let train_item_id = train_item.train_item_id
502 let editButton = createVNode(
505 class: "btn btn-default btn-xs",
508 editItem(train_item_id)
513 class: "fa fa-pencil",
514 "aria-hidden": "true",
521 let removeButton = createVNode(
524 class: "btn btn-default btn-xs",
527 removeItem(train_item_id)
532 class: "fa fa-trash",
533 "aria-hidden": "true",
539 let buttons = [editButton, " ", removeButton]
541 if (train.received_on !== null) {
547 class: "btn btn-default btn-xs",
550 selectTrainForCopy(train_item_id)
556 "aria-hidden": "true",
565 if (train_item.processing.letter_code !== null) {
566 let printButton = createVNode(
569 class: "btn btn-default btn-xs",
572 printSlip(train_item_id)
577 class: "fa fa-print",
578 "aria-hidden": "true",
584 buttons.push(printButton)
587 let n = createVNode("span", {}, buttons)
594 components: { Toolbar, ToolbarButton },
612 overflow-y: inherit !important;
617 background-color: rgba(0, 0, 0, 0.5);
619 transition: opacity 0.3s ease;
622 background-color: #fff;
624 box-shadow: 0 2px 8px rgba(0, 0, 0, 0.33);
625 transition: all 0.3s ease;