Created
November 28, 2011 12:15
-
-
Save moski/1400188 to your computer and use it in GitHub Desktop.
A sample New View backbone class that uses iframe.
This file contains 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
Lifelane.Views.Posts ||= {} | |
class Lifelane.Views.Posts.NewView extends Backbone.View | |
template: JST["backbone/templates/posts/new"] | |
events: | |
"submit #create-post": "save" | |
# The constructor for creating new post. | |
constructor: (options) -> | |
super(options) | |
@model = new @collection.model() | |
@model.bind("change:errors", () => this.render()) | |
# Saving a new post. | |
# options: | |
# success | |
# error | |
# iframe | |
# | |
save: (e) -> | |
e.preventDefault() | |
e.stopPropagation() | |
@model.unset("errors") | |
@collection.create(@model.toJSON(), | |
success: (post) => | |
if(post.isNew()) | |
@model.set({errors: post}) | |
else | |
@model = post | |
window.location.hash = "/index" | |
error: (post, jqXHR) => | |
@model.set({errors: $.parseJSON(jqXHR.responseText)}) | |
iframe: true | |
) | |
render: -> | |
$(this.el).html(@template(@model.toJSON() )) | |
this.$("form").customBackboneLink(@model) | |
this |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment