Sha256: 5709da39fb5be540e59df749110e56459c6d17763bfa25acd270f0e9963c2ef7

Contents?: true

Size: 1.57 KB

Versions: 10

Compression:

Stored size: 1.57 KB

Contents

$ ->
  PostsApp.PostView = Backbone.View.extend
    tagName: 'tr'

    events:
      'click .delete' : 'deletePost'
      'click .publish' : 'togglePublish'
      'click .review' : 'toggleReview'

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

    render: ->
      this.$el.html(this.template({post: this.model.toJSON(), publisher: PostsApp.publisher}))
      this.paintButtons()
      this

    deletePost: (e) ->
      e.preventDefault()
      if confirm('Are you sure?')
        this.model.destroy()

    togglePublish: (e) ->
      e.preventDefault()

      if this.model.get('published?')
        this.model.save
          transition: 'draft'
        this.model.set('published?', false)
      else
        this.model.save
          transition: 'publish'
        this.model.set('published?', true)

      this.paintButtons()

    toggleReview: (e) ->
      e.preventDefault()
      if this.model.get('ready_for_review')
        this.model.save
          ready_for_review: false
        this.model.set 'ready_for_review', false
      else
        this.model.save
          ready_for_review: true
        this.model.set 'ready_for_review', true

      this.paintButtons()

    paintButtons: ->
      this.$el.find('.publish').removeClass('btn-success btn-danger')
      this.$el.find('.publish').addClass('btn-success') if this.model.get('published?')
      this.$el.find('.publish').addClass('btn-danger') unless this.model.get('published?')

      this.$el.find('.review').removeClass('btn-warning')
      this.$el.find('.review').addClass('btn-warning') if this.model.get 'ready_for_review'

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
crowdblog-0.0.16 app/assets/javascripts/crowdblog/views/posts/post_view.js.coffee
crowdblog-0.0.15 app/assets/javascripts/crowdblog/views/posts/post_view.js.coffee
crowdblog-0.0.14 app/assets/javascripts/crowdblog/views/posts/post_view.js.coffee
crowdblog-0.0.13 app/assets/javascripts/crowdblog/views/posts/post_view.js.coffee
crowdblog-0.0.12 app/assets/javascripts/crowdblog/views/posts/post_view.js.coffee
crowdblog-0.0.10 app/assets/javascripts/crowdblog/views/posts/post_view.js.coffee
crowdblog-0.0.9 app/assets/javascripts/crowdblog/views/posts/post_view.js.coffee
crowdblog-0.0.8 app/assets/javascripts/crowdblog/views/posts/post_view.js.coffee
crowdblog-0.0.7 app/assets/javascripts/crowdblog/views/posts/post_view.js.coffee
crowdblog-0.0.6 app/assets/javascripts/crowdblog/views/posts/post_view.js.coffee