[1240] | 1 |
|
---|
| 2 | package gov.va.med.edp.command.reports
|
---|
| 3 | {
|
---|
| 4 | import com.adobe.cairngorm.business.ServiceLocator;
|
---|
| 5 | import com.adobe.cairngorm.commands.ICommand;
|
---|
| 6 | import com.adobe.cairngorm.control.CairngormEvent;
|
---|
| 7 |
|
---|
| 8 | import flash.events.Event;
|
---|
| 9 | import flash.events.IOErrorEvent;
|
---|
| 10 | import flash.net.FileReference;
|
---|
| 11 | import flash.net.URLRequest;
|
---|
| 12 |
|
---|
| 13 | import gov.va.med.edp.business.CSPService;
|
---|
| 14 | import gov.va.med.edp.control.reports.ReportDownloadEvent;
|
---|
| 15 | import gov.va.med.edp.util.Vista;
|
---|
| 16 | import gov.va.med.edp.widget.InfoDialog;
|
---|
| 17 |
|
---|
| 18 | public class DownloadReportCommand implements ICommand
|
---|
| 19 | {
|
---|
| 20 | private var fr:FileReference = new FileReference();
|
---|
| 21 |
|
---|
| 22 | public function execute(event:CairngormEvent):void
|
---|
| 23 | {
|
---|
| 24 | fr.addEventListener(Event.OPEN, openHandler);
|
---|
| 25 | fr.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);
|
---|
| 26 | fr.addEventListener(Event.COMPLETE, completeHandler);
|
---|
| 27 |
|
---|
| 28 | var reportEvent: ReportDownloadEvent = ReportDownloadEvent(event);
|
---|
| 29 | var service:CSPService = ServiceLocator.getInstance().getHTTPService("downloadReports") as CSPService;
|
---|
| 30 | var startFMDate:String = Vista.DatetoFM(reportEvent.reportParams.startDate);
|
---|
| 31 | var endFMDate:String = Vista.DatetoFM(reportEvent.reportParams.stopDate);
|
---|
| 32 |
|
---|
| 33 | var urlPrefix:String = "";
|
---|
| 34 |
|
---|
| 35 | if (service.callType == CSPService.SERVICE_USE_VLJ){
|
---|
| 36 | urlPrefix = service.vlj;
|
---|
| 37 | } else if (service.callType == CSPService.SERVICE_USE_CSP){
|
---|
| 38 | urlPrefix = service.csp;
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | var completeUrl: String = urlPrefix + "?command=" + service.command + "&report=" + reportEvent.reportParams.reportName.toLowerCase() +
|
---|
| 42 | "&start=" + startFMDate + "&stop=" + endFMDate + "&id=" + reportEvent.reportParams.id;
|
---|
| 43 |
|
---|
| 44 | var request:URLRequest = new URLRequest(completeUrl);
|
---|
| 45 | var fileName:String = reportEvent.reportParams.reportName + "Report.xls";
|
---|
| 46 |
|
---|
| 47 | fr.download(request, fileName);
|
---|
| 48 |
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | private function completeHandler(event:Event):void {
|
---|
| 52 | InfoDialog.show("Download Complete");
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | private function errorHandler(event:Event):void {
|
---|
| 56 | InfoDialog.show("An error occured while downloading the file" + event.currentTarget.toString());
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | private function openHandler(event:Event):void {
|
---|
| 60 | trace("Dialog Opened");
|
---|
| 61 | }
|
---|
| 62 |
|
---|
| 63 |
|
---|
| 64 | }
|
---|
| 65 | }
|
---|