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 463-469 Link Here
463
                            <li>
463
                            <li>
464
                                <label for="pickup">Pickup at:</label>
464
                                <label for="pickup">Pickup at:</label>
465
                            [% UNLESS ( multi_hold ) %]
465
                            [% UNLESS ( multi_hold ) %]
466
                                <select name="pickup" id="pickup" data-biblio-id="[% biblio.biblionumber | html %]" data-patron-id="[% patron.borrowernumber | html %]">
466
                                <select name="pickup" id="pickup"
467
                                        data-biblio-id="[% biblio.biblionumber | html %]"
468
                                        data-patron-id="[% patron.borrowernumber | html %]"
469
                                        data-pickup-location-source="biblio">
467
                                    [% PROCESS options_for_libraries libraries => Branches.pickup_locations({ search_params => { biblio => biblionumber, patron => patron }, selected => pickup }) %]
470
                                    [% PROCESS options_for_libraries libraries => Branches.pickup_locations({ search_params => { biblio => biblionumber, patron => patron }, selected => pickup }) %]
468
                            [% ELSE %]
471
                            [% ELSE %]
469
                                <select name="pickup" id="pickup_multi" data-patron-id="[% patron.borrowernumber | html %]">
472
                                <select name="pickup" id="pickup_multi" data-patron-id="[% patron.borrowernumber | html %]">
Lines 740-746 Link Here
740
                                                    [% IF (itemloo.pickup_locations_count > 0) %]
743
                                                    [% IF (itemloo.pickup_locations_count > 0) %]
741
                                                        <select name="item_pickup_[% itemloo.itemnumber | html %]" class="pickup_locations"
744
                                                        <select name="item_pickup_[% itemloo.itemnumber | html %]" class="pickup_locations"
742
                                                                data-item-id="[% itemloo.itemnumber | html %]"
745
                                                                data-item-id="[% itemloo.itemnumber | html %]"
743
                                                                data-patron-id="[% patron.borrowernumber | html %]">
746
                                                                data-patron-id="[% patron.borrowernumber | html %]"
747
                                                                data-pickup-location-source="item">
744
                                                        [% IF (itemloo.default_pickup_location) %]
748
                                                        [% IF (itemloo.default_pickup_location) %]
745
                                                            <option value="[% itemloo.default_pickup_location.branchcode | html %]" selected="selected">[% itemloo.default_pickup_location.branchname | html %]</option>
749
                                                            <option value="[% itemloo.default_pickup_location.branchcode | html %]" selected="selected">[% itemloo.default_pickup_location.branchname | html %]</option>
746
                                                        [% END %]
750
                                                        [% END %]
Lines 1233-1274 Link Here
1233
            [% END %]
1237
            [% END %]
1234
1238
1235
            $(".pickup_location_dropdown").each( function () {
1239
            $(".pickup_location_dropdown").each( function () {
1236
                var this_dropdown = $(this);
1240
                $(this).pickup_locations_dropdown();
1237
                var hold_id = $(this).data('hold_id');
1238
1239
                this_dropdown.select2({
1240
                    allowClear: false,
1241
                    ajax: {
1242
                        url: '/api/v1/holds/' + encodeURIComponent(hold_id) + '/pickup_locations',
1243
                        delay: 300, // wait 300 milliseconds before triggering the request
1244
                        dataType: 'json',
1245
                        data: function (params) {
1246
                            var search_term = (params.term === undefined) ? '' : params.term;
1247
                            var query = {
1248
                                "q": JSON.stringify({"name":{"-like":'%'+search_term+'%'}}),
1249
                                "_order_by": "name",
1250
                                "_page": params.page
1251
                            };
1252
1253
                            return query;
1254
                        },
1255
                        processResults: function (data, params) {
1256
                            var results = [];
1257
                            data.results.forEach( function ( pickup_location ) {
1258
                                results.push(
1259
                                    {
1260
                                        "id": pickup_location.library_id.escapeHtml(),
1261
                                        "text": pickup_location.name.escapeHtml(),
1262
                                        "needs_override": pickup_location.needs_override
1263
                                    }
1264
                                );
1265
                            });
1266
                            return { "results": results, "pagination": { "more": data.pagination.more } };
1267
                        },
1268
                        transport: kohaSelect2Transport
1269
                    },
1270
                    templateResult: display_pickup_location
1271
                });
1272
            });
1241
            });
1273
1242
1274
            $("#pickup_multi").select2({
1243
            $("#pickup_multi").select2({
Lines 1295-1377 Link Here
1295
            });
1264
            });
1296
1265
1297
            $("#pickup").each( function () {
1266
            $("#pickup").each( function () {
1298
                var this_dropdown = $(this);
1267
                $(this).pickup_locations_dropdown();
1299
                var patron_id = $(this).data('patron-id');
1300
                var biblio_id = $(this).data('biblio-id');
1301
1302
                this_dropdown.select2({
1303
                    width: 'style',
1304
                    allowClear: false,
1305
                    ajax: {
1306
                        url: '/api/v1/biblios/' + encodeURIComponent(biblio_id) + '/pickup_locations',
1307
                        delay: 300, // wait 300 milliseconds before triggering the request
1308
                        dataType: 'json',
1309
                        data: function (params) {
1310
                            var search_term = (params.term === undefined) ? '' : params.term;
1311
                            var query = {
1312
                                "q": JSON.stringify({"name":{"-like":'%'+search_term+'%'}}),
1313
                                "_order_by": "name",
1314
                                "patron_id": patron_id,
1315
                                "_page": params.page
1316
                            };
1317
                            return query;
1318
                        },
1319
                        processResults: function (data) {
1320
                            var results = [];
1321
                            data.results.forEach( function ( pickup_location ) {
1322
                                results.push(
1323
                                    {
1324
                                        "id": pickup_location.library_id.escapeHtml(),
1325
                                        "text": pickup_location.name.escapeHtml(),
1326
                                        "needs_override": pickup_location.needs_override
1327
                                    }
1328
                                );
1329
                            });
1330
                            return { "results": results, "pagination": { "more": data.pagination.more } };
1331
                        },
1332
                        transport: kohaSelect2Transport,
1333
                    },
1334
                    templateResult: display_pickup_location
1335
                });
1336
            });
1268
            });
1337
            $(".pickup_locations").each( function () {
1269
1338
                var this_dropdown = $(this);
1270
            $(".pickup_locations").each(function () {
1339
                var patron_id = $(this).data('patron-id');
1271
                $(this).pickup_locations_dropdown();
1340
                var item_id   = $(this).data('item-id');
1341
1342
                this_dropdown.select2({
1343
                    allowClear: true,
1344
                    ajax: {
1345
                        url: '/api/v1/items/' + encodeURIComponent(item_id) + '/pickup_locations',
1346
                        delay: 300, // wait 300 milliseconds before triggering the request
1347
                        dataType: 'json',
1348
                        data: function (params) {
1349
                            var search_term = (params.term === undefined) ? '' : params.term;
1350
                            var query = {
1351
                                "q": JSON.stringify({"name":{"-like":'%'+search_term+'%'}}),
1352
                                "_order_by": "name",
1353
                                "patron_id": patron_id,
1354
                                "_page": params.page
1355
                            };
1356
                            return query;
1357
                        },
1358
                        processResults: function (data) {
1359
                            var results = [];
1360
                            data.results.forEach( function ( pickup_location ) {
1361
                                results.push(
1362
                                    {
1363
                                        "id": pickup_location.library_id.escapeHtml(),
1364
                                        "text": pickup_location.name.escapeHtml(),
1365
                                        "needs_override": pickup_location.needs_override
1366
                                    }
1367
                                );
1368
                            });
1369
                            return { "results": results, "pagination": { "more": data.pagination.more } };
1370
                        },
1371
                        transport: kohaSelect2Transport
1372
                    },
1373
                    templateResult: display_pickup_location
1374
                });
1375
            });
1272
            });
1376
        });
1273
        });
