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-10-01 13:07:45 -07:00
|
|
|
_.bindAll(this, 'on_change', 'on_remove', 'update_counts');
|
2012-06-14 17:38:09 -07:00
|
|
|
// this.bind('change', this.on_change);
|
2012-05-23 12:10:35 -07:00
|
|
|
this.bind('remove', this.on_remove);
|
2012-10-01 13:07:45 -07:00
|
|
|
|
|
|
|
this.bind('change:ps', this.update_counts);
|
|
|
|
this.bind('change:nt', this.update_counts);
|
|
|
|
this.bind('change:ng', this.update_counts);
|
|
|
|
|
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() {
|
2012-07-10 15:26:34 -07:00
|
|
|
NEWSBLUR.log(["Remove Feed", this, this.views]);
|
2012-05-23 12:10:35 -07:00
|
|
|
_.each(this.views, function(view) { view.remove(); });
|
|
|
|
},
|
2012-10-01 13:07:45 -07:00
|
|
|
|
|
|
|
update_counts: function() {
|
|
|
|
NEWSBLUR.assets.social_feeds.trigger('change:counts');
|
|
|
|
},
|
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
|
|
|
},
|
|
|
|
|
2013-08-16 16:02:45 -07:00
|
|
|
is_starred: function() {
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
2017-03-06 19:55:18 -08:00
|
|
|
is_search: function() {
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
2012-06-07 13:56:54 -07:00
|
|
|
unread_counts: function() {
|
|
|
|
return {
|
2013-08-05 13:26:51 -07:00
|
|
|
ps: this.get('ps') || 0,
|
|
|
|
nt: this.get('nt') || 0,
|
|
|
|
ng: this.get('ng') || 0
|
2012-06-07 13:56:54 -07:00
|
|
|
};
|
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-10-01 13:07:45 -07:00
|
|
|
},
|
|
|
|
|
2013-04-22 11:45:06 -07:00
|
|
|
unread_counts: function(existing_counts) {
|
|
|
|
existing_counts = existing_counts || {};
|
2012-10-01 13:07:45 -07:00
|
|
|
var counts = this.reduce(function(counts, item) {
|
|
|
|
var feed_counts = item.unread_counts();
|
|
|
|
counts['ps'] += feed_counts['ps'];
|
|
|
|
counts['nt'] += feed_counts['nt'];
|
|
|
|
counts['ng'] += feed_counts['ng'];
|
|
|
|
return counts;
|
|
|
|
}, {
|
2013-04-22 11:45:06 -07:00
|
|
|
ps: existing_counts['ps'] || 0,
|
|
|
|
nt: existing_counts['nt'] || 0,
|
|
|
|
ng: existing_counts['ng'] || 0
|
2012-10-01 13:07:45 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
return counts;
|
2012-04-24 13:18:08 -07:00
|
|
|
}
|
2012-02-10 12:48:14 -08:00
|
|
|
|
|
|
|
});
|