Skip to content

Commit

Permalink
feat: close all open dialogs
Browse files Browse the repository at this point in the history
Closes #341
Closes #314
  • Loading branch information
Shlomi Assaf (shlassaf) committed Aug 29, 2017
1 parent 2373226 commit c674446
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ngx-modialog",
"description": "Modal / Dialog for Angular",
"version": "4.0.0-beta.2",
"version": "4.0.0-beta.3",
"repository": {
"type": "git",
"url": "https://github.com/shlomiassaf/ngx-modialog.git"
Expand Down
23 changes: 18 additions & 5 deletions src/demo/app/bootstrap-demo/presets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,30 @@ export function cascading(modal: Modal) {
presets.push(prompt(modal));
presets.push(confirm(modal));
presets.push(
modal.prompt()
modal.alert()
.size('sm')
.title('Cascading modals!')
.body('Find your way out...')
.body('Find your way out step by step or click CLOSE ALL to close all open dialogs at once')
.addButton('btn-primary', 'CLOSE ALL',
(cmp: any, $event: MouseEvent) => cmp.dialog.close('all'))
);

return {
open: () => {
let ret = presets.shift().open();
while (presets.length > 0) presets.shift().open();
return ret;
let first = presets.shift().open();
let last: any;
while (presets.length > 0) {
last = presets.shift().open();
}

last.result.then( value => {
if (value === 'all' && modal.overlay.stackLength > 0) {
// you can also inject OverlayService and use it to close all.
modal.overlay.closeAll();
}
});

return first;
}
};
}
Expand Down
25 changes: 19 additions & 6 deletions src/demo/app/vex-demo/presets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,29 @@ export function cascading(modal: Modal): DropInPresetBuilder {
presets.push(prompt.call(this, modal));
presets.push(confirm.call(this, modal));
presets.push(
modal.alert()
.className(this.theme)
.message('Cascading modals! Find your way out...')
modal.alert()
.className(this.theme)
.message('Find your way out step by step or click CLOSE ALL to close all open dialogs at once')
.addButton('btn-primary', 'CLOSE ALL',
(cmp: any, $event: MouseEvent) => cmp.dialog.close('all'))
);

return <any>{
open: () => {
let ret = presets.shift().open();
while (presets.length > 0) presets.shift().open();
return ret;
let first = presets.shift().open();
let last: any;
while (presets.length > 0) {
last = presets.shift().open();
}

last.result.then( value => {
if (value === 'all' && modal.overlay.stackLength > 0) {
// you can also inject OverlayService and use it to close all.
modal.overlay.closeAll();
}
});

return first;
}
};
}
2 changes: 1 addition & 1 deletion src/ngx-modialog/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ngx-modialog",
"description": "Modal / Dialog for Angular",
"version": "4.0.0-beta.2",
"version": "4.0.0-beta.3",
"libConfig": {
"entry": "ngx-modialog",
"inlineResources": true,
Expand Down
2 changes: 1 addition & 1 deletion src/ngx-modialog/plugins/bootstrap/package.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"version": "4.0.0-beta.2"
"version": "4.0.0-beta.3"
}
2 changes: 1 addition & 1 deletion src/ngx-modialog/plugins/js-native/package.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"version": "4.0.0-beta.2"
"version": "4.0.0-beta.3"
}
2 changes: 1 addition & 1 deletion src/ngx-modialog/plugins/vex/package.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"version": "4.0.0-beta.2"
"version": "4.0.0-beta.3"
}
6 changes: 6 additions & 0 deletions src/ngx-modialog/src/models/dialog-ref-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ export class DialogRefStack<T> {
this._stackMap = new Map<DialogRef<T>, any>();
}

closeAll(result: any = null): void {
for (let i=0, len=this._stack.length; i<len; i++) {
this._stack.pop().close(result);
}
}

push(dialogRef: DialogRef<T>, group?: any): void {
if (this._stack.indexOf(dialogRef) === -1) {
this._stack.push(dialogRef);
Expand Down
3 changes: 3 additions & 0 deletions src/ngx-modialog/src/overlay/overlay.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ export class Overlay {
return _stack.groupLength(_stack.groupOf(dialogRef));
}

closeAll(result: any = null): void {
_stack.closeAll(result);
}

/**
* Creates an overlay and returns a dialog ref.
Expand Down

0 comments on commit c674446

Please sign in to comment.