This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/models/top_list.js.erb
2014-01-14 01:09:12 +01:00

38 lines
1.0 KiB
Plaintext

/**
A data model representing a list of top topic lists
@class TopList
@extends Discourse.Model
@namespace Discourse
@module Discourse
**/
Discourse.TopList = Discourse.Model.extend({});
Discourse.TopList.reopenClass({
PERIODS: <%= TopTopic.periods.map(&:to_s) %>,
find: function(period, category) {
return PreloadStore.getAndRemove("top_lists", function() {
var url = "";
if (category) { url += category.get("url") + "/l"; }
url += "/top";
if (period) { url += "/" + period; }
return Discourse.ajax(url + ".json");
}).then(function (result) {
var topList = Discourse.TopList.create({});
_.each(Discourse.TopList.PERIODS, function(period) {
// if there is a list for that period
if (result[period]) {
// instanciate a new topic list with no sorting
topList.set(period, Discourse.TopicList.from(result[period]));
topList.set(period + ".sortOrder", undefined);
}
});
return topList;
});
}
});