2012-10-01 13:07:45 -07:00
|
|
|
NEWSBLUR.Views.SidebarHeader = Backbone.View.extend({
|
2012-05-22 13:25:21 -07:00
|
|
|
|
|
|
|
options: {
|
2013-01-23 18:24:27 -08:00
|
|
|
el: '.left-north'
|
2012-05-22 13:25:21 -07:00
|
|
|
},
|
2012-05-18 16:59:39 -07:00
|
|
|
|
|
|
|
events: {
|
2013-01-29 16:47:44 -08:00
|
|
|
'click .NB-feeds-header-user-dashboard' : 'show_splash_page',
|
|
|
|
'click .NB-feeds-header-user-interactions' : 'show_interactions_popover'
|
2012-05-18 16:59:39 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
initialize: function() {
|
2012-07-15 22:51:27 -07:00
|
|
|
_.bindAll(this, 'render', 'defer_render');
|
2013-04-22 11:45:06 -07:00
|
|
|
this.feed_collection = this.options.feed_collection;
|
|
|
|
this.socialfeed_collection = this.options.socialfeed_collection;
|
|
|
|
|
|
|
|
this.feed_collection.bind('reset', this.defer_render);
|
|
|
|
this.feed_collection.bind('add', this.defer_render);
|
|
|
|
this.feed_collection.bind('remove', this.defer_render);
|
|
|
|
this.feed_collection.bind('change:ps', this.defer_render);
|
|
|
|
this.feed_collection.bind('change:nt', this.defer_render);
|
|
|
|
this.feed_collection.bind('change:ng', this.defer_render);
|
|
|
|
this.socialfeed_collection.bind('reset', this.defer_render);
|
|
|
|
this.socialfeed_collection.bind('add', this.defer_render);
|
|
|
|
this.socialfeed_collection.bind('remove', this.defer_render);
|
|
|
|
this.socialfeed_collection.bind('change:ps', this.defer_render);
|
|
|
|
this.socialfeed_collection.bind('change:nt', this.defer_render);
|
|
|
|
this.socialfeed_collection.bind('change:ng', this.defer_render);
|
2012-07-15 22:51:27 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
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');
|
2013-04-22 11:45:06 -07:00
|
|
|
// NEWSBLUR.log(["render feed list header", this.feed_collection.length, this.feeds_count, hide_read_feeds]);
|
2012-05-18 16:59:39 -07:00
|
|
|
var $header = _.template('\
|
2013-01-23 18:24:27 -08:00
|
|
|
<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>\
|
2012-05-18 16:59:39 -07:00
|
|
|
</div>\
|
|
|
|
', {
|
2013-02-25 12:24:18 -08:00
|
|
|
positive_count : Inflector.commas(this.unread_counts['ps']),
|
|
|
|
neutral_count : Inflector.commas(this.unread_counts['nt']),
|
|
|
|
negative_count : Inflector.commas(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
|
|
|
});
|
|
|
|
|
2013-01-23 18:24:27 -08:00
|
|
|
this.$('.NB-feeds-header-dashboard').html($header);
|
2012-05-18 16:59:39 -07:00
|
|
|
|
2012-07-26 18:24:41 -07:00
|
|
|
this.toggle_hide_read_preference();
|
2013-03-26 13:49:35 -07:00
|
|
|
NEWSBLUR.reader.toggle_focus_in_slider();
|
2012-07-26 18:24:41 -07:00
|
|
|
|
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');
|
2014-05-28 16:54:51 -07:00
|
|
|
if (NEWSBLUR.reader.flags['feed_list_showing_starred']) hide_read_feeds = true;
|
2012-07-26 18:24:41 -07:00
|
|
|
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();
|
2013-04-22 11:45:06 -07:00
|
|
|
this.unread_counts = NEWSBLUR.assets.social_feeds.unread_counts(this.unread_counts);
|
|
|
|
|
2013-01-03 18:53:01 -08:00
|
|
|
if (!NEWSBLUR.Globals.is_authenticated) return;
|
2013-01-06 15:55:24 -08:00
|
|
|
if (!NEWSBLUR.assets.preference('title_counts')) return;
|
2013-01-03 18:53:01 -08:00
|
|
|
|
|
|
|
var counts = [];
|
|
|
|
var unread_view = _.isNumber(this.options.unread_view) && this.options.unread_view || NEWSBLUR.assets.preference('unread_view');
|
|
|
|
if (unread_view <= -1) {
|
2013-02-25 12:24:18 -08:00
|
|
|
counts.push(Inflector.commas(this.unread_counts['ng']));
|
2013-01-03 18:53:01 -08:00
|
|
|
}
|
|
|
|
if (unread_view <= 0) {
|
2013-02-25 12:24:18 -08:00
|
|
|
counts.push(Inflector.commas(this.unread_counts['nt']));
|
2013-01-03 18:53:01 -08:00
|
|
|
}
|
|
|
|
if (unread_view <= 1) {
|
2013-02-25 12:24:18 -08:00
|
|
|
counts.push(Inflector.commas(this.unread_counts['ps']));
|
2013-01-03 18:53:01 -08:00
|
|
|
}
|
|
|
|
if (!this.unread_counts['ng'] && !this.unread_counts['ps']) {
|
2013-02-25 12:24:18 -08:00
|
|
|
counts = [Inflector.commas(this.unread_counts['nt'])];
|
2012-05-18 16:59:39 -07:00
|
|
|
}
|
2013-01-04 12:06:00 -08:00
|
|
|
var title = "NewsBlur";
|
|
|
|
if (_.any(counts)) {
|
|
|
|
title = '(' + counts.join('/') + ') ' + title;
|
|
|
|
}
|
2013-01-03 18:53:01 -08:00
|
|
|
document.title = title;
|
2012-05-18 16:59:39 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
count_feeds: function() {
|
2013-04-22 11:45:06 -07:00
|
|
|
return this.feed_collection.select(function(f) {
|
2012-05-18 16:59:39 -07:00
|
|
|
return f.get('active');
|
|
|
|
}).length;
|
|
|
|
},
|
|
|
|
|
2013-01-30 18:28:37 -08:00
|
|
|
update_interactions_count: function(interactions_count) {
|
|
|
|
var $badge = this.$(".NB-feeds-header-user-interactions-badge");
|
|
|
|
|
|
|
|
if (!interactions_count) {
|
|
|
|
$badge.addClass('NB-hidden').text('');
|
|
|
|
} else {
|
|
|
|
$badge.removeClass('NB-hidden').text('' + interactions_count);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-05-18 16:59:39 -07:00
|
|
|
// ==========
|
|
|
|
// = Events =
|
|
|
|
// ==========
|
|
|
|
|
|
|
|
show_splash_page: function() {
|
|
|
|
NEWSBLUR.reader.show_splash_page();
|
2013-01-29 16:47:44 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
show_interactions_popover: function() {
|
|
|
|
NEWSBLUR.InteractionsPopover.create({});
|
2012-05-18 16:59:39 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|