diff --git a/README.md b/README.md index f1d6141..332a1fc 100644 --- a/README.md +++ b/README.md @@ -215,7 +215,11 @@ Template `dialog-layouts/delete.hbs`: ```hbs

Confirm Deletion

- {{yield}} + {{#if templateName}} +
{{partial templateName}}
+ {{else}} + {{component "dialog-body" layout=template contextObject=contextObject context=context class="dialog-body"}} + {{/if}}
diff --git a/addon/components/dialog-body.js b/addon/components/dialog-body.js new file mode 100644 index 0000000..62051cd --- /dev/null +++ b/addon/components/dialog-body.js @@ -0,0 +1,3 @@ +import Ember from "ember"; + +export default Ember.Component.extend(); diff --git a/addon/services/dialog.js b/addon/services/dialog.js index a8f3d4b..c9452f5 100644 --- a/addon/services/dialog.js +++ b/addon/services/dialog.js @@ -61,12 +61,11 @@ export default Ember.Service.extend(Ember.Evented, { * @param {module:ember-dialog/components/presenter} presenter */ remove(presenter) { + if (this.get('isDestroyed')) return; var id = presenter.get("presenterId") || guidFor(presenter); var dialogs = this.get("dialogs").filter((item) => { return item.id !== id; }); - - //filter would return Array not EmberArray? this.set("dialogs", Ember.A(dialogs)); }, @@ -261,7 +260,7 @@ export default Ember.Service.extend(Ember.Evented, { */ show(layout, template, context, options = {}, componentName = DEFAULT_COMPONENT_NAME) { - /* Generate presenterId from (layoutName + templateName) or provided id + /* Generate presenterId from (layoutName + templateName) or provided id to make sure the dialog won't open multiple times */ var presenterId = options.id || ""; if(typeof layout === "string" && typeof template === "string"){ @@ -291,9 +290,12 @@ export default Ember.Service.extend(Ember.Evented, { } if (Ember.typeOf(template) === "object") { + // The template will be included into the presenter's body as + // dialog-body component options = Ember.merge(options, { template: template }); } else { - options = Ember.merge(options, { template: getOwner(this).lookup(["template", template].join(":")) }); + // The template will be included into the presenter's body as partial + options = Ember.merge(options, { templateName: template }); } presenter = presenter.reopen(options); diff --git a/app/components/dialog-body.js b/app/components/dialog-body.js new file mode 100644 index 0000000..1401b9e --- /dev/null +++ b/app/components/dialog-body.js @@ -0,0 +1 @@ +export { default } from 'ember-dialog/components/dialog-body'; diff --git a/app/templates/layouts/alert.hbs b/app/templates/layouts/alert.hbs index cc0d43c..2e62a97 100644 --- a/app/templates/layouts/alert.hbs +++ b/app/templates/layouts/alert.hbs @@ -6,7 +6,11 @@
{{title}}
-
{{yield}}
+ {{#if templateName}} +
{{partial templateName}}
+ {{else}} + {{component "dialog-body" layout=template contextObject=contextObject context=context class="dialog-body"}} + {{/if}} diff --git a/app/templates/layouts/confirm.hbs b/app/templates/layouts/confirm.hbs index 9eec46d..15494b6 100644 --- a/app/templates/layouts/confirm.hbs +++ b/app/templates/layouts/confirm.hbs @@ -3,10 +3,14 @@
-
{{ title }}
+
{{title}}
-
{{yield}}
+ {{#if templateName}} +
{{partial templateName}}
+ {{else}} + {{component "dialog-body" layout=template contextObject=contextObject context=context class="dialog-body"}} + {{/if}}