|
Line 0
Link Here
|
|
|
1 |
<template> |
| 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"> |
| 8 |
<ol> |
| 9 |
<li> |
| 10 |
<label class="required" for="train_list" |
| 11 |
>{{ $__("Select a train") }}:</label |
| 12 |
> |
| 13 |
<v-select |
| 14 |
v-model="train_id_selected_for_copy" |
| 15 |
label="name" |
| 16 |
:options="train_list" |
| 17 |
:reduce="t => t.train_id" |
| 18 |
> |
| 19 |
<template #search="{ attributes, events }"> |
| 20 |
<input |
| 21 |
:required=" |
| 22 |
!train_id_selected_for_copy |
| 23 |
" |
| 24 |
class="vs__search" |
| 25 |
v-bind="attributes" |
| 26 |
v-on="events" |
| 27 |
/> |
| 28 |
</template> |
| 29 |
</v-select> |
| 30 |
<span class="required">{{ |
| 31 |
$__("Required") |
| 32 |
}}</span> |
| 33 |
</li> |
| 34 |
</ol> |
| 35 |
</fieldset> |
| 36 |
<fieldset class="action"> |
| 37 |
<input type="submit" value="Copy" /> |
| 38 |
<input |
| 39 |
type="button" |
| 40 |
@click="show_modal = false" |
| 41 |
:value="$__('Close')" |
| 42 |
/> |
| 43 |
</fieldset> |
| 44 |
</div> |
| 45 |
</form> |
| 46 |
</div> |
| 47 |
</transition> |
| 48 |
<div v-if="!initialized">{{ $__("Loading") }}</div> |
| 49 |
<div v-else id="trains_show"> |
| 50 |
<div id="toolbar" class="btn-toolbar"> |
| 51 |
<router-link |
| 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 |
| 56 |
> |
| 57 |
<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 |
| 62 |
> |
| 63 |
<a @click="deleteTrain(train)" class="btn btn-default" |
| 64 |
><font-awesome-icon icon="trash" /> {{ $__("Delete") }}</a |
| 65 |
> |
| 66 |
<a |
| 67 |
v-if="!train.closed_on" |
| 68 |
class="btn btn-default" |
| 69 |
@click="closeTrain" |
| 70 |
><font-awesome-icon icon="remove" /> {{ $__("Close") }}</a |
| 71 |
> |
| 72 |
<a |
| 73 |
v-else-if="!train.sent_on" |
| 74 |
class="btn btn-default" |
| 75 |
@click="sendTrain" |
| 76 |
><font-awesome-icon icon="paper-plane" /> {{ $__("Send") }}</a |
| 77 |
> |
| 78 |
<a |
| 79 |
v-else-if="!train.received_on" |
| 80 |
class="btn btn-default" |
| 81 |
@click="receiveTrain" |
| 82 |
><font-awesome-icon icon="inbox" /> {{ $__("Receive") }}</a |
| 83 |
> |
| 84 |
</div> |
| 85 |
<h2> |
| 86 |
{{ $__("Train #%s").format(train.train_id) }} |
| 87 |
</h2> |
| 88 |
<div> |
| 89 |
<fieldset class="rows"> |
| 90 |
<ol> |
| 91 |
<li> |
| 92 |
<label>{{ $__("Name") }}:</label> |
| 93 |
<span> |
| 94 |
{{ train.name }} |
| 95 |
</span> |
| 96 |
</li> |
| 97 |
<li> |
| 98 |
<label>{{ $__("Description") }}:</label> |
| 99 |
<span> |
| 100 |
{{ train.description }} |
| 101 |
</span> |
| 102 |
</li> |
| 103 |
<li v-if="train.closed_on"> |
| 104 |
<label>{{ $__("Closed on") }}:</label> |
| 105 |
<span> |
| 106 |
{{ format_date(train.closed_on) }} |
| 107 |
</span> |
| 108 |
</li> |
| 109 |
<li v-if="train.sent_on"> |
| 110 |
<label>{{ $__("Sent on") }}:</label> |
| 111 |
<span> |
| 112 |
{{ format_date(train.sent_on) }} |
| 113 |
</span> |
| 114 |
</li> |
| 115 |
<li v-if="train.received_on"> |
| 116 |
<label>{{ $__("Received on") }}:</label> |
| 117 |
<span> |
| 118 |
{{ format_date(train.received_on) }} |
| 119 |
</span> |
| 120 |
</li> |
| 121 |
<li> |
| 122 |
<label |
| 123 |
>{{ |
| 124 |
$__("Status for item added to this train") |
| 125 |
}}:</label |
| 126 |
> |
| 127 |
<span>{{ |
| 128 |
get_lib_from_av("av_notforloan", train.not_for_loan) |
| 129 |
}}</span> |
| 130 |
</li> |
| 131 |
<li> |
| 132 |
<label>{{ $__("Default processing") }}:</label> |
| 133 |
<span> |
| 134 |
{{ train.default_processing.name }} |
| 135 |
</span> |
| 136 |
</li> |
| 137 |
</ol> |
| 138 |
</fieldset> |
| 139 |
<fieldset v-if="train.items.length" class="rows"> |
| 140 |
<legend>{{ $__("Items") }}</legend> |
| 141 |
<table v-if="item_table.display" :id="table_id"></table> |
| 142 |
<ol v-else> |
| 143 |
<li |
| 144 |
:id="`item_${counter}`" |
| 145 |
class="rows" |
| 146 |
v-for="(item, counter) in train.items" |
| 147 |
v-bind:key="counter" |
| 148 |
> |
| 149 |
<!-- FIXME Counter here may change, we should pass an order by clause when retrieving the items --> |
| 150 |
<label |
| 151 |
>{{ counter + 1 }} |
| 152 |
<span class="action_links"> |
| 153 |
<router-link |
| 154 |
:to="`/cgi-bin/koha/preservation/trains/${train.train_id}/items/edit/${item.train_item_id}`" |
| 155 |
:title="$__('Edit')" |
| 156 |
><i class="fa fa-pencil"></i></router-link |
| 157 |
></span> |
| 158 |
</label> |
| 159 |
<div class="attributes_values"> |
| 160 |
<span |
| 161 |
:id="`attribute_${counter_attribute}`" |
| 162 |
class="attribute_value" |
| 163 |
v-for="( |
| 164 |
attribute, counter_attribute |
| 165 |
) in item.attributes" |
| 166 |
v-bind:key="counter_attribute" |
| 167 |
> |
| 168 |
<!-- FIXME We need to display the description of the AV here --> |
| 169 |
{{ attribute.processing_attribute.name }}={{ |
| 170 |
attribute.value |
| 171 |
}} |
| 172 |
</span> |
| 173 |
</div> |
| 174 |
</li> |
| 175 |
</ol> |
| 176 |
</fieldset> |
| 177 |
<fieldset class="action"> |
| 178 |
<router-link |
| 179 |
to="/cgi-bin/koha/preservation/trains" |
| 180 |
role="button" |
| 181 |
class="cancel" |
| 182 |
>{{ $__("Close") }}</router-link |
| 183 |
> |
| 184 |
</fieldset> |
| 185 |
</div> |
| 186 |
</div> |
| 187 |
</template> |
| 188 |
|
| 189 |
<script> |
| 190 |
import { inject, createVNode, render } from "vue" |
| 191 |
import { APIClient } from "../../fetch/api-client" |
| 192 |
import { useDataTable } from "../../composables/datatables" |
| 193 |
|
| 194 |
export default { |
| 195 |
setup() { |
| 196 |
const format_date = $date |
| 197 |
|
| 198 |
const AVStore = inject("AVStore") |
| 199 |
const { get_lib_from_av } = AVStore |
| 200 |
|
| 201 |
const { setConfirmationDialog, setMessage } = inject("mainStore") |
| 202 |
|
| 203 |
const table_id = "item_list" |
| 204 |
useDataTable(table_id) |
| 205 |
|
| 206 |
return { |
| 207 |
format_date, |
| 208 |
get_lib_from_av, |
| 209 |
table_id, |
| 210 |
setConfirmationDialog, |
| 211 |
setMessage, |
| 212 |
} |
| 213 |
}, |
| 214 |
data() { |
| 215 |
return { |
| 216 |
train: { |
| 217 |
train_id: null, |
| 218 |
name: "", |
| 219 |
description: "", |
| 220 |
}, |
| 221 |
initialized: false, |
| 222 |
show_modal: false, |
| 223 |
item_table: { |
| 224 |
display: false, |
| 225 |
data: [], |
| 226 |
columns: [], |
| 227 |
}, |
| 228 |
train_list: [], |
| 229 |
train_id_selected_for_copy: null, |
| 230 |
train_item_id_to_copy: null, |
| 231 |
} |
| 232 |
}, |
| 233 |
beforeRouteEnter(to, from, next) { |
| 234 |
next(vm => { |
| 235 |
vm.getTrain(to.params.train_id).then(() => vm.build_datatable()) |
| 236 |
vm.getTrainList() |
| 237 |
}) |
| 238 |
}, |
| 239 |
methods: { |
| 240 |
async getTrain(train_id) { |
| 241 |
const client = APIClient.preservation |
| 242 |
await client.trains.get(train_id).then( |
| 243 |
train => { |
| 244 |
this.train = train |
| 245 |
let display = this.train.items.every( |
| 246 |
item => |
| 247 |
item.processing_id == |
| 248 |
this.train.default_processing_id |
| 249 |
) |
| 250 |
if (display) { |
| 251 |
this.item_table.data = [] |
| 252 |
this.train.items.forEach(item => { |
| 253 |
let item_row = {} |
| 254 |
this.train.default_processing.attributes.forEach( |
| 255 |
attribute => { |
| 256 |
if (item.attributes.length <= 0) return "" |
| 257 |
item_row[ |
| 258 |
attribute.processing_attribute_id |
| 259 |
] = item.attributes.find( |
| 260 |
a => |
| 261 |
a.processing_attribute_id == |
| 262 |
attribute.processing_attribute_id |
| 263 |
).value |
| 264 |
} |
| 265 |
) |
| 266 |
item_row.item = item |
| 267 |
this.item_table.data.push(item_row) |
| 268 |
}) |
| 269 |
this.item_table.columns = [] |
| 270 |
this.item_table.columns.push({ |
| 271 |
name: "id", |
| 272 |
title: this.$__("ID"), |
| 273 |
render: (data, type, row) => { |
| 274 |
return 42 |
| 275 |
}, |
| 276 |
}) |
| 277 |
train.default_processing.attributes.forEach(a => |
| 278 |
this.item_table.columns.push({ |
| 279 |
name: a.name, |
| 280 |
title: a.name, |
| 281 |
data: a.processing_attribute_id, |
| 282 |
}) |
| 283 |
) |
| 284 |
this.item_table.columns.push({ |
| 285 |
name: "actions", |
| 286 |
className: "actions noExport", |
| 287 |
title: this.$__("Actions"), |
| 288 |
searchable: false, |
| 289 |
orderable: false, |
| 290 |
render: (data, type, row) => { |
| 291 |
return "" |
| 292 |
}, |
| 293 |
}) |
| 294 |
} |
| 295 |
this.initialized = true |
| 296 |
this.item_table.display = display |
| 297 |
}, |
| 298 |
error => {} |
| 299 |
) |
| 300 |
}, |
| 301 |
getTrainList: function () { |
| 302 |
const client = APIClient.preservation |
| 303 |
let q = { "me.closed_on": null } |
| 304 |
client.trains.getAll(q).then( |
| 305 |
trains => (this.train_list = trains), |
| 306 |
error => {} |
| 307 |
) |
| 308 |
}, |
| 309 |
deleteTrain: function (train) { |
| 310 |
this.setConfirmationDialog( |
| 311 |
{ |
| 312 |
title: this.$__( |
| 313 |
"Are you sure you want to remove this train?" |
| 314 |
), |
| 315 |
message: train.name, |
| 316 |
accept_label: this.$__("Yes, delete"), |
| 317 |
cancel_label: this.$__("No, do not delete"), |
| 318 |
}, |
| 319 |
() => { |
| 320 |
const client = APIClient.preservation |
| 321 |
client.trains.delete(train.train_id).then( |
| 322 |
success => { |
| 323 |
this.setMessage( |
| 324 |
this.$__("Train %s deleted").format(train.name), |
| 325 |
true |
| 326 |
) |
| 327 |
}, |
| 328 |
error => {} |
| 329 |
) |
| 330 |
} |
| 331 |
) |
| 332 |
}, |
| 333 |
async updateTrainDate(attribute) { |
| 334 |
let train = JSON.parse(JSON.stringify(this.train)) |
| 335 |
let train_id = train.train_id |
| 336 |
delete train.train_id |
| 337 |
delete train.items |
| 338 |
delete train.default_processing |
| 339 |
train[attribute] = new Date() |
| 340 |
const client = APIClient.preservation |
| 341 |
if (train_id) { |
| 342 |
client.trains |
| 343 |
.update(train, train_id) |
| 344 |
.then(() => this.getTrain(this.train.train_id)) |
| 345 |
} else { |
| 346 |
client.trains |
| 347 |
.create(train) |
| 348 |
.then(() => this.getTrain(this.train.train_id)) |
| 349 |
} |
| 350 |
}, |
| 351 |
closeTrain() { |
| 352 |
this.updateTrainDate("closed_on") |
| 353 |
}, |
| 354 |
sendTrain() { |
| 355 |
this.updateTrainDate("sent_on") |
| 356 |
}, |
| 357 |
receiveTrain() { |
| 358 |
this.updateTrainDate("received_on") |
| 359 |
}, |
| 360 |
editItem(train_item_id) { |
| 361 |
this.$router.push( |
| 362 |
`/cgi-bin/koha/preservation/trains/${this.train.train_id}/items/edit/${train_item_id}` |
| 363 |
) |
| 364 |
}, |
| 365 |
removeItem(train_item_id) { |
| 366 |
this.setConfirmationDialog( |
| 367 |
{ |
| 368 |
title: this.$__( |
| 369 |
"Are you sure you want to remove this item?" |
| 370 |
), |
| 371 |
accept_label: this.$__("Yes, remove"), |
| 372 |
cancel_label: this.$__("No, do not remove"), |
| 373 |
}, |
| 374 |
() => { |
| 375 |
const client = APIClient.preservation |
| 376 |
client.train_items |
| 377 |
.delete(this.train.train_id, train_item_id) |
| 378 |
.then( |
| 379 |
success => { |
| 380 |
this.setMessage(this.$__("Item removed"), true) |
| 381 |
this.getTrain(this.train.train_id).then(() => { |
| 382 |
$("#" + this.table_id) |
| 383 |
.DataTable() |
| 384 |
.destroy() |
| 385 |
this.build_datatable() |
| 386 |
}) |
| 387 |
}, |
| 388 |
error => {} |
| 389 |
) |
| 390 |
} |
| 391 |
) |
| 392 |
}, |
| 393 |
selectTrainForCopy(train_item_id) { |
| 394 |
this.show_modal = true |
| 395 |
this.train_item_id_to_copy = train_item_id |
| 396 |
}, |
| 397 |
copyItem(event) { |
| 398 |
event.preventDefault() |
| 399 |
const client = APIClient.preservation |
| 400 |
let new_train_item = {} |
| 401 |
client.train_items |
| 402 |
.get(this.train.train_id, this.train_item_id_to_copy) |
| 403 |
.then(train_item => { |
| 404 |
new_train_item = { |
| 405 |
attributes: train_item.attributes.map(attr => { |
| 406 |
return { |
| 407 |
processing_attribute_id: |
| 408 |
attr.processing_attribute_id, |
| 409 |
value: attr.value, |
| 410 |
} |
| 411 |
}), |
| 412 |
item_id: train_item.item_id, |
| 413 |
processing_id: train_item.processing_id, |
| 414 |
} |
| 415 |
}) |
| 416 |
.then(() => |
| 417 |
client.train_items |
| 418 |
.create(new_train_item, this.train_id_selected_for_copy) |
| 419 |
.then( |
| 420 |
success => { |
| 421 |
this.setMessage( |
| 422 |
this.$__("Item copied successfully.") |
| 423 |
) |
| 424 |
this.show_modal = false |
| 425 |
}, |
| 426 |
error => {} |
| 427 |
) |
| 428 |
) |
| 429 |
}, |
| 430 |
build_datatable: function () { |
| 431 |
let table_id = this.table_id |
| 432 |
let item_table = this.item_table |
| 433 |
let removeItem = this.removeItem |
| 434 |
let editItem = this.editItem |
| 435 |
let selectTrainForCopy = this.selectTrainForCopy |
| 436 |
let train = this.train |
| 437 |
|
| 438 |
let table = KohaTable(table_id, { |
| 439 |
data: item_table.data, |
| 440 |
ordering: false, |
| 441 |
autoWidth: false, |
| 442 |
columns: item_table.columns, |
| 443 |
drawCallback: function (settings) { |
| 444 |
var api = new $.fn.dataTable.Api(settings) |
| 445 |
$.each($(this).find("td.actions"), function (index, e) { |
| 446 |
let tr = $(this).parent() |
| 447 |
let train_item_id = api.row(tr).data() |
| 448 |
.item.train_item_id |
| 449 |
|
| 450 |
let editButton = createVNode( |
| 451 |
"a", |
| 452 |
{ |
| 453 |
class: "btn btn-default btn-xs", |
| 454 |
role: "button", |
| 455 |
onClick: () => { |
| 456 |
editItem(train_item_id) |
| 457 |
}, |
| 458 |
}, |
| 459 |
[ |
| 460 |
createVNode("i", { |
| 461 |
class: "fa fa-pencil", |
| 462 |
"aria-hidden": "true", |
| 463 |
}), |
| 464 |
__("Edit"), |
| 465 |
] |
| 466 |
) |
| 467 |
|
| 468 |
let removeButton = createVNode( |
| 469 |
"a", |
| 470 |
{ |
| 471 |
class: "btn btn-default btn-xs", |
| 472 |
role: "button", |
| 473 |
onClick: () => { |
| 474 |
removeItem(train_item_id) |
| 475 |
}, |
| 476 |
}, |
| 477 |
[ |
| 478 |
createVNode("i", { |
| 479 |
class: "fa fa-trash", |
| 480 |
"aria-hidden": "true", |
| 481 |
}), |
| 482 |
__("Remove"), |
| 483 |
] |
| 484 |
) |
| 485 |
let buttons = [editButton, "", removeButton] |
| 486 |
|
| 487 |
if (train.received_on !== null) { |
| 488 |
buttons.push("") |
| 489 |
buttons.push( |
| 490 |
createVNode( |
| 491 |
"a", |
| 492 |
{ |
| 493 |
class: "btn btn-default btn-xs", |
| 494 |
role: "button", |
| 495 |
onClick: () => { |
| 496 |
selectTrainForCopy(train_item_id) |
| 497 |
}, |
| 498 |
}, |
| 499 |
[ |
| 500 |
createVNode("i", { |
| 501 |
class: "fa fa-copy", |
| 502 |
"aria-hidden": "true", |
| 503 |
}), |
| 504 |
__("Copy"), |
| 505 |
] |
| 506 |
) |
| 507 |
) |
| 508 |
} |
| 509 |
|
| 510 |
let n = createVNode("span", {}, buttons) |
| 511 |
render(n, e) |
| 512 |
}) |
| 513 |
}, |
| 514 |
}) |
| 515 |
}, |
| 516 |
}, |
| 517 |
name: "TrainsShow", |
| 518 |
} |
| 519 |
</script> |
| 520 |
<style scoped> |
| 521 |
.action_links a { |
| 522 |
padding-left: 0.2em; |
| 523 |
font-size: 11px; |
| 524 |
} |
| 525 |
.attributes_values { |
| 526 |
float: left; |
| 527 |
} |
| 528 |
.attribute_value { |
| 529 |
display: block; |
| 530 |
} |
| 531 |
.modal { |
| 532 |
position: fixed; |
| 533 |
z-index: 9998; |
| 534 |
top: 0; |
| 535 |
left: 0; |
| 536 |
width: 35%; |
| 537 |
height: 30%; |
| 538 |
background-color: rgba(0, 0, 0, 0.5); |
| 539 |
display: table; |
| 540 |
transition: opacity 0.3s ease; |
| 541 |
margin: auto; |
| 542 |
padding: 20px 30px; |
| 543 |
background-color: #fff; |
| 544 |
border-radius: 2px; |
| 545 |
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.33); |
| 546 |
transition: all 0.3s ease; |
| 547 |
} |
| 548 |
</style> |