initial commit
[CPE_learningsite] / CPEFlex / EngagementAdminPod / src / EngagementAdminPod.mxml
1 <?xml version="1.0" encoding="utf-8"?>
2 <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 
3                                 xmlns:components="com.adobe.sync.components.*" 
4                                 layout="absolute" minWidth="200" minHeight="200" >
5         
6         <mx:Script>
7                 <![CDATA[
8                         import com.adobe.sync.events.SyncSwfEvent;
9                         
10                         import mx.controls.Alert;
11                         import mx.messaging.channels.StreamingAMFChannel;
12                         import mx.rpc.events.FaultEvent;
13                         import mx.rpc.events.ResultEvent;
14                         import mx.utils.URLUtil;
15                         
16                         [Embed(source="assets/config.xml")]
17                         private var configXml:Class;
18
19                         [Bindable] public var version:String = "1.0.0";
20                         
21                         [Bindable] private var accountID:Number;
22                         [Bindable] private var roomSCO_ID:Number;
23                         [Bindable] private var roomFullUrl:String ="";
24                         [Bindable] private var roomHostUrl:String ="";
25                         [Bindable] private var roomUrl:String ="";
26                         [Bindable] private var currentUserID:Number;
27                         [Bindable] private var currentUserName:String;
28                         [Bindable] private var currentRole:String;
29                         private var commonInfo:XML;
30                         private var scoInfo:XML;
31                         
32                         [Bindable] private var baseServiceUrl:String;
33                         [Bindable] private var podId:Number;
34                         [Bindable] public var principalId:Number;
35                         [Bindable] public var accountId:Number;
36                         [Bindable] public var meetingFolderId:Number;
37                         [Bindable] public var host:String;
38                         [Bindable] public var adminHost:String;
39                         [Bindable] public var session:String;
40                         
41                         private function init() : void
42                         {
43                                 loadSettings();
44                                 
45                                 currentUserID = syncConnector.userID;
46                                 currentUserName = syncConnector.userName;
47                                 currentRole = syncConnector.role;
48                                 accountID = syncConnector.accountID;
49                                 roomSCO_ID = syncConnector.roomSCOID;
50                                 roomFullUrl = syncConnector.url;
51                                 podId = syncConnector.podID;
52                                 serviceCommonInfo.send();
53                                 serviceGetSetting.send();
54                                 roomHostUrl = URLUtil.getProtocol(roomFullUrl) + "://" +  URLUtil.getServerName(roomFullUrl);
55                                 var url:String = roomFullUrl.replace(roomHostUrl, "");
56                                 roomUrl = url.substring(0,url.lastIndexOf("/"));
57                         }       
58
59                         protected function commonInfo_resultHandler(event:ResultEvent):void
60                         {
61                                 commonInfo = XML(event.result);
62                                 principalId = Number(XML(commonInfo..user).attribute("user-id"));
63                                 accountId = Number(XML(commonInfo..account).attribute("account-id"));
64                                 host = commonInfo..host.toString().replace("http://", "").replace("https://", "");
65                                 adminHost = commonInfo.descendants("admin-host");
66                                 session = commonInfo..cookie;
67                                 //Alert.show(commonInfo.toString());
68                         }
69                         
70                         private function loadSettings():void {
71                                 var config:XML = configXml.data as XML;
72                                 baseServiceUrl = config.descendants("ServiceUrl");
73                         }
74                         
75                         protected function getMeetingSettings_resultHandler(event:ResultEvent):void
76                         {
77                                 var result:Object = event.result;
78                                 var interval:String = result.Setting.Interval.toString();
79                                 var text:String = result.Setting.Text == null ? "" : result.Setting.Text as String;
80                                 txtInterval.text = interval;
81                                 txtButtonText.text = text;              
82                         }
83                         
84                         protected function saveSettings():void{
85                                 var url:String = baseServiceUrl + '/static/services/engagement/service.asmx/SetMeetingSettings?sco_id=' + roomSCO_ID.toString() + '&connectUrl=' + encodeURIComponent(roomHostUrl) + '&url=' + encodeURIComponent(roomUrl) + '&interval=' + txtInterval.text + '&text=' + encodeURIComponent(txtButtonText.text);
86                                 var service:HTTPService = new HTTPService();
87                                 service.url = url;
88                                 service.contentType="application/x-www-form-urlencoded";
89                                 service.resultFormat = "object";
90                                 service.method = "POST";
91                                 service.addEventListener(ResultEvent.RESULT, setMeetingSettings_resultHandler);
92                                 service.addEventListener(FaultEvent.FAULT, service_faultHandler);
93                                 service.send();
94                         }
95                         protected function setMeetingSettings_resultHandler(event:ResultEvent):void
96                         {
97                                 var result:Object = event.result;
98                                 var success:Boolean = result.ServiceStatus.Success as Boolean;
99                                 if(success){
100                                         Alert.show("Settings saved.");
101                                         
102                                 }
103                                 else{
104                                         Alert.show("Problem saving settings.");
105                                 }
106                         }
107                         protected function service_faultHandler(event:FaultEvent):void{
108                                 Alert.show("CPE Service Error:"+ event.fault.message, "Error");
109                                 Alert.show(event.message.toString());
110                         }
111                         private function syncMessageReceived(p_evt:SyncSwfEvent):void
112                         {
113                         }
114                         
115                         protected function btnSave_clickHandler(event:MouseEvent):void
116                         {
117                                 if(txtInterval.text.length > 0)
118                                 {
119                                         saveSettings(); 
120                                 }
121                                 else{
122                                         Alert.show("Please enter an interval.");
123                                 }
124                                         
125                         }
126                         
127                 ]]>
128         </mx:Script>
129         
130
131         
132         <mx:VBox height="100%" width="100%" paddingTop="20" paddingLeft="10" paddingRight="10" paddingBottom="20">
133                 <mx:HBox width="100%">
134                         <mx:Label width="200" text="Polling interval in minutes"/>
135                         <mx:TextInput id="txtInterval" width="80" restrict="0-9" maxChars="4"/>
136                 </mx:HBox>
137                 <mx:HBox width="100%">
138                         <mx:Label width="200" text="Button Text"/>
139                         <mx:TextInput id="txtButtonText" width="80" maxChars="50" />
140                 </mx:HBox>
141                 <mx:HBox width="100%" horizontalAlign="left" >
142                         <mx:Button id="btnSave" label="Save" click="btnSave_clickHandler(event)"/>
143                 </mx:HBox>
144         </mx:VBox>
145         
146         <components:SyncConnector id = "syncConnector" syncMessageReceived = "syncMessageReceived(event)" caughtUp="init()"/>
147         <!-- Comment out the BreezeConnectionEmulator before loading the SWF in the Meeting client -->
148         <!--    <ns1:ConnectionEmulator id = "connectionEmulator" bSyncConnector="{syncConnector}"/>
149         -->     
150         <mx:HTTPService id="serviceCommonInfo" resultFormat="xml" url="/api/xml?action=common-info" result="commonInfo_resultHandler(event)" />
151         <mx:HTTPService id="serviceGetSetting" 
152                                         resultFormat="object" 
153                                         url="{baseServiceUrl + '/static/services/engagement/service.asmx/GetMeetingSettings?sco_id=' + roomSCO_ID.toString()}" 
154                                         result="getMeetingSettings_resultHandler(event)" 
155                                         method="POST"
156                                         contentType="application/x-www-form-urlencoded" fault="service_faultHandler(event)"/>
157 </mx:Application>