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

(-)a/Koha/Hold.pm (+14 lines)
Lines 338-343 sub biblio { Link Here
338
    return $self->{_biblio};
338
    return $self->{_biblio};
339
}
339
}
340
340
341
=head3 patron
342
343
Returns the related Koha::Patron object for this hold
344
345
=cut
346
347
sub patron {
348
    my ($self) = @_;
349
350
    $self->{_patron} ||= Koha::Patrons->find( $self->borrowernumber() );
351
352
    return $self->{_patron};
353
}
354
341
=head3 item
355
=head3 item
342
356
343
Returns the related Koha::Item object for this Hold
357
Returns the related Koha::Item object for this Hold
(-)a/Koha/REST/V1/Holds.pm (+32 lines)
Lines 395-398 sub update_priority { Link Here
395
    };
395
    };
396
}
396
}
397
397
398
=head3 pickup_locations
399
400
Method that returns the possible pickup_locations for a given hold
401
used for building the dropdown selector
402
403
=cut
404
405
sub pickup_locations {
406
    my $c = shift->openapi->valid_input or return;
407
408
    my $hold_id = $c->validation->param('hold_id');
409
    my $hold = Koha::Holds->find($hold_id);
410
411
    unless ($hold) {
412
        return $c->render(
413
            status  => 404,
414
            openapi => { error => "Hold not found" }
415
        );
416
    }
417
418
    return try {
419
        my $pickup_locations = $hold->itemnumber ?
420
        $hold->item->pickup_locations({ patron => $hold->patron }) : $hold->biblio->pickup_locations({ patron => $hold->patron });
421
        warn Data::Dumper::Dumper( $pickup_locations );
422
423
        return $c->render( status => 200, openapi => $pickup_locations );
424
    }
425
    catch {
426
        $c->unhandled_exception($_);
427
    };
428
}
429
398
1;
430
1;
(-)a/api/v1/swagger/paths.json (+3 lines)
Lines 59-64 Link Here
59
  "/holds/{hold_id}/suspension": {
59
  "/holds/{hold_id}/suspension": {
60
    "$ref": "paths/holds.json#/~1holds~1{hold_id}~1suspension"
60
    "$ref": "paths/holds.json#/~1holds~1{hold_id}~1suspension"
61
  },
61
  },
62
  "/holds/{hold_id}/pickup_locations": {
63
    "$ref": "paths/holds.json#/~1holds~1{hold_id}~1pickup_locations"
64
  },
62
  "/items": {
65
  "/items": {
63
    "$ref": "paths/items.json#/~1items"
66
    "$ref": "paths/items.json#/~1items"
64
  },
67
  },
(-)a/api/v1/swagger/paths/holds.json (+57 lines)
Lines 613-617 Link Here
613
        }
613
        }
614
      }
614
      }
615
    }
615
    }
616
  },
617
  "/holds/{hold_id}/pickup_locations": {
618
    "get": {
619
      "x-mojo-to": "Holds#pickup_locations",
620
      "operationId": "getHoldPickupLocations",
621
      "tags": ["holds"],
622
      "parameters": [{
623
          "$ref": "../parameters.json#/hold_id_pp"
624
        }],
625
      "produces": ["application/json"],
626
      "responses": {
627
        "200": {
628
          "description": "Hold pickup location"
629
        },
630
        "400": {
631
          "description": "Missing or wrong parameters",
632
          "schema": {
633
            "$ref": "../definitions.json#/error"
634
          }
635
        },
636
        "401": {
637
          "description": "Authentication required",
638
          "schema": {
639
            "$ref": "../definitions.json#/error"
640
          }
641
        },
642
        "403": {
643
          "description": "Hold pickup location list not allowed",
644
          "schema": {
645
            "$ref": "../definitions.json#/error"
646
          }
647
        },
648
        "404": {
649
          "description": "Hold not found",
650
          "schema": {
651
            "$ref": "../definitions.json#/error"
652
          }
653
        },
654
        "500": {
655
          "description": "Internal server error",
656
          "schema": {
657
            "$ref": "../definitions.json#/error"
658
          }
659
        },
660
        "503": {
661
          "description": "Under maintenance",
662
          "schema": {
663
            "$ref": "../definitions.json#/error"
664
          }
665
        }
666
      },
667
      "x-koha-authorization": {
668
        "permissions": {
669
          "reserveforothers": "1"
670
        }
671
      }
672
    }
616
  }
