mirror of
https://github.com/samuelclay/NewsBlur.git
synced 2025-08-31 21:41:33 +00:00
Adding counters for selection in organizer. Also hooking up select all and select none actions.
This commit is contained in:
parent
f10406bf28
commit
633bdf99b5
4 changed files with 65 additions and 14 deletions
|
@ -233,7 +233,7 @@ NEWSBLUR.Models.Feed = Backbone.Model.extend({
|
|||
_.without(this.get('highlighted_in_folders'), folder_title), {silent: true});
|
||||
}
|
||||
|
||||
this.set('highlighted', !!this.get('highlighted_in_folders').length, {silent: true});
|
||||
this.set('highlighted', !!this.get('highlighted_in_folders').length);
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
@ -43,9 +43,8 @@ _.extend(NEWSBLUR.ReaderOrganizer.prototype, {
|
|||
]),
|
||||
$.make('div', { className: 'NB-organizer-selects' }, [
|
||||
$.make('div', { className: 'NB-organizer-action-title' }, 'Select'),
|
||||
$.make('div', { className: 'NB-organizer-action' }, 'All'),
|
||||
$.make('div', { className: 'NB-organizer-action' }, 'None'),
|
||||
$.make('div', { className: 'NB-organizer-action' }, 'Invert')
|
||||
$.make('div', { className: 'NB-organizer-action NB-action-select-all' }, 'All'),
|
||||
$.make('div', { className: 'NB-organizer-action NB-action-select-none' }, 'None')
|
||||
])
|
||||
]),
|
||||
this.make_feeds()
|
||||
|
@ -104,7 +103,10 @@ _.extend(NEWSBLUR.ReaderOrganizer.prototype, {
|
|||
|
||||
NEWSBLUR.Collections.Folders.organizer_sortorder = null;
|
||||
NEWSBLUR.assets.folders.sort();
|
||||
|
||||
|
||||
NEWSBLUR.assets.feeds.off('change:highlighted')
|
||||
.on('change:highlighted', _.bind(this.change_selection, this));
|
||||
|
||||
return $feeds;
|
||||
},
|
||||
|
||||
|
@ -112,6 +114,24 @@ _.extend(NEWSBLUR.ReaderOrganizer.prototype, {
|
|||
// = Selecting =
|
||||
// =============
|
||||
|
||||
change_select: function(select) {
|
||||
if (select == "all") {
|
||||
this.feedlist.folder_view.highlight_feeds({force_highlight: true});
|
||||
} else if (select == "none") {
|
||||
this.feedlist.folder_view.highlight_feeds({force_deselect: true});
|
||||
}
|
||||
},
|
||||
|
||||
change_selection: function() {
|
||||
var $title = $(".NB-organizer-selects .NB-organizer-action-title", this.$modal);
|
||||
|
||||
var count = this.feedlist.folder_view.highlighted_count();
|
||||
if (!count) {
|
||||
$title.text("Select");
|
||||
} else {
|
||||
$title.text(count + " selected");
|
||||
}
|
||||
},
|
||||
|
||||
// ===========
|
||||
// = Sorting =
|
||||
|
@ -140,6 +160,14 @@ _.extend(NEWSBLUR.ReaderOrganizer.prototype, {
|
|||
this.change_sort(sort);
|
||||
}, this));
|
||||
|
||||
$.targetIs(e, { tagSelector: '.NB-organizer-action', childOf: '.NB-organizer-selects' },
|
||||
_.bind(function($t, $p) {
|
||||
e.preventDefault();
|
||||
|
||||
var select = $t.attr('class').match(/\bNB-action-select-(\w+)\b/)[1];
|
||||
this.change_select(select);
|
||||
}, this));
|
||||
|
||||
}
|
||||
|
||||
});
|
|
@ -58,18 +58,18 @@ NEWSBLUR.Views.FeedList = Backbone.View.extend({
|
|||
|
||||
this.$el.empty();
|
||||
this.$s.$story_taskbar.css({'display': 'block'});
|
||||
var $feeds = new NEWSBLUR.Views.Folder({
|
||||
this.folder_view = new NEWSBLUR.Views.Folder({
|
||||
collection: folders,
|
||||
root: true,
|
||||
feed_chooser: this.options.feed_chooser,
|
||||
organizer: this.options.organizer
|
||||
}).render().el;
|
||||
}).render();
|
||||
this.$el.css({
|
||||
'display': 'block',
|
||||
'opacity': 0
|
||||
});
|
||||
this.$el.addClass("NB-sort-" + this.options.sorting);
|
||||
this.$el.html($feeds);
|
||||
this.$el.html(this.folder_view.el);
|
||||
this.$el.animate({'opacity': 1}, {'duration': 700});
|
||||
// this.count_collapsed_unread_stories();
|
||||
this.$s.$feed_link_loader.fadeOut(250, _.bind(function() {
|
||||
|
|
|
@ -394,11 +394,9 @@ NEWSBLUR.Views.Folder = Backbone.View.extend({
|
|||
var folder_title = this.options.folder_title;
|
||||
var all_children_highlighted = this.collection.all(function(item) {
|
||||
if (item.is_feed()) {
|
||||
var view = _.detect(item.feed.views, function(view) {
|
||||
if (view.options.feed_chooser &&
|
||||
view.options.folder_title == folder_title) {
|
||||
return view;
|
||||
}
|
||||
var view = _.any(item.feed.views, function(view) {
|
||||
return view.options.feed_chooser &&
|
||||
view.options.folder_title == folder_title;
|
||||
});
|
||||
|
||||
if (!view) return true;
|
||||
|
@ -406,6 +404,7 @@ NEWSBLUR.Views.Folder = Backbone.View.extend({
|
|||
return item.feed.highlighted_in_folder(folder_title);
|
||||
} else if (item.is_folder()) {
|
||||
return _.all(item.folder_views, function(view) {
|
||||
if (!view.options.feed_chooser) return true;
|
||||
return view.all_children_highlighted();
|
||||
});
|
||||
}
|
||||
|
@ -415,6 +414,29 @@ NEWSBLUR.Views.Folder = Backbone.View.extend({
|
|||
return all_children_highlighted;
|
||||
},
|
||||
|
||||
highlighted_count: function() {
|
||||
var folder_title = this.options.folder_title;
|
||||
var count = this.collection.reduce(function(memo, item) {
|
||||
if (item.is_feed()) {
|
||||
var view = _.detect(item.feed.views, function(view) {
|
||||
return view.options.feed_chooser &&
|
||||
view.options.folder_title == folder_title;
|
||||
});
|
||||
|
||||
if (!view) return memo;
|
||||
|
||||
return item.feed.highlighted_in_folder(folder_title) ? memo + 1 : memo;
|
||||
} else {
|
||||
return memo + _.reduce(item.folder_views, function(m, view) {
|
||||
if (!view.options.feed_chooser) return m;
|
||||
return m + view.highlighted_count();
|
||||
}, 0);
|
||||
}
|
||||
}, 0);
|
||||
|
||||
return count;
|
||||
},
|
||||
|
||||
highlight_feeds: function(options) {
|
||||
options = options || {};
|
||||
if (!this.options.feed_chooser) return;
|
||||
|
@ -422,6 +444,7 @@ NEWSBLUR.Views.Folder = Backbone.View.extend({
|
|||
if ($folder && $folder[0] != this.el) return;
|
||||
var all_children_highlighted = this.all_children_highlighted();
|
||||
if (options.force_highlight) all_children_highlighted = false;
|
||||
if (options.force_deselect) all_children_highlighted = true;
|
||||
var folder_title = this.options.folder_title;
|
||||
|
||||
this.collection.each(function(item) {
|
||||
|
@ -445,7 +468,7 @@ NEWSBLUR.Views.Folder = Backbone.View.extend({
|
|||
if (!all_children_highlighted) {
|
||||
view.highlight_feeds({force_highlight: true});
|
||||
} else {
|
||||
view.highlight_feeds();
|
||||
view.highlight_feeds({force_deselect: options.force_deselect});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue