Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
{{#linkTo 'firms.new'}}New{/linkTo}}
{{outlet}}
<form>
{{view Ember.TextField valueBinding="name"}}
{{#if errors.name}}
<span>{{errors.name}}</span>
{{/if}}
<button {{action 'save'}}>Ok</button>
<button {{action 'cancel'}}>Cancel</button>
</form>
App.FirmsNewController = Ember.ObjectController.extend({
needs: ['currentUser', 'currentFirm'],
errors: null,
createModel: function(attrributes) {
return this.get('store').transaction().createRecord(App.Firm, attrributes);
},
subscribeSave: function() {
this.get('content').on('didCreate', this, function() {
return this.transitionToRoute('index');
});
this.get('content').on('becameInvalid', this, function() {
this.handleFailure();
});
this.get('content').on('becameError', this, function() {
this.handleFailure();
});
},
handleFailure: function() {
this.set('errors', this.get('content.errors'));
this.get('transaction').rollback();
this.set('content', this.createModel(this.get('toJSON')));
this.subscribeSave();
},
save: function() {
var user = this.get('controllers.currentUser.content');
this.get('users').addObject(user);
if (this.get('isValid') && !this.get('isSaving')) {
this.get('transaction').commit();
}
},
cancel: function() {
this.transitionToRoute('index');
}
});
App.FirmsNewRoute = Ember.Route.extend({
model: function() {
return this.controllerFor('firmsNew').createModel();
},
setupController: function(controller, model) {
controller.set('errors', null);
controller.subscribeSave();
},
deactivate: function() {
this.controllerFor('firmsNew').get("transaction").rollback();
}
});
DEBUG: -------------------------------
DEBUG: Ember.VERSION : 1.0.0-rc.3
DEBUG: Handlebars.VERSION : 1.0.0-rc.3
DEBUG: jQuery.VERSION : 1.9.1
DEBUG: -------------------------------
App.Router.map(function() {
this.resource('firms', function() {
this.route('new');
});
});
App.Store = DS.Store.extend({
revision: 12,
adapter: DS.RESTAdapter.extend({
namespace: 'api/v1'
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.