<div ngbDropdownMenu>
<a ngbDropdownItem routerLink="../brief-record"
queryParamsHandling="merge" i18n>Add Brief Record</a>
+ <button ngbDropdownItem (click)="deleteLineitems()"
+ [disabled]="!canDeleteLis()" i18n>Delete Selected Lineitems</button>
<div class="dropdown-divider"></div>
<h6 class="dropdown-header" i18n>Selection List Actions</h6>
- <button ngbDropdownItem (click)="deleteLineitems()"
- [disabled]="!picklistId" i18n>Delete Selected Lineitems</button>
<button ngbDropdownItem (click)="createPo()"
[disabled]="!picklistId" i18n>Create Purchase Order from Selected Lineitems</button>
<button ngbDropdownItem (click)="createPo(true)"
import {Component, OnInit, Input, Output, ViewChild} from '@angular/core';
import {Router, ActivatedRoute, ParamMap} from '@angular/router';
-import {Observable} from 'rxjs';
-import {tap} from 'rxjs/operators';
+import {Observable, from} from 'rxjs';
+import {tap, concatMap} from 'rxjs/operators';
import {Pager} from '@eg/share/util/pager';
import {EgEvent, EventService} from '@eg/core/event.service';
import {IdlObject} from '@eg/core/idl.service';
import {HoldingsService} from '@eg/staff/share/holdings/holdings.service';
import {CancelDialogComponent} from './cancel-dialog.component';
+const DELETABLE_STATES = [
+ 'new', 'selector-ready', 'order-ready', 'approved', 'pending-order'
+]
+
@Component({
templateUrl: 'lineitem-list.component.html',
selector: 'eg-lineitem-list',
'open-ils.acq.purchase_order.lineitem.delete' :
'open-ils.acq.picklist.lineitem.delete';
- let promise = Promise.resolve();
-
- this.loading = true;
-
- ids.forEach(id => {
- promise = promise
- .then(_ => this.net.request(
- 'open-ils.acq', method, this.auth.token(), id).toPromise()
- );
- });
-
- promise.then(_ => this.load());
+ from(ids)
+ .pipe(concatMap(id =>
+ this.net.request('open-ils.acq', method, this.auth.token(), id)
+ ))
+ .pipe(concatMap(_ => from(this.load())))
+ .subscribe();
}
liHasRealCopies(li: IdlObject): boolean {
queryParams: {li: fromAll ? this.lineitemIds : this.selectedIds()}
});
}
+
+ // For PO's, lineitems can only be deleted if they are pending order.
+ canDeleteLis(): boolean {
+ const li = this.pageOfLineitems[0];
+ return Boolean(this.picklistId) || (
+ Boolean(li) &&
+ DELETABLE_STATES.includes(li.state()) &&
+ Boolean(this.poId)
+ );
+ }
}