mirror of
https://github.com/moodle/moodle.git
synced 2025-05-02 14:28:30 +02:00
Test client using Flex 3 compiler to produce a Flash 9 client for moodle web services.
This commit is contained in:
parent
72b9b78682
commit
69afc75844
20
webservice/amf/testclient/index.php
Normal file
20
webservice/amf/testclient/index.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
require "../../../config.php";
|
||||
print_header_simple('Test Client', 'Test Client');
|
||||
|
||||
$url = addslashes_js("$CFG->wwwroot/webservice/amf/testclient/moodleclient.swf");
|
||||
$serverurl = addslashes_js("$CFG->wwwroot/webservice/amf/server.php");
|
||||
echo '<span id="moodletestclient">
|
||||
<p>You need to install Flash 9.0</p>
|
||||
</span>';
|
||||
|
||||
echo <<<EOF
|
||||
<script type="text/javascript">
|
||||
//<![CDATA[
|
||||
var FO = { movie:"$url", width:"100%", height:"500", majorversion:"9", build:"0",
|
||||
allowscriptaccess:"never", quality: "high", flashvars:"amfurl=$serverurl", setcontainercss:"true"};
|
||||
UFO.create(FO, "moodletestclient");
|
||||
//]]>
|
||||
</script>
|
||||
EOF;
|
||||
print_footer();
|
313
webservice/amf/testclient/moodleclient.mxml
Normal file
313
webservice/amf/testclient/moodleclient.mxml
Normal file
@ -0,0 +1,313 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="initApp(); true;">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<mx:Script>
|
||||
<![CDATA[
|
||||
|
||||
import mx.collections.*;
|
||||
function print_props(varname:String, objecttoprint:Object):void{
|
||||
if (textarea1.text == null){
|
||||
textarea1.text = '';
|
||||
}
|
||||
if (objecttoprint == null){
|
||||
textarea1.text += "\n"+varname+" = null\n";
|
||||
} else {
|
||||
textarea1.text += "\n"+varname+" = "+objecttoprint+"("+typeof(objecttoprint)+")"+"\n";
|
||||
for (var props:String in objecttoprint){
|
||||
textarea1.text += varname+"["+props+"] = "+objecttoprint[props]+"("+typeof(objecttoprint[props])+")"+"\n";
|
||||
if (typeof(objecttoprint[props])=='object'){
|
||||
print_props(varname+"["+props+"]", objecttoprint[props]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public function objectToArray(obj:Object):Array{
|
||||
var arr:Array = new Array();
|
||||
for (var prop:String in obj){
|
||||
if (obj[prop] != ''){
|
||||
arr[prop] = obj[prop];
|
||||
}
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
import mx.rpc.remoting.mxml.RemoteObject;
|
||||
import mx.messaging.*;
|
||||
import mx.messaging.channels.*;
|
||||
import mx.rpc.events.*;
|
||||
public var moodleWebServices : RemoteObject;
|
||||
|
||||
public function initApp():void{
|
||||
moodleWebServices = new RemoteObject();
|
||||
var cs:ChannelSet = new ChannelSet();
|
||||
cs.addChannel(new AMFChannel("myAmf", Application.application.parameters.amfurl));
|
||||
moodleWebServices.destination = "Dest";
|
||||
moodleWebServices.channelSet = cs;
|
||||
moodleWebServices.showBusyCursor = true;
|
||||
|
||||
moodleWebServices.get_users.addEventListener('result', handleReturnGetUsers);
|
||||
moodleWebServices.update_users.addEventListener('result', handleReturn);
|
||||
moodleWebServices.create_users.addEventListener('result', handleReturn);
|
||||
|
||||
moodleWebServices.addEventListener('fault', handleFault);
|
||||
moodleWebServices.addEventListener('result', handleReturn);
|
||||
|
||||
print_props('Application.application.parameters.amfurl', Application.application.parameters.amfurl);
|
||||
print_props('moodleWebServices', moodleWebServices);
|
||||
getUsers('');
|
||||
}
|
||||
public function handleReturn(e:ResultEvent):void{
|
||||
print_props('createUsersService event.result', e.result);
|
||||
getUsers(search.text);
|
||||
}
|
||||
|
||||
public function handleReturnGetUsers(e:ResultEvent):void{
|
||||
print_props('createUsersService event.result', e.result);
|
||||
initData(e.result);
|
||||
}
|
||||
|
||||
public function handleFault(e:FaultEvent):void{
|
||||
mx.controls.Alert.show(e.fault.faultString);
|
||||
}
|
||||
|
||||
public function getUsers(searchText:String=''):void{
|
||||
var params:Array = new Array();
|
||||
params['search']=searchText;
|
||||
moodleWebServices.get_users(params);
|
||||
}
|
||||
public function updateUsers():void{
|
||||
var params:Array = new Array();
|
||||
print_props('initDG.source', initDG.source);
|
||||
for each(var record:Object in initDG.source){
|
||||
if (record.status == 'to update'){
|
||||
params.push(objectToArray(record));
|
||||
}
|
||||
}
|
||||
print_props('updateUsers() params', params);
|
||||
if (params.length){
|
||||
moodleWebServices.update_users(params);
|
||||
}
|
||||
}
|
||||
public function createUsers():void{
|
||||
var params:Array = new Array();
|
||||
for each(var record:Object in initDG.source){
|
||||
if (record.status == 'to insert'){
|
||||
params.push(objectToArray(record));
|
||||
}
|
||||
}
|
||||
print_props('createUsers() params', params);
|
||||
if (params.length){
|
||||
moodleWebServices.create_users(params);
|
||||
}
|
||||
}
|
||||
import mx.events.DataGridEvent;
|
||||
private function itemEditEndEvent(event:DataGridEvent):void {
|
||||
print_props('event:DataGridEvent', event);
|
||||
var newData:String=
|
||||
TextInput(event.currentTarget.itemEditorInstance).text;
|
||||
if (newData!=userlist.editedItemRenderer.data[event.dataField])
|
||||
{
|
||||
userlist.editedItemRenderer.data.status='to update';
|
||||
};
|
||||
userlist.dataProvider.itemUpdated(event.itemRenderer.data);
|
||||
print_props('event.dataField', event.dataField);
|
||||
print_props('newData', newData);
|
||||
print_props('initDG[event.rowIndex]', initDG[event.rowIndex]);
|
||||
}
|
||||
import mx.events.ValidationResultEvent;
|
||||
public function handleFormSubmit(){
|
||||
var vResult:ValidationResultEvent;
|
||||
|
||||
var invalid:Boolean = false;
|
||||
vResult = usernameValidator.validate();
|
||||
if (vResult.type==ValidationResultEvent.INVALID)
|
||||
invalid=true;
|
||||
vResult = passwordValidator.validate();
|
||||
if (vResult.type==ValidationResultEvent.INVALID)
|
||||
invalid=true;
|
||||
vResult = firstnameValidator.validate();
|
||||
if (vResult.type==ValidationResultEvent.INVALID)
|
||||
invalid=true;
|
||||
vResult = lastnameValidator.validate();
|
||||
if (vResult.type==ValidationResultEvent.INVALID)
|
||||
invalid=true;
|
||||
vResult = emailValidator.validate();
|
||||
if (vResult.type==ValidationResultEvent.INVALID)
|
||||
invalid=true;
|
||||
if (invalid){
|
||||
return;
|
||||
}
|
||||
var itemToAdd:Object=
|
||||
{status:'to insert',
|
||||
username : username.text,
|
||||
idnumber : idnumber.text,
|
||||
firstname : firstname.text,
|
||||
lastname : lastname.text,
|
||||
email : email.text,
|
||||
password : password.text,
|
||||
auth : auth.text,
|
||||
confirmed : confirmed.text,
|
||||
timezone : timezone.text,
|
||||
country : country.text,
|
||||
emailstop : emailstop.text,
|
||||
theme : theme.text,
|
||||
lang : lang.text,
|
||||
mailformat : mailformat.text};
|
||||
if (initDG==null){
|
||||
initData(new Array(itemToAdd))
|
||||
}else{
|
||||
initDG.addItem(itemToAdd)
|
||||
};
|
||||
print_props('initDG.source', initDG.source);
|
||||
accordion1.selectedIndex=1;
|
||||
}
|
||||
[Bindable]
|
||||
public var initDG:ArrayCollection;
|
||||
|
||||
public function initData(DGArray):void {
|
||||
print_props('DGArraye', DGArray);
|
||||
initDG=new ArrayCollection(DGArray);
|
||||
}
|
||||
|
||||
|
||||
]]>
|
||||
</mx:Script>
|
||||
<mx:Accordion height="100%" width="100%" id="accordion1">
|
||||
<mx:VBox width="100%" label="Introduction" >
|
||||
<mx:Text width="100%">
|
||||
<mx:text>
|
||||
<![CDATA[
|
||||
This is a test of the batch amf web services exposed by user/external.php.
|
||||
|
||||
1. You can add users to the datagrid using the form and add several users at once using the button to call create_users.
|
||||
2. You can edit user details in the data grid itself and commit changes to several users at once using the button to call update_users.
|
||||
|
||||
If you get a 'no permissions' error message then try logging in to your Moodle installation. The same session used for the normal http sessions are also used by this client since the same cookies are sent along to the server with the web service request as are sent to the server with a web page request.
|
||||
|
||||
The text area below displays some debug messages.
|
||||
]]>
|
||||
</mx:text>
|
||||
</mx:Text>
|
||||
<mx:TextArea id="textarea1" width="80%" height="300"/>
|
||||
</mx:VBox>
|
||||
<mx:VBox width="100%" label="List of Users">
|
||||
|
||||
<mx:Form width="500" defaultButton="{tmpgetusers}">
|
||||
|
||||
<mx:HBox>
|
||||
<mx:Label text="Filter for name"/>
|
||||
<mx:TextInput id="search"/>
|
||||
<mx:Button id="tmpgetusers" label="Refresh User List" click="getUsers(search.text);true;"/>
|
||||
</mx:HBox>
|
||||
</mx:Form>
|
||||
|
||||
|
||||
|
||||
<mx:DataGrid id ="userlist" itemEditEnd="itemEditEndEvent(event);" editable="true" width="100%" height="400"
|
||||
dataProvider="{initDG}" >
|
||||
|
||||
<mx:columns>
|
||||
|
||||
<mx:DataGridColumn editable="false" dataField="id" width="30" headerText="ID"/>
|
||||
<mx:DataGridColumn editable="false" dataField="status" headerText="Status"/>
|
||||
<mx:DataGridColumn editable="false" dataField="username" headerText="Username"/>
|
||||
<mx:DataGridColumn editable="true" dataField="firstname" headerText="First Name"/>
|
||||
<mx:DataGridColumn editable="true" dataField="lastname" headerText="Last Name"/>
|
||||
<mx:DataGridColumn editable="true" dataField="email" headerText="E-mail"/>
|
||||
<mx:DataGridColumn editable="true" dataField="password" headerText="Password"/>
|
||||
<mx:DataGridColumn editable="true" dataField="idnumber" headerText="ID Number"/>
|
||||
<mx:DataGridColumn editable="true" dataField="auth" headerText="auth"/>
|
||||
<mx:DataGridColumn editable="true" dataField="confirmed" headerText="confirmed"/>
|
||||
<mx:DataGridColumn editable="true" dataField="timezone" headerText="timezone"/>
|
||||
<mx:DataGridColumn editable="true" dataField="country" headerText="country"/>
|
||||
<mx:DataGridColumn editable="true" dataField="emailstop" headerText="emailstop"/>
|
||||
<mx:DataGridColumn editable="true" dataField="theme" headerText="theme"/>
|
||||
<mx:DataGridColumn editable="true" dataField="lang" headerText="lang"/>
|
||||
<mx:DataGridColumn editable="true" dataField="mailformat" headerText="mailformat"/>
|
||||
</mx:columns>
|
||||
</mx:DataGrid>
|
||||
<mx:HBox>
|
||||
<mx:Button id="button_update_users" label="Call update_users" click="updateUsers();true;"/>
|
||||
<mx:Button id="button_create_users" label="Call create_users" click="createUsers();true;"/>
|
||||
</mx:HBox>
|
||||
|
||||
|
||||
</mx:VBox>
|
||||
<mx:Form width="500" defaultButton="{create_users}" label="Add A User">
|
||||
<mx:FormHeading label="Required Fields"/>
|
||||
|
||||
|
||||
<mx:HBox>
|
||||
<mx:Label text="Username"/>
|
||||
<mx:TextInput id="username"/>
|
||||
</mx:HBox>
|
||||
<mx:HBox>
|
||||
<mx:Label text="First Name"/>
|
||||
<mx:TextInput id="firstname"/>
|
||||
</mx:HBox>
|
||||
<mx:HBox>
|
||||
<mx:Label text="Last Name"/>
|
||||
<mx:TextInput id="lastname"/>
|
||||
</mx:HBox>
|
||||
<mx:HBox>
|
||||
<mx:Label text="E-mail"/>
|
||||
<mx:TextInput id="email"/>
|
||||
</mx:HBox>
|
||||
<mx:HBox>
|
||||
<mx:Label text="Password"/>
|
||||
<mx:TextInput id="password"/>
|
||||
</mx:HBox>
|
||||
<mx:FormHeading label="Optional Fields"/>
|
||||
<mx:HBox>
|
||||
<mx:Label text="ID Number"/>
|
||||
<mx:TextInput id="idnumber"/>
|
||||
</mx:HBox>
|
||||
<mx:HBox>
|
||||
<mx:Label text="auth"/>
|
||||
<mx:TextInput id="auth"/>
|
||||
</mx:HBox>
|
||||
<mx:HBox>
|
||||
<mx:Label text="confirmed"/>
|
||||
<mx:TextInput id="confirmed"/>
|
||||
</mx:HBox>
|
||||
<mx:HBox>
|
||||
<mx:Label text="timezone"/>
|
||||
<mx:TextInput id="timezone"/>
|
||||
</mx:HBox>
|
||||
<mx:HBox>
|
||||
<mx:Label text="country"/>
|
||||
<mx:TextInput id="country"/>
|
||||
</mx:HBox>
|
||||
<mx:HBox>
|
||||
<mx:Label text="emailstop"/>
|
||||
<mx:TextInput id="emailstop"/>
|
||||
</mx:HBox>
|
||||
<mx:HBox>
|
||||
<mx:Label text="theme"/>
|
||||
<mx:TextInput id="theme"/>
|
||||
</mx:HBox>
|
||||
<mx:HBox>
|
||||
<mx:Label text="lang"/>
|
||||
<mx:TextInput id="lang"/>
|
||||
</mx:HBox>
|
||||
<mx:HBox>
|
||||
<mx:Label text="mailformat"/>
|
||||
<mx:TextInput id="mailformat"/>
|
||||
</mx:HBox>
|
||||
<mx:Button id="create_users" label="Call create_users" click="handleFormSubmit();"/>
|
||||
</mx:Form>
|
||||
</mx:Accordion>
|
||||
<mx:EmailValidator id="emailValidator"
|
||||
source="{email}" property="text"/>
|
||||
<mx:StringValidator id="usernameValidator"
|
||||
source="{username}" property="text"/>
|
||||
<mx:StringValidator id="passwordValidator"
|
||||
source="{password}" property="text"/>
|
||||
<mx:StringValidator id="firstnameValidator"
|
||||
source="{firstname}" property="text"/>
|
||||
<mx:StringValidator id="lastnameValidator"
|
||||
source="{lastname}" property="text"/>
|
||||
</mx:Application>
|
BIN
webservice/amf/testclient/moodleclient.swf
Normal file
BIN
webservice/amf/testclient/moodleclient.swf
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user