[readOnly]="fieldIsDisabled('fund')"
[asyncSupportsEmptyTermClick]="true"
#fundSelector [entries]="fundEntries"
+ [displayTemplate]="fundTmpl"
[selectedId]="copy.fund()" (onChange)="valueChange('fund', $event)"
[idlQuerySort]="{acqf: 'year DESC, code'}"
[idlQueryAnd]="{active: 't'}">
</ng-container>
</div>
+<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>
@Component({
templateUrl: 'copy-attrs.component.html',
+ styleUrls: ['copy-attrs.component.css'],
selector: 'eg-lineitem-copy-attrs'
})
export class LineitemCopyAttrsComponent implements OnInit {
@Output() becameDirty = new EventEmitter<Boolean>();
fundEntries: ComboboxEntry[];
+ _fundBalanceCache: string[] = [];
+ _inflight: Promise<string>[] = [];
circModEntries: ComboboxEntry[];
private _copy: IdlObject;
}
}
+ 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];
+ });
+ }
+
fieldIsDisabled(field: string) {
if (this.batchMode) { return false; }