NewsBlur/media/js/newsblur/models/feeds.js

126 lines
3.4 KiB
JavaScript
Raw Normal View History

NEWSBLUR.Models.Feed = Backbone.Model.extend({
initialize: function() {
2012-05-23 12:10:35 -07:00
_.bindAll(this, 'on_change', 'delete_feed');
this.bind('change', this.on_change);
2012-05-23 10:02:30 -07:00
this.views = [];
},
on_change: function() {
2012-05-24 13:31:23 -07:00
if (!('selected' in this.changedAttributes())) {
NEWSBLUR.log(['Feed Change', this.changedAttributes(), this.previousAttributes()]);
}
},
2012-05-23 12:10:35 -07:00
delete_feed: function(options) {
options = options || {};
var view = options.view || this.get_view();
2012-05-23 20:10:28 -07:00
console.log(["Delete Feed", this, view, view.collection.options.title]);
2012-05-23 12:10:35 -07:00
2012-05-23 20:10:28 -07:00
NEWSBLUR.assets.delete_feed(this.id, view.collection.options.title);
2012-05-23 12:10:35 -07:00
view.delete_feed();
},
move_to_folder: function(to_folder, options) {
options = options || {};
var view = options.view || this.get_view();
var in_folder = view.options.folder_title;
if (in_folder == to_folder) return false;
NEWSBLUR.assets.move_feed_to_folder(this.id, in_folder, to_folder, function() {
_.delay(function() {
NEWSBLUR.reader.$s.$feed_list.css('opacity', 1).animate({'opacity': 0}, {
'duration': 100,
'complete': function() {
NEWSBLUR.app.feed_list.make_feeds();
}
});
}, 250);
});
return true;
},
2012-05-23 12:27:59 -07:00
rename: function(new_title) {
this.set('feed_title', new_title);
NEWSBLUR.assets.rename_feed(this.id, new_title);
},
2012-05-23 12:10:35 -07:00
get_view: function($feed) {
return _.detect(this.views, function(view) {
if ($feed) {
return view.el == $feed.get(0);
} else {
return true;
}
});
},
is_social: function() {
return false;
},
is_feed: function() {
return true;
},
is_light: function() {
var is_light = this.is_light;
if (!_.isUndefined(is_light)) {
return is_light;
}
var color = this.get('favicon_color');
if (!color) return false;
var r = parseInt(color.substr(0, 2), 16) / 255.0;
var g = parseInt(color.substr(2, 2), 16) / 255.0;
var b = parseInt(color.substr(4, 2), 16) / 255.0;
is_light = $.textColor({r: r, g: g, b: b}) != 'white';
this.is_light = is_light;
return is_light;
}
});
NEWSBLUR.Collections.Feeds = Backbone.Collection.extend({
model: NEWSBLUR.Models.Feed,
url: '/reader/feeds',
fetch: function(options) {
options = _.extend({
data: {
v: 2
},
silent: true
}, options);
return Backbone.Collection.prototype.fetch.call(this, options);
},
parse: function(data) {
2012-05-23 12:10:35 -07:00
_.each(data.feeds, function(feed) {
feed.selected = false;
});
return data.feeds;
},
2012-05-23 12:10:35 -07:00
selected: function() {
return this.detect(function(feed) { return feed.get('selected'); });
},
has_chosen_feeds: function() {
return this.any(function(feed) {
return feed.get('active');
});
},
deselect: function() {
2012-05-23 12:10:35 -07:00
this.each(function(feed){
feed.set('selected', false);
});
}
});