{"size": 1049, "ext": "js", "max_stars_repo_path": "ember-accounts/app/components/update-email.js", "max_stars_repo_name": "schoolofacceleratedlearning/huboard-web", "max_stars_repo_stars_event_min_datetime": "2015-01-28T07:47:29.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-14T17:39:29.000Z", "max_issues_repo_path": "ember-accounts/app/components/update-email.js", "max_issues_repo_name": "schoolofacceleratedlearning/huboard-web", "max_issues_repo_issues_event_min_datetime": "2015-03-09T15:20:01.000Z", "max_issues_repo_issues_event_max_datetime": "2017-08-17T18:31:54.000Z", "max_forks_repo_path": "ember-accounts/app/components/update-email.js", "max_forks_repo_name": "schoolofacceleratedlearning/huboard-web", "max_forks_repo_forks_event_min_datetime": "2015-02-25T05:50:33.000Z", "max_forks_repo_forks_event_max_datetime": "2019-03-22T10:09:58.000Z"}
{"max_stars_count": 65, "max_issues_count": 284, "max_forks_count": 39, "avg_line_length": 27.6052631579, "max_line_length": 89, "alphanum_fraction": 0.5643469971}
import Ember from 'ember';

export default Ember.Component.extend({
  customer: Ember.computed.alias('model.details.plans.firstObject.customer'),
  onChange: Ember.observer('email', function() {
    let errors;
    errors = this.get('errors');
    if (errors) {
      this.set('errors', null);
    }
  }),
  isDisabled: function() {
    return this.get('errors') || this.get('processing');
  },
  processing: false,
  actions: {
    update() {
      this.set('processing', true);
      Ember.$.ajax({
        url: '/settings/email/' + this.get('customer'),
        data: {billing_email: this.get('email')},
        type: "PUT"
      }).then(() => {
        this.set('model.details.account_email', this.get('email'));
        this.set('processing', false);
        this.set('email', '');
        this.sendAction('close');
      }).fail(() => {
        this.set('errors', 'Your email address could not be updated, please try again.');
        this.set('processing', false);
      });
    },
    close() {
      this.sendAction('close');
    }
  }
});