1377
1274
(-)a/koha-tmpl/intranet-tmpl/prog/js/holds.js (-41 / +75 lines)
Lines 14-19 function display_pickup_location (state) { Link Here
14
    return $text;
14
    return $text;
15
};
15
};
16
16
17
/**
18
 * Generate a Select2 dropdown for pickup locations
19
 *
20
 * It expects the select object to contain several data-* attributes
21
 * - data-pickup-location-source: 'biblio', 'item' or 'hold' (default)
22
 * - data-patron-id: required for 'biblio' and 'item'
23
 * - data-biblio-id: required for 'biblio' only
24
 * - data-item-id: required for 'item' only
25
 */
26
27
(function ($) {
28
    $.fn.pickup_locations_dropdown = function () {
29
        var this_dropdown = $(this);
30
        var pickup_location_source = $(this).data('pickup-location-source');
31
        var patron_id = $(this).data('patron-id');
32
        var biblio_id = $(this).data('biblio-id');
33
        var item_id = $(this).data('item-id');
34
        var hold_id = $(this).data('hold-id');
35
36
        var url;
37
38
        if ( pickup_location_source === 'biblio' ) {
39
            url = '/api/v1/biblios/' + encodeURIComponent(biblio_id) + '/pickup_locations';
40
        }
41
        else if ( pickup_location_source === 'item' ) {
42
            url = '/api/v1/items/' + encodeURIComponent(item_id) + '/pickup_locations';
43
        }
44
        else { // hold
45
            url = '/api/v1/holds/' + encodeURIComponent(hold_id) + '/pickup_locations';
46
        }
47
48
        this_dropdown.select2({
49
            width: 'style',
50
            allowClear: false,
51
            ajax: {
52
                url: url,
53
                delay: 300, // wait 300 milliseconds before triggering the request
54
                cache: true,
55
                dataType: 'json',
56
                data: function (params) {
57
                    var search_term = (params.term === undefined) ? '' : params.term;
58
                    var query = {
59
                        "q": JSON.stringify({"name":{"-like":'%'+search_term+'%'}}),
60
                        "_order_by": "name",
61
                        "_page": params.page
62
                    };
63
64
                    if ( pickup_location_source !== 'hold' ) {
65
                        query["patron_id"] = patron_id;
66
                    }
67
68
                    return query;
69
                },
70
                processResults: function (data) {
71
                    var results = [];
72
                    data.results.forEach( function ( pickup_location ) {
73
                        results.push(
74
                            {
75
                                "id": pickup_location.library_id.escapeHtml(),
76
                                "text": pickup_location.name.escapeHtml(),
77
                                "needs_override": pickup_location.needs_override
78
                            }
79
                        );
80
                    });
81
                    return { "results": results, "pagination": { "more": data.pagination.more } };
82
                },
83
                transport: kohaSelect2Transport,
84
            },
85
            templateResult: display_pickup_location
86
        });
87
    };
88
})(jQuery);
89
17
/* global __ dataTablesDefaults borrowernumber SuspendHoldsIntranet */
90
/* global __ dataTablesDefaults borrowernumber SuspendHoldsIntranet */
18
$(document).ready(function() {
91
$(document).ready(function() {
19
    var holdsTable;
92
    var holdsTable;
Lines 94-100 $(document).ready(function() { Link Here
94
                    {
167
                    {
95
                        "mDataProp": function( oObj ) {
168
                        "mDataProp": function( oObj ) {
96
                            if( oObj.branches.length > 1 && oObj.found !== 'W' && oObj.found !== 'T' ){
169
                            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">';
170
                                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++ ){
171
                                for ( var i=0; i < oObj.branches.length; i++ ){
99
                                    var selectedbranch;
172
                                    var selectedbranch;
100
                                    var setbranch;
173
                                    var setbranch;
Lines 235-279 $(document).ready(function() { Link Here
235
                    });
308
                    });
236
                });
309
                });
237
310
238
                $(".hold_location_select").each( function () {
311
                $(".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
312
278
                $(".hold_location_select").on("change", function(){
313
                $(".hold_location_select").on("change", function(){
279
                    $(this).prop("disabled",true);
314
                    $(this).prop("disabled",true);
280
- 

Return to bug 29407