Sha256: 026f9854b83faa20859f0f5a3397398765ff0e1611740e7b03b5cc2a719756db

Contents?: true

Size: 1.35 KB

Versions: 5

Compression:

Stored size: 1.35 KB

Contents

class App.Views.Main.Pages.ArticleList extends App.Views.Base
  constructor: (opts = {}) ->
    super opts
    @page = 1

  render: ->
    this._handleLoadMore()

  renderArticles: (articles) ->
    for article in articles
      $('#articles').append JST["templates/main/articles/article_for_list"] {article: article}

  renderNewArticle: (article) ->
    $('#articles').prepend JST["templates/main/articles/article_for_list"] {article: article}

  updateArticle: (articleId) ->
    return if $("#article_#{articleId}").length is 0
    App.Models.Article.find(id: articleId, abbr: true).then (article) ->
      template = JST["templates/main/articles/article_for_list"] {article: article}
      $("#article_#{article.id}").replaceWith template

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

  _handleLoadMore: ->
    $('#load_more').click (e) =>
      e.preventDefault()
      @page += 1
      App.Models.Article.get('all', page: @page).then (resp) =>
        if resp.resources.length > 0
          this.renderArticles resp.resources
        else
          $('#load_more').replaceWith('<p>No more posts.</p>')

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
loco-rails-3.0.3 test/dummy/node_modules/loco-js/spec_coffee/dummy/views/main/pages/article_list.coffee
loco-rails-3.0.2 test/dummy/node_modules/loco-js/spec_coffee/dummy/views/main/pages/article_list.coffee
loco-rails-3.0.1 test/dummy/node_modules/loco-js/spec_coffee/dummy/views/main/pages/article_list.coffee
loco-rails-3.0.0 test/dummy/node_modules/loco-js/spec_coffee/dummy/views/main/pages/article_list.coffee
loco-rails-0.0.1 test/dummy/app/assets/javascripts/views/main/pages/article_list.coffee