(onChange)="charge.fund($event ? $event.id : null)"
i18n-placeholder placeholder="Fund..."
[asyncSupportsEmptyTermClick]="true"
+ [displayTemplate]="fundTmpl"
[required]="true" [readOnly]="!charge.isnew() && !charge.ischanged()"
[idlQuerySort]="{acqf: 'year DESC, code'}"
[idlQueryAnd]="{org: owners, active: 't'}">
</div>
</div>
</ng-container>
+
+<ng-template #fundTmpl let-r="result" i18n>
+ <span [ngClass]="{'fund-balance-state-stop': checkFundBalance(r.fm.id()) === 'stop',
+ 'fund-balance-state-warning': checkFundBalance(r.fm.id()) === 'warning'}">{{r.label}}</span>
+</ng-template>
\ No newline at end of file
poSubscription: Subscription;
owners: number[];
classNames: string[];
+ _fundBalanceCache: string[] = [];
+ _inflight: Promise<string>[] = [];
@ViewChild('disencumberChargeDialog') disencumberChargeDialog: DisencumberChargeDialogComponent;
}).then(_ => this.poService.refreshOrderSummary(true));
}
}
+
+ // duplicated from acq/lineitem/copy-attrs.component
+ checkFundBalance(fundId: number): string {
+ if (this._fundBalanceCache[fundId]) {
+ return this._fundBalanceCache[fundId];
+ }
+ if (this._inflight[fundId]) {
+ return 'ok';
+ }
+ this._inflight[fundId] = this.net.request(
+ 'open-ils.acq',
+ 'open-ils.acq.fund.check_balance_percentages',
+ this.auth.token(), fundId
+ ).toPromise().then(r => {
+ if (r[0]) {
+ this._fundBalanceCache[fundId] = 'stop';
+ } else if (r[1]) {
+ this._fundBalanceCache[fundId] = 'warning';
+ } else {
+ this._fundBalanceCache[fundId] = 'ok';
+ }
+
+ delete this._inflight[fundId];
+ return this._fundBalanceCache[fundId];
+ });
+ }
}