- add time remaining display on result window

This commit is contained in:
Richard Alam 2013-10-21 13:36:14 -07:00
parent d62af354d4
commit bf81aa4e56

View File

@ -19,18 +19,43 @@
[Bindable] public var pollID:String;
[Bindable] private var _showStopButton:Boolean = false;
[Bindable] private var pollTimeRemaining:String = "";
private var timeRemainTimerStarted:Boolean = false;
private var _activationTimer:Timer = null;
private function onCreationComplete():void{
setCurrentState("BarChart");
if (UsersUtil.amIModerator() || UsersUtil.amIPresenter()) {
var poll:PollVO = viewModel.getPoll(pollID);
if (poll.started && !poll.stopped) {
_showStopButton = true;
pollTimeRemaining = formatTimeRemaining(poll.timeRemaining);
startTimer();
} else {
_showStopButton = false;
}
}
}
private function startTimer():void {
timeRemainTimerStarted = true;
_activationTimer = new Timer(1000, 0);
_activationTimer.addEventListener(TimerEvent.TIMER, updateTimeRemaining);
_activationTimer.start();
}
private function formatTimeRemaining(timeLeft:int):String {
var minutes:int = timeLeft / 60;
var seconds:int = timeLeft % 60;
return minutes + ":" + seconds;
}
private function updateTimeRemaining(e:TimerEvent):void {
var poll:PollVO = viewModel.getPoll(pollID);
pollTimeRemaining = formatTimeRemaining(poll.timeRemaining);
}
private function switchChart(event:ItemClickEvent):void {
if (event.currentTarget.selectedValue == "piechart") {
setCurrentState("PieChart");
@ -40,6 +65,10 @@
}
private function stop():void {
if (timeRemainTimerStarted) {
_activationTimer.stop();
}
btnStop.visible = false;
dispatchEvent(new PollEvent(PollEvent.STOP_POLL, pollID));
}
@ -52,15 +81,18 @@
</mx:Script>
<mx:VBox id="resultsBox" horizontalAlign="center" width="100%" height="100%">
<!--
<mx:HBox height="5%" width="100%" id="chartbox" horizontalAlign="center" borderThickness="1" borderStyle="solid">
<mx:RadioButtonGroup id="charttype" selectedValue="barChart" itemClick="switchChart(event);"/>
<mx:RadioButton groupName="charttype" id="barChart" label="Bar Chart" value="barchart" width="100" />
<mx:RadioButton groupName="charttype" id="pieChart" label="Pie Chart" value="piechart" width="100" />
</mx:HBox>
<mx:Spacer height="5"/>
-->
<mx:Spacer id="spacer" height="5"/>
<mx:HBox height="5%" width="100%" horizontalAlign="right">
<mx:Spacer width="5"/>
<mx:Label text="Time remaining:" fontSize="12" styleName="micSettingsWindowTitleStyle" visible="false" />
<mx:Label text="Time remaining:" fontSize="12" styleName="micSettingsWindowTitleStyle" visible="true" />
<mx:Label id="timeRemaining" text="{pollTimeRemaining}" fontSize="12" styleName="micSettingsWindowTitleStyle" visible="true" />
<mx:Spacer width="100%"/>
<mx:Button id="btnStop" label="Stop Polling" visible="{_showStopButton}" click="stop()"/>
<mx:Spacer width="5"/>
@ -71,12 +103,12 @@
<mx:states>
<mx:State name="PieChart" >
<mx:AddChild relativeTo="{chartbox}" position="before" >
<mx:AddChild relativeTo="{spacer}" position="before" >
<poll:DisplayResultPieChartPanel width="100%" height="80%" viewModel="{viewModel}" pollID="{pollID}" horizontalAlign="center"/>
</mx:AddChild>
</mx:State>
<mx:State name="BarChart">
<mx:AddChild relativeTo="{chartbox}" position="before">
<mx:AddChild relativeTo="{spacer}" position="before">
<poll:DisplayResultBarChartPanel width="100%" height="80%" viewModel="{viewModel}" pollID="{pollID}" horizontalAlign="center"/>
</mx:AddChild>
</mx:State>