Skip to content

Commit

Permalink
[frontend] gh-81: Using model to store state instead of controller proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
holandes22 committed Apr 5, 2015
1 parent 566794f commit 1a9d859
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions frontend/app/pods/admin/users/add/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,26 @@ import Ember from 'ember';

export default Ember.Route.extend({

setupController: function(controller) {
setupController: function(controller, model) {
controller.set('model', model);
this.store.find('team').then(function(teams) {
controller.set('allTeams', teams);
});
},

model: function() {
return this.store.createRecord('user', {
username: null,
email: null,
fullName: null,
isStaff: null,
});
},

actions: {
submit: function() {
var user = this.store.createRecord('user', {
username: this.controller.get('username'),
email: this.controller.get('email'),
fullName: this.controller.get('fullName'),
isStaff: this.controller.get('isStaff'),
});
submit: function(model) {
var self = this;

user.save().then(function(){
var teams = self.controller.get('teams');
if (teams) {
user.get('teams').addObjects(teams);
}
user.save();
}).then(function(){
model.save().then(function(){
self.transitionTo('admin.users');
}, function(reason){
//TODO: Handle the error properly
Expand Down

0 comments on commit 1a9d859

Please sign in to comment.