Browse Source

refactor: simplify isFormDirty logic

pull/3544/head
Arman Ozak 7 years ago
parent
commit
e112cf8dc7
  1. 26
      npm/ng-packs/packages/theme-shared/src/lib/components/modal/modal.component.ts

26
npm/ng-packs/packages/theme-shared/src/lib/components/modal/modal.component.ts

@ -102,17 +102,7 @@ export class ModalComponent implements OnDestroy {
destroy$ = new Subject<void>();
get isFormDirty(): boolean {
let node: HTMLDivElement;
if (!this.modalContent) {
node = document.getElementById('modal-container') as HTMLDivElement;
}
const nodes = getFlatNodes(
((node || this.modalContent.nativeElement).querySelector('#abp-modal-body') as HTMLElement)
.childNodes,
);
return hasNgDirty(nodes);
return Boolean(document.querySelector('.modal-dialog .ng-dirty'));
}
constructor(private renderer: Renderer2, private confirmationService: ConfirmationService) {}
@ -178,17 +168,3 @@ export class ModalComponent implements OnDestroy {
this.init.emit();
}
}
function getFlatNodes(nodes: NodeList): HTMLElement[] {
return Array.from(nodes).reduce(
(acc, val) => [
...acc,
...(val.childNodes && val.childNodes.length ? getFlatNodes(val.childNodes) : [val]),
],
[],
);
}
function hasNgDirty(nodes: HTMLElement[]) {
return nodes.findIndex(node => (node.className || '').indexOf('ng-dirty') > -1) > -1;
}

Loading…
Cancel
Save