rendered paste body<?xml version="1.0" encoding="utf-8"?>
<mx:Application creationComplete="init()" xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
import com.pixco.*;
import mx.collections.ArrayCollection;
[Bindable]
private var arrRules:ArrayCollection;
[Bindable]
private var arrRoles:ArrayCollection;
[Bindable]
private var arrUnlinkedRoles:ArrayCollection;
private function init():void {
arrRules = ActiveRecords.SecurityRule.findAll();
arrRoles = ActiveRecords.SecurityRole.findAll();
}
private function lstChanged():void {
arrUnlinkedRoles = new ArrayCollection();
for each(var role:SecurityRole in arrRoles)
{
// TODO: filter linked roles so they don't get added to the unlinked roles collection
arrUnlinkedRoles.addItem(role);
}
}
private function saveRule():void {
SecurityRule(lstRules.selectedItem).save();
}
]]>
</mx:Script>
<mx:Binding source="txtNameResourceCode.text" destination="lstRules.selectedItem.NameResourceCode" />
<mx:List change="lstChanged()" x="10" y="10" width="200" height="365" dataProvider="{arrRules}" labelField="NameResourceCode" id="lstRules" />
<mx:Form x="218" y="10" width="375" height="365">
<mx:FormItem label="NameResourceCode" width="100%">
<mx:TextInput id="txtNameResourceCode" text="{lstRules.selectedItem.NameResourceCode}" width="100%"/>
</mx:FormItem>
<mx:FormItem label="Linked roles" width="100%" height="100%">
<mx:List dataProvider="{SecurityRule(lstRules.selectedItem).RelatedSecurityRuleSecurityRole}" width="100%" height="140"/>
</mx:FormItem>
<mx:FormItem label="Unlinked roles" width="100%" height="100%">
<mx:List dataProvider="{arrUnlinkedRoles}" width="100%" height="140"/>
</mx:FormItem>
<mx:FormItem>
<mx:Button label="Save" click="saveRule()"/>
</mx:FormItem>
</mx:Form>
</mx:Application>