Last active
August 29, 2015 13:57
-
-
Save rjcorwin/9494916 to your computer and use it in GitHub Desktop.
Boiler Backbone.js helper code for a Form Route to do CRUD operations on a Model.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Boiler Backbone.js helper code for a Form Route to do CRUD operations on a Model. | |
| FormRoute = function(modelId, modelClass, formClass, redirect) { | |
| var model = new App.Models[modelClass]() | |
| var form = new App.Views[formClass]({model: model}) | |
| App.$el.children('.body').html(form.el) | |
| form.once('Form:done', function() { | |
| Backbone.history.navigate(redirect, {trigger: true}) | |
| }) | |
| if (modelId) { | |
| model.id = modelId | |
| model.fetch({success: function() { | |
| form.render() | |
| }}) | |
| } | |
| else { | |
| form.render() | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment