Confirmation dialog

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

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://emberjs.com/guides/cookbook/user_interface_and_interaction/using_modal_dialogs/

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

@jasonmit Yes, exactly

@seif any progress on this?

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.