Sha256: 855e2f939259b7fcff2f438dbc058716965fcfc7c2b68e3e1f7066e320325525

Contents?: true

Size: 1 KB

Versions: 11

Compression:

Stored size: 1 KB

Contents

$ ->
  PostsApp.EditPostView = Backbone.View.extend
    events:
      'click .cancel' : 'cancelPost'
      'click .update' : 'updatePost'

    template:
      JST["crowdblog/templates/posts/edit"]

    render: ->
      this.model.fetch()
      this.$el.html(this.template({post: this.model.toJSON(), isNew: this.model.isNew()}))
      this

    cancelPost: (e) ->
      e.preventDefault()
      this.goHome()

    updatePost: (e) ->
      e.preventDefault()
      this.model.save this.extractData(),
        success: =>
          this.goHome()

        error: (e) =>
          errors = $.parseJSON(e.responseText).errors
          console.log errors[0]

          $.each errors, (key, value) =>
            this.$('.control-group.' + key).addClass('error')
            this.$('.' + key + '.help-inline').html(value.join(','))

    extractData: ->
      {
        'body' : this.$('#post_body').val(),
        'title' : this.$('#post_title').val()
      }

    goHome: ->
      PostsApp.router.navigate '/'
        trigger: true

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
crowdblog-0.0.12 app/assets/javascripts/crowdblog/views/posts/edit_post_view.js.coffee
crowdblog-0.0.10 app/assets/javascripts/crowdblog/views/posts/edit_post_view.js.coffee
crowdblog-0.0.9 app/assets/javascripts/crowdblog/views/posts/edit_post_view.js.coffee
crowdblog-0.0.8 app/assets/javascripts/crowdblog/views/posts/edit_post_view.js.coffee
crowdblog-0.0.7 app/assets/javascripts/crowdblog/views/posts/edit_post_view.js.coffee
crowdblog-0.0.6 app/assets/javascripts/crowdblog/views/posts/edit_post_view.js.coffee
crowdblog-0.0.5 app/assets/javascripts/crowdblog/views/posts/edit_post_view.js.coffee
crowdblog-0.0.4 app/assets/javascripts/crowdblog/views/posts/edit_post_view.js.coffee
crowdblog-0.0.3 app/assets/javascripts/crowdblog/views/posts/edit_post_view.js.coffee
crowdblog-0.0.2 app/assets/javascripts/crowdblog/views/posts/edit_post_view.js.coffee
crowdblog-0.0.1 app/assets/javascripts/crowdblog/views/posts/edit_post_view.js.coffee