2012-02-10 12:48:14 -08:00
|
|
|
NEWSBLUR.Models.SocialSubscription = Backbone.Model.extend({
|
|
|
|
|
2012-03-14 12:38:59 -07:00
|
|
|
initialize: function() {
|
2012-03-14 17:48:28 -07:00
|
|
|
if (!this.get('page_url')) {
|
|
|
|
this.set('page_url', '/social/page/' + this.get('user_id'));
|
2012-03-14 12:38:59 -07:00
|
|
|
}
|
2012-05-23 10:02:30 -07:00
|
|
|
|
2012-05-23 12:10:35 -07:00
|
|
|
_.bindAll(this, 'on_change', 'on_remove');
|
2012-05-23 10:02:30 -07:00
|
|
|
this.bind('change', this.on_change);
|
2012-05-23 12:10:35 -07:00
|
|
|
this.bind('remove', this.on_remove);
|
2012-05-23 10:02:30 -07:00
|
|
|
this.views = [];
|
2012-05-18 16:59:39 -07:00
|
|
|
},
|
2012-05-23 10:02:30 -07:00
|
|
|
|
|
|
|
on_change: function() {
|
|
|
|
NEWSBLUR.log(['Social Feed Change', this.changedAttributes(), this.previousAttributes()]);
|
|
|
|
},
|
2012-05-23 12:10:35 -07:00
|
|
|
|
|
|
|
on_remove: function() {
|
|
|
|
console.log(["Remove Feed", this, this.views]);
|
|
|
|
_.each(this.views, function(view) { view.remove(); });
|
|
|
|
},
|
2012-05-23 10:02:30 -07:00
|
|
|
|
2012-05-18 16:59:39 -07:00
|
|
|
is_social: function() {
|
|
|
|
return true;
|
2012-05-22 17:39:21 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
is_feed: function() {
|
|
|
|
return false;
|
2012-06-07 13:56:54 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
unread_counts: function() {
|
|
|
|
return {
|
|
|
|
ps: this.get('ps'),
|
|
|
|
nt: this.get('nt'),
|
|
|
|
ng: this.get('ng')
|
|
|
|
};
|
2012-03-14 12:38:59 -07:00
|
|
|
}
|
|
|
|
|
2012-02-10 12:48:14 -08:00
|
|
|
});
|
|
|
|
|
|
|
|
NEWSBLUR.Collections.SocialSubscriptions = Backbone.Collection.extend({
|
|
|
|
|
2012-04-24 13:18:08 -07:00
|
|
|
model : NEWSBLUR.Models.SocialSubscription,
|
|
|
|
|
2012-05-23 16:02:32 -07:00
|
|
|
parse: function(models) {
|
|
|
|
_.each(models, function(feed) {
|
|
|
|
feed.selected = false;
|
|
|
|
});
|
|
|
|
return models;
|
|
|
|
},
|
|
|
|
|
2012-04-24 13:18:08 -07:00
|
|
|
comparator: function(a, b) {
|
|
|
|
var sort_order = NEWSBLUR.reader.model.preference('feed_order');
|
2012-04-25 12:18:26 -07:00
|
|
|
var title_a = a.get('feed_title') || '';
|
|
|
|
var title_b = b.get('feed_title') || '';
|
|
|
|
title_a = title_a.toLowerCase();
|
|
|
|
title_b = title_b.toLowerCase();
|
2012-04-24 13:18:08 -07:00
|
|
|
|
|
|
|
if (sort_order == 'MOSTUSED') {
|
|
|
|
var opens_a = a.get('feed_opens');
|
|
|
|
var opens_b = b.get('feed_opens');
|
|
|
|
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;
|
2012-05-21 20:08:27 -07:00
|
|
|
},
|
|
|
|
|
2012-05-23 16:02:32 -07:00
|
|
|
selected: function() {
|
|
|
|
return this.detect(function(feed) { return feed.get('selected'); });
|
|
|
|
},
|
|
|
|
|
2012-05-21 20:08:27 -07:00
|
|
|
deselect: function() {
|
|
|
|
this.chain().select(function(feed) {
|
|
|
|
return feed.get('selected');
|
|
|
|
}).each(function(feed){
|
|
|
|
feed.set('selected', false);
|
|
|
|
});
|
2012-04-24 13:18:08 -07:00
|
|
|
}
|
2012-02-10 12:48:14 -08:00
|
|
|
|
|
|
|
});
|