# Confirmation dialog

**URL:** https://discuss.emberjs.com/t/confirmation-dialog/6014
**Category:** Design
**Created:** [August 2, 2014, 2:42pm UTC](https://discuss.emberjs.com/t/confirmation-dialog/6014 "2014-08-02T14:42:51Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![seif](https://avatars.discourse-cdn.com/v4/letter/s/3be4f8/32.png) [@seif](https://discuss.emberjs.com/u/seif)
#### Post date: [August 2, 2014, 2:42pm UTC](https://discuss.emberjs.com/t/confirmation-dialog/6014/1 "2014-08-02T14:42:51Z")

</div>

I’m working on a custom dialog like `alert.js`, `smoke.js`, …etc. and i was wondering what is the best practice do something like this.

Currently it works like this…

1. When app starts, I create an initializer called alert, which is an `Ember.Object`.
2. To create a dialog, I would call `this.alert.confirm('message');`
3. When `confirm` function is called it would update `message` attribute, and setup interval function of 250ms, so it would poll `answer` property.
4. When message gets updated, `x-alert` component would show dialog. On confirmation or cancel, it would set shared property `answer` (alias for `alert.answer`)
5. `confirm` function will return a promise. Promise is resolve or rejected based on answer (true =\> resolve, false =\> reject), and it would clear interval if answer was found. Other than that, interval will keep checking.

Is there a simpler approach or a way around using `setInterval` for checking for answer?

### Update

I’ve created a gist for the alert service that gets injected in Route, Controller, Component scope.

> <https://gist.github.com/seifsallam/af68c6aff2cf3b4837f6>

---

<div class="post-metadata">

### Author: ![Hummingbird](https://avatars.discourse-cdn.com/v4/letter/h/59ef9b/32.png) [@Hummingbird](https://discuss.emberjs.com/u/Hummingbird)
#### Post date: [August 3, 2014, 10:43pm UTC](https://discuss.emberjs.com/t/confirmation-dialog/6014/2 "2014-08-03T22:43:30Z")

</div>

I am pretty new to emberjs myself, so I don’t think I can provide any reliable input on your questions, but I felt probably these links might be useful to you:

[http://aaron.haurwitz.com/#!/posts/growllike-notifications-with-emberjs](http://aaron.haurwitz.com/#!/posts/growllike-notifications-with-emberjs)[http://emberjs.com/guides/cookbook/user\_interface\_and\_interaction/using\_modal\_dialogs/](http://emberjs.com/guides/cookbook/user_interface_and_interaction/using_modal_dialogs/)

---

<div class="post-metadata">

### Author: ![jasonmit](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/jasonmit/32/182_2.png) [@jasonmit](https://discuss.emberjs.com/u/jasonmit)
#### Post date: [August 4, 2014, 7:52am UTC](https://discuss.emberjs.com/t/confirmation-dialog/6014/3 "2014-08-04T07:52:45Z")

</div>

Ideally you would want the promise to resolve/reject solely based on a user action - correct? Is that what setInterval is doing?

---

<div class="post-metadata">

### Author: ![seif](https://avatars.discourse-cdn.com/v4/letter/s/3be4f8/32.png) [@seif](https://discuss.emberjs.com/u/seif)
#### Post date: [August 4, 2014, 8:45am UTC](https://discuss.emberjs.com/t/confirmation-dialog/6014/4 "2014-08-04T08:45:28Z")

</div>

@jasonmit Yes, exactly

---

<div class="post-metadata">

### Author: ![dquinn45](https://avatars.discourse-cdn.com/v4/letter/d/90db22/32.png) [@dquinn45](https://discuss.emberjs.com/u/dquinn45)
#### Post date: [October 6, 2014, 4:26pm UTC](https://discuss.emberjs.com/t/confirmation-dialog/6014/5 "2014-10-06T16:26:04Z")

</div>

@seif any progress on this?

---

<div class="post-metadata">

### Author: ![buuda](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/buuda/32/14443_2.png) [@buuda](https://discuss.emberjs.com/u/buuda)
#### Post date: [October 6, 2014, 8:40pm UTC](https://discuss.emberjs.com/t/confirmation-dialog/6014/6 "2014-10-06T20:40:55Z")

</div>

I have implemented the same functionality in a different way, using only actions, with no need for promises:

1. Implement ‘confirm’ action on application route with associated hidden view in application template.
2. Other actions that need to be confirmed have a confirmed boolean parameter. If not confirmed, these actions trigger ‘confirm’ action and do nothing else.
3. For confirm action handling: application route sets message on confirmation dialog and dialog is shown (it is always in the application template). If confirmed the original action is re-sent to the triggering action with the flag confirmed=true and all other arguments. You may need to send the target for the action to the confirm action if it is not a route.
