</div>
<ng-container *ngIf="volcopy.defaults.values.unified_display">
<div class="mt-2">
- <eg-copy-attrs [context]="context"
+ <eg-copy-attrs [context]="context" #copyAttrs
(canSaveChange)="attrsCanSaveChange($event)"></eg-copy-attrs>
</div>
</ng-container>
<a ngbNavLink i18n>Item Attributes</a>
<ng-template ngbNavContent>
<div class="mt-2">
- <eg-copy-attrs [context]="context"
+ <eg-copy-attrs [context]="context" #copyAttrs
(canSaveChange)="attrsCanSaveChange($event)"></eg-copy-attrs>
</div>
</ng-template>
import {VolCopyService} from './volcopy.service';
import {NgbNav, NgbNavChangeEvent} from '@ng-bootstrap/ng-bootstrap';
import {BroadcastService} from '@eg/share/util/broadcast.service';
+import {CopyAttrsComponent} from './copy-attrs.component';
const COPY_FLESH = {
flesh: 1,
volsCanSave = true;
attrsCanSave = true;
changesPending = false;
+ routingAllowed = false;
@ViewChild('pendingChangesDialog', {static: false})
pendingChangesDialog: ConfirmDialogComponent;
+ @ViewChild('copyAttrs', {static: false}) copyAttrs: CopyAttrsComponent;
+
constructor(
private router: Router,
private route: ActivatedRoute,
// Changing the route ultimately results in changing the tab.
beforeTabChange(evt: NgbNavChangeEvent) {
evt.preventDefault();
- this.tab = evt.nextId;
- this.routeToTab();
+
+ let promise = this.canDeactivate();
+ if (!(promise instanceof Promise)) {
+ promise = Promise.resolve(promise);
+ }
+
+ promise.then(ok => {
+ if (ok) {
+ this.routingAllowed = true;
+ this.tab = evt.nextId;
+ this.routeToTab();
+ }
+ });
}
routeToTab() {
}
@HostListener('window:beforeunload', ['$event'])
- canDeactivate($event?: Event): Promise<boolean> {
+ canDeactivate($event?: Event): boolean | Promise<boolean> {
+
+ if (this.routingAllowed) {
+ // We call canDeactive manually when routing between volcopy
+ // tabs. If routingAllowed, it means we'ave already confirmed
+ // the tag change is OK.
+ this.routingAllowed = false;
+ return true;
+ }
+
+ const editing = this.copyAttrs ? this.copyAttrs.hasActiveInput() : false;
- if (!this.changesPending) { return Promise.resolve(true); }
+ if (!editing && !this.changesPending) { return true; }
// Each warning dialog clears the current "changes are pending"
// flag so the user is not presented with the dialog again
- // unless new changes are made.
+ // unless new changes are made. The 'editing' value will reset
+ // since the attrs component is getting destroyed.
this.changesPending = false;
if ($event) { // window.onbeforeunload