source: EDIS/trunk/java/tracking-ui-core/src/main/flex/gov/va/med/edp/util/ReportUtil.as@ 1227

Last change on this file since 1227 was 1227, checked in by George Lilly, 13 years ago

initial load of EDIS 1.0

File size: 6.3 KB
Line 
1package gov.va.med.edp.util
2{
3 import gov.va.med.edp.control.reports.ReportDownloadEvent;
4 import gov.va.med.edp.model.TrackingModelLocator;
5 import gov.va.med.edp.view.reports.print.ReportDataGridPrintView;
6 import gov.va.med.edp.vo.reports.ReportParamsVO;
7
8 import mx.containers.HBox;
9 import mx.controls.dataGridClasses.DataGridColumn;
10 import mx.core.Application;
11 import mx.printing.FlexPrintJob;
12 import mx.utils.ObjectUtil;
13
14 public class ReportUtil
15 {
16 private static var model: TrackingModelLocator = TrackingModelLocator.getInstance();
17 public static const millisecondsPerHour:int = 1000 * 60 * 60;
18 private static const DT_FORMAT: String = "DD MMM YY JJ:NN";
19 private static const ACCESSIBLE_DT_FORMAT: String = "MMMM DD, YYYY JJ:NN";
20
21 static public function buildReportLabelText(initilizationText:String): String
22 {
23 var startDate:String = Vista.formattedDate(model.reports.startDate, DT_FORMAT);
24 var stopDate:String = Vista.formattedDate(model.reports.stopDate, DT_FORMAT);
25 var lbltext:String = initilizationText + " from " + startDate + " to " + stopDate;
26 return lbltext;
27 }
28
29 static public function accessibleReportLabelText(initilizationText:String): String
30 {
31 var startDate:String = Vista.formattedDate(model.reports.startDate, ACCESSIBLE_DT_FORMAT);
32 var stopDate:String = Vista.formattedDate(model.reports.stopDate, ACCESSIBLE_DT_FORMAT);
33 var lbltext:String = initilizationText + " from " + startDate + " to " + stopDate;
34
35 return lbltext;
36 }
37
38 static public function calculateEndTimeForShiftReport(startDate:Date): Date
39 {
40 var endDate:Date = new Date(startDate.getTime());
41 endDate.setTime(endDate.getTime() + (24* millisecondsPerHour));
42 return endDate;
43 }
44
45 static public function formatReportDate(item: Object, column: DataGridColumn): String
46 {
47 var dataField:String = column.dataField;
48 if ((item != null) && (item[dataField] != null)) {
49 return Vista.formattedDate(item[dataField], "M/D/YY JJ:NN");
50 } else {
51 return "";
52 }
53 }
54
55 static public function sortTimeInDates(obj1:Object, obj2:Object):int
56 {
57 var date1: Date = obj1.timeIn;
58 var date2: Date = obj2.timeIn;
59 return ObjectUtil.dateCompare(date1, date2);
60 }
61
62 static public function sortTimeOutDates(obj1:Object, obj2:Object):int
63 {
64 var date1: Date = obj1.timeOut;
65 var date2: Date = obj2.timeOut;
66 return ObjectUtil.dateCompare(date1, date2);
67 }
68
69 static public function exportReport(reportName:String, reportId:String=null): void
70 {
71 var reportEvent: ReportDownloadEvent = new ReportDownloadEvent(ReportDownloadEvent.EVENT_DOWNLOAD_REPORT);
72 var reportParams: ReportParamsVO = new ReportParamsVO();
73 reportParams.reportName = reportName;
74 reportParams.startDate = new Date(model.reports.startDate);
75 reportParams.stopDate = new Date(model.reports.stopDate);
76 reportParams.id = reportId;
77 reportEvent.reportParams = reportParams;
78 reportEvent.dispatch();
79 }
80
81 static public function setExportButtonState(button:HBox): void
82 {
83 button.visible = model.session.canExport;
84 }
85
86 static public function printDataGrid(printJob:FlexPrintJob, gridColumns:Array, dataProviderForGrid:Object, reportHeaderText: String, gridFontSize:int=8, reportHeaderFontSize:int=8):void{
87 // Create a FormPrintView control as a child of the current view.
88 var dataGridPrintView:ReportDataGridPrintView = new ReportDataGridPrintView();
89 Application.application.addChild(dataGridPrintView);
90
91 //Set the print view properties.
92 //FlexPrintJobScaleType
93 dataGridPrintView.width=printJob.pageWidth;
94 dataGridPrintView.height=printJob.pageHeight;
95 dataGridPrintView.lblHeaderText = reportHeaderText;
96 // Set the data provider of the FormPrintView component's data grid
97 // to be the data provider of the displayed data grid.
98 dataGridPrintView.reportDataGrid.columns = gridColumns;
99 dataGridPrintView.reportDataGrid.dataProvider = dataProviderForGrid;
100 dataGridPrintView.reportDataGrid.setStyle('fontSize', gridFontSize);
101 dataGridPrintView.header.setStyle('fontSize', reportHeaderFontSize);
102 // Create a single-page image.
103 dataGridPrintView.showPage("single");
104 // If the print image's data grid can hold all the provider's rows,
105 // add the page to the print job.
106 if(!dataGridPrintView.reportDataGrid.validNextPage)
107 {
108 printJob.addObject(dataGridPrintView);
109 }
110 // Otherwise, the job requires multiple pages.
111 else
112 {
113 // Create the first page and add it to the print job.
114 dataGridPrintView.showPage("first");
115 printJob.addObject(dataGridPrintView);
116 dataGridPrintView.pageNumber++;
117 // Loop through the following code until all pages are queued.
118 while(true)
119 {
120 // Move the next page of data to the top of the print grid.
121 dataGridPrintView.reportDataGrid.nextPage();
122 dataGridPrintView.showPage("last");
123 // If the page holds the remaining data, or if the last page
124 // was completely filled by the last grid data, queue it for printing.
125 // Test if there is data for another PrintDataGrid page.
126 if(!dataGridPrintView.reportDataGrid.validNextPage)
127 {
128 // This is the last page; queue it and exit the print loop.
129 printJob.addObject(dataGridPrintView);
130 break;
131 }
132 else
133 // This is not the last page. Queue a middle page.
134 {
135 dataGridPrintView.showPage("middle");
136 printJob.addObject(dataGridPrintView);
137 dataGridPrintView.pageNumber++;
138 }
139 }
140 }
141 // All pages are queued; remove the FormPrintView control to free memory.
142 Application.application.removeChild(dataGridPrintView);
143 }
144
145 }
146}
Note: See TracBrowser for help on using the repository browser.