oneiota
oneiota

Reputation: 341

Ember js detect save on model in application

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

Answers (2)

user663031
user663031

Reputation:

Use the isSaving property on the model.

Upvotes: 3

Kingpin2k
Kingpin2k

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

Related Questions