2012-05-17 18:40:46 -07:00
|
|
|
NEWSBLUR.Models.Feed = Backbone.Model.extend({
|
|
|
|
|
2012-05-22 17:39:21 -07:00
|
|
|
initialize: function() {
|
2012-05-23 12:10:35 -07:00
|
|
|
_.bindAll(this, 'on_change', 'delete_feed');
|
2012-05-22 17:39:21 -07:00
|
|
|
this.bind('change', this.on_change);
|
2012-05-23 10:02:30 -07:00
|
|
|
this.views = [];
|
2012-05-22 17:39:21 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
on_change: function() {
|
2012-05-23 10:02:30 -07:00
|
|
|
// NEWSBLUR.log(['Feed Change', this.changedAttributes(), this.previousAttributes()]);
|
2012-05-22 17:39:21 -07:00
|
|
|
},
|
|
|
|
|
2012-05-23 12:10:35 -07:00
|
|
|
delete_feed: function(options) {
|
|
|
|
options = options || {};
|
|
|
|
var view = options.view || this.get_view();
|
|
|
|
console.log(["Delete Feed", this, view, view.options.folder_title]);
|
|
|
|
|
|
|
|
NEWSBLUR.assets.delete_feed(this.id, view.options.folder_title);
|
|
|
|
view.delete_feed();
|
|
|
|
},
|
|
|
|
|
|
|
|
get_view: function($feed) {
|
|
|
|
return _.detect(this.views, function(view) {
|
|
|
|
if ($feed) {
|
|
|
|
return view.el == $feed.get(0);
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2012-05-18 16:59:39 -07:00
|
|
|
is_social: function() {
|
|
|
|
return false;
|
2012-05-22 17:39:21 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
is_feed: function() {
|
|
|
|
return true;
|
2012-05-18 16:59:39 -07:00
|
|
|
}
|
|
|
|
|
2012-05-17 18:40:46 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
NEWSBLUR.Collections.Feeds = Backbone.Collection.extend({
|
|
|
|
|
|
|
|
model: NEWSBLUR.Models.Feed,
|
|
|
|
|
|
|
|
url: '/reader/feeds',
|
|
|
|
|
|
|
|
fetch: function(options) {
|
|
|
|
options = _.extend({
|
|
|
|
data: {
|
|
|
|
v: 2
|
2012-05-17 20:50:08 -07:00
|
|
|
},
|
|
|
|
silent: true
|
2012-05-17 18:40:46 -07:00
|
|
|
}, 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;
|
|
|
|
});
|
2012-05-17 18:40:46 -07:00
|
|
|
return data.feeds;
|
2012-05-18 18:13:45 -07:00
|
|
|
},
|
2012-05-17 18:40:46 -07:00
|
|
|
|
2012-05-23 12:10:35 -07:00
|
|
|
selected: function() {
|
|
|
|
return this.detect(function(feed) { return feed.get('selected'); });
|
|
|
|
},
|
|
|
|
|
2012-05-18 18:13:45 -07:00
|
|
|
has_chosen_feeds: function() {
|
|
|
|
return this.any(function(feed) {
|
|
|
|
return feed.get('active');
|
|
|
|
});
|
2012-05-21 20:08:27 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
deselect: function() {
|
2012-05-23 12:10:35 -07:00
|
|
|
this.each(function(feed){
|
2012-05-21 20:08:27 -07:00
|
|
|
feed.set('selected', false);
|
|
|
|
});
|
2012-05-18 18:13:45 -07:00
|
|
|
}
|
2012-05-17 18:40:46 -07:00
|
|
|
|
|
|
|
});
|