View | Details | Raw Unified | Return to bug 29002
Collapse All | Expand All

(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/cat-toolbar.inc (+4 lines)
Lines 189-194 Link Here
189
    [% END %]
189
    [% END %]
190
[% END %]
190
[% END %]
191
191
192
<div class="btn-group"><button id="placbooking" class="btn btn-default" data-toggle="modal" data-target="#placeBookingModal" data-biblionumber="[% biblionumber | html %]"><i class="fa fa-calendar"></i> Place booking</button></div>
193
192
[% IF Koha.Preference('ArticleRequests') %]
194
[% IF Koha.Preference('ArticleRequests') %]
193
    <div class="btn-group"><a id="placehold" class="btn btn-default" href="/cgi-bin/koha/circ/request-article.pl?biblionumber=[% biblionumber | html %]"><i class="fa fa-file-text-o"></i> Request article</a></div>
195
    <div class="btn-group"><a id="placehold" class="btn btn-default" href="/cgi-bin/koha/circ/request-article.pl?biblionumber=[% biblionumber | html %]"><i class="fa fa-file-text-o"></i> Request article</a></div>
194
[% END %]
196
[% END %]
Lines 239-241 Link Here
239
        </div>
241
        </div>
240
        </div>
242
        </div>
241
    </div>
243
    </div>
244
245
    [% INCLUDE modals/place_booking.inc %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/modals/place_booking.inc (+42 lines)
Line 0 Link Here
1
<!-- Place booking modal -->
2
<div class="modal" id="placeBookingModal" tabindex="-1" role="dialog" aria-labelledby="placeBookingLabel">
3
    <form id="placeBookingForm">
4
        <div class="modal-dialog" role="document">
5
            <div class="modal-content">
6
                <div class="modal-header">
7
                    <button type="button" class="closebtn" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
8
                    <h4 class="modal-title" id="placeBookingLabel">Place booking</h4>
9
                </div>
10
                <div class="modal-body">
11
                    <div id="booking_result"></div>
12
                    <fieldset class="rows">
13
                        <input type="hidden" name="biblio_id" id="booking_biblio_id">
14
                        <input type="hidden" name="start_date" id="booking_start_date">
15
                        <input type="hidden" name="end_date" id="booking_end_date">
16
                        <ol>
17
                            <li>
18
                                <div class="hint">Enter patron card number or partial name:</div>
19
                                <label class="required" for="booking_patron_id">Patron: </label>
20
                                <select name="booking_patron_id" id="booking_patron_id" required="required">
21
                                    <option></option>
22
                                    [% IF patron %]
23
                                    <option value="[% borrowernumber | uri %]" selected="selected">[% patron.firstname | html %] [% patron.surname %] ([% patron.cardnumber %] )</option>
24
                                    [% END %]
25
                                </select>
26
                            </li>
27
                            <li>
28
                                <label class="required" for="period">Period: </label>
29
                                <input type="text" id="period" name="period" class="flatpickr" required="required" disabled="true" autocomplete="off">
30
                                <span class="required">Required</span>
31
                            </li>
32
                        </ol>
33
                    </fieldset>
34
                </div> <!-- /.modal-body -->
35
                <div class="modal-footer">
36
                    <button type="submit" class="btn btn-primary">Submit</button>
37
                    <button type="button" class="btn btn-default" data-dismiss="modal" aria-hidden="true">Cancel</button>
38
                </div> <!-- /.modal-footer -->
39
            </div> <!-- /.modal-content -->
40
        </div> <!-- /.modal-dialog -->
41
    </form>
42
</div> <!-- /#placeBookingModal -->
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt (+4 lines)
Lines 1022-1027 Note that permanent location is a code, and location may be an authval. Link Here
1022
1022
1023
[% MACRO jsinclude BLOCK %]
1023
[% MACRO jsinclude BLOCK %]
1024
    [% INCLUDE 'catalog-strings.inc' %]
1024
    [% INCLUDE 'catalog-strings.inc' %]
1025
    [% INCLUDE 'calendar.inc' %]
1026
    [% INCLUDE 'select2.inc' %]
1027
    [% INCLUDE 'js-date-format.inc' %]
1025
    [% Asset.js("js/catalog.js") | $raw %]
1028
    [% Asset.js("js/catalog.js") | $raw %]
1026
    [% Asset.js("js/coce.js") | $raw %]
1029
    [% Asset.js("js/coce.js") | $raw %]
1027
    [% Asset.js("lib/Chocolat/js/chocolat.js") | $raw %]
1030
    [% Asset.js("lib/Chocolat/js/chocolat.js") | $raw %]
Lines 1317-1322 Note that permanent location is a code, and location may be an authval. Link Here
1317
    [% INCLUDE 'columns_settings.inc' %]
1320
    [% INCLUDE 'columns_settings.inc' %]
1318
    [% Asset.js("js/browser.js") | $raw %]
1321
    [% Asset.js("js/browser.js") | $raw %]
1319
    [% Asset.js("js/table_filters.js") | $raw %]
1322
    [% Asset.js("js/table_filters.js") | $raw %]
1323
    [% Asset.js("js/place_booking_modal.js") | $raw %]
1320
    <script>
1324
    <script>
1321
        var browser;
1325
        var browser;
1322
        browser = KOHA.browser('[% searchid | html %]', parseInt(biblionumber, 10));
1326
        browser = KOHA.browser('[% searchid | html %]', parseInt(biblionumber, 10));
(-)a/koha-tmpl/intranet-tmpl/prog/js/place_booking_modal.js (-1 / +129 lines)
Line 0 Link Here
0
- 
1
function update_picker(periodPicker, biblionumber) {
2
3
    // Disable input whilst we fetch dates
4
    $("#period").prop('disabled', true);
5
6
    // Fetch dates and re-enable input
7
    $.ajax({
8
        url: '/api/v1/bookings?biblio_id=' + biblionumber,
9
        async: true,
10
        success: function(data) {
11
            var dates_to_disable = [];
12
            for (booking of data) {
13
                dates_to_disable.push({
14
                    from: booking.start_date,
15
                    to: booking.end_date
16
                });
17
            }
18
            periodPicker.set('disable', dates_to_disable);
19
            $("#period").prop('disabled', false);
20
        }
21
    });
22
};
23
24
$('#placeBookingModal').on('show.bs.modal', function(e) {
25
    var button = $(e.relatedTarget);
26
    var biblionumber = button.data('biblionumber');
27
    $('#booking_biblio_id').val(biblionumber);
28
29
    $("#booking_patron_id").select2({
30
        dropdownParent: $(".modal-content", "#placeBookingModal"),
31
        width: '30%',
32
        dropdownAutoWidth: true,
33
        allowClear: true,
34
        minimumInputLength: 3,
35
        ajax: {
36
            url: '/api/v1/patrons',
37
            delay: 250,
38
            dataType: 'json',
39
            data: function(params) {
40
                var search_term = (params.term === undefined) ? '' : params.term;
41
                var query = {
42
                    'q': JSON.stringify({
43
                        "-or": [
44
                            {
45
                                "firstname": {
46
                                    "-like": search_term + '%'
47
                                }
48
                            },
49
                            {
50
                                "surname": {
51
                                    "-like": search_term + '%'
52
                                }
53
                            },
54
                            {
55
                                "cardnumber": {
56
                                    "-like": search_term + '%'
57
                                }
58
                            }
59
                        ]
60
                    }),
61
                    '_order_by': 'firstname'
62
                };
63
                return query;
64
            },
65
            processResults: function(data) {
66
                var results = [];
67
                data.forEach(function(patron) {
68
                    results.push({
69
                        "id": patron.patron_id,
70
                        "text": escape_str(patron.firstname) + " " + escape_str(patron.surname) + " (" + escape_str(patron.cardnumber) + ")"
71
                    });
72
                });
73
                return {
74
                    "results": results
75
                };
76
            }
77
        },
78
        placeholder: "Search for a patron"
79
    });
80
81
    var periodPicker = $("#period").flatpickr({
82
        mode: "range",
83
        minDate: "today",
84
        dateFormat: "Y-m-d",
85
        onChange: function(selectedDates) {
86
            var _this = this;
87
            var dateArr = selectedDates.map(function(date) {
88
                return _this.formatDate(date, 'Y-m-d');
89
            });
90
            $('#booking_start_date').val(dateArr[0]);
91
            $('#booking_end_date').val(dateArr[1]);
92
        }
93
    });
94
95
    // Get blocked dates
96
    update_picker(periodPicker, biblionumber);
97
});
98
99
$("#placeBookingForm").on('submit', function(e) {
100
    e.preventDefault();
101
102
    var url = '/api/v1/bookings';
103
104
    var start_date = $datetime($('#booking_start_date').val(), {
105
        dateformat: "rfc3339"
106
    });
107
    var end_date = $datetime($('#booking_end_date').val(), {
108
        dateformat: "rfc3339"
109
    });
110
111
    var posting = $.post(
112
        url,
113
        JSON.stringify({
114
            "start_date": start_date,
115
            "end_date": end_date,
116
            "biblio_id": $('#booking_biblio_id').val(),
117
            "item_id": $('#booking_item_id').val() ? $('#booking_item_id').val() : null,
118
            "patron_id": $('#booking_patron_id').find(':selected').val()
119
        })
120
    );
121
122
    posting.done(function(data) {
123
        $('#placeBookingModal').modal('hide');
124
    });
125
126
    posting.fail(function(data) {
127
        $('#result').replaceWith('<div id="result" class="alert alert-danger">Failure</div>');
128
    });
129
});

Return to bug 29002