import Ember from 'ember';

export default Ember.Route.extend({
  stepName: 'security-controls',

  model(params) {
    let securityControlGroups = this.modelFor('settings.security-controls');
    return securityControlGroups.findBy('handle', params.handle);
  },

  save() {
    Ember.run(() => window.scrollTo(0, 0));

    let { schemaDocument, attestation } = this.currentModel;
    let documentClone = Ember.$.extend(true, {}, schemaDocument.dump({ excludeInvalid: true }));

    attestation.set('document', documentClone);
    attestation.setUser(this.session.get('currentUser'));
    return attestation.save();
  },

  setupController(controller, model) {
    let securityControlGroups = this.modelFor('settings.security-controls');

    controller.set('model', model);
    controller.set('securityControlGroups', securityControlGroups);
  },

  actions: {
    onSave() {
      this.save();
    }
  }
});

@@ -604,24 +604,318 @@
 ation.save()
+.then(() =%3E %7B%0A      let message = 'Changes saved!';%0A      Ember.get(this, 'flashMessages').success(message);%0A    %7D, (e) =%3E %7B%0A      let message = Ember.getWithDefault(e, 'responseJSON.message', 'An error occured');%0A      Ember.get(this, 'flashMessages').danger(%60Save Failed! $%7Bmessage%7D%60);%0A    %7D)
 ;%0A  %7D,%0A%0A  se

add success/error flash messages to security control settings