673
  }
617
}
674
}
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/holds_table.inc (-2 / +4 lines)
Lines 132-140 Link Here
132
                    [% IF Koha.Preference('IndependentBranches') && Branches.all().size == 1 %]
132
                    [% IF Koha.Preference('IndependentBranches') && Branches.all().size == 1 %]
133
                        [% Branches.GetName(hold.branchcode) | html %] <input type="hidden" name="pickup" value="[% hold.branchcode | html %]" />
133
                        [% Branches.GetName(hold.branchcode) | html %] <input type="hidden" name="pickup" value="[% hold.branchcode | html %]" />
134
                    [% ELSE %]
134
                    [% ELSE %]
135
                        <select name="pickup">
135
                        <select class="pickup_location_dropdown" data-selected="[% hold.branchcode | html %]" data-hold_id="[% hold.reserve_id | html %]" name="pickup">
136
                            [% PROCESS options_for_libraries libraries => Branches.pickup_locations( { search_params => { item => hold.itemnumber, biblio => hold.biblionumber, patron => hold.patron }, selected => hold.branchcode }) %]
136
                            <option selected="selected" value="[% hold.branchcode | html %]">[% Branches.GetName(hold.branchcode) | html %]</option>
137
                            <option value="" disabled="disabled" class="loading">Loading...</option>
137
                        </select>
138
                        </select>
139
                        <img class="loading_[% hold.reserve_id %]" src="[% interface | html %]/[% theme | html %]/img/spinner-small.gif" alt="" style="display:none;"/>
138
                    [% END %]
140
                    [% END %]
139
                [% END %]
141
                [% END %]
140
            </td>
142
            </td>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt (+1 lines)
Lines 985-990 Link Here
985
    [% INCLUDE 'columns_settings.inc' %]
985
    [% INCLUDE 'columns_settings.inc' %]
986
    [% Asset.js("lib/hc-sticky.js") | $raw %]
986
    [% Asset.js("lib/hc-sticky.js") | $raw %]
987
    [% Asset.js("js/circ-patron-search-results.js") | $raw %]
987
    [% Asset.js("js/circ-patron-search-results.js") | $raw %]
988
    [% Asset.js("js/holds.js") | $raw %]
988
    <script>
989
    <script>
989
        var Sticky;
990
        var Sticky;
990
        var biblionumber = "[% biblionumber | $raw %]";
991
        var biblionumber = "[% biblionumber | $raw %]";
(-)a/koha-tmpl/intranet-tmpl/prog/js/holds.js (-1 / +30 lines)
Lines 302-305 $(document).ready(function() { Link Here
302
        });
302
        });
303
    });
303
    });
304
304
305
    $(".pickup_location_dropdown").on( "click",function(){
306
        var this_dropdown = $(this);
307
        if(this_dropdown.data('loaded')===1){ return true};
308
        var hold_id = $(this).data('hold_id');
309
        $(".loading_"+hold_id).show();
310
        var preselected = $(this).data('selected');
311
        var api_url = '/api/v1/holds/'+hold_id+'/pickup_locations';
312
        $.ajax({
313
            method: "GET",
314
            url: api_url,
315
            success: function( data ){
316
                var dropdown = "";
317
                $.each(data, function(index,library) {
318
                    if( preselected == library.branchcode ){
319
                        selected = ' selected="selected" ';
320
                    } else { selected = ""; }
321
                    dropdown += '<option value="'+library.branchcode+'"'+selected+'>'+library.branchname+'</option>';
322
                });
323
                this_dropdown.html( dropdown);
324
                this_dropdown.data("loaded",1);
325
                $(".loading_"+hold_id).hide();
326
            },
327
            error: function( jqXHR, textStatus, errorThrown) {
328
                alert('There was an error:'+textStatus+" "+errorThrown);
329
                $(".loading_"+hold_id).hide();
330
            },
331
        });
332
    });
333
334
305
});
335
});
306
- 

Return to bug 26988