class ReportManager extends Listenable { constructor() { super(); //Register the reports statically for the time being. this.registerReport("project", new ProjectReport()); } /** * Registers a new report with the given key. The key must be unique. */ registerReport(key, report) { if (!this.reports) { this.reports = { }; } if (key in this.reports) { console.error("There is already a report with this key (\"" + key + "\")."); return; } this.reports[key] = report; } /** * Loads the report with the given key. Filter parameters and options may be passed as the optional second parameter. * A reportloaded event is fired after the report has finished loading. * A reporterror event is fired when an error occurs during the loading of the report. */ loadReport(key, options = null) { if (!(key in this.reports)) { console.error("Trying to load the report \"" + key + "\", but no report was registered with this key."); return; } this.loadingReport = this.reports[key]; this.loadReportRequest = new Request(OnTime.REQUEST_URI + this.loadingReport.requestPath, Request.GET, this.onReportLoaded.bind(this), this.onReportLoadingError.bind(this)); this.loadReportRequest.send(options); } /** * Called when an error occurs while loading the report. */ onReportLoadingError(request, status, error) { var errorEvent = new Event("reporterror"); errorEvent.report = this.loadingReport; this.dispatchEvent(errorEvent); this.loadingReport = null; } /** * Called after a report has been successfully loaded. */ onReportLoaded(data) { var loadedEvent = new Event("reportloaded"); this.loadingReport.data = data; loadedEvent.report = this.loadingReport; this.dispatchEvent(loadedEvent); this.loadingReport = null; } }