Deselecting sites properly. Also adding context option to folders to add a site directly to that folder.

This commit is contained in:
Samuel Clay 2012-05-24 11:54:10 -07:00
parent f14a4f4d69
commit b4a6791d77
10 changed files with 96 additions and 32 deletions

View file

@ -4847,6 +4847,9 @@ form.opml_import_form input {
.NB-menu-manage .NB-menu-manage-mark-read .NB-menu-manage-image {
background: transparent url('/media/embed/icons/silk/cut.png') no-repeat 0 2px;
}
.NB-menu-manage .NB-menu-manage-folder-subscribe .NB-menu-manage-image {
background: transparent url('/media/embed/icons/silk/add.png') no-repeat 0 1px;
}
.NB-menu-manage .NB-menu-manage-social-profile .NB-menu-manage-image {
background: transparent url('/media/embed/icons/silk/user_orange.png') no-repeat 0 1px;
}

View file

@ -368,16 +368,17 @@ NEWSBLUR.AssetModel = Backbone.Router.extend({
this.stories = data.stories;
this.feed_tags = data.feed_tags || {};
this.feed_authors = data.feed_authors || {};
this.active_feed = this.get_feed(feed_id) || {};
this.active_feed = this.get_feed(feed_id);
if (this.active_feed) {
this.active_feed.set({
feed_title: data.feed_title || this.active_feed.get('feed_title'),
last_update: data.last_update || this.active_feed.get('last_update'),
last_update: data.updated || this.active_feed.get('updated'),
updated: data.updated || this.active_feed.get('updated'),
feed_address: data.feed_address || this.active_feed.get('feed_address')
}, {silent: true});
if (this.active_feed.hasChanged()) {
this.active_feed.change();
}
}
this.feed_id = feed_id;
if (_.string.include(feed_id, ':')) {
_.extend(this.classifiers, data.classifiers);

View file

@ -7,7 +7,7 @@ NEWSBLUR.Models.Feed = Backbone.Model.extend({
},
on_change: function() {
// NEWSBLUR.log(['Feed Change', this.changedAttributes(), this.previousAttributes()]);
NEWSBLUR.log(['Feed Change', this.changedAttributes(), this.previousAttributes()]);
},
delete_feed: function(options) {

View file

@ -130,6 +130,15 @@ NEWSBLUR.Collections.Folders = Backbone.Collection.extend({
return _.compact(_.flatten(this.map(function(item) {
return item.feed_ids_in_folder();
})));
},
deselect: function() {
this.each(function(item) {
if (item.is_folder()) {
item.set('selected', false);
item.folders.deselect();
}
});
}
}, {

View file

@ -66,6 +66,7 @@ NEWSBLUR.Collections.SocialSubscriptions = Backbone.Collection.extend({
},
deselect: function() {
console.log(["deselect social"]);
this.chain().select(function(feed) {
return feed.get('selected');
}).each(function(feed){

View file

@ -1435,17 +1435,21 @@
'show_story_in_feed': 0
});
this.active_feed = null;
this.active_story = null;
this.$s.$story_titles.data('feed_id', null);
this.$s.$feed_stories.scrollTop(0);
this.$s.$feed_stories.empty();
this.$s.$story_titles.empty();
this.$s.$feed_stories.scrollTop(0);
this.$s.$starred_header.removeClass('NB-selected');
this.$s.$river_header.removeClass('NB-selected');
this.$s.$tryfeed_header.removeClass('NB-selected');
console.log(["old active", this.active_feed]);
this.model.feeds.deselect();
if (_.string.contains(this.active_feed, 'social:')) {
this.model.social_feeds.deselect();
}
if (_.string.contains(this.active_feed, 'river:')) {
this.model.folders.deselect();
}
this.$s.$body.removeClass('NB-view-river');
$('.task_view_page', this.$s.$taskbar).removeClass('NB-disabled');
$('.task_view_story', this.$s.$taskbar).removeClass('NB-disabled');
@ -1458,6 +1462,8 @@
this.hide_tryfeed_view();
}
this.active_feed = null;
this.active_story = null;
},
open_feed: function(feed_id, options) {
@ -1484,11 +1490,14 @@
this.active_feed = feed.id;
this.next_feed = feed.id;
this.show_stories_progress_bar();
feed.set('selected', true, options);
if (NEWSBLUR.app.story_unread_counter) {
NEWSBLUR.app.story_unread_counter.remove();
}
// this.show_stories_progress_bar();
$story_titles.data('feed_id', feed.id);
this.iframe_scroll = null;
this.set_correct_story_view_for_feed(feed.id);
feed.set('selected', true, options);
this.make_feed_title_in_stories(feed.id);
this.show_feedbar_loading();
this.switch_taskbar_view(this.story_view);
@ -1739,6 +1748,7 @@
open_river_stories: function($folder, folder_title) {
var $story_titles = this.$s.$story_titles;
$folder = $folder || this.$s.$feed_list;
var folder_view = NEWSBLUR.assets.folders.get_view($folder);
$story_titles.empty().scrollTop('0px');
this.reset_feed();
@ -1748,7 +1758,7 @@
this.$s.$river_header.addClass('NB-selected');
} else {
this.active_feed = 'river:' + folder_title;
$folder.addClass('NB-selected');
folder_view.model.set('selected', true);
}
$story_titles.data('feed_id', null);
@ -1768,6 +1778,7 @@
this.switch_taskbar_view(this.story_view);
this.setup_mousemove_on_views();
NEWSBLUR.router.navigate('');
var feeds = this.list_feeds_with_unreads_in_folder($folder, false, true);
this.cache['river_feeds_with_unreads'] = feeds;
this.show_stories_progress_bar(feeds.length);
@ -2404,7 +2415,9 @@
feed.set('ng', count, {instant: true});
}
if (story_unread_counter) {
story_unread_counter.flash();
}
// if ((unread_view == 'positive' && feed.get('ps') == 0) ||
// (unread_view == 'neutral' && feed.get('ps') == 0 && feed.get('nt') == 0) ||
@ -2419,12 +2432,20 @@
this.mark_feed_as_read_update_counts(feed_id);
this.model.mark_feed_as_read([feed_id]);
if (this.model.preference('folder_counts')) {
var $feed = this.find_feed_in_feed_list(feed_id);
var $folder_title = $feed.closest('li.folder:visible').children('.folder_title');
var $children = $folder_title.closest('li.folder').children('ul.folder, .feed');
this.show_collapsed_folder_count($folder_title, $children);
if (active_feed && _.contains(feeds, active_feed.id)) {
$('.story:not(.read)', this.$s.$story_titles).addClass('read');
_.each(this.model.stories, _.bind(function(story) {
this.mark_story_as_read_in_feed_view(story.id);
}, this));
}
// if (this.model.preference('folder_counts')) {
// var $feed = this.find_feed_in_feed_list(feed_id);
// var $folder_title = $feed.closest('li.folder:visible').children('.folder_title');
// var $children = $folder_title.closest('li.folder').children('ul.folder, .feed');
// this.show_collapsed_folder_count($folder_title, $children);
// }
},
mark_folder_as_read: function(folder_name, $folder) {
@ -4748,6 +4769,10 @@
$.make('div', { className: 'NB-menu-manage-image' }),
$.make('div', { className: 'NB-menu-manage-title' }, 'Mark folder as read')
]),
$.make('li', { className: 'NB-menu-manage-feed NB-menu-manage-folder-subscribe' }, [
$.make('div', { className: 'NB-menu-manage-image' }),
$.make('div', { className: 'NB-menu-manage-title' }, 'Add a site to this folder')
]),
$.make('li', { className: 'NB-menu-separator' }),
$.make('li', { className: 'NB-menu-manage-feed NB-menu-manage-move NB-menu-manage-folder-move' }, [
$.make('div', { className: 'NB-menu-manage-image' }),
@ -6835,6 +6860,12 @@
var $folder = $t.parents('.NB-menu-manage').data('$folder');
self.mark_folder_as_read(folder_name, $folder);
});
$.targetIs(e, { tagSelector: '.NB-menu-manage-folder-subscribe' }, function($t, $p){
e.preventDefault();
var folder_name = $t.parents('.NB-menu-manage').data('folder_name');
var $folder = $t.parents('.NB-menu-manage').data('$folder');
self.open_add_feed_modal({folder_title: folder_name});
});
$.targetIs(e, { tagSelector: '.NB-menu-manage-story-open' }, function($t, $p){
e.preventDefault();
if (!self.flags['showing_confirm_input_on_manage_menu']) {

View file

@ -35,7 +35,7 @@ _.extend(NEWSBLUR.ReaderAddFeed.prototype, {
$.make('div', { className: 'NB-add-form' }, [
$.make('div', { className: 'NB-fieldset NB-add-add-url NB-modal-submit' }, [
$.make('h5', [
$.make('div', { className: 'NB-add-folders' }, NEWSBLUR.utils.make_folders(this.model)),
$.make('div', { className: 'NB-add-folders' }, NEWSBLUR.utils.make_folders(this.model, this.options.folder_title)),
'Add a new site'
]),
$.make('div', { className: 'NB-fieldset-fields' }, [
@ -50,7 +50,7 @@ _.extend(NEWSBLUR.ReaderAddFeed.prototype, {
]),
$.make('div', { className: 'NB-fieldset NB-add-add-folder NB-modal-submit' }, [
$.make('h5', [
$.make('div', { className: 'NB-add-folders' }, NEWSBLUR.utils.make_folders(this.model)),
$.make('div', { className: 'NB-add-folders' }, NEWSBLUR.utils.make_folders(this.model, this.options.folder_title)),
'Add a new folder'
]),
$.make('div', { className: 'NB-fieldset-fields' }, [

View file

@ -88,7 +88,7 @@ NEWSBLUR.utils = {
is_feed_floater_gradient_light: function(feed) {
if (!feed) return false;
var is_light = feed.get('is_light');
var is_light = feed.is_light;
if (!_.isUndefined(is_light)) {
return is_light;
}
@ -100,7 +100,7 @@ NEWSBLUR.utils = {
var b = parseInt(color.substr(4, 2), 16) / 255.0;
is_light = $.textColor({r: r, g: g, b: b}) != 'white';
feed.set('is_light', is_light, {silent: true});
feed.is_light = is_light;
return is_light;
},
@ -109,19 +109,19 @@ NEWSBLUR.utils = {
return _.string.include(feed_id, 'social:');
},
make_folders: function(model) {
make_folders: function(model, selected_folder_title) {
var folders = model.get_folders();
var $options = $.make('select', { className: 'NB-folders'});
var $option = $.make('option', { value: '' }, "Top Level");
$options.append($option);
$options = this.make_folder_options($options, folders, '   ');
$options = this.make_folder_options($options, folders, '   ', selected_folder_title);
return $options;
},
make_folder_options: function($options, items, depth) {
make_folder_options: function($options, items, depth, selected_folder_title) {
var self = this;
items.each(function(item) {
if (item.is_folder()) {
@ -129,7 +129,10 @@ NEWSBLUR.utils = {
value: item.get('folder_title')
}, depth + ' ' + item.get('folder_title'));
$options.append($option);
$options = self.make_folder_options($options, item.folders, depth+'   ');
if (item.get('folder_title') == selected_folder_title) {
$option.attr('selected', true);
}
$options = self.make_folder_options($options, item.folders, depth+'   ', selected_folder_title);
}
});

View file

@ -35,10 +35,15 @@ NEWSBLUR.Views.Feed = Backbone.View.extend({
var only_counts_changed = options.changes && !_.any(_.keys(options.changes), function(key) {
return !_.contains(['ps', 'nt', 'ng'], key);
});
var only_selected_changed = options.changes && !_.any(_.keys(options.changes), function(key) {
return key != 'selected';
});
if (only_counts_changed) {
this.add_extra_classes();
if (!options.instant) this.flash_changes();
} else if (only_selected_changed) {
this.select_feed();
} else {
this.render();
if (!options.instant && counts_changed) this.flash_changes();
@ -142,6 +147,12 @@ NEWSBLUR.Views.Feed = Backbone.View.extend({
}
},
select_feed: function() {
console.log(["only selected"]);
this.$el.toggleClass('selected', this.model.get('selected'));
this.$el.toggleClass('NB-selected', this.model.get('selected'));
},
flash_changes: function() {
var $highlight = this.$('.NB-feed-highlight');

View file

@ -20,10 +20,11 @@ NEWSBLUR.Views.Folder = Backbone.View.extend({
},
initialize: function() {
_.bindAll(this, 'update_title', 'delete_folder');
_.bindAll(this, 'update_title', 'update_selected', 'delete_folder');
if (this.model) {
// Root folder does not have a model.
this.model.bind('change:folder_title', this.update_title);
this.model.bind('change:selected', this.update_selected);
this.model.bind('delete', this.delete_folder);
}
},
@ -88,6 +89,10 @@ NEWSBLUR.Views.Folder = Backbone.View.extend({
this.$('.folder_title_text').html(this.model.get('folder_title'));
},
update_selected: function() {
this.$el.toggleClass('NB-selected', this.model.get('selected'));
},
// ==========
// = Events =
// ==========