Sha256: 0a28277e749a18ba067c5846a5318d845d05a273e46c43bd9989ee745f5c285a

Contents?: true

Size: 1.23 KB

Versions: 31

Compression:

Stored size: 1.23 KB

Contents

class App.Views.User.Articles.List extends App.Views.Base
  constructor: (opts = {}) ->
    super opts
    @articles = opts.articles

  renderArticles: (articles) ->
    this.renderArticle article for article in articles

  renderArticle: (article) ->
    template = JST["templates/user/articles/article"] {article: article}
    if $("#article_#{article.id}").length is 1
      $("#article_#{article.id}").replaceWith template
    else
      $("table").append template
    this._handleDeletingArticle article

  deleteArticle: (articleId) ->
    $("#article_#{articleId}").remove()

  commentsQuantityChangedForArticle: (articleId, quantity) ->
    sel = $("#article_#{articleId} td.comments_quantity")
    return if sel.length is 0
    match = /\d+/.exec sel.text()
    quantity = parseInt(match[0]) + quantity
    sel.text quantity

  _handleDeletingArticle: (article) ->
    $("tr#article_#{article.id} a.delete_article").click (e) =>
      e.preventDefault()
      return if not confirm "Are you sure?"
      article.delete(null).then (data) =>
        flash = new App.Views.Shared.Flash
        if data.success
          this.deleteArticle data.id
          flash.setNotice data.notice
        else
          flash.setAlert data.alert
        flash.render()

Version data entries

31 entries across 27 versions & 1 rubygems

Version Path
loco-rails-3.0.3 test/dummy/app/assets/javascripts/views/user/articles/list.coffee
loco-rails-3.0.3 test/dummy/node_modules/loco-js/spec_coffee/dummy/views/user/articles/list.coffee
loco-rails-2.5.3 test/dummy/app/assets/javascripts/views/user/articles/list.coffee
loco-rails-2.5.2 test/dummy/app/assets/javascripts/views/user/articles/list.coffee
loco-rails-3.0.2 test/dummy/node_modules/loco-js/spec_coffee/dummy/views/user/articles/list.coffee
loco-rails-3.0.2 test/dummy/app/assets/javascripts/views/user/articles/list.coffee
loco-rails-3.0.1 test/dummy/node_modules/loco-js/spec_coffee/dummy/views/user/articles/list.coffee
loco-rails-3.0.1 test/dummy/app/assets/javascripts/views/user/articles/list.coffee
loco-rails-2.5.1 test/dummy/app/assets/javascripts/views/user/articles/list.coffee
loco-rails-2.5.0 test/dummy/app/assets/javascripts/views/user/articles/list.coffee
loco-rails-2.4.0 test/dummy/app/assets/javascripts/views/user/articles/list.coffee
loco-rails-2.3.0 test/dummy/app/assets/javascripts/views/user/articles/list.coffee
loco-rails-3.0.0 test/dummy/node_modules/loco-js/spec_coffee/dummy/views/user/articles/list.coffee
loco-rails-3.0.0 test/dummy/app/assets/javascripts/views/user/articles/list.coffee
loco-rails-2.2.2 test/dummy/app/assets/javascripts/views/user/articles/list.coffee
loco-rails-2.2.1 test/dummy/app/assets/javascripts/views/user/articles/list.coffee
loco-rails-2.2.0 test/dummy/app/assets/javascripts/views/user/articles/list.coffee
loco-rails-2.1.0 test/dummy/app/assets/javascripts/views/user/articles/list.coffee
loco-rails-2.0.0 test/dummy/app/assets/javascripts/views/user/articles/list.coffee
loco-rails-1.5.2 test/dummy/app/assets/javascripts/views/user/articles/list.coffee