[ Index ] |
PHP Cross Reference of moodle-2.8 |
[Summary view] [Print] [Text view]
1 <?xml version="1.0" encoding="utf-8"?> 2 <mx:Application 3 xmlns:mx="http://www.adobe.com/2006/mxml" 4 backgroundColor="white" 5 layout="vertical" 6 creationPolicy="all" 7 height="100%" width="100%" 8 applicationComplete="init()" 9 xmlns:cv="customValidators.*" 10 defaultButton="{call}"> 11 12 <mx:Script> 13 <![CDATA[ 14 import mx.rpc.remoting.Operation; 15 import mx.rpc.events.ResultEvent; 16 import mx.rpc.events.FaultEvent; 17 import mx.messaging.Channel; 18 import mx.rpc.remoting.RemoteObject; 19 import mx.events.ValidationResultEvent; 20 import mx.validators.Validator; 21 /** 22 * Main class/dialog 23 * 24 * This program is free software. It comes without any warranty, to 25 * the extent permitted by applicable law. You can redistribute it 26 * and/or modify it under the terms of the Do What The Fuck You Want 27 * To Public License, Version 2, as published by Sam Hocevar. See 28 * http://sam.zoy.org/wtfpl/COPYING for more details. 29 * 30 * @author Jordi Boggiano <[email protected]> 31 * @author Jamie Pratt <[email protected]> 32 */ 33 34 import mx.controls.Label; 35 import mx.controls.Alert; 36 import mx.messaging.channels.AMFChannel; 37 import com.adobe.serialization.json.JSON; 38 39 // Import the debugger 40 // import nl.demonsters.debugger.MonsterDebugger; 41 42 protected var methods:Array; 43 protected var introspector:String; 44 45 public var rooturl:String; 46 47 [Bindable] 48 public var serviceurl:String; 49 50 public var channel:AMFChannel; 51 52 [Bindable] 53 public var argumentToolTip:String = "You can use JSON syntax for method arguments ie. an array is written like this [item1, item2, etc.] objects are written {\"propname\":value, \"propname2\":value2, etc}"; 54 55 // Variable to hold the debugger 56 // private var debugger:MonsterDebugger; 57 58 /** 59 * restores the last settings if available 60 */ 61 public function init():void 62 { 63 // Init the debugger 64 // debugger = new MonsterDebugger(this); 65 66 // Send a simple trace 67 // MonsterDebugger.trace(this, "Hello World!"); 68 69 var so:SharedObject = SharedObject.getLocal('AMFTester'); 70 if (so.data.token) { 71 token.text = so.data.token; 72 } 73 if (so.data.username) { 74 username.text = so.data.username; 75 password.text = so.data.password; 76 } 77 if (so.data.mode == 'username'){ 78 loginType.selectedIndex = 1; 79 } 80 this.rememberpassword.selected = so.data.rememberpassword; 81 this.remembertoken.selected = so.data.remembertoken; 82 this.rooturl = Application.application.parameters.rooturl; 83 this.urllabel1.text = 'Root URL :'+this.rooturl; 84 this.urllabel2.text = 'Root URL :'+this.rooturl; 85 86 } 87 public function doConnectToken():void 88 { 89 serviceurl = this.rooturl + '/webservice/amf/server.php?'+ 90 'wstoken='+this.token.text; 91 this.doConnect(); 92 // saving settings for next time 93 var so:SharedObject = SharedObject.getLocal('AMFTester'); 94 if (this.rememberpassword.selected == true ){ 95 so.setProperty('token', this.token.text); 96 } else { 97 so.setProperty('token', null);//delete shared obj prop 98 } 99 so.setProperty('remembertoken', this.remembertoken.selected); 100 so.setProperty('mode', 'token'); 101 so.flush(); 102 } 103 public function doConnectUsername():void 104 { 105 serviceurl = this.rooturl + '/webservice/amf/simpleserver.php?'+ 106 'wsusername=' + this.username.text+ 107 '&wspassword=' + this.password.text; 108 this.doConnect(); 109 // saving settings for next time 110 var so:SharedObject = SharedObject.getLocal('AMFTester'); 111 if (this.rememberpassword.selected == true ){ 112 so.setProperty('username', this.username.text); 113 so.setProperty('password', this.password.text); 114 } else { 115 so.setProperty('username', null);//delete shared obj prop 116 so.setProperty('password', null); 117 } 118 so.setProperty('rememberpassword', this.rememberpassword.selected); 119 so.setProperty('mode', 'username'); 120 so.flush(); 121 } 122 123 /** 124 * initializes the connection 125 */ 126 private function doConnect():void 127 { 128 push("Connecting to "+serviceurl); 129 //api.source = 'MethodDescriptor'; 130 api.setCredentials(this.username.text, this.password.text); 131 api.removeEventListener("result", outputResult); 132 api.addEventListener("result", handleConnection); 133 api.getOperation("MethodDescriptor.getMethods").send(); 134 if (!api.hasEventListener("fault")) { 135 api.addEventListener("fault", faultHandler); 136 } 137 this.panelDebug.enabled = false; 138 } 139 140 /** 141 * initializes the debugger dialog with the method list and everything 142 */ 143 protected function handleConnection(event:ResultEvent):void 144 { 145 methods = []; 146 for (var cls:String in event.result) { 147 for (var meth:String in event.result[cls]['methods']) { 148 methods.push({label: cls+'.'+meth, docs: event.result[cls]['methods'][meth]['docs'], args: event.result[cls]['methods'][meth]['params']}); 149 } 150 } 151 methods.sortOn('label', Array.CASEINSENSITIVE); 152 153 this.panelDebug.enabled = true; 154 this.maintabs.selectedIndex = 1; 155 func.dataProvider = methods; 156 api.removeEventListener("result", handleConnection); 157 api.addEventListener("result", outputResult); 158 reloadArgs(); 159 160 } 161 162 163 /** 164 * outputs a response from the server 165 */ 166 protected function outputResult(event:ResultEvent):void 167 { 168 var keys:Array = new Array(); 169 for (var key:String in event.result){ 170 keys.push(key); 171 } 172 push("Result returned \n" + obj2string(event.result)); 173 } 174 175 protected function obj2string(obj:Object, depth:Number=0):String{ 176 var string:String = ''; 177 if (obj==null){ 178 return 'NULL'; 179 } 180 switch (typeof(obj)){ 181 case 'object': 182 if (obj is Array){ 183 string += "Array\n"; 184 } else { 185 string += "Object\n"; 186 } 187 string += depth2string(depth+1)+"(\n"; 188 for (var key:String in obj){ 189 string += depth2string(depth+2)+'['+key+'] => '+obj2string(obj[key], depth+3); 190 } 191 string += depth2string(depth+1)+")\n"; 192 break; 193 case 'string': 194 var formattedstring:String = obj.toString(); 195 formattedstring = formattedstring.replace(/\r/g, ""); 196 formattedstring = formattedstring.replace(/\n/g, "\n"+depth2string(depth+3)); 197 string += '"'+formattedstring+'"'+"-("+typeof(obj)+")"+"\n"; 198 break; 199 default : 200 string += obj.toString()+"-("+typeof(obj)+")"+"\n"; 201 } 202 return string; 203 } 204 205 protected function depth2string(depth:Number):String{ 206 var string:String = ''; 207 var i:Number = 0; 208 while (i<depth){ 209 string += ' '; 210 i++; 211 } 212 return string; 213 } 214 215 /** 216 * updates the display of arguments when the selected method changes 217 * 218 * it's hardly optimal to do it that way but it was faster to copy paste, I just hope nobody needs more than 7 args 219 */ 220 protected function reloadArgs():void 221 { 222 var i:int; 223 for (i = 1; i <= 7; i++) { 224 this['arg'+i].visible = false; 225 this['arg'+i].includeInLayout = false; 226 this['larg'+i].visible = false; 227 this['larg'+i].includeInLayout = false; 228 this['cbarg'+i].visible = false; 229 this['cbarg'+i].includeInLayout = false; 230 this['JSONV'+i].enabled = false; 231 } 232 i = 1; 233 for (var arg:String in func.selectedItem.args) { 234 (this['arg'+i] as TextInput).visible = true; 235 (this['arg'+i] as TextInput).includeInLayout = true; 236 if (func.selectedItem.args[arg]['required']){ 237 (this['arg'+i] as TextInput).enabled = true; 238 this['cbarg'+i].selected = true; 239 } 240 (this['larg'+i] as Label).visible = true; 241 (this['larg'+i] as Label).includeInLayout = true; 242 this['cbarg'+i].visible = !func.selectedItem.args[arg]['required']; 243 this['cbarg'+i].includeInLayout = !func.selectedItem.args[arg]['required']; 244 this['JSONV'+i].enabled = this['cbarg'+i].selected; 245 this['JSONV'+i].required = true; 246 247 (this['larg'+i] as Label).text = func.selectedItem.args[arg]['name'] + (func.selectedItem.args[arg]['required'] ? "*":""); 248 i++; 249 } 250 while (i <= 7) { 251 this['cbarg'+i].selected = false; 252 i++; 253 } 254 if (func.selectedItem.docs == ""){ 255 (this.methodDescription as TextArea).text = ""; 256 (this.methodDescription as TextArea).visible = false; 257 (this.methodDescription as TextArea).includeInLayout = false; 258 } else { 259 (this.methodDescription as TextArea).text = func.selectedItem.docs.replace(/[\n\r\f]+/g, "\n"); 260 (this.methodDescription as TextArea).visible = true; 261 (this.methodDescription as TextArea).includeInLayout = true; 262 } 263 } 264 265 public function toggleCheckBoxes(startAt:uint):void{ 266 var i:uint= startAt; 267 if (this['cbarg'+i].selected){ 268 i--; 269 while (i >= 1){ 270 this['cbarg'+i].selected = true; 271 i--; 272 } 273 } else { 274 i++; 275 while (i <= 7){ 276 this['cbarg'+i].selected = false; 277 i++; 278 } 279 } 280 } 281 282 /** 283 * calls a method on the server 284 */ 285 protected function execute():void 286 { 287 var input:TextInput; 288 var argumentArray:Array = []; 289 var argumentErrors:Array = Validator.validateAll(argumentValidators); 290 if (argumentErrors.length != 0){ 291 // MonsterDebugger.trace(this, argumentErrors); 292 return; 293 } 294 for(var i:int = 1; i <= 7; i++) 295 { 296 input = this['arg' +i] as TextInput; 297 if(input && input.visible) 298 { 299 if (!this['cbarg' +i].selected){ 300 break; 301 } else if (input.text.indexOf("\"") == 0 || input.text.indexOf("{") == 0 || input.text.indexOf("[") == 0) 302 try { 303 argumentArray.push(JSON.decode(input.text)); 304 } catch (err:Error){ 305 return; 306 } 307 else 308 argumentArray.push(input.text as String); 309 } 310 } 311 //no other way to pass arguments as array : 312 switch (argumentArray.length){ 313 case 0: 314 api.getOperation(func.selectedLabel).send(); 315 break; 316 case 1: 317 api.getOperation(func.selectedLabel).send(argumentArray[0]); 318 break; 319 case 2: 320 api.getOperation(func.selectedLabel).send(argumentArray[0], argumentArray[1]); 321 break; 322 case 3: 323 api.getOperation(func.selectedLabel).send(argumentArray[0], argumentArray[1], argumentArray[2]); 324 break; 325 case 4: 326 api.getOperation(func.selectedLabel).send(argumentArray[0], argumentArray[1], argumentArray[2], argumentArray[3]); 327 break; 328 case 5: 329 api.getOperation(func.selectedLabel).send(argumentArray[0], argumentArray[1], argumentArray[2], argumentArray[3], argumentArray[4]); 330 break; 331 case 6: 332 api.getOperation(func.selectedLabel).send(argumentArray[0], argumentArray[1], argumentArray[2], argumentArray[3], argumentArray[4], argumentArray[5]); 333 break; 334 case 7: 335 api.getOperation(func.selectedLabel).send(argumentArray[0], argumentArray[1], argumentArray[2], argumentArray[3], argumentArray[4], argumentArray[5], argumentArray[6]); 336 break; 337 338 } 339 340 341 // MonsterDebugger.trace(this, [func.selectedLabel, argumentArray[0], argumentArray[1], argumentArray[2], argumentArray[3], argumentArray[4], argumentArray[5], argumentArray[6]]); 342 push("Calling "+func.selectedLabel+" with arguments \n"+obj2string(argumentArray)); 343 } 344 345 /** 346 * clears debug consoles 347 */ 348 protected function clear():void 349 { 350 output.text = output.text = ""; 351 } 352 353 /** 354 * clears debug consoles 355 */ 356 protected function goBottom():void 357 { 358 output.verticalScrollPosition = output.maxVerticalScrollPosition; 359 } 360 361 /** 362 * refreshes the method list 363 */ 364 protected function refresh():void 365 { 366 api.removeEventListener("result", outputResult); 367 api.addEventListener("result", handleConnection); 368 api.exec(introspector); 369 } 370 371 /** 372 * returns timestamp string 373 */ 374 protected function time():String 375 { 376 var d:Date = new Date(); 377 var ret:String = d.hours+":"+d.minutes+":"+d.seconds+"."+d.milliseconds; 378 return ret + "000000000000".substring(ret.length); 379 } 380 381 /** 382 * handler for specific net events 383 */ 384 public function faultHandler(event:FaultEvent):void 385 { 386 push("Error("+event.type+" - "+ event.fault.faultCode + "): "+event.fault.faultString+", "+event.fault.faultDetail); 387 } 388 389 390 391 /** 392 * pushes text into a console and scrolls it down automatically 393 */ 394 public function push(text:String):void 395 { 396 output.text += time() + ": "+ text + "\n"; 397 output.verticalScrollPosition = output.maxVerticalScrollPosition; 398 } 399 400 ]]> 401 </mx:Script> 402 <mx:RemoteObject id="api" destination="zend" endpoint="{serviceurl}" /> 403 404 <mx:Array id="argumentValidators"> 405 <cv:JSONValidator id="JSONV1" required="true" enabled="{cbarg1.selected}" source="{arg1}" property="text" /> 406 <cv:JSONValidator id="JSONV2" required="true" enabled="{cbarg2.selected}" source="{arg2}" property="text" /> 407 <cv:JSONValidator id="JSONV3" required="true" enabled="{cbarg3.selected}" source="{arg3}" property="text" /> 408 <cv:JSONValidator id="JSONV4" required="true" enabled="{cbarg4.selected}" source="{arg4}" property="text" /> 409 <cv:JSONValidator id="JSONV5" required="true" enabled="{cbarg5.selected}" source="{arg5}" property="text" /> 410 <cv:JSONValidator id="JSONV6" required="true" enabled="{cbarg6.selected}" source="{arg6}" property="text" /> 411 <cv:JSONValidator id="JSONV7" required="true" enabled="{cbarg7.selected}" source="{arg7}" property="text" /> 412 </mx:Array> 413 414 415 416 <mx:HBox width="100%" height="550"> 417 <mx:TabNavigator id="maintabs" height="100%" width="100%" > 418 419 <mx:TabNavigator label="Connect" id="loginType" borderStyle="solid" height="100%" width="100%"> 420 <mx:Panel label="Use Token" id="panelConnectToken"> 421 <mx:HBox width="100%"> 422 <mx:Label text="Token"/> 423 <mx:TextInput id="token" text="" width="100%"/> 424 </mx:HBox> 425 <mx:HBox width="100%"> 426 <mx:Label text="Remember"/> 427 <mx:CheckBox id="remembertoken" width="100%"/> 428 </mx:HBox> 429 <mx:Label id="urllabel1" text="URL :" /> 430 <mx:HBox width="100%"> 431 <mx:Spacer width="100%" /> 432 <mx:Button label="Connect" click="doConnectToken()"/> 433 <mx:Spacer width="100%" /> 434 </mx:HBox> 435 </mx:Panel> 436 <mx:Panel label="Use Username and Password" id="panelConnectUsername"> 437 <mx:HBox width="100%"> 438 <mx:Label text="Username"/> 439 <mx:TextInput id="username" text="" width="100%"/> 440 </mx:HBox> 441 442 <mx:HBox width="100%"> 443 <mx:Label text="Password"/> 444 <mx:TextInput id="password" text="" displayAsPassword="true" width="100%"/> 445 </mx:HBox> 446 <mx:HBox width="100%"> 447 <mx:Label text="Remember"/> 448 <mx:CheckBox id="rememberpassword" width="100%"/> 449 </mx:HBox> 450 <mx:Label id="urllabel2" text="URL :" /> 451 452 <mx:HBox width="100%"> 453 <mx:Spacer width="100%" /> 454 <mx:Button label="Connect" click="doConnectUsername()"/> 455 <mx:Spacer width="100%" /> 456 </mx:HBox> 457 </mx:Panel> 458 </mx:TabNavigator> 459 <mx:Panel label="Service Browser" width="100%" height="100%" layout="vertical" title="Moodle AMF Service Browser" enabled="false" id="panelDebug"> 460 <mx:HBox width="100%"> 461 <mx:Label text="Func "/> 462 <mx:ComboBox id="func" change="reloadArgs()"> 463 </mx:ComboBox> 464 </mx:HBox> 465 <mx:TextArea id="methodDescription" text="" width="100%" height="150"/> 466 <mx:HBox width="100%"> 467 <mx:Label id="larg1" text="Arg 1"/> 468 <mx:CheckBox id="cbarg1" click="toggleCheckBoxes(1)"/> 469 <mx:TextInput id="arg1" toolTip="{argumentToolTip}" width="100%" enabled="{cbarg1.selected}"/> 470 </mx:HBox> 471 <mx:HBox width="100%"> 472 <mx:Label id="larg2" text="Arg 2"/> 473 <mx:CheckBox id="cbarg2" click="toggleCheckBoxes(2)"/> 474 <mx:TextInput id="arg2" toolTip="{argumentToolTip}" width="100%" enabled="{cbarg2.selected}"/> 475 </mx:HBox> 476 <mx:HBox width="100%"> 477 <mx:Label id="larg3" text="Arg 3"/> 478 <mx:CheckBox id="cbarg3" click="toggleCheckBoxes(3)"/> 479 <mx:TextInput id="arg3" toolTip="{argumentToolTip}" width="100%" enabled="{cbarg3.selected}"/> 480 </mx:HBox> 481 <mx:HBox width="100%"> 482 <mx:Label id="larg4" text="Arg 4"/> 483 <mx:CheckBox id="cbarg4" click="toggleCheckBoxes(4)"/> 484 <mx:TextInput id="arg4" toolTip="{argumentToolTip}" width="100%" enabled="{cbarg4.selected}"/> 485 </mx:HBox> 486 <mx:HBox width="100%"> 487 <mx:Label id="larg5" text="Arg 5"/> 488 <mx:CheckBox id="cbarg5" click="toggleCheckBoxes(5)"/> 489 <mx:TextInput id="arg5" toolTip="{argumentToolTip}" width="100%" enabled="{cbarg5.selected}"/> 490 </mx:HBox> 491 <mx:HBox width="100%"> 492 <mx:Label id="larg6" text="Arg 6"/> 493 <mx:CheckBox id="cbarg6" click="toggleCheckBoxes(6)"/> 494 <mx:TextInput id="arg6" toolTip="{argumentToolTip}" width="100%" enabled="{cbarg6.selected}"/> 495 </mx:HBox> 496 <mx:HBox width="100%"> 497 <mx:Label id="larg7" text="Arg 7"/> 498 <mx:CheckBox id="cbarg7" click="toggleCheckBoxes(7)"/> 499 <mx:TextInput id="arg7" toolTip="{argumentToolTip}" width="100%" enabled="{cbarg7.selected}"/> 500 </mx:HBox> 501 <mx:HBox width="100%"> 502 <mx:Button id="call" label="Call" click="execute()"/> 503 <mx:Button label="Clear" click="clear()"/> 504 <mx:Button label="Scroll to bottom of debug output" click="goBottom()"/> 505 </mx:HBox> 506 </mx:Panel> 507 </mx:TabNavigator> 508 </mx:HBox> 509 <mx:HBox width="100%" height="100%"> 510 <mx:TextArea id="output" width="100%" height="100%"/> 511 </mx:HBox> 512 </mx:Application>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:29:05 2014 | Cross-referenced by PHPXref 0.7.1 |