5 [% INCLUDE 'doc-head-open.inc' %]
6 <title>Bookings for [% INCLUDE 'biblio-title-head.inc' %] › Bookings › Circulation › Koha</title>
7 [% INCLUDE 'doc-head-close.inc' %]
10 <body id="circ_request" class="catalog">
12 [% WRAPPER 'header.inc' %]
13 [% INCLUDE 'cat-search.inc' %]
16 [% WRAPPER 'sub-header.inc' %]
17 [% WRAPPER breadcrumbs %]
18 [% WRAPPER breadcrumb_item %]
19 <a href="/cgi-bin/koha/catalogue/search.pl">Catalog</a>
21 [% WRAPPER breadcrumb_item %]
22 [% INCLUDE 'biblio-title.inc' link = 1 %]
24 [% WRAPPER breadcrumb_item bc_active= 1 %]
27 [% END #/ WRAPPER breadcrumbs %]
28 [% END #/ WRAPPER sub-header.inc %]
30 <div class="main container-fluid">
32 <div class="col-sm-10 col-sm-push-2">
35 [% INCLUDE 'cat-toolbar.inc' %]
36 <h1>Bookings for [% INCLUDE 'biblio-title-head.inc' %]</h1>
37 <div class="page-section" id="bookings-timeline"></div>
38 <div class="page-section">
39 <table id="bookings_table"></table>
43 </div> <!-- /.col-sm-10.col-sm-push-2 -->
45 <div class="col-sm-2 col-sm-pull-10">
47 [% INCLUDE 'biblio-view-menu.inc' %]
49 </div> <!-- /.col-sm-2.col-sm-pull-10 -->
52 [% INCLUDE modals/cancel_booking.inc %]
54 [% MACRO jsinclude BLOCK %]
55 [% Asset.js("lib/dayjs/dayjs.min.js") | $raw %]
56 [% Asset.js("lib/vis-timeline/vis-timeline-graph2d.min.js") | $raw %]
57 [% INCLUDE 'datatables.inc' %]
58 [% INCLUDE 'columns_settings.inc' %]
59 [% INCLUDE 'calendar.inc' %]
60 [% INCLUDE 'select2.inc' %]
61 [% INCLUDE 'js-patron-format.inc' %]
62 [% INCLUDE 'js-date-format.inc' %]
63 [% Asset.js("js/place_booking_modal.js") | $raw %]
64 [% Asset.js("js/cancel_booking_modal.js") | $raw %]
66 var cancel_success = 0;
67 var update_success = 0;
70 $(document).ready(function(){
73 url: '/api/v1/biblios/[% biblionumber | uri %]/items?bookable=1',
77 var bookings = $.ajax({
78 url: '/api/v1/biblios/[% biblionumber | uri %]/bookings',
83 $.when(items, bookings).then(
84 function(items, bookings){
85 var itemsSet = new vis.DataSet([{
87 content: "Biblio level"
89 for (item of items[0]) {
92 content: "Item " + item.external_id,
96 var bookingsSet = new vis.DataSet();
97 for (booking of bookings[0]){
99 id: booking.booking_id,
100 booking: booking.booking_id,
101 patron: booking.patron_id,
102 start: dayjs(booking.start_date).toDate(),
103 end: dayjs(booking.end_date).toDate(),
104 content: 'Booking: ' + booking.booking_id,
105 editable: { remove: true, updateTime: true },
107 group: booking.item_id ? booking.item_id : 0
111 var container = document.getElementById('bookings-timeline');
114 verticalScroll: true,
119 timeAxis: {scale: 'day', step: 1},
120 dataAttributes: [ 'booking' ],
122 // always snap to full days, independent of the scale
123 snap: function (date, scale, step) {
124 let offset = date.getTimezoneOffset() * 60 * 1000;
125 let day = 24 * 60 * 60 * 1000;
126 let seconds = Math.round(date / day) * day;
127 return seconds + offset;
130 // prevent overlapping bookings
131 onMoving: function (item, callback) {
132 var overlapping = bookingsSet.get({
133 filter: function(testItem) {
134 if (testItem.id == item.id) {
137 if (testItem.group != item.group) {
140 return ((item.start < testItem.end) && (item.end > testItem.start));
144 if (overlapping.length == 0) {
150 onMove: function (item, callback) {
152 let startDate = new Date(item.start);
154 // set end datetime hours and minutes to the end of the day
155 let endDate = new Date(item.end);
156 endDate.setHours(endDate.getHours()+23);
157 endDate.setMinutes(endDate.getMinutes()+59);
159 let url = '/api/v1/bookings/'+item.booking;
160 var putting = $.ajax({
163 data: JSON.stringify({
164 "booking_id": item.booking,
165 "start_date": startDate.toISOString(),
166 "end_date": endDate.toISOString(),
167 "biblio_id": [% biblionumber | uri %],
168 "item_id": item.group != 0 ? item.group : null,
169 "patron_id": item.patron
173 putting.done(function(data) {
178 putting.fail(function(data) {
179 $('#booking_result').replaceWith('<div id="booking_result" class="alert alert-danger">Failure</div>');
182 onRemove: function (item, callback) {
183 $('#cancelBookingModal').modal('show', $('<button data-booking="'+item.id+'">'));
184 $('#cancelBookingModal').on('hide.bs.modal', function(e) {
185 if (cancel_success) {
192 timeline = new vis.Timeline(container, bookingsSet, itemsSet, options);
194 function(jqXHR, textStatus, errorThrown){
195 console.log("Fetch failed");
199 var bookings_table_url = "/api/v1/biblios/[% biblionumber | uri %]/bookings";
200 bookings_table = $('#bookings_table').kohaTable({
202 "url": bookings_table_url
209 "data": "booking_id",
210 "title": "Booking ID",
216 "data": "item.external_id",
220 "defaultContent": "Any item",
221 "render": function(data,type,row,meta) {
223 return row.item.external_id;
230 "data": "patron.firstname:patron.surname",
234 "render": function(data, type, row, meta) {
235 return $patron_to_html(row.patron, {
236 display_cardnumber: false,
242 "data": "start_date",
243 "title": "Start date",
246 "render": function(data, type, row, meta) {
247 return $date(row.start_date);
255 "render": function(data, type, row, meta) {
256 return $date(row.end_date);
264 "render": function(data, type, row, meta) {
265 var result = '<button type="button" class="btn btn-default btn-xs cancel-action" data-toggle="modal" data-target="#cancelBookingModal" data-booking="'+row.booking_id+'"><i class="fa fa-trash" aria-hidden="true"></i> '+_("Cancel")+'</button>';
274 [% INCLUDE 'intranet-bottom.inc' %]