2016-02-27 15:51:42 -08:00
|
|
|
NEWSBLUR.Models.SavedSearchFeed = Backbone.Model.extend({
|
|
|
|
|
|
|
|
initialize: function() {
|
2020-12-08 18:14:09 -05:00
|
|
|
var feed_title = NEWSBLUR.reader.feed_title(this.get('feed_id'));
|
2017-03-06 16:23:03 -08:00
|
|
|
var favicon_url = this.favicon_url();
|
2017-03-06 19:55:18 -08:00
|
|
|
this.set('feed_title', "\"<b>" + this.get('query') + "</b>\" in <b>" + feed_title + "</b>");
|
2017-03-06 16:23:03 -08:00
|
|
|
this.set('favicon_url', favicon_url);
|
2017-03-06 19:55:18 -08:00
|
|
|
this.list_view;
|
2016-02-27 15:51:42 -08:00
|
|
|
},
|
|
|
|
|
2017-03-06 16:23:03 -08:00
|
|
|
favicon_url: function() {
|
|
|
|
var url;
|
|
|
|
var feed_id = this.get('feed_id');
|
|
|
|
|
2017-11-05 14:32:16 -08:00
|
|
|
if (feed_id == 'river:' || feed_id == 'river:infrequent') {
|
2017-03-06 16:23:03 -08:00
|
|
|
url = NEWSBLUR.Globals.MEDIA_URL + 'img/icons/circular/ak-icon-allstories.png';
|
|
|
|
} else if (_.string.startsWith(feed_id, 'river:')) {
|
|
|
|
url = NEWSBLUR.Globals.MEDIA_URL + 'img/icons/circular/g_icn_folder.png';
|
|
|
|
} else if (feed_id == "read") {
|
|
|
|
url = NEWSBLUR.Globals.MEDIA_URL + 'img/icons/circular/g_icn_unread.png';
|
2017-03-06 21:01:10 -08:00
|
|
|
} else if (feed_id == "starred") {
|
|
|
|
url = NEWSBLUR.Globals.MEDIA_URL + 'img/icons/circular/clock.png';
|
2017-03-06 16:23:03 -08:00
|
|
|
} else if (_.string.startsWith(feed_id, 'starred:')) {
|
|
|
|
url = NEWSBLUR.Globals.MEDIA_URL + 'img/reader/tag.png';
|
|
|
|
} else if (_.string.startsWith(feed_id, 'feed:')) {
|
|
|
|
url = $.favicon(parseInt(feed_id.replace('feed:', ''), 10));
|
|
|
|
} else if (_.string.startsWith(feed_id, 'social:')) {
|
|
|
|
url = $.favicon(NEWSBLUR.assets.get_feed(feed_id));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!url) {
|
|
|
|
url = NEWSBLUR.Globals.MEDIA_URL + 'img/icons/circular/g_icn_search_black.png';
|
|
|
|
}
|
|
|
|
|
|
|
|
return url;
|
|
|
|
},
|
|
|
|
|
2016-02-27 15:51:42 -08:00
|
|
|
is_social: function() {
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
is_feed: function() {
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
is_starred: function() {
|
2017-03-03 18:12:27 -05:00
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
is_search: function() {
|
2016-02-27 15:51:42 -08:00
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
unread_counts: function() {
|
|
|
|
return {
|
|
|
|
ps: this.get('count') || 0,
|
|
|
|
nt: 0,
|
|
|
|
ng: 0
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
tag_slug: function() {
|
|
|
|
return Inflector.sluggify(this.get('tag') || '');
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
NEWSBLUR.Collections.SearchesFeeds = Backbone.Collection.extend({
|
|
|
|
|
|
|
|
model: NEWSBLUR.Models.SavedSearchFeed,
|
|
|
|
|
|
|
|
parse: function(models) {
|
|
|
|
_.each(models, function(feed) {
|
2017-03-03 18:12:27 -05:00
|
|
|
feed.id = 'search:' + feed.feed_id + ":" + feed.query;
|
2016-02-27 15:51:42 -08:00
|
|
|
});
|
|
|
|
return models;
|
|
|
|
},
|
|
|
|
|
|
|
|
comparator: function(a, b) {
|
|
|
|
var sort_order = NEWSBLUR.reader.model.preference('feed_order');
|
2017-03-03 18:12:27 -05:00
|
|
|
var title_a = a.get('query') || '';
|
|
|
|
var title_b = b.get('query') || '';
|
2016-02-27 15:51:42 -08:00
|
|
|
title_a = title_a.toLowerCase();
|
|
|
|
title_b = title_b.toLowerCase();
|
|
|
|
|
|
|
|
if (sort_order == 'MOSTUSED') {
|
|
|
|
var opens_a = a.get('count');
|
|
|
|
var opens_b = b.get('count');
|
|
|
|
if (opens_a > opens_b) return -1;
|
|
|
|
if (opens_a < opens_b) return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if (!sort_order || sort_order == 'ALPHABETICAL')
|
|
|
|
if (title_a > title_b) return 1;
|
|
|
|
else if (title_a < title_b) return -1;
|
|
|
|
return 0;
|
|
|
|
},
|
|
|
|
|
|
|
|
selected: function() {
|
|
|
|
return this.detect(function(feed) { return feed.get('selected'); });
|
|
|
|
},
|
|
|
|
|
|
|
|
deselect: function() {
|
|
|
|
this.chain().select(function(feed) {
|
|
|
|
return feed.get('selected');
|
|
|
|
}).each(function(feed){
|
|
|
|
feed.set('selected', false);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
all_searches: function() {
|
|
|
|
return this.pluck('saved_search');
|
|
|
|
},
|
|
|
|
|
|
|
|
get_feed: function(feed_id) {
|
|
|
|
return this.detect(function(feed) {
|
|
|
|
return feed.get('feed_id') == feed_id;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-12-08 18:14:09 -05:00
|
|
|
});
|