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

(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/holds_table.inc (-1 / +5 lines)
Lines 129-135 Link Here
129
                    [%- IF Koha.Preference('IndependentBranches') && Branches.all().size == 1 -%]
129
                    [%- IF Koha.Preference('IndependentBranches') && Branches.all().size == 1 -%]
130
                        [% Branches.GetName(hold.branchcode) | html %] <input type="hidden" name="pickup" value="[% hold.branchcode | html %]" />
130
                        [% Branches.GetName(hold.branchcode) | html %] <input type="hidden" name="pickup" value="[% hold.branchcode | html %]" />
131
                    [%- ELSE -%]
131
                    [%- ELSE -%]
132
                        <select class="pickup_location_dropdown" data-selected="[% hold.branchcode | html %]" data-hold_id="[% hold.reserve_id | html %]" name="pickup">
132
                        <select class="pickup_location_dropdown"
133
                                data-selected="[% hold.branchcode | html %]"
134
                                data-hold-id="[% hold.reserve_id | html %]"
135
                                data-pickup-location-source="hold"
136
                                name="pickup">
133
                            <option selected="selected" value="[% hold.branchcode | html %]">[% Branches.GetName(hold.branchcode) | html %]</option>
137
                            <option selected="selected" value="[% hold.branchcode | html %]">[% Branches.GetName(hold.branchcode) | html %]</option>
134
                            <option value="" disabled="disabled" class="loading">Loading...</option>
138
                            <option value="" disabled="disabled" class="loading">Loading...</option>
135
                        </select>
139
                        </select>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt (-114 / +11 lines)
Lines 486-492 Link Here
486
                            <li>
486
                            <li>
487
                                <label for="pickup">Pickup at:</label>
487
                                <label for="pickup">Pickup at:</label>
488
                            [% UNLESS ( multi_hold ) %]
488
                            [% UNLESS ( multi_hold ) %]
489
                                <select name="pickup" id="pickup" data-biblio-id="[% biblio.biblionumber | html %]" data-patron-id="[% patron.borrowernumber | html %]">
489
                                <select name="pickup" id="pickup"
490
                                        data-biblio-id="[% biblio.biblionumber | html %]"
491
                                        data-patron-id="[% patron.borrowernumber | html %]"
492
                                        data-pickup-location-source="biblio">
490
                                    [% PROCESS options_for_libraries libraries => Branches.pickup_locations({ search_params => { biblio => biblionumber, patron => patron }, selected => pickup }) %]
493
                                    [% PROCESS options_for_libraries libraries => Branches.pickup_locations({ search_params => { biblio => biblionumber, patron => patron }, selected => pickup }) %]
491
                            [% ELSE %]
494
                            [% ELSE %]
492
                                <select name="pickup" id="pickup_multi" data-patron-id="[% patron.borrowernumber | html %]">
495
                                <select name="pickup" id="pickup_multi" data-patron-id="[% patron.borrowernumber | html %]">
Lines 763-769 Link Here
763
                                                    [% IF (itemloo.pickup_locations_count > 0) %]
766
                                                    [% IF (itemloo.pickup_locations_count > 0) %]
764
                                                        <select name="item_pickup_[% itemloo.itemnumber | html %]" class="pickup_locations"
767
                                                        <select name="item_pickup_[% itemloo.itemnumber | html %]" class="pickup_locations"
765
                                                                data-item-id="[% itemloo.itemnumber | html %]"
768
                                                                data-item-id="[% itemloo.itemnumber | html %]"
766
                                                                data-patron-id="[% patron.borrowernumber | html %]">
769
                                                                data-patron-id="[% patron.borrowernumber | html %]"
770
                                                                data-pickup-location-source="item">
767
                                                        [% IF (itemloo.default_pickup_location) %]
771
                                                        [% IF (itemloo.default_pickup_location) %]
768
                                                            <option value="[% itemloo.default_pickup_location.branchcode | html %]" selected="selected">[% itemloo.default_pickup_location.branchname | html %]</option>
772
                                                            <option value="[% itemloo.default_pickup_location.branchcode | html %]" selected="selected">[% itemloo.default_pickup_location.branchname | html %]</option>
769
                                                        [% END %]
773
                                                        [% END %]
Lines 1292-1333 Link Here
1292
            [% END %]
1296
            [% END %]
1293
1297
1294
            $(".pickup_location_dropdown").each( function () {
1298
            $(".pickup_location_dropdown").each( function () {
1295
                var this_dropdown = $(this);
1299
                $(this).pickup_locations_dropdown();
1296
                var hold_id = $(this).data('hold_id');
1297
1298
                this_dropdown.select2({
1299
                    allowClear: false,
1300
                    ajax: {
1301
                        url: '/api/v1/holds/' + encodeURIComponent(hold_id) + '/pickup_locations',
1302
                        delay: 300, // wait 300 milliseconds before triggering the request
1303
                        dataType: 'json',
1304
                        data: function (params) {
1305
                            var search_term = (params.term === undefined) ? '' : params.term;
1306
                            var query = {
1307
                                "q": JSON.stringify({"name":{"-like":'%'+search_term+'%'}}),
1308
                                "_order_by": "name",
1309
                                "_page": params.page
1310
                            };
1311
1312
                            return query;
1313
                        },
1314
                        processResults: function (data, params) {
1315
                            var results = [];
1316
                            data.results.forEach( function ( pickup_location ) {
1317
                                results.push(
1318
                                    {
1319
                                        "id": pickup_location.library_id.escapeHtml(),
1320
                                        "text": pickup_location.name.escapeHtml(),
1321
                                        "needs_override": pickup_location.needs_override
1322
                                    }
1323
                                );
1324
                            });
1325
                            return { "results": results, "pagination": { "more": data.pagination.more } };
1326
                        },
1327
                        transport: kohaSelect2Transport
1328
                    },
1329
                    templateResult: display_pickup_location
1330
                });
1331
            });
1300
            });
1332
1301
1333
            $("#pickup_multi").select2({
1302
            $("#pickup_multi").select2({
Lines 1354-1436 Link Here
1354
            });
1323
            });
1355
1324
1356
            $("#pickup").each( function () {
1325
            $("#pickup").each( function () {
1357
                var this_dropdown = $(this);
1326
                $(this).pickup_locations_dropdown();
1358
                var patron_id = $(this).data('patron-id');
1359
                var biblio_id = $(this).data('biblio-id');
1360
1361
                this_dropdown.select2({
1362
                    width: 'style',
1363
                    allowClear: false,
1364
                    ajax: {
1365
                        url: '/api/v1/biblios/' + encodeURIComponent(biblio_id) + '/pickup_locations',
1366
                        delay: 300, // wait 300 milliseconds before triggering the request
1367
                        dataType: 'json',
1368
                        data: function (params) {
1369
                            var search_term = (params.term === undefined) ? '' : params.term;
1370
                            var query = {
1371
                                "q": JSON.stringify({"name":{"-like":'%'+search_term+'%'}}),
1372
                                "_order_by": "name",
1373
                                "patron_id": patron_id,
1374
                                "_page": params.page
1375
                            };
1376
                            return query;
1377
                        },
1378
                        processResults: function (data) {
1379
                            var results = [];
1380
                            data.results.forEach( function ( pickup_location ) {
1381
                                results.push(
1382
                                    {
1383
                                        "id": pickup_location.library_id.escapeHtml(),
1384
                                        "text": pickup_location.name.escapeHtml(),
1385
                                        "needs_override": pickup_location.needs_override
1386
                                    }
1387
                                );
1388
                            });
1389
                            return { "results": results, "pagination": { "more": data.pagination.more } };
1390
                        },
1391
                        transport: kohaSelect2Transport,
1392
                    },
1393
                    templateResult: display_pickup_location
1394
                });
1395
            });
1327
            });
1396
            $(".pickup_locations").each( function () {
1328
1397
                var this_dropdown = $(this);
1329
            $(".pickup_locations").each(function () {
1398
                var patron_id = $(this).data('patron-id');
1330
                $(this).pickup_locations_dropdown();
1399
                var item_id   = $(this).data('item-id');
1400
1401
                this_dropdown.select2({
1402
                    allowClear: true,
1403
                    ajax: {
1404
                        url: '/api/v1/items/' + encodeURIComponent(item_id) + '/pickup_locations',
1405
                        delay: 300, // wait 300 milliseconds before triggering the request
1406
                        dataType: 'json',
1407
                        data: function (params) {
1408
                            var search_term = (params.term === undefined) ? '' : params.term;
1409
                            var query = {
1410
                                "q": JSON.stringify({"name":{"-like":'%'+search_term+'%'}}),
1411
                                "_order_by": "name",
1412
                                "patron_id": patron_id,
1413
                                "_page": params.page
1414
                            };
1415
                            return query;
1416
                        },
1417
                        processResults: function (data) {
1418
                            var results = [];
1419
                            data.results.forEach( function ( pickup_location ) {
1420
                                results.push(
1421
                                    {
1422
                                        "id": pickup_location.library_id.escapeHtml(),
1423
                                        "text": pickup_location.name.escapeHtml(),
1424
                                        "needs_override": pickup_location.needs_override
1425
                                    }
1426
                                );
1427
                            });
1428
                            return { "results": results, "pagination": { "more": data.pagination.more } };
1429
                        },
1430
                        transport: kohaSelect2Transport
1431
                    },
1432
                    templateResult: display_pickup_location
1433
                });
1434
            });
1331
            });
1435
        });
1332
        });
1436
1333
(-)a/koha-tmpl/intranet-tmpl/prog/js/holds.js (-41 / +80 lines)
Lines 14-19 function display_pickup_location (state) { Link Here
14
    return $text;
14
    return $text;
15
};
15
};
16
16
17
(function ($) {
18
19
    /**
20
     * Generate a Select2 dropdown for pickup locations
21
     *
22
     * It expects the select object to contain several data-* attributes
23
     * - data-pickup-location-source: 'biblio', 'item' or 'hold' (default)
24
     * - data-patron-id: required for 'biblio' and 'item'
25
     * - data-biblio-id: required for 'biblio' only
26
     * - data-item-id: required for 'item' only
27
     *
28
     * @return {Object} The Select2 instance
29
     */
30
31
    $.fn.pickup_locations_dropdown = function () {
32
        var select = $(this);
33
        var pickup_location_source = $(this).data('pickup-location-source');
34
        var patron_id = $(this).data('patron-id');
35
        var biblio_id = $(this).data('biblio-id');
36
        var item_id = $(this).data('item-id');
37
        var hold_id = $(this).data('hold-id');
38
39
        var url;
40
41
        if ( pickup_location_source === 'biblio' ) {
42
            url = '/api/v1/biblios/' + encodeURIComponent(biblio_id) + '/pickup_locations';
43
        }
44
        else if ( pickup_location_source === 'item' ) {
45
            url = '/api/v1/items/' + encodeURIComponent(item_id) + '/pickup_locations';
46
        }
47
        else { // hold
48
            url = '/api/v1/holds/' + encodeURIComponent(hold_id) + '/pickup_locations';
49
        }
50
51
        select.select2({
52
            width: 'style',
53
            allowClear: false,
54
            ajax: {
55
                url: url,
56
                delay: 300, // wait 300 milliseconds before triggering the request
57
                cache: true,
58
                dataType: 'json',
59
                data: function (params) {
60
                    var search_term = (params.term === undefined) ? '' : params.term;
61
                    var query = {
62
                        "q": JSON.stringify({"name":{"-like":'%'+search_term+'%'}}),
63
                        "_order_by": "name",
64
                        "_page": params.page
65
                    };
66
67
                    if ( pickup_location_source !== 'hold' ) {
68
                        query["patron_id"] = patron_id;
69
                    }
70
71
                    return query;
72
                },
73
                processResults: function (data) {
74
                    var results = [];
75
                    data.results.forEach( function ( pickup_location ) {
76
                        results.push(
77
                            {
78
                                "id": pickup_location.library_id.escapeHtml(),
79
                                "text": pickup_location.name.escapeHtml(),
80
                                "needs_override": pickup_location.needs_override
81
                            }
82
                        );
83
                    });
84
                    return { "results": results, "pagination": { "more": data.pagination.more } };
85
                },
86
                transport: kohaSelect2Transport,
87
            },
88
            templateResult: display_pickup_location
89
        });
90
91
        return select;
92
    };
93
})(jQuery);
94
17
/* global __ dataTablesDefaults borrowernumber SuspendHoldsIntranet */
95
/* global __ dataTablesDefaults borrowernumber SuspendHoldsIntranet */
18
$(document).ready(function() {
96
$(document).ready(function() {
19
    var holdsTable;
97
    var holdsTable;
Lines 94-100 $(document).ready(function() { Link Here
94
                    {
172
                    {
95
                        "mDataProp": function( oObj ) {
173
                        "mDataProp": function( oObj ) {
96
                            if( oObj.branches.length > 1 && oObj.found !== 'W' && oObj.found !== 'T' ){
174
                            if( oObj.branches.length > 1 && oObj.found !== 'W' && oObj.found !== 'T' ){
97
                                var branchSelect='<select priority='+oObj.priority+' class="hold_location_select" data-hold-id="'+oObj.reserve_id+'" reserve_id="'+oObj.reserve_id+'" name="pick-location">';
175
                                var branchSelect='<select priority='+oObj.priority+' class="hold_location_select" data-hold-id="'+oObj.reserve_id+'" reserve_id="'+oObj.reserve_id+'" name="pick-location" data-pickup-location-source="hold">';
98
                                for ( var i=0; i < oObj.branches.length; i++ ){
176
                                for ( var i=0; i < oObj.branches.length; i++ ){
99
                                    var selectedbranch;
177
                                    var selectedbranch;
100
                                    var setbranch;
178
                                    var setbranch;
Lines 235-279 $(document).ready(function() { Link Here
235
                    });
313
                    });
236
                });
314
                });
237
315
238
                $(".hold_location_select").each( function () {
316
                $(".hold_location_select").each(function(){ $(this).pickup_locations_dropdown(); });
239
                    var this_dropdown = $(this);
240
                    var hold_id = $(this).data('hold-id');
241
242
                    this_dropdown.select2({
243
                        allowClear: false,
244
                        ajax: {
245
                            url: '/api/v1/holds/' + encodeURIComponent(hold_id) + '/pickup_locations',
246
                            delay: 300, // wait 300 milliseconds before triggering the request
247
                            dataType: 'json',
248
                            cache: true,
249
                            data: function (params) {
250
                                var search_term = (params.term === undefined) ? '' : params.term;
251
                                var query = {
252
                                    "q": JSON.stringify({"name":{"-like":'%'+search_term+'%'}}),
253
                                    "_order_by": "name",
254
                                    "_page": params.page
255
                                };
256
                                return query;
257
                            },
258
                            processResults: function (data) {
259
                                var results = [];
260
                                data.results.forEach( function ( pickup_location ) {
261
                                    results.push(
262
                                        {
263
                                            "id": pickup_location.library_id.escapeHtml(),
264
                                            "text": pickup_location.name.escapeHtml(),
265
                                            "needs_override": pickup_location.needs_override
266
                                        }
267
                                    );
268
                                });
269
                                return { "results": results, "pagination": { "more": data.pagination.more } };
270
                            },
271
                            transport: kohaSelect2Transport
272
                        },
273
                        templateResult: display_pickup_location
274
                    });
275
                    $('.select2-container').css('width','100%');
276
                });
277
317
278
                $(".hold_location_select").on("change", function(){
318
                $(".hold_location_select").on("change", function(){
279
                    $(this).prop("disabled",true);
319
                    $(this).prop("disabled",true);
280
- 

Return to bug 29407