discourse/app/assets/javascripts/admin/models/report.js
Robin Ward e1e1bdd0b1 Merge pull request #469 from wojciechka/master
Support for running discourse with a prefix (i.e. as http://servername/discourse)
2013-03-18 07:24:11 -07:00

27 lines
725 B
JavaScript

Discourse.Report = Discourse.Model.extend({});
Discourse.Report.reopenClass({
find: function(type) {
var model = Discourse.Report.create({type: type});
$.ajax(Discourse.getURL("/admin/reports/") + type, {
type: 'GET',
success: function(json) {
// Add a percent field to each tuple
var maxY = 0;
json.report.data.forEach(function (row) {
if (row.y > maxY) maxY = row.y;
});
if (maxY > 0) {
json.report.data.forEach(function (row) {
row.percentage = Math.round((row.y / maxY) * 100);
});
}
model.mergeAttributes(json.report);
model.set('loaded', true);
}
});
return(model);
}
});