+<eg-string #successMsg i18n-text text="Penalty Successfully Applied"></eg-string>
+<eg-string #errorMsg i18n-text text="Failed To Apply New Penalty"></eg-string>
+
<ng-template #dialogContent>
<div class="modal-header bg-info">
<h4 class="modal-title">
<select class="form-control"
[(ngModel)]="penaltyTypeFromSelect">
<option value='' i18n>Penalty Type...</option>
- <option value="pen.id()" *ngFor="let pen of penaltyTypes">
+ <option value="{{pen.id()}}" *ngFor="let pen of penaltyTypes">
{{pen.label()}}
</option>
</select>
</div>
</div>
<div class="modal-footer flex">
- <div *ngIf="requireInitials">
- <input type="text" class="form-control" size="3" [(ngModel)]="initials"/>
+ <div *ngIf="requireInitials" class="form-validated">
+ <input type="text" class="form-control" size="3" required
+ i18n-placeholder placeholder="Initials..." [(ngModel)]="initials"/>
</div>
<div class="flex-1"></div>
<!-- initials.. disable -->
<button type="button" class="btn btn-success"
- [disabled]="!penaltyType" (click)="apply()" i18n>OK</button>
+ [disabled]="requireInitials && !initials" (click)="apply()" i18n>OK</button>
<button type="button" class="btn btn-warning"
(click)="close()" i18n>Cancel</button>
</div>
import {IdlService, IdlObject} from '@eg/core/idl.service';
import {OrgService} from '@eg/core/org.service';
import {AuthService} from '@eg/core/auth.service';
+import {NetService} from '@eg/core/net.service';
+import {EventService} from '@eg/core/event.service';
+import {ToastService} from '@eg/share/toast/toast.service';
import {PcrudService} from '@eg/core/pcrud.service';
import {NgbModal} from '@ng-bootstrap/ng-bootstrap';
import {DialogComponent} from '@eg/share/dialog/dialog.component';
+import {StringComponent} from '@eg/share/string/string.component';
/**
STAFF_CHR = 25;
staffInitials: string = '';
- penaltyTypes: IdlObject[] = [];
+ penaltyTypes: IdlObject[];
penaltyTypeFromSelect = '';
penaltyTypeFromButton;
patron: IdlObject;
dataLoaded = false;
requireInitials = false;
initials: string;
+ noteText = '';
+
+ @ViewChild('successMsg', {static: false}) successMsg: StringComponent;
+ @ViewChild('errorMsg', {static: false}) errorMsg: StringComponent;
constructor(
private modal: NgbModal,
+ private idl: IdlService,
private org: OrgService,
+ private net: NetService,
+ private evt: EventService,
+ private toast: ToastService,
private auth: AuthService,
private pcrud: PcrudService) {
super(modal);
const obs1 = this.pcrud.retrieve('au', this.patronId)
.pipe(tap(usr => this.patron = usr));
- if (this.penaltyTypes.length > 0) { return obs1; }
+ if (this.penaltyTypes) { return obs1; }
return obs1.pipe(switchMap(_ => {
return this.pcrud.search('csp', {id: {'>': 100}}, {}, {atomic: true})
}
apply() {
- this.close();
+
+ const pen = this.idl.create('ausp');
+ pen.usr(this.patronId);
+ pen.org_unit(this.auth.user().ws_ou());
+ pen.set_date('now');
+ pen.staff(this.auth.user().id());
+
+ pen.note(this.initials ?
+ `${this.noteText} [${this.initials}]` : this.noteText);
+
+ pen.standing_penalty(
+ this.penaltyTypeFromSelect || this.penaltyTypeFromButton);
+
+ this.net.request(
+ 'open-ils.actor',
+ 'open-ils.actor.user.penalty.apply',
+ this.auth.token(), pen
+ ).subscribe(resp => {
+ const e = this.evt.parse(resp);
+ if (e) {
+ this.errorMsg.current().then(msg => this.toast.danger(msg));
+ this.error(e, true);
+ } else {
+ // resp == penalty ID on success
+ this.successMsg.current().then(msg => this.toast.success(msg));
+ this.close(resp);
+ }
+ });
}
buttonClass(pType: number): string {