[1240] | 1 | <?xml version="1.0" encoding="utf-8"?>
|
---|
| 2 | <mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml"
|
---|
| 3 | width="100%" height="100%"
|
---|
| 4 | paddingBottom="0" paddingRight="0" paddingLeft="0" paddingTop="0"
|
---|
| 5 | show="initDisplayBoard()"
|
---|
| 6 | hide="stopBoardTimer()" xmlns:widget="gov.va.med.edp.widget.*">
|
---|
| 7 |
|
---|
| 8 | <mx:Script>
|
---|
| 9 | <![CDATA[
|
---|
| 10 | import mx.utils.ObjectUtil;
|
---|
| 11 | import gov.va.med.edp.util.BoardTools;
|
---|
| 12 | import gov.va.med.edp.view.LoadingDialog;
|
---|
| 13 | import mx.events.FlexEvent;
|
---|
| 14 | import mx.binding.utils.ChangeWatcher;
|
---|
| 15 | import mx.collections.ArrayCollection;
|
---|
| 16 | import mx.formatters.DateFormatter;
|
---|
| 17 | import mx.core.Application;
|
---|
| 18 | import mx.controls.dataGridClasses.DataGridColumn;
|
---|
| 19 | import mx.events.DataGridEvent;
|
---|
| 20 |
|
---|
| 21 | import gov.va.med.edp.vo.ColumnSpecVO;
|
---|
| 22 | import gov.va.med.edp.control.DisplayBoardEvent;
|
---|
| 23 | import gov.va.med.edp.model.TrackingModelLocator;
|
---|
| 24 | import gov.va.med.edp.widget.ColorCellRenderer;
|
---|
| 25 | import gov.va.med.edp.control.SortHeaderEvent;
|
---|
| 26 | import gov.va.med.edp.control.NumberEvent;
|
---|
| 27 |
|
---|
| 28 | [Bindable]
|
---|
| 29 | private var dateFormatter:DateFormatter;
|
---|
| 30 | private var sortColumn:DataGridColumn;
|
---|
| 31 |
|
---|
| 32 | [Bindable]
|
---|
| 33 | private var model: TrackingModelLocator = TrackingModelLocator.getInstance();
|
---|
| 34 |
|
---|
| 35 | private var visibleBoardTimer: Timer = new Timer(1200, 1);
|
---|
| 36 | private var refreshTimer: Timer = new Timer(30000);
|
---|
| 37 | private var autoScrollTimer: Timer = new Timer(10000);
|
---|
| 38 | private var counter:int = 0;
|
---|
| 39 | private var boardName: String = "";
|
---|
| 40 |
|
---|
| 41 | private var _disconnected:Boolean = false;
|
---|
| 42 | private var _connecting:Boolean = false;
|
---|
| 43 |
|
---|
| 44 | private static var MINIMUM_FONT_SIZE:Number = 9;
|
---|
| 45 | private static var MINIMUM_ROW_HEIGHT:int = 18;
|
---|
| 46 |
|
---|
| 47 | [Bindable]
|
---|
| 48 | public function get disconnected():Boolean {
|
---|
| 49 | return _disconnected;
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | public function set disconnected(b:Boolean):void {
|
---|
| 53 | _disconnected = b;
|
---|
| 54 | if (_disconnected) {
|
---|
| 55 | if (dateFormatter == null) {
|
---|
| 56 | dateFormatter = new DateFormatter();
|
---|
| 57 | dateFormatter.formatString = "MMM DD,YY JJ:NN";
|
---|
| 58 | }
|
---|
| 59 | stopBoardTimer();
|
---|
| 60 | currentState = 'disconnected';
|
---|
| 61 | } else {
|
---|
| 62 | currentState = '';
|
---|
| 63 | startBoardTimer();
|
---|
| 64 | }
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 | [Bindable]
|
---|
| 68 | public function get connecting():Boolean {
|
---|
| 69 | return _connecting;
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | public function set connecting(b:Boolean):void {
|
---|
| 73 | _connecting = b;
|
---|
| 74 | if (_connecting) {
|
---|
| 75 | connectingSpinner.play();
|
---|
| 76 | } else {
|
---|
| 77 | connectingSpinner.stop();
|
---|
| 78 | }
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | private function initDisplayBoard(): void
|
---|
| 82 | {
|
---|
| 83 | if (model.session.area < 1) return;
|
---|
| 84 |
|
---|
| 85 | boardName = Application.application.parameters.board;
|
---|
| 86 | model.reloadFunction = reload;
|
---|
| 87 |
|
---|
| 88 | dispatchBoardInit();
|
---|
| 89 | visibleBoardTimer.addEventListener(TimerEvent.TIMER_COMPLETE, removeLoadingDialog);
|
---|
| 90 | refreshTimer.addEventListener(TimerEvent.TIMER, refreshDisplayBoard);
|
---|
| 91 | refreshTimer.start();
|
---|
| 92 | visibleBoardTimer.start();
|
---|
| 93 |
|
---|
| 94 | autoScrollTimer.addEventListener(TimerEvent.TIMER, doScroll);
|
---|
| 95 |
|
---|
| 96 | model.reconnectFunction = reconnect;
|
---|
| 97 |
|
---|
| 98 | LoadingDialog.show();
|
---|
| 99 | }
|
---|
| 100 |
|
---|
| 101 | private function dispatchBoardInit(): void {
|
---|
| 102 | var resetEvent: DisplayBoardEvent = new DisplayBoardEvent(DisplayBoardEvent.EVENT_INIT_DISPLAY_BOARD);
|
---|
| 103 | resetEvent.name = boardName;
|
---|
| 104 | resetEvent.dispatch();
|
---|
| 105 | }
|
---|
| 106 |
|
---|
| 107 | private function reconnect():void {
|
---|
| 108 | dispatchBoardInit();
|
---|
| 109 | }
|
---|
| 110 |
|
---|
| 111 | private function reload():void {
|
---|
| 112 | var url:String = TrackingModelLocator.getInstance().rootURL;
|
---|
| 113 | if (TrackingModelLocator.getInstance().contextRoot.indexOf("main") != -1) {
|
---|
| 114 | url += "board.html";
|
---|
| 115 | } else {
|
---|
| 116 | url += "bigboard.html";
|
---|
| 117 | }
|
---|
| 118 | if (Application.application.parameters.board || Application.application.parameters.area) {
|
---|
| 119 | url += "?";
|
---|
| 120 | }
|
---|
| 121 | if (Application.application.parameters.board) {
|
---|
| 122 | url += "board=" + Application.application.parameters.board;
|
---|
| 123 | }
|
---|
| 124 | if (Application.application.parameters.area) {
|
---|
| 125 | if (Application.application.parameters.board) url += "&";
|
---|
| 126 | url += "area=" + Application.application.parameters.area;
|
---|
| 127 | }
|
---|
| 128 | navigateToURL(new URLRequest(url), "_top");
|
---|
| 129 | }
|
---|
| 130 |
|
---|
| 131 | private function stopBoardTimer(): void
|
---|
| 132 | {
|
---|
| 133 | refreshTimer.reset();
|
---|
| 134 | }
|
---|
| 135 |
|
---|
| 136 | private function startBoardTimer(): void
|
---|
| 137 | {
|
---|
| 138 | if (!refreshTimer.running) refreshTimer.start();
|
---|
| 139 | }
|
---|
| 140 |
|
---|
| 141 | private function refreshDisplayBoard(event: TimerEvent): void
|
---|
| 142 | {
|
---|
| 143 | if (model.session.area < 1) return;
|
---|
| 144 |
|
---|
| 145 | var refreshEvent: DisplayBoardEvent =
|
---|
| 146 | new DisplayBoardEvent(DisplayBoardEvent.EVENT_REFRESH_DISPLAY_BOARD);
|
---|
| 147 | refreshEvent.name = boardName;
|
---|
| 148 | refreshEvent.dispatch();
|
---|
| 149 |
|
---|
| 150 | }
|
---|
| 151 |
|
---|
| 152 | private function removeLoadingDialog(event: TimerEvent): void
|
---|
| 153 | {
|
---|
| 154 | LoadingDialog.hide();
|
---|
| 155 | }
|
---|
| 156 |
|
---|
| 157 | private function set readyToBuild(value: Boolean): void
|
---|
| 158 | {
|
---|
| 159 | if (value == true) {
|
---|
| 160 | callLater(buildColumns);
|
---|
| 161 | }
|
---|
| 162 | }
|
---|
| 163 |
|
---|
| 164 | private function buildColumns(): void
|
---|
| 165 | {
|
---|
| 166 | clearBoardProperties();
|
---|
| 167 | var newCols:Array = new Array();
|
---|
| 168 | var newCol: DataGridColumn;
|
---|
| 169 | for each (var colInfo: ColumnSpecVO in model.boardSpec.columns) {
|
---|
| 170 | newCol = new DataGridColumn(colInfo.attribute);
|
---|
| 171 | newCol.headerText = colInfo.header;
|
---|
| 172 | newCol.dataField = colInfo.attribute;
|
---|
| 173 | newCol.width = colInfo.width;
|
---|
| 174 |
|
---|
| 175 | //set the label and sort function for any minute based columns
|
---|
| 176 | if (colInfo.attribute.indexOf("min") != -1) {
|
---|
| 177 | newCol.sortCompareFunction = sortMinutes;
|
---|
| 178 | newCol.labelFunction = BoardTools.displayTimeAsHrsAndMins;
|
---|
| 179 | }
|
---|
| 180 |
|
---|
| 181 |
|
---|
| 182 | if ((colInfo.attribute == "@last4") || (colInfo.attribute == "@ptNm")) {
|
---|
| 183 | newCol.itemRenderer = new ClassFactory(gov.va.med.edp.widget.PatientCellRenderer);
|
---|
| 184 | } else if (colInfo.attribute == "@visit") {
|
---|
| 185 | newCol.itemRenderer = new ClassFactory(gov.va.med.edp.widget.VisitRenderer);
|
---|
| 186 | } else {
|
---|
| 187 | newCol.itemRenderer = new ClassFactory(gov.va.med.edp.widget.ColorCellRenderer);
|
---|
| 188 | }
|
---|
| 189 | newCols.push(newCol);
|
---|
| 190 | }
|
---|
| 191 |
|
---|
| 192 | board.columns = newCols;
|
---|
| 193 |
|
---|
| 194 | //Set the Board properties here..
|
---|
| 195 | board.width = model.boardSpec.displayBoardProperties.displaySize.width;
|
---|
| 196 |
|
---|
| 197 | //start the timer and get original DG properties
|
---|
| 198 | doScroll(new TimerEvent(TimerEvent.TIMER));
|
---|
| 199 | initAutoScrollTimer();
|
---|
| 200 |
|
---|
| 201 | board.setVisible(true);
|
---|
| 202 | }
|
---|
| 203 |
|
---|
| 204 | private function initAutoScrollTimer(): void {
|
---|
| 205 | autoScrollTimer.reset();
|
---|
| 206 | autoScrollTimer.delay = model.boardSpec.displayBoardProperties.scrollDelay * 1000;
|
---|
| 207 | autoScrollTimer.start();
|
---|
| 208 | }
|
---|
| 209 |
|
---|
| 210 | private function clearBoardProperties(): void
|
---|
| 211 | {
|
---|
| 212 | counter = 0;
|
---|
| 213 | if (board != null) {
|
---|
| 214 | board.invalidateSize();
|
---|
| 215 | board.invalidateDisplayList();
|
---|
| 216 | board.invalidateProperties();
|
---|
| 217 | board.invalidateList();
|
---|
| 218 | board.initialize();
|
---|
| 219 | }
|
---|
| 220 | }
|
---|
| 221 |
|
---|
| 222 | // this must be called later by handleHeader for the sortField to be accurate
|
---|
| 223 | private function saveSortInfo(col:DataGridColumn): void
|
---|
| 224 | {
|
---|
| 225 | var sortEvent:SortHeaderEvent =
|
---|
| 226 | new SortHeaderEvent(SortHeaderEvent.EVENT_SORT_DISPLAY_BOARD);
|
---|
| 227 | sortEvent.sortDescending = col.sortDescending;
|
---|
| 228 | sortEvent.sortField = col.dataField;
|
---|
| 229 | sortEvent.dispatch();
|
---|
| 230 | }
|
---|
| 231 |
|
---|
| 232 | private function handleHeader(event:DataGridEvent): void
|
---|
| 233 | {
|
---|
| 234 | sortColumn = DataGridColumn(event.currentTarget.columns[event.columnIndex]);
|
---|
| 235 | callLater(saveSortInfo, [sortColumn]);
|
---|
| 236 | }
|
---|
| 237 |
|
---|
| 238 |
|
---|
| 239 | private function sortMinutes(obj1:Object, obj2:Object):int
|
---|
| 240 | {
|
---|
| 241 | if (sortColumn == null) return 0;
|
---|
| 242 |
|
---|
| 243 | var num1:Number = parseInt(obj1[sortColumn.dataField]);
|
---|
| 244 | var num2:Number = parseInt(obj2[sortColumn.dataField]);
|
---|
| 245 | return ObjectUtil.numericCompare(num1, num2);
|
---|
| 246 | }
|
---|
| 247 |
|
---|
| 248 | private function doScroll(event: TimerEvent): void
|
---|
| 249 | {
|
---|
| 250 | if (isSquishOrAutoScrollingNeeded()) {
|
---|
| 251 | if (model.boardSpec.displayBoardProperties.squish) {
|
---|
| 252 | doSquishIfPossible();
|
---|
| 253 | } else {
|
---|
| 254 | startScrolling();
|
---|
| 255 | }
|
---|
| 256 | } else {
|
---|
| 257 | board.verticalScrollPosition = 0;
|
---|
| 258 | resetOriginalBoardProperties();
|
---|
| 259 | }
|
---|
| 260 | }
|
---|
| 261 |
|
---|
| 262 |
|
---|
| 263 | private function isSquishOrAutoScrollingNeeded(): Boolean
|
---|
| 264 | {
|
---|
| 265 | var neededRowHeight: Number = model.boardData.length * getGridRowHeight();
|
---|
| 266 | if ((neededRowHeight + board.headerHeight) < board.height) {
|
---|
| 267 | return false;
|
---|
| 268 | }
|
---|
| 269 | return true;
|
---|
| 270 | }
|
---|
| 271 |
|
---|
| 272 |
|
---|
| 273 | private function doSquishIfPossible(): void
|
---|
| 274 | {
|
---|
| 275 | if (isSquishPossible()) {
|
---|
| 276 | squishDGRows();
|
---|
| 277 | } else {
|
---|
| 278 | startScrolling();
|
---|
| 279 | }
|
---|
| 280 | }
|
---|
| 281 |
|
---|
| 282 |
|
---|
| 283 | private function isSquishPossible(): Boolean
|
---|
| 284 | {
|
---|
| 285 | if (getSquishedGridRowHt() >= MINIMUM_ROW_HEIGHT) {
|
---|
| 286 | return true;
|
---|
| 287 | }
|
---|
| 288 | return false;
|
---|
| 289 | }
|
---|
| 290 |
|
---|
| 291 | private function squishDGRows(): void
|
---|
| 292 | {
|
---|
| 293 | board.verticalScrollPolicy = "off";
|
---|
| 294 | var userConfiguredFontSize:int = model.boardSpec.displayBoardProperties.fontSize;
|
---|
| 295 | var squishedFontSize: Number = (getSquishedGridRowHt() / getGridRowHeight()) * userConfiguredFontSize;
|
---|
| 296 |
|
---|
| 297 | var changeEvent: NumberEvent = new NumberEvent(NumberEvent.EVENT_CHANGE_SQUISH_FONT_SIZE);
|
---|
| 298 |
|
---|
| 299 | if (squishedFontSize >= MINIMUM_FONT_SIZE && squishedFontSize <= userConfiguredFontSize) {
|
---|
| 300 | changeEvent.value = squishedFontSize;
|
---|
| 301 | board.setStyle("fontSize", squishedFontSize);
|
---|
| 302 | board.rowHeight = getSquishedGridRowHt();
|
---|
| 303 |
|
---|
| 304 | } else if (squishedFontSize > userConfiguredFontSize) {
|
---|
| 305 | changeEvent.value = userConfiguredFontSize;
|
---|
| 306 | board.setStyle("fontSize", userConfiguredFontSize);
|
---|
| 307 | board.rowHeight = getGridRowHeight();
|
---|
| 308 | } else {
|
---|
| 309 | changeEvent.value = MINIMUM_FONT_SIZE;
|
---|
| 310 | board.setStyle("fontSize", MINIMUM_FONT_SIZE);
|
---|
| 311 | board.rowHeight = MINIMUM_ROW_HEIGHT
|
---|
| 312 | }
|
---|
| 313 | changeEvent.dispatch();
|
---|
| 314 | }
|
---|
| 315 |
|
---|
| 316 | private function getSquishedGridRowHt(): Number
|
---|
| 317 | {
|
---|
| 318 | //40 pixels for making sure we see all the screen...Sometimes there is plastic that cover the actual screen in laptops etc..
|
---|
| 319 | //saw this on one of testing laptops where some portion of last row was hidden under plastic covering..
|
---|
| 320 | var boardHeight:Number = (board.height - board.headerHeight - 40);
|
---|
| 321 | var rowHeight:Number = boardHeight / (model.boardData.length + 1);
|
---|
| 322 | return rowHeight
|
---|
| 323 | }
|
---|
| 324 |
|
---|
| 325 | //There is now way to calculate row height since everything is dynamic
|
---|
| 326 | //we can only go of something that we do know and it's user configured Font size.
|
---|
| 327 | private function getGridRowHeight(): int {
|
---|
| 328 | var rowHt:int = Math.floor(model.boardSpec.displayBoardProperties.fontSize * 2);
|
---|
| 329 | return rowHt;
|
---|
| 330 | }
|
---|
| 331 |
|
---|
| 332 | private function startScrolling(): void {
|
---|
| 333 | //Reset the board properties back to original settings
|
---|
| 334 | resetOriginalBoardProperties();
|
---|
| 335 |
|
---|
| 336 | //recalcuate the loops here in case the dataprovider has changed..
|
---|
| 337 | var actualRowCountNum:Number = (board.height - board.headerHeight) / getGridRowHeight(); //account for header
|
---|
| 338 | var actualRowCount:int = Math.floor(actualRowCountNum);
|
---|
| 339 | var loopsNum:Number = (model.boardData.length + 1) / (actualRowCount);
|
---|
| 340 | var numOfLoops:int = Math.ceil(loopsNum);
|
---|
| 341 |
|
---|
| 342 |
|
---|
| 343 | if (counter >= numOfLoops) counter = 0;
|
---|
| 344 | board.verticalScrollPosition = (counter * actualRowCount);
|
---|
| 345 | counter++;
|
---|
| 346 | }
|
---|
| 347 |
|
---|
| 348 | private function resetOriginalBoardProperties(): void {
|
---|
| 349 | board.verticalScrollPolicy = "auto";
|
---|
| 350 | board.setStyle("fontSize", model.boardSpec.displayBoardProperties.fontSize);
|
---|
| 351 | board.rowHeight = getGridRowHeight();
|
---|
| 352 | var changeEvent: NumberEvent = new NumberEvent(NumberEvent.EVENT_CHANGE_SQUISH_FONT_SIZE);
|
---|
| 353 | changeEvent.value = model.boardSpec.displayBoardProperties.fontSize;
|
---|
| 354 | changeEvent.dispatch();
|
---|
| 355 | }
|
---|
| 356 |
|
---|
| 357 | ]]>
|
---|
| 358 | </mx:Script>
|
---|
| 359 |
|
---|
| 360 | <mx:HBox
|
---|
| 361 | id="mainArea"
|
---|
| 362 | width="100%" height="100%"
|
---|
| 363 | styleName="contentArea">
|
---|
| 364 | <widget:DataGrid
|
---|
| 365 | id="board"
|
---|
| 366 | dataProvider="{model.boardData}"
|
---|
| 367 | headerRelease="handleHeader(event)"
|
---|
| 368 | width="100%" height="100%"
|
---|
| 369 | useRollOver="false"/>
|
---|
| 370 | </mx:HBox>
|
---|
| 371 |
|
---|
| 372 | <mx:Binding source="model.boardSpec.specReady" destination="readyToBuild"/>
|
---|
| 373 | <mx:Binding source="model.disconnected" destination="disconnected"/>
|
---|
| 374 | <mx:Binding source="model.connecting" destination="connecting"/>
|
---|
| 375 |
|
---|
| 376 | <mx:states>
|
---|
| 377 | <mx:State name="disconnected">
|
---|
| 378 | <mx:AddChild relativeTo="{mainArea}" position="before">
|
---|
| 379 | <mx:target>
|
---|
| 380 | <mx:VBox id="disconnectedBoardPanel" width="100%">
|
---|
| 381 | <mx:ApplicationControlBar paddingBottom="0" paddingTop="0" dock="true" width="100%"
|
---|
| 382 | fillColors="[#FF0000,#BF0000]" fillAlphas="[0.8,0.8]">
|
---|
| 383 | <mx:Text id="disconnectionMessage" horizontalCenter="0" verticalCenter="0"
|
---|
| 384 | textAlign="center" width="100%" height="100%" color="white"
|
---|
| 385 | fontSize="{model.boardSpec.displayBoardProperties.fontSize}">
|
---|
| 386 | <mx:text>This board is disconnected from the server. Last updated
|
---|
| 387 | {dateFormatter.format(model.boardLastUpdated)}. {model.connecting ? "Trying to reconnect..." : "Will try to reconnect in " + model.reconnectSeconds + " seconds."}
|
---|
| 388 | </mx:text>
|
---|
| 389 | </mx:Text>
|
---|
| 390 | <widget:Spinner id="connectingSpinner" autoPlay="false" tickColor="#FFFFFF"/>
|
---|
| 391 | </mx:ApplicationControlBar>
|
---|
| 392 | </mx:VBox>
|
---|
| 393 | </mx:target>
|
---|
| 394 | </mx:AddChild>
|
---|
| 395 | </mx:State>
|
---|
| 396 | </mx:states>
|
---|
| 397 | </mx:VBox>
|
---|