import {StringService} from '@eg/share/string/string.service';
interface CheckoutStat {
- override?: boolean;
- redo?: boolean;
- renew?: boolean;
+ override: boolean;
+ redo: boolean;
+ renew: boolean;
+ displayText: string;
+ displayTextArgs: any;
+ alertSound: string;
+ shouldPopup: boolean;
}
@Injectable({providedIn: 'root'})
} else if (stat.renew) {
return this.renew(barcode);
}
- });
- // return this.router.navigate(['/scko']);
+ // Checkout actions always takes us back to the main page
+ // so we can see our items out in progress.
+ })
+ .then(stat => this.notifyPatron(stat))
+ .finally(() => this.router.navigate(['/scko']));
}
renew(barcode: string, override?: boolean): Promise<any> {
});
}
- notifyPatron(text: string, sound: string, popup?: boolean, stringArgs?: any) {
+ notifyPatron(stat: CheckoutStat) {
this.statusDisplayText = '';
- if (this.alertAudio && sound) {
- this.audio.play(sound);
+ if (this.alertAudio && stat.alertSound) {
+ this.audio.play(stat.alertSound);
}
- if (!text) { return; }
+ if (!stat.displayText) { return; }
- this.strings.interpolate(text, stringArgs).then(str => {
+ this.strings.interpolate(stat.displayText, stat.displayTextArgs)
+ .then(str => {
this.statusDisplayText = str;
- if (this.alertPopup && popup && str) {
+ if (this.alertPopup && stat.shouldPopup && str) {
this.alertDialog.dialogBody = str;
this.alertDialog.open().toPromise();
}
});
}
- handleCheckoutResult(result: any,
- barcode: string, action: string): Promise<CheckoutStat> {
+ handleCheckoutResult(
+ result: any, barcode: string, action: string): Promise<CheckoutStat> {
if (Array.isArray(result)) {
result = result[0];
return;
}
- let alertText = '';
- let alertSound = '';
+ const checkoutStat: CheckoutStat = {
+ displayText: 'scko.unknown',
+ alertSound: '',
+ shouldPopup: false,
+ redo: false,
+ override: false,
+ renew: false,
+ displayTextArgs: {}
+ };
if (evt.textcode === 'SUCCESS') {
- alertText = `scko.${action}.success`;
- alertSound = `success.scko.${action}`;
- this.notifyPatron;
- return Promise.resolve({});
+ checkoutStat.displayText = `scko.${action}.success`;
+ checkoutStat.alertSound = `success.scko.${action}`;
}
- return Promise.resolve({});
+ return Promise.resolve(checkoutStat);
}
}