discourse/app/assets/javascripts/discourse/adapters/topic-list.js.es6
2015-07-21 10:54:39 +08:00

39 lines
919 B
JavaScript

import RestAdapter from 'discourse/adapters/rest';
export function finderFor(filter, params) {
return function() {
let url = Discourse.getURL("/") + filter + ".json";
if (params) {
const keys = Object.keys(params),
encoded = [];
keys.forEach(function(p) {
const value = encodeURI(params[p]);
if (typeof value !== 'undefined') {
encoded.push(p + "=" + value);
}
});
if (encoded.length > 0) {
url += "?" + encoded.join('&');
}
}
return Discourse.ajax(url);
};
}
export default RestAdapter.extend({
find(store, type, findArgs) {
const filter = findArgs.filter;
const params = findArgs.params;
return PreloadStore.getAndRemove("topic_list_" + filter, finderFor(filter, params)).then(function(result) {
result.filter = filter;
result.params = params;
return result;
});
}
});