/
PollingStatsWindow.mxml
273 lines (239 loc) · 9.34 KB
/
PollingStatsWindow.mxml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
<?xml version="1.0" encoding="utf-8"?>
<!--
BigBlueButton open source conferencing system - http://www.bigbluebutton.org
Copyright (c) 2010 BigBlueButton Inc. and by respective authors (see below).
BigBlueButton is free software; you can redistribute it and/or modify it under the
terms of the GNU Lesser General Public License as published by the Free Software
Foundation; either version 2.1 of the License, or (at your option) any later
version.
BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along
with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
$Id: $
-->
<MDIWindow xmlns="flexlib.mdi.containers.*" xmlns:mx="http://www.adobe.com/2006/mxml"
height="150"
width="380"
xmlns:mate="http://mate.asfusion.com/"
implements="org.bigbluebutton.common.IBbbModuleWindow"
initialize="init();"
creationComplete="onCreationComplete()"
label="{ResourceUtil.getInstance().getString('bbb.polling.toolbar.toolTip')}"
title="{ResourceUtil.getInstance().getString('bbb.polling.toolbar.toolTip')}"
layout="absolute">
<mx:Script>
<![CDATA[
import flexlib.mdi.events.MDIWindowEvent;
import org.bigbluebutton.main.views.MainCanvas;
import mx.controls.Alert;
import org.bigbluebutton.common.LogUtil;
import org.bigbluebutton.modules.polling.events.StartPollingEvent;
import org.bigbluebutton.modules.polling.managers.PollingManager;
import org.bigbluebutton.modules.polling.events.VoteEvent;
import org.bigbluebutton.modules.polling.events.PollingStatsWindowEvent;
import org.bigbluebutton.modules.polling.events.PollRefreshEvent;
import org.bigbluebutton.modules.polling.events.StopPollEvent;
import org.bigbluebutton.modules.polling.events.SavePollEvent;
import org.bigbluebutton.modules.polling.events.PublishPollEvent;
import org.bigbluebutton.modules.polling.events.GenerateWebKeyEvent;
import org.bigbluebutton.modules.polling.model.PollObject;
import org.bigbluebutton.core.managers.UserManager;
import org.bigbluebutton.main.model.users.Conference
import org.bigbluebutton.main.model.users.BBBUser;
import org.bigbluebutton.common.Role;
import mx.validators.Validator;
import mx.utils.ObjectUtil;
import org.bigbluebutton.util.i18n.ResourceUtil;
import mx.collections.ArrayCollection;
import mx.core.IUIComponent;
import mx.controls.Text;
import mx.controls.TextArea;
import mx.containers.*;
import mx.controls.*;
public static const LOGNAME:String = "[PollingStatsWindow] ";
[Bindable] public var question:String;
[Bindable] public var answers:Array;
[Bindable] public var trackingPoll:PollObject;
[Bindable] public var webPollUrl:String;
public var viewingClosedPoll:Boolean = false;
public var moduleAttributes:Object;
private var _userid:Number;
private var window:PollingStatsWindow;
private var conference:Conference;
public var reviewing:Boolean = false;
private function init():void{
webPollBox.visible = (!reviewing && trackingPoll.publishToWeb);
if (!reviewing && trackingPoll.publishToWeb){
var generate: GenerateWebKeyEvent = new GenerateWebKeyEvent(GenerateWebKeyEvent.GENERATE);
generate.poll = trackingPoll;
dispatchEvent(generate);
}
}
private function onCreationComplete():void{
conference = UserManager.getInstance().getConference();
// If the statistics window is being opened to view a poll that has been published and closed, the interface will
// immediately appear with only the option to close the window.
if(viewingClosedPoll)
stopPoll();
if (trackingPoll.publishToWeb){
webPollURLBox.text = webPollUrl;
}
answers = trackingPoll.answers;
question = trackingPoll.question;
var lines:int = (question.length / 28) + 1;
for(var s:String in answers){
lines = lines + ((s.length / 28) + 1);
}
height = height + ((lines+1) * 45);
createResultsTable(answers.length, answers);
}
public function getPrefferedPosition():String{
return MainCanvas.POPUP;
}
private function refreshPoll():void{
var e:PollRefreshEvent = new PollRefreshEvent(PollRefreshEvent.GET);
e.poll.title = trackingPoll.title;
dispatchEvent(e);
} // end of function refreshResults
private function closeWindow():void{
dispatchEvent(new PollingStatsWindowEvent(PollingStatsWindowEvent.CLOSE));
}
public function refreshWindow(newVotes:Array, totalVotes:int, noVoteYet:int):void{
trackingPoll.votes = newVotes;
trackingPoll.totalVotes = totalVotes;
trackingPoll.didNotVote = noVoteYet;
createResultsTable(trackingPoll.answers.length, trackingPoll.answers);
invalidateDisplayList();
validateNow();
}
private function stopPoll():void{
refreshPoll();
btnRefreshResults.label = ResourceUtil.getInstance().getString('bbb.polling.stats.repost');
btnRefreshResults.removeEventListener(MouseEvent.CLICK, refreshWindow);
btnRefreshResults.addEventListener(MouseEvent.CLICK, publishPollAgain);
btnClosePoll.label = ResourceUtil.getInstance().getString('bbb.polling.stats.close');
btnClosePoll.removeEventListener(MouseEvent.CLICK, closeWindow);
btnClosePoll.addEventListener(MouseEvent.CLICK, closeButtonClick);
trackingPoll.status = false;
stopViewersPolls();
}
private function publishPollAgain(e:Event):void{
var event:PublishPollEvent = new PublishPollEvent(PublishPollEvent.REPOST);
event.poll = trackingPoll;
dispatchEvent(event);
closeWindow();
}
private function closeButtonClick(e:Event):void{
closeWindow();
}
private function stopViewersPolls():void{
var stopPollEvent:StopPollEvent = new StopPollEvent(StopPollEvent.STOP_POLL);
stopPollEvent.poll = trackingPoll;
dispatchEvent(stopPollEvent);
}
// function receives Array.length and ArrayCollection
private function createResultsTable(amount:uint, content:Array):void{
var _tx: Text;
var _votes: Text;
var _percent: Text;
var _hb: HBox;
var _line: HRule;
var totalVotes:int = 0;
for (var n:int = 0; n < trackingPoll.votes.length; n++){
totalVotes+= int(trackingPoll.votes[n]);
}
// delete existing rows
resultBox.removeAllChildren();
// creating rows one by one
for (var i:int = 0; i < amount; i++) {
_tx = new Text();
_votes= new Text;
_percent= new Text();
_hb = new HBox();
_line = new HRule();
_line.width = 290;
_tx.name = "option" +i;
_tx.width = 200;
_tx.text =content[i].toString();
_votes.name = "votes" +i;
_votes.width = 30;
_votes.text = trackingPoll.votes[i];
_percent.name = "percent" +i;
_percent.width = 50;
// Percentage is in terms of how many votes each option has in terms of total votes
if (totalVotes > 0){
_percent.text = Math.round(100*(trackingPoll.votes[i]/totalVotes)) + "%";
}else{
// Prevents percentages from displaying misleading results before any votes come in, and from dividing by zero
_percent.text = " ";
}
resultBox.addChild(_hb);
_hb.addChild(_tx);
_hb.addChild(_votes);
_hb.addChild(_percent);
resultBox.addChild(_line);
} // end of loop
didNotVote();
invalidateDisplayList();
resultBox.validateNow();
} // end of function createResultsTable
private function didNotVote():void{
var _tx:Text = new Text();
var _votes:Text= new Text;
var _hb:HBox = new HBox();
_tx.name = "optionNull";
_tx.width = 200;
_tx.text = ResourceUtil.getInstance().getString('bbb.polling.stats.didNotVote');
_votes.name = "voteNull";
_votes.width = 30;
_votes.text = trackingPoll.didNotVote.toString();
resultBox.addChild(_hb);
_hb.addChild(_tx);
_hb.addChild(_votes);
}
]]>
</mx:Script>
<!-- Prototype of Polling Statistics View Design -->
<mx:VBox width="100%"
height="75%"
horizontalAlign="center"
paddingLeft="10"
paddingRight="10">
<mx:HBox width="90%"
paddingTop="10">
<mx:Text text="{ResourceUtil.getInstance().getString('bbb.polling.stats.webPollURL')}"
width="140"/>
</mx:HBox>
<mx:HBox id="webPollBox"
width="90%" >
<mx:TextArea id="webPollURLBox"
editable="false"
text=""
horizontalScrollPolicy="off"
verticalScrollPolicy="off"
height="25"
width="95%"/>
</mx:HBox>
<mx:Text width="200"
paddingTop="15" paddingBottom="10"
fontWeight="bold" textAlign="center"
text="{question}"/>
<mx:Box id="resultBox"
width="90%"
height="90%" />
</mx:VBox>
<mx:ControlBar width="100%"
horizontalAlign="center">
<mx:Button id="btnRefreshResults"
label="{ResourceUtil.getInstance().getString('bbb.polling.stats.refresh')}"
click="refreshPoll()"
width="100"
height="30"/>
<mx:Button id="btnClosePoll"
label="{ResourceUtil.getInstance().getString('bbb.polling.stats.stopPoll')}"
click="stopPoll()"
width="100" height="30"/>
</mx:ControlBar>
</MDIWindow>