Skip to content

Commit

Permalink
circulation: fix on loan tab behaviour
Browse files Browse the repository at this point in the history
* Fixes '403 error' managing (checkout not allowed by ci-po).
* Fixes input clearing and focus.

Co-Authored-by: Alicia Zangger <alicia.zangger@rero.ch>
  • Loading branch information
Alicia Zangger authored and AoNoOokami committed Feb 7, 2020
1 parent 8113817 commit 78f78f5
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions projects/admin/src/app/circulation/patron/loan/loan.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export class LoanComponent implements OnInit {
* @param barcode: barcode of the item to get
*/
getItem(barcode: string) {
this.searchInputFocus = false;
const item = this.checkedOutItems.find(currItem => currItem.barcode === barcode);
if (item && item.actions.includes(ItemAction.checkin)) {
item.currentAction = ItemAction.checkin;
Expand All @@ -106,18 +107,24 @@ export class LoanComponent implements OnInit {
this.translate.instant('Item not found'),
this.translate.instant('Checkout')
);
this.searchText = '';
this.searchInputFocus = true;
} else {
if (newItem.status === ItemStatus.ON_LOAN) {
this.toastService.error(
this.translate.instant('The item is already on loan'),
this.translate.instant('Checkout')
);
this.searchText = '';
this.searchInputFocus = true;
} else {
if (newItem.pending_loans && newItem.pending_loans[0].patron_pid !== this.patron.pid) {
this.toastService.warning(
this.translate.instant('The item has a request'),
this.translate.instant('Checkout')
);
this.searchText = '';
this.searchInputFocus = true;
} else {
newItem.currentAction = ItemAction.checkout;
this.applyItems([newItem]);
Expand All @@ -130,6 +137,8 @@ export class LoanComponent implements OnInit {
error.message,
this.translate.instant('Checkout')
);
this.searchText = '';
this.searchInputFocus = true;
},
() => {
console.log('loan success');
Expand All @@ -142,7 +151,6 @@ export class LoanComponent implements OnInit {
* @param items: checked in and checked out items
*/
applyItems(items: Item[]) {
this.searchInputFocus = false;
const observables = [];
for (const item of items) {
if (item.currentAction !== ItemAction.no) {
Expand Down Expand Up @@ -178,7 +186,7 @@ export class LoanComponent implements OnInit {
if (err && err.error && err.error.status) {
errorMessage = err.error.status;
}
if ( err.error.status.includes('403 Forbidden')) {
if (err.error.status === 403) {
this.toastService.error(
this.translate.instant('Checkout is not allowed by circulation policy'),
this.translate.instant('Checkout')
Expand All @@ -189,6 +197,8 @@ export class LoanComponent implements OnInit {
this.translate.instant('Circulation')
);
}
this.searchText = '';
this.searchInputFocus = true;
}
);
}
Expand Down

0 comments on commit 78f78f5

Please sign in to comment.