import {Component, OnInit, Input, Output} from '@angular/core';
-import {ActivatedRoute, Router, ParamMap} from '@angular/router';
+import {ActivatedRoute, Router, ParamMap, NavigationStart} from '@angular/router';
import {IdlService, IdlObject} from '@eg/core/idl.service';
import {NetService} from '@eg/core/net.service';
import {EventService, EgEvent} from '@eg/core/event.service';
targetPo: number;
creationRequested = false;
creatingAssets = false;
+ activatePo = false;
creationStatus: AssetCreationResponse = {
liProcessed: 0,
) { }
ngOnInit() {
+ this.activatePo = history.state.activatePo ? true : false;
this.route.parent.paramMap.subscribe((params: ParamMap) => {
this.targetPo = +params.get('poId');
});
createAssets = (args: Object) => {
this.creatingAssets = true;
this.creationRequested = true;
+ this.creationErrors = [];
const assetArgs = {
vandelay: args['vandelay']
},
err => {},
() => {
- this.creatingAssets = false;
+ if (!this.creationErrors.length) {
+ this.creatingAssets = false;
+ if (this.activatePo) {
+ this.router.navigate(
+ ['/staff/acq/po/' + this.targetPo],
+ { state: { finishPoActivation: true } }
+ );
+ }
+ }
}
);
}
canActivate: boolean = null;
canFinalize = false;
showLegacyLinks = false;
+ doingActivation = false;
+ finishPoActivation = false;
activationBlocks: EgEvent[] = [];
activationWarnings: EgEvent[] = [];
return this.poService.currentPo;
}
- load(): Promise<any> {
+ load(useCache: boolean = true): Promise<any> {
if (!this.poId) { return Promise.resolve(); }
this.dupeResults.dupeFound = false;
this.dupeResults.dupePoId = -1;
- return this.poService.getFleshedPo(this.poId, {fromCache: true, toCache: true})
+ if (history.state.finishPoActivation) {
+ this.doingActivation = true;
+ useCache = false;
+ }
+
+ return this.poService.getFleshedPo(this.poId, {fromCache: useCache, toCache: true})
.then(po => {
// EDI message count
})
.then(_ => this.setCanActivate())
.then(_ => this.setCanFinalize())
- .then(_ => this.loadUiPrefs());
+ .then(_ => this.loadUiPrefs())
+ .then(_ => this.activatePoIfRequested());
}
// Can run via Enter or blur. If it just ran via Enter, avoid
zero_copy_activate: this.zeroCopyActivate
};
- this.net.request('open-ils.acq',
+ return this.net.request('open-ils.acq',
'open-ils.acq.purchase_order.activate.dry_run',
this.auth.token(), this.poId, null, options
}
activatePo(noAssets?: boolean) {
+ this.doingActivation = true;
if (this.activationWarnings.length) {
this.confirmActivate.open().subscribe(confirmed => {
- if (!confirmed) { return; }
+ if (!confirmed) {
+ this.doingActivation = true;
+ return;
+ }
this._activatePo(noAssets);
});
}
_activatePo(noAssets?: boolean) {
+ if (noAssets) {
+ // Bypass any Vandelay choices and force-load all records.
+ const vandelay = {
+ import_no_match: true,
+ queue_name: `ACQ ${new Date().toISOString()}`
+ };
+
+ const options = {
+ zero_copy_activate: this.zeroCopyActivate,
+ no_assets: noAssets
+ };
+
+ this._doActualActivate(vandelay, options);
+ } else {
+ this.poService.checkIfImportNeeded().then(importNeeded => {
+ if (importNeeded) {
+ this.router.navigate(
+ ['/staff/acq/po/' + this.po().id() + '/create-assets'],
+ { state: { activatePo: true } }
+ );
+ } else {
+ // LIs are linked to bibs, so charge forward and activate with no options set
+ this._doActualActivate({}, {});
+ }
+ });
+ }
+ }
+
+ _doActualActivate(vandelay: any, options: any) {
this.activationEvent = null;
this.progressDialog.open();
this.progressDialog.update({max: this.po().lineitem_count() * 3});
- // Bypass any Vandelay choices and force-load all records.
- // TODO: Add intermediate Vandelay options.
- const vandelay = {
- import_no_match: true,
- queue_name: `ACQ ${new Date().toISOString()}`
- };
-
- const options = {
- zero_copy_activate: this.zeroCopyActivate,
- no_assets: noAssets
- };
-
- this.net.request(
+ this.net.request(
'open-ils.acq',
'open-ils.acq.purchase_order.activate',
this.auth.token(), this.poId, vandelay, options
if (Number(resp) === 1) {
this.progressDialog.close();
// Refresh everything.
- location.href = location.href;
+ this.initDone = false;
+ this.doingActivation = false;
+ this.load(false).then(_ => this.initDone = true);
} else {
this.progressDialog.update(
});
}
+ activatePoIfRequested() {
+ if (this.canActivate && history.state.finishPoActivation) {
+ this.activatePo(false);
+ }
+ }
+
finalizePo() {
this.confirmFinalize.open().subscribe(confirmed => {