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 v-if="train.closed_on == null"
53 :to="`/cgi-bin/koha/preservation/trains/${train.train_id}/items/add`"
54 class="btn btn-default"
55 ><font-awesome-icon icon="plus" />
56 {{ $__("Add items") }}</router-link
60 class="btn btn-default"
62 :title="$__('Cannot add items to a closed train')"
64 <font-awesome-icon icon="plus" /> {{ $__("Add items") }}
67 :to="`/cgi-bin/koha/preservation/trains/edit/${train.train_id}`"
68 class="btn btn-default"
69 ><font-awesome-icon icon="pencil" />
70 {{ $__("Edit") }}</router-link
72 <a @click="deleteTrain(train)" class="btn btn-default"
73 ><font-awesome-icon icon="trash" /> {{ $__("Delete") }}</a
76 v-if="!train.closed_on"
77 class="btn btn-default"
79 ><font-awesome-icon icon="remove" /> {{ $__("Close") }}</a
82 v-else-if="!train.sent_on"
83 class="btn btn-default"
85 ><font-awesome-icon icon="paper-plane" /> {{ $__("Send") }}</a
88 v-else-if="!train.received_on"
89 class="btn btn-default"
91 ><font-awesome-icon icon="inbox" /> {{ $__("Receive") }}</a
95 {{ $__("Train #%s").format(train.train_id) }}
98 <fieldset class="rows">
101 <label>{{ $__("Name") }}:</label>
107 <label>{{ $__("Description") }}:</label>
109 {{ train.description }}
112 <li v-if="train.closed_on">
113 <label>{{ $__("Closed on") }}:</label>
115 {{ format_date(train.closed_on) }}
118 <li v-if="train.sent_on">
119 <label>{{ $__("Sent on") }}:</label>
121 {{ format_date(train.sent_on) }}
124 <li v-if="train.received_on">
125 <label>{{ $__("Received on") }}:</label>
127 {{ format_date(train.received_on) }}
133 $__("Status for item added to this train")
137 get_lib_from_av("av_notforloan", train.not_for_loan)
141 <label>{{ $__("Default processing") }}:</label>
143 {{ train.default_processing.name }}
148 <fieldset v-if="train.items.length" class="rows">
149 <legend>{{ $__("Items") }}</legend>
150 <table v-if="item_table.display" :id="table_id"></table>
153 :id="`item_${counter}`"
155 v-for="(item, counter) in train.items"
159 >{{ item.user_train_item_id }}
160 <span class="action_links">
162 :to="`/cgi-bin/koha/preservation/trains/${train.train_id}/items/edit/${item.train_item_id}`"
164 ><i class="fa fa-pencil"></i></router-link
167 <div class="attributes_values">
169 :id="`attribute_${counter_attribute}`"
170 class="attribute_value"
172 attribute, counter_attribute
173 ) in item.attributes"
174 v-bind:key="counter_attribute"
176 {{ attribute.processing_attribute.name }}={{
177 attribute._strings.value.str
184 <fieldset class="action">
186 to="/cgi-bin/koha/preservation/trains"
189 >{{ $__("Close") }}</router-link
197 import { inject, createVNode, render } from "vue"
198 import { APIClient } from "../../fetch/api-client"
199 import { useDataTable } from "../../composables/datatables"
203 const format_date = $date
205 const AVStore = inject("AVStore")
206 const { get_lib_from_av } = AVStore
208 const { setConfirmationDialog, setMessage, setWarning } =
211 const table_id = "item_list"
212 useDataTable(table_id)
218 setConfirmationDialog,
238 train_id_selected_for_copy: null,
239 train_item_id_to_copy: null,
243 beforeRouteEnter(to, from, next) {
245 vm.getTrain(to.params.train_id).then(() => vm.build_datatable())
250 async getTrain(train_id) {
251 const client = APIClient.preservation
252 await client.trains.get(train_id).then(
255 let display_table = this.train.items.every(
257 item.processing_id ==
258 this.train.default_processing_id
261 this.item_table.data = []
262 this.train.items.forEach(item => {
264 this.train.default_processing.attributes.forEach(
267 attribute.processing_attribute_id
271 a.processing_attribute_id ==
272 attribute.processing_attribute_id
274 .map(a => a._strings.value.str)
278 this.item_table.data.push(item_row)
280 this.item_table.columns = []
281 this.item_table.columns.push({
283 title: this.$__("ID"),
284 data: "item.user_train_item_id",
286 train.default_processing.attributes.forEach(a =>
287 this.item_table.columns.push({
290 data: a.processing_attribute_id,
291 render: (data, type, row) => {
292 return data.join("<br/>")
296 this.item_table.columns.push({
298 className: "actions noExport",
299 title: this.$__("Actions"),
302 render: (data, type, row) => {
307 this.initialized = true
308 this.item_table.display = display_table
313 getTrainList: function () {
314 const client = APIClient.preservation
315 let q = { "me.closed_on": null }
316 client.trains.getAll(q).then(
317 trains => (this.train_list = trains),
321 deleteTrain: function (train) {
322 this.setConfirmationDialog(
325 "Are you sure you want to remove this train?"
328 accept_label: this.$__("Yes, delete"),
329 cancel_label: this.$__("No, do not delete"),
332 const client = APIClient.preservation
333 client.trains.delete(train.train_id).then(
336 this.$__("Train %s deleted").format(train.name),
345 async updateTrainDate(attribute) {
346 let train = JSON.parse(JSON.stringify(this.train))
347 let train_id = train.train_id
348 delete train.train_id
350 delete train.default_processing
351 train[attribute] = new Date()
352 const client = APIClient.preservation
355 .update(train, train_id)
356 .then(() => this.getTrain(this.train.train_id))
360 .then(() => this.getTrain(this.train.train_id))
364 this.updateTrainDate("closed_on")
367 this.updateTrainDate("sent_on")
370 this.updateTrainDate("received_on").then(
372 // Rebuild the table to show the "copy" button
373 $("#" + this.table_id)
376 this.build_datatable()
381 editItem(train_item_id) {
383 `/cgi-bin/koha/preservation/trains/${this.train.train_id}/items/edit/${train_item_id}`
386 removeItem(train_item_id) {
387 this.setConfirmationDialog(
390 "Are you sure you want to remove this item?"
392 accept_label: this.$__("Yes, remove"),
393 cancel_label: this.$__("No, do not remove"),
396 const client = APIClient.preservation
398 .delete(this.train.train_id, train_item_id)
401 this.setMessage(this.$__("Item removed"), true)
402 this.getTrain(this.train.train_id).then(() => {
403 $("#" + this.table_id)
406 this.build_datatable()
414 selectTrainForCopy(train_item_id) {
415 this.show_modal = true
416 this.train_item_id_to_copy = train_item_id
419 event.preventDefault()
420 const client = APIClient.preservation
423 this.train_id_selected_for_copy,
425 this.train_item_id_to_copy
429 this.setMessage(this.$__("Item copied successfully."))
430 this.show_modal = false
435 "Item cannot be copied to a train, it is already in a non-received train."
441 build_datatable: function () {
442 let table_id = this.table_id
443 let item_table = this.item_table
444 let removeItem = this.removeItem
445 let editItem = this.editItem
446 let selectTrainForCopy = this.selectTrainForCopy
447 let train = this.train
449 let table = KohaTable(table_id, {
450 data: item_table.data,
453 columns: item_table.columns,
454 drawCallback: function (settings) {
455 var api = new $.fn.dataTable.Api(settings)
456 $.each($(this).find("td.actions"), function (index, e) {
457 let tr = $(this).parent()
458 let train_item_id = api.row(tr).data()
461 let editButton = createVNode(
464 class: "btn btn-default btn-xs",
467 editItem(train_item_id)
472 class: "fa fa-pencil",
473 "aria-hidden": "true",
479 let removeButton = createVNode(
482 class: "btn btn-default btn-xs",
485 removeItem(train_item_id)
490 class: "fa fa-trash",
491 "aria-hidden": "true",
496 let buttons = [editButton, "", removeButton]
498 if (train.received_on !== null) {
504 class: "btn btn-default btn-xs",
507 selectTrainForCopy(train_item_id)
513 "aria-hidden": "true",
521 let n = createVNode("span", {}, buttons)
549 background-color: rgba(0, 0, 0, 0.5);
551 transition: opacity 0.3s ease;
554 background-color: #fff;
556 box-shadow: 0 2px 8px rgba(0, 0, 0, 0.33);
557 transition: all 0.3s ease;