2012-05-17 20:50:08 -07:00
|
|
|
NEWSBLUR.Models.FeedOrFolder = Backbone.Model.extend({
|
|
|
|
|
|
|
|
initialize: function(model) {
|
|
|
|
if (_.isNumber(model)) {
|
2012-05-18 16:59:39 -07:00
|
|
|
this.feed = NEWSBLUR.assets.feeds.get(model);
|
|
|
|
this.set('is_feed', true);
|
|
|
|
} else if (model) {
|
|
|
|
var title = _.keys(model)[0];
|
|
|
|
var children = model[title];
|
2012-05-21 20:08:27 -07:00
|
|
|
this.set('is_folder', true);
|
2012-05-18 16:59:39 -07:00
|
|
|
this.set('folder_title', title);
|
|
|
|
this.folders = new NEWSBLUR.Collections.Folders([], {title: title});
|
2012-05-23 10:02:30 -07:00
|
|
|
this.folders.reset(children);
|
2012-05-17 20:50:08 -07:00
|
|
|
}
|
2012-05-18 16:59:39 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
is_feed: function() {
|
|
|
|
return this.get('is_feed', false);
|
2012-05-21 20:08:27 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
is_folder: function() {
|
|
|
|
return this.get('is_folder', false);
|
2012-05-17 20:50:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
NEWSBLUR.Collections.Folders = Backbone.Collection.extend({
|
|
|
|
|
2012-05-18 16:59:39 -07:00
|
|
|
options: {
|
|
|
|
title: ''
|
|
|
|
},
|
|
|
|
|
|
|
|
initialize: function() {
|
|
|
|
this.comparator = NEWSBLUR.Collections.Folders.comparator;
|
|
|
|
},
|
|
|
|
|
2012-05-23 10:02:30 -07:00
|
|
|
model: NEWSBLUR.Models.FeedOrFolder
|
2012-05-17 20:50:08 -07:00
|
|
|
|
2012-05-18 16:59:39 -07:00
|
|
|
}, {
|
|
|
|
|
|
|
|
comparator: function(modelA, modelB) {
|
|
|
|
var sort_order = NEWSBLUR.assets.preference('feed_order');
|
|
|
|
|
|
|
|
|
2012-05-23 14:29:05 -07:00
|
|
|
if (modelA.is_feed() != modelB.is_feed()) {
|
|
|
|
// Feeds above folders
|
|
|
|
return modelA.is_feed() ? -1 : 1;
|
|
|
|
}
|
|
|
|
if (modelA.is_folder()) {
|
|
|
|
// Folders are alphabetical
|
|
|
|
return modelA.get('folder_title').toLowerCase() > modelB.get('folder_title').toLowerCase() ? 1 : -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
var feedA = modelA.feed;
|
|
|
|
var feedB = modelB.feed;
|
2012-05-18 16:59:39 -07:00
|
|
|
if (sort_order == 'ALPHABETICAL' || !sort_order) {
|
2012-05-23 14:29:05 -07:00
|
|
|
return feedA.get('feed_title').toLowerCase() > feedB.get('feed_title').toLowerCase() ? 1 : -1;
|
2012-05-18 16:59:39 -07:00
|
|
|
} else if (sort_order == 'MOSTUSED') {
|
2012-05-23 14:29:05 -07:00
|
|
|
return feedA.get('feed_opens') < feedB.get('feed_opens') ? 1 :
|
|
|
|
(feedA.get('feed_opens') > feedB.get('feed_opens') ? -1 :
|
|
|
|
(feedA.get('feed_title').toLowerCase() > feedB.get('feed_title').toLowerCase() ? 1 : -1));
|
2012-05-18 16:59:39 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-17 20:50:08 -07:00
|
|
|
});
|