class="modal-header"> <button class="close" data-dismiss="modal" aria-hidden="true">×</button> <h3>Are you sure?</h3> </div> <div class="modal-body"> <p>There are changes that have not been saved.</p> </div> <div class="modal-footer"> <a {{action "falseAnswer" target="view"}} class="btn">Keep changes</a> <a {{action "trueAnswer" target="view"}} class="btn-primary">Discard changes</a> </div> </div> what the user sees on the page modalAction is the entry point target=view
class="modal-header"> <button class="close" data-dismiss="modal" aria-hidden="true">×</button> <h3>Are you sure?</h3> </div> <div class="modal-body"> <p>There are changes that have not been saved.</p> </div> <div class="modal-footer"> <a {{action "falseAnswer" target="view"}} class="btn">Keep changes</a> <a {{action "trueAnswer" target="view"}} class="btn-primary">Discard changes</a> </div> </div> Using Bootstrap’s markup for modal Hidden by default Prompts user to continue with this action 3 actions to handle in the view logic
class="modal-header"> <button class="close" data-dismiss="modal" aria-hidden="true">×</button> <h3>Are you sure?</h3> </div> <div class="modal-body"> <p>There are changes that have not been saved.</p> </div> <div class="modal-footer"> <a {{action "falseAnswer" target="view"}} class="btn">Keep changes</a> <a {{action "trueAnswer" target="view"}} class="btn-primary">Discard changes</a> </div> </div> Using Bootstrap’s markup for modal Hidden by default Prompts user to continue with this action 3 actions to handle in the view logic
if(this.get('confirm')){ this.$('.modal').modal(); } else { this.triggerAction(); } }, answer: false, trueAnswer: function(){ this.set('answer', true); this.$('.modal').modal('hide'); }, falseAnswer: function(){ this.set('answer', false); this.$('.modal').modal('hide'); }, eventManager: { hidden: function (event, view) { if (view.get('answer')) { view.set('answer', false); view.triggerAction(); } } } modalAction: confirm by default, can bind to this on controller for example, isDirty this.$() selects within scope of the view ViewTargetActionSupport trigger action works just like the action helper
this.set('answer', false); this.$('.modal').modal('hide'); }, eventManager: { hidden: function (event, view) { if (view.get('answer')) { view.set('answer', false); view.triggerAction(); } } } }); App = Ember.Application.create({ customEvents: { 'hidden': 'hidden' } }); Ember.Handlebars.helper('modal', App.ModalView); Bootstrap fires the `hidden` event when the modal animation is complete eventManager to register for DOM events no bind on or off. Handles event delegation for you injects the Ember view
{ view.set('answer', false); view.triggerAction(); } } } }); App = Ember.Application.create({ customEvents: { 'hidden': 'hidden' } }); Ember.Handlebars.helper('modal', App.ModalView); Create your own handlebars helper out of a view Can pass in the view class directly But first let’s see what it would look like with the view helper
final product: very similar to an action helper, but confirms with the user first if necessary An example for delete: always confirm use different template w/ red button etc