2012-10-01 13:07:45 -07:00
|
|
|
NEWSBLUR.Views.SidebarHeader = Backbone.View.extend({
|
2012-05-22 13:25:21 -07:00
|
|
|
|
|
|
|
options: {
|
|
|
|
el: '.NB-feeds-header-dashboard'
|
|
|
|
},
|
2012-05-18 16:59:39 -07:00
|
|
|
|
|
|
|
events: {
|
|
|
|
'click .NB-feeds-header-dashboard' : 'show_splash_page'
|
|
|
|
},
|
|
|
|
|
|
|
|
initialize: function() {
|
2012-07-15 22:51:27 -07:00
|
|
|
_.bindAll(this, 'render', 'defer_render');
|
|
|
|
this.collection.bind('reset', this.defer_render);
|
|
|
|
this.collection.bind('add', this.defer_render);
|
|
|
|
this.collection.bind('remove', this.defer_render);
|
|
|
|
this.collection.bind('change:ps', this.defer_render);
|
|
|
|
this.collection.bind('change:nt', this.defer_render);
|
|
|
|
this.collection.bind('change:ng', this.defer_render);
|
|
|
|
},
|
|
|
|
|
|
|
|
defer_render: function() {
|
|
|
|
_.defer(this.render);
|
2012-05-18 16:59:39 -07:00
|
|
|
},
|
|
|
|
|
2012-05-21 20:08:27 -07:00
|
|
|
render: function() {
|
2012-07-11 17:45:55 -07:00
|
|
|
this.count();
|
|
|
|
|
2012-05-18 18:13:45 -07:00
|
|
|
var hide_read_feeds = NEWSBLUR.assets.preference('hide_read_feeds');
|
2012-07-10 15:26:34 -07:00
|
|
|
// NEWSBLUR.log(["render feed list header", this.collection.length, this.feeds_count, hide_read_feeds]);
|
2012-05-18 16:59:39 -07:00
|
|
|
var $header = _.template('\
|
|
|
|
<div class="NB-feeds-header-dashboard">\
|
|
|
|
<div class="NB-feeds-header-right">\
|
2012-08-30 16:04:35 -07:00
|
|
|
<div class="NB-feeds-header-sites <%= hide_read_feeds ? "NB-feedlist-hide-read-feeds" : "" %>"><%= feeds_count %></div>\
|
2012-05-18 16:59:39 -07:00
|
|
|
</div>\
|
|
|
|
<div class="NB-feeds-header-left">\
|
|
|
|
<span class="NB-feeds-header-count NB-feeds-header-negative <% if (!negative_count) { %>NB-empty<% } %>"><%= negative_count %></span>\
|
|
|
|
<span class="NB-feeds-header-count NB-feeds-header-neutral <% if (!neutral_count) { %>NB-empty<% } %>"><%= neutral_count %></span>\
|
|
|
|
<span class="NB-feeds-header-count NB-feeds-header-positive <% if (!positive_count) { %>NB-empty<% } %>"><%= positive_count %></span>\
|
|
|
|
</div>\
|
|
|
|
<div class="NB-feeds-header-home">Dashboard</div>\
|
|
|
|
</div>\
|
|
|
|
', {
|
|
|
|
feeds_count : (this.feeds_count ? Inflector.pluralize(' site', this.feeds_count, true) : ' '),
|
2012-11-16 12:49:39 -08:00
|
|
|
positive_count : this.unread_counts['ps'],
|
|
|
|
neutral_count : this.unread_counts['nt'],
|
|
|
|
negative_count : this.unread_counts['ng'],
|
2012-05-18 18:13:45 -07:00
|
|
|
hide_read_feeds : !!hide_read_feeds
|
2012-05-18 16:59:39 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
$(this.el).html($header);
|
|
|
|
|
2012-07-26 18:24:41 -07:00
|
|
|
this.toggle_hide_read_preference();
|
|
|
|
|
2012-05-18 16:59:39 -07:00
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2012-07-26 18:24:41 -07:00
|
|
|
toggle_hide_read_preference: function() {
|
|
|
|
var hide_read_feeds = NEWSBLUR.assets.preference('hide_read_feeds');
|
|
|
|
this.$('.NB-feeds-header-sites').toggleClass('NB-feedlist-hide-read-feeds', !!hide_read_feeds);
|
|
|
|
$("body").toggleClass("NB-feedlist-hide-read-feeds", !!hide_read_feeds);
|
|
|
|
},
|
|
|
|
|
2012-05-18 16:59:39 -07:00
|
|
|
count: function() {
|
2012-11-16 12:49:39 -08:00
|
|
|
this.unread_counts = NEWSBLUR.assets.folders.unread_counts();
|
2012-07-11 17:45:55 -07:00
|
|
|
this.feeds_count = this.count_feeds();
|
2012-05-18 16:59:39 -07:00
|
|
|
|
2013-01-03 18:53:01 -08:00
|
|
|
if (!NEWSBLUR.Globals.is_authenticated) return;
|
|
|
|
|
|
|
|
var counts = [];
|
|
|
|
var unread_view = _.isNumber(this.options.unread_view) && this.options.unread_view || NEWSBLUR.assets.preference('unread_view');
|
|
|
|
if (unread_view <= -1) {
|
|
|
|
counts.push(this.unread_counts['ng']);
|
|
|
|
}
|
|
|
|
if (unread_view <= 0) {
|
|
|
|
counts.push(this.unread_counts['nt']);
|
|
|
|
}
|
|
|
|
if (unread_view <= 1) {
|
|
|
|
counts.push(this.unread_counts['ps']);
|
|
|
|
}
|
|
|
|
if (!this.unread_counts['ng'] && !this.unread_counts['ps']) {
|
|
|
|
counts = [this.unread_counts['nt']];
|
2012-05-18 16:59:39 -07:00
|
|
|
}
|
2013-01-03 18:53:01 -08:00
|
|
|
var title = '(' + counts.join('/') + ') NewsBlur';
|
|
|
|
document.title = title;
|
2012-05-18 16:59:39 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
count_unreads_across_all_sites: function() {
|
|
|
|
return this.collection.reduce(function(m, v) {
|
2012-07-11 17:45:55 -07:00
|
|
|
if (v.get('active') && v.views && v.views.length) {
|
2012-05-18 16:59:39 -07:00
|
|
|
m['positive'] += v.get('ps');
|
|
|
|
m['neutral'] += v.get('nt');
|
|
|
|
m['negative'] += v.get('ng');
|
|
|
|
}
|
|
|
|
return m;
|
|
|
|
}, {'positive': 0, 'negative': 0, 'neutral': 0});
|
|
|
|
},
|
|
|
|
|
|
|
|
count_feeds: function() {
|
|
|
|
return this.collection.select(function(f) {
|
|
|
|
return f.get('active');
|
|
|
|
}).length;
|
|
|
|
},
|
|
|
|
|
|
|
|
// ==========
|
|
|
|
// = Events =
|
|
|
|
// ==========
|
|
|
|
|
|
|
|
show_splash_page: function() {
|
|
|
|
NEWSBLUR.reader.show_splash_page();
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|