UNPKG

muffin.io

Version:

A full stack development tool for creating modern webapps

45 lines (33 loc) 1.13 kB
Backbone = require 'Backbone' Form = require 'muffin/forms' <$- classified $> = require '../models/<$- classified $>' class <$- classified $>NewView extends Backbone.View template: _.template(require '../templates/<$- classified $>NewView.html') events: 'click form .btn-primary': 'onSubmit' 'click form .btn.cancel': 'onCancel' initialize: -> @$el.html @template() # Set up data structures backing the view @model = new <$- classified $>() # Set up form @form = new Form el: @$('form') model: @model render: => @ onSubmit: (e) -> # Validate the fields and update the model errors = @form.commit() return false if errors @model.save {}, sender: @model success: (model, response) => logging.debug "Created <$- classified $>." Backbone.history.navigate '#<$- underscored_plural $>', true error: (model, response) => logging.debug "Failed to create <$- classified $>." false onCancel: (e) -> Backbone.history.navigate '#<$- underscored_plural $>', true false module.exports = <$- classified $>NewView