Add more reports
This commit is contained in:
50
js/actions/ReportActions.js
Normal file
50
js/actions/ReportActions.js
Normal file
@ -0,0 +1,50 @@
|
||||
var ReportConstants = require('../constants/ReportConstants');
|
||||
|
||||
var ErrorActions = require('./ErrorActions');
|
||||
|
||||
var Report = models.Report;
|
||||
var Error = models.Error;
|
||||
|
||||
function fetchReport(reportId) {
|
||||
return {
|
||||
type: ReportConstants.FETCH_REPORT,
|
||||
reportId: reportId
|
||||
}
|
||||
}
|
||||
|
||||
function reportFetched(report) {
|
||||
return {
|
||||
type: ReportConstants.REPORT_FETCHED,
|
||||
report: report
|
||||
}
|
||||
}
|
||||
|
||||
function fetch(reportId) {
|
||||
return function (dispatch) {
|
||||
dispatch(fetchReport(reportId));
|
||||
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
dataType: "json",
|
||||
url: "report/?id="+reportId,
|
||||
success: function(data, status, jqXHR) {
|
||||
var e = new Error();
|
||||
e.fromJSON(data);
|
||||
if (e.isError()) {
|
||||
dispatch(ErrorActions.serverError(e));
|
||||
} else {
|
||||
var r = new Report();
|
||||
r.fromJSON(data);
|
||||
dispatch(reportFetched(r));
|
||||
}
|
||||
},
|
||||
error: function(jqXHR, status, error) {
|
||||
dispatch(ErrorActions.ajaxError(e));
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
fetch: fetch
|
||||
};
|
Reference in New Issue
Block a user