2012-05-17 20:50:08 -07:00
|
|
|
NEWSBLUR.Views.Feed = Backbone.View.extend({
|
|
|
|
|
2012-05-21 14:35:05 -07:00
|
|
|
options: {
|
2012-05-21 20:08:27 -07:00
|
|
|
depth: 0,
|
|
|
|
selected: false
|
2012-05-21 14:35:05 -07:00
|
|
|
},
|
|
|
|
|
2012-05-18 18:13:45 -07:00
|
|
|
events: {
|
2012-05-21 14:35:05 -07:00
|
|
|
"contextmenu" : "show_manage_menu",
|
2012-05-18 18:13:45 -07:00
|
|
|
"click .NB-feedlist-manage-icon" : "show_manage_menu",
|
2012-05-21 14:35:05 -07:00
|
|
|
"click" : "open",
|
2012-05-23 16:02:32 -07:00
|
|
|
"mouseenter" : "add_hover_inverse",
|
|
|
|
"mouseleave" : "remove_hover_inverse"
|
2012-05-18 18:13:45 -07:00
|
|
|
},
|
|
|
|
|
2012-05-21 20:08:27 -07:00
|
|
|
initialize: function() {
|
2012-05-23 12:10:35 -07:00
|
|
|
_.bindAll(this, 'render', 'changed', 'delete_feed');
|
2012-05-22 15:02:37 -07:00
|
|
|
this.model.bind('change', this.changed);
|
|
|
|
|
|
|
|
if (this.model.is_social() && !this.model.get('feed_title')) {
|
|
|
|
var profile = NEWSBLUR.assets.user_profiles.get(this.model.get('user_id')) || {};
|
|
|
|
this.model.set('feed_title', profile.feed_title);
|
|
|
|
}
|
2012-05-21 20:08:27 -07:00
|
|
|
},
|
|
|
|
|
2012-05-22 13:25:21 -07:00
|
|
|
destroy: function() {
|
|
|
|
this.remove();
|
2012-05-22 15:02:37 -07:00
|
|
|
this.model.unbind('change', this.changed);
|
2012-05-22 13:25:21 -07:00
|
|
|
},
|
|
|
|
|
2012-05-22 15:02:37 -07:00
|
|
|
changed: function(model, options) {
|
2012-05-22 17:39:21 -07:00
|
|
|
var counts_changed = options.changes && _.any(_.keys(options.changes), function(key) {
|
|
|
|
return _.contains(['ps', 'nt', 'ng'], key);
|
|
|
|
});
|
2012-05-22 15:02:37 -07:00
|
|
|
var only_counts_changed = options.changes && !_.any(_.keys(options.changes), function(key) {
|
|
|
|
return !_.contains(['ps', 'nt', 'ng'], key);
|
|
|
|
});
|
2012-05-24 11:54:10 -07:00
|
|
|
var only_selected_changed = options.changes && !_.any(_.keys(options.changes), function(key) {
|
|
|
|
return key != 'selected';
|
|
|
|
});
|
2012-05-22 15:02:37 -07:00
|
|
|
|
2012-05-22 17:39:21 -07:00
|
|
|
if (only_counts_changed) {
|
2012-05-22 15:02:37 -07:00
|
|
|
this.add_extra_classes();
|
2012-05-22 17:39:21 -07:00
|
|
|
if (!options.instant) this.flash_changes();
|
2012-05-24 11:54:10 -07:00
|
|
|
} else if (only_selected_changed) {
|
|
|
|
this.select_feed();
|
2012-05-22 17:39:21 -07:00
|
|
|
} else {
|
2012-05-22 15:02:37 -07:00
|
|
|
this.render();
|
2012-05-22 17:39:21 -07:00
|
|
|
if (!options.instant && counts_changed) this.flash_changes();
|
2012-05-18 16:59:39 -07:00
|
|
|
}
|
2012-05-22 15:02:37 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
|
|
|
var feed = this.model;
|
|
|
|
var extra_classes = this.extra_classes();
|
2012-05-21 20:08:27 -07:00
|
|
|
var $feed = $(_.template('\
|
2012-05-22 15:02:37 -07:00
|
|
|
<<%= list_type %> class="feed <% if (selected) { %>selected<% } %> <%= extra_classes %> <% if (toplevel) { %>NB-toplevel<% } %>" data-id="<%= feed.id %>">\
|
2012-05-18 16:59:39 -07:00
|
|
|
<div class="feed_counts">\
|
|
|
|
</div>\
|
2012-05-18 18:13:45 -07:00
|
|
|
<img class="feed_favicon" src="<%= $.favicon(feed) %>">\
|
2012-05-18 16:59:39 -07:00
|
|
|
<span class="feed_title">\
|
2012-05-23 15:41:02 -07:00
|
|
|
<% if (type == "story") { %>\
|
|
|
|
<div class="NB-story-title-indicator">\
|
|
|
|
<div class="NB-story-title-indicator-count"></div>\
|
|
|
|
<span class="NB-story-title-indicator-text">show hidden stories</span>\
|
|
|
|
</div>\
|
|
|
|
<% } %>\
|
2012-05-18 16:59:39 -07:00
|
|
|
<%= feed.get("feed_title") %>\
|
|
|
|
<% if (type == "story") { %>\
|
|
|
|
<span class="NB-feedbar-train-feed" title="Train Intelligence"></span>\
|
|
|
|
<span class="NB-feedbar-statistics" title="Statistics"></span>\
|
|
|
|
<% } %>\
|
|
|
|
</span>\
|
|
|
|
<% if (type == "story") { %>\
|
|
|
|
<div class="NB-feedbar-last-updated">\
|
|
|
|
<span class="NB-feedbar-last-updated-label">Updated:</span>\
|
|
|
|
<span class="NB-feedbar-last-updated-date">\
|
|
|
|
<% if (feed.get("updated")) { %>\
|
|
|
|
<%= feed.get("updated") %> ago\
|
|
|
|
<% } else { %>\
|
|
|
|
Loading...\
|
|
|
|
<% } %>\
|
|
|
|
</span>\
|
|
|
|
</div>\
|
|
|
|
<div class="NB-feedbar-mark-feed-read">Mark All as Read</div>\
|
|
|
|
<% } %>\
|
|
|
|
<div class="NB-feed-exception-icon"></div>\
|
|
|
|
<div class="NB-feed-unfetched-icon"></div>\
|
|
|
|
<div class="NB-feedlist-manage-icon"></div>\
|
2012-05-22 13:25:21 -07:00
|
|
|
<div class="NB-feed-highlight"></div>\
|
2012-05-18 16:59:39 -07:00
|
|
|
</<%= list_type %>>\
|
|
|
|
', {
|
|
|
|
feed : feed,
|
|
|
|
type : this.options.type,
|
2012-05-22 15:02:37 -07:00
|
|
|
extra_classes : extra_classes,
|
2012-05-18 16:59:39 -07:00
|
|
|
toplevel : this.options.depth == 0,
|
|
|
|
list_type : this.options.type == 'feed' ? 'li' : 'div',
|
2012-05-21 20:08:27 -07:00
|
|
|
selected : this.model.get('selected') || NEWSBLUR.reader.active_feed == this.model.id
|
|
|
|
}));
|
|
|
|
|
2012-05-22 13:25:21 -07:00
|
|
|
this.$el.replaceWith($feed);
|
2012-05-18 16:59:39 -07:00
|
|
|
this.setElement($feed);
|
2012-05-22 15:02:37 -07:00
|
|
|
this.render_counts();
|
2012-05-21 20:08:27 -07:00
|
|
|
|
2012-05-17 20:50:08 -07:00
|
|
|
return this;
|
2012-05-18 18:13:45 -07:00
|
|
|
},
|
|
|
|
|
2012-05-22 15:02:37 -07:00
|
|
|
extra_classes: function() {
|
|
|
|
var feed = this.model;
|
|
|
|
var extra_classes = '';
|
2012-05-22 17:39:21 -07:00
|
|
|
|
2012-05-22 15:02:37 -07:00
|
|
|
if (feed.get('ps')) {
|
|
|
|
extra_classes += ' unread_positive';
|
|
|
|
}
|
|
|
|
if (feed.get('nt')) {
|
|
|
|
extra_classes += ' unread_neutral';
|
|
|
|
}
|
|
|
|
if (feed.get('ng')) {
|
|
|
|
extra_classes += ' unread_negative';
|
|
|
|
}
|
2012-05-22 17:39:21 -07:00
|
|
|
|
|
|
|
if (feed.is_feed()) {
|
|
|
|
if (feed.get('has_exception') && feed.get('exception_type') == 'feed') {
|
|
|
|
extra_classes += ' NB-feed-exception';
|
|
|
|
}
|
|
|
|
if (!feed.get('fetched_once') && !feed.get('has_exception')) {
|
|
|
|
extra_classes += ' NB-feed-unfetched';
|
|
|
|
}
|
|
|
|
if (!feed.get('active') && !feed.get('subscription_user_id')) {
|
|
|
|
extra_classes += ' NB-feed-inactive';
|
|
|
|
}
|
2012-05-22 15:02:37 -07:00
|
|
|
}
|
2012-05-22 17:39:21 -07:00
|
|
|
|
|
|
|
if (feed.is_social()) {
|
|
|
|
if (feed.get('subscription_user_id') && !feed.get('shared_stories_count')) {
|
|
|
|
extra_classes += ' NB-feed-inactive';
|
|
|
|
}
|
2012-05-22 15:02:37 -07:00
|
|
|
}
|
2012-05-24 17:32:01 -07:00
|
|
|
|
|
|
|
if (this.options.type == 'story') {
|
|
|
|
extra_classes += ' NB-feedbar';
|
|
|
|
}
|
2012-05-22 15:02:37 -07:00
|
|
|
return extra_classes;
|
|
|
|
},
|
|
|
|
|
|
|
|
render_counts: function() {
|
|
|
|
this.counts_view = new NEWSBLUR.Views.FeedCount({model: this.model}).render();
|
|
|
|
this.$('.feed_counts').html(this.counts_view.el);
|
2012-05-23 15:41:02 -07:00
|
|
|
if (this.options.type == 'story') {
|
|
|
|
this.$('.NB-story-title-indicator-count').html(this.counts_view.$el.clone());
|
|
|
|
}
|
2012-05-22 15:02:37 -07:00
|
|
|
},
|
|
|
|
|
2012-05-24 11:54:10 -07:00
|
|
|
select_feed: function() {
|
|
|
|
this.$el.toggleClass('selected', this.model.get('selected'));
|
|
|
|
this.$el.toggleClass('NB-selected', this.model.get('selected'));
|
|
|
|
},
|
|
|
|
|
2012-05-22 15:02:37 -07:00
|
|
|
flash_changes: function() {
|
2012-05-22 13:25:21 -07:00
|
|
|
var $highlight = this.$('.NB-feed-highlight');
|
2012-05-23 10:02:30 -07:00
|
|
|
|
2012-05-22 13:25:21 -07:00
|
|
|
$highlight.css({
|
|
|
|
'backgroundColor': '#F0F076',
|
|
|
|
'display': 'block'
|
|
|
|
});
|
|
|
|
$highlight.animate({
|
|
|
|
'opacity': .7
|
|
|
|
}, {
|
|
|
|
'duration': 800,
|
|
|
|
'queue': false,
|
|
|
|
'complete': function() {
|
|
|
|
$highlight.animate({'opacity': 0}, {
|
|
|
|
'duration': 1000,
|
|
|
|
'queue': false,
|
|
|
|
'complete': function() {
|
|
|
|
$highlight.css('display', 'none');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2012-05-21 20:08:27 -07:00
|
|
|
},
|
|
|
|
|
2012-05-22 15:02:37 -07:00
|
|
|
add_extra_classes: function() {
|
|
|
|
var extra_classes = this.extra_classes();
|
|
|
|
$(this.el).removeClass("unread_positive unread_neutral unread_negative");
|
|
|
|
$(this.el).addClass(extra_classes);
|
|
|
|
},
|
|
|
|
|
2012-05-23 10:02:30 -07:00
|
|
|
// ===========
|
|
|
|
// = Actions =
|
|
|
|
// ===========
|
|
|
|
|
|
|
|
|
2012-05-18 18:13:45 -07:00
|
|
|
// ==========
|
|
|
|
// = Events =
|
|
|
|
// ==========
|
|
|
|
|
2012-05-19 10:29:27 -07:00
|
|
|
open: function(e) {
|
2012-05-23 16:02:32 -07:00
|
|
|
if (this.options.type != 'feed') return;
|
|
|
|
|
2012-05-23 17:21:06 -07:00
|
|
|
if (this.model.get('has_exception') && this.model.get('exception_type') == 'feed') {
|
|
|
|
NEWSBLUR.reader.open_feed_exception_modal(this.model.id);
|
2012-05-21 14:35:05 -07:00
|
|
|
} else if (this.model.is_social()) {
|
2012-05-23 10:02:30 -07:00
|
|
|
NEWSBLUR.reader.open_social_stories(this.model.id, {force: true, $feed: this.$el});
|
2012-05-19 10:29:27 -07:00
|
|
|
} else {
|
2012-05-23 10:02:30 -07:00
|
|
|
NEWSBLUR.reader.open_feed(this.model.id, {$feed: this.$el});
|
2012-05-19 10:29:27 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-05-18 18:13:45 -07:00
|
|
|
show_manage_menu: function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
2012-05-22 13:25:21 -07:00
|
|
|
// console.log(["showing manage menu", this.model.is_social() ? 'socialfeed' : 'feed', $(this.el), this]);
|
2012-05-23 16:02:32 -07:00
|
|
|
NEWSBLUR.reader.show_manage_menu(this.model.is_social() ? 'socialfeed' : 'feed', this.$el, {
|
2012-05-21 20:08:27 -07:00
|
|
|
feed_id: this.model.id,
|
2012-05-21 14:35:05 -07:00
|
|
|
toplevel: this.options.depth == 0
|
|
|
|
});
|
2012-05-18 18:13:45 -07:00
|
|
|
return false;
|
2012-05-23 12:10:35 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
delete_feed: function() {
|
|
|
|
this.$el.slideUp(500);
|
|
|
|
|
|
|
|
if (this.model.get('selected')) {
|
|
|
|
NEWSBLUR.reader.reset_feed();
|
|
|
|
NEWSBLUR.reader.show_splash_page();
|
|
|
|
}
|
2012-05-23 16:02:32 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
add_hover_inverse: function() {
|
|
|
|
if (NEWSBLUR.app.feed_list.is_sorting()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.$el.offset().top > $(window).height() - 314) {
|
|
|
|
this.$el.addClass('NB-hover-inverse');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
remove_hover_inverse: function() {
|
|
|
|
this.$el.removeClass('NB-hover-inverse');
|
2012-05-17 20:50:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|