Reputation: 341
I am trying to figure out a way of setting a property on the Application controller that observes or can detect when a model in the application is saving.
Ideally what I am trying to achieve is a save button that turns into a spinner when the model is being saved - giving the user visual feedback of the save.
The obvious way seems to be manually setting a variable on the application controller pre and post save but ideally I would like to avoid this in place of a property that can observe when the application is saving.
Upvotes: 0
Views: 64
Reputation: 47367
I'd use jquery's ajaxStart
and ajaxStop
.
App.ApplicationRoute = Em.Route.extend({
beforeModel: function(){
this.setupAjaxMonitor();
},
setupAjaxMonitor: function(){
var self = this;
$(document)
.ajaxStart(function(){ self.startAjax(); })
.ajaxStop(function(){ self.stopAjax(); } );
},
startAjax: function(){
console.log('ajax starting');
},
stopAjax: function(){
console.log('ajax stopping');
}
});
Upvotes: 0