Permalink
Browse files

Move sidebar stats to separate view.

  • Loading branch information...
1 parent 32aba77 commit e10a0f942a0030de6f0264c2e80c1461b1552f78 @paulmillr paulmillr committed Apr 9, 2012
@@ -1,6 +1,7 @@
mediator = require 'mediator'
-CompositeView = require 'views/composite_view'
-StatusView = require 'views/status_view'
+CompositeView = require './composite_view'
+StatsView = require './stats_view'
+StatusView = require './status_view'
template = require './templates/sidebar'
module.exports = class SidebarView extends CompositeView
@@ -16,6 +17,7 @@ module.exports = class SidebarView extends CompositeView
initialize: ->
super
@attachView new StatusView()
+ @attachView new StatsView()
@subscribeEvent 'loginStatus', @loginStatusHandler
@subscribeEvent 'userData', @render
@@ -0,0 +1,21 @@
+mediator = require 'mediator'
+View = require 'views/view'
+template = require './templates/stats'
+
+module.exports = class StatsView extends View
+ @template: template
+ className: 'stats'
+ tagName: 'ul'
+ containerSelector: '#stats-container'
+
+ initialize: ->
+ super
+ @subscribeEvent 'loginStatus', @loginStatusHandler
+ @subscribeEvent 'userData', @render
+
+ loginStatusHandler: (loggedIn) =>
+ if loggedIn
+ @model = mediator.user
+ else
+ @model = null
+ @render()
@@ -8,7 +8,6 @@ module.exports = class StatusView extends View
id: 'status'
className: 'status'
containerSelector: '#status-container'
- autoRender: no
initialize: ->
super
@@ -30,19 +29,22 @@ module.exports = class StatusView extends View
$charCount.removeClass 'status-character-count-invalid'
$createButton.removeAttr 'disabled'
else
- $charCount.addClass 'status-character-count-invalid'
+ # TODO: check this in model.
+ $charCount.addClass 'status-character-count-invalid' unless count is 140
$createButton.attr 'disabled', 'disabled'
updateStatusText: (event) =>
text = $(event.currentTarget).val()
- @updateCharacterCount (@model.set {text}), @model.calcCharCount text.length
+ valid = @model.set {text}
+ count = @model.calcCharCount text.length
+ @updateCharacterCount valid, count
createStatus: (event) =>
@model.save {},
error: (model, error) =>
- console.log 'Tweet error', error
+ console.error 'Tweet error', error
success: (model, attributes) =>
- console.log 'Tweet success', attributes
+ console.debug 'Tweet success', attributes
@$('.status-text').val('').trigger('keydown')
render: =>
@@ -8,11 +8,7 @@
</div>
</div>
</div>
- <ul class="stats">
- <li class="stat-tweets"><strong>{{statuses_count}}</strong> tweets</li>
- <li class="stat-following"><strong>{{friends_count}}</strong> following</li>
- <li class="stat-followers"><strong>{{followers_count}}</strong> followers</li>
- </ul>
+ <div class="stats-container" id="stats-container"></div>
<div class="status-container" id="status-container"></div>
{{else}}
<div class="app-description">
@@ -0,0 +1,3 @@
+<li class="stat-tweets"><strong>{{statuses_count}}</strong> tweets</li>
+<li class="stat-following"><strong>{{friends_count}}</strong> following</li>
+<li class="stat-followers"><strong>{{followers_count}}</strong> followers</li>
Oops, something went wrong.

0 comments on commit e10a0f9

Please sign in to comment.