rendered paste body<?xml version="1.0" encoding="utf-8"?>
<mx:Panel
xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:View="Pixco.Framework.Localization.View.*"
layout="absolute" width="660" height="410"
creationComplete="OnCreationComplete()"
>
<mx:Script>
<![CDATA[
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.rpc.AsyncToken;
import mx.controls.Alert;
import weborb.data.DynamicLoadEvent;
import mx.events.CollectionEvent;
import mx.events.ListEvent;
import mx.collections.ArrayCollection;
import Pixco.Framework.Localization.Data.*;
import mx.rpc.Responder;
private const SAVE:String = "Save resource";
private const UPDATE:String = "Create resource";
[Bindable]
private var currentLocalizationResource:LocalizationResource;
[Bindable]
private var currentLocalizationGroup:LocalizationGroup;
[Bindable]
private var LocalizationResources:ArrayCollection;
[Bindable]
private var LocalizationGroups:ArrayCollection;
private function OnCreationComplete():void
{
LocalizationGroups = ActiveRecords.LocalizationGroup.findAll();
LocalizationGroups.addEventListener("loaded", function(e:DynamicLoadEvent):void {
OnDdlGroupChange();
});
}
private function OnCreate():void
{
var newResource:LocalizationResource = new LocalizationResource();
currentLocalizationResource = newResource;
txtCode.setFocus();
txtCode.selectionBeginIndex = 0;
txtCode.selectionEndIndex = 0;
lstLocalizationResources.selectedIndex = -1;
}
private function OnDelete():void
{
var resp:mx.rpc.Responder = new mx.rpc.Responder(
function(result:LocalizationResource):void
{
lstLocalizationResources.selectedIndex = 0;
// this works, but when deleting the first item of the list, selectedindex is set to 0,
// but after this method, it updates the curretnLocalizationGroup, and removes the item
// therefor selectedindex is set to -1
},null);
currentLocalizationResource.remove(resp);
}
private function OnSave():void
{
currentLocalizationResource.Code = txtCode.text;
currentLocalizationResource.GroupID = currentLocalizationGroup.ID;
currentLocalizationResource.save();
OnCreate();
}
private function OnDdlGroupChange(e:ListEvent=null):void
{
currentLocalizationGroup = (cboGroup.selectedItem as LocalizationGroup);
LocalizationResources = (cboGroup.selectedItem as LocalizationGroup).RelatedLocalizationResource;
LocalizationResources.addEventListener("loaded",function(e:DynamicLoadEvent):void {
lstLocalizationResources.selectedIndex = 0;
currentLocalizationResource = lstLocalizationResources.selectedItem as LocalizationResource;
});
}
private function OnDdlGroupsChanged(e:ListEvent):void {
currentLocalizationResource = lstLocalizationResources.selectedItem as LocalizationResource;
}
private function OnLstLocalizationResourceDataChange(e:Event):void {
lstLocalizationResources.selectedIndex = 0;
}
]]>
</mx:Script>
<mx:VBox paddingBottom="10" paddingLeft="10" paddingRight="10" paddingTop="10" x="0" y="0" width="100%" height="100%">
<mx:HBox width="100%">
<mx:Label id="lblGroup" width="75" textAlign="right"/>
<mx:Box buttonMode="true" mouseChildren="false" paddingTop="3">
</mx:Box>
<mx:ComboBox rowCount="10" id="cboGroup" change="OnDdlGroupChange(event)" labelField="Name" dataProvider="{LocalizationGroups}" width="100%"/>
<mx:Button id="btnGetResources"/>
</mx:HBox>
<mx:HRule width="100%" />
<mx:HBox width="100%" height="100%">
<mx:List change="OnDdlGroupsChanged(event)" labelField="Code" id="lstLocalizationResources" width="200" height="100%" dataProvider="{LocalizationResources}" />
<mx:VBox enabled="{currentLocalizationResource != null}">
<mx:Form defaultButton="{btnSaveLocalizationResource}" width="100%" height="100%">
<mx:FormItem label="Code" width="100%">
<mx:TextInput width="100%" id="txtCode" text="{currentLocalizationResource.Code}" />
</mx:FormItem>
<mx:FormItem>
<mx:Button id="btnSaveLocalizationResource" label="{currentLocalizationResource.IsPrimaryKeyInitialized ? SAVE : UPDATE}" click="OnSave()" />
</mx:FormItem>
</mx:Form>
<mx:Repeater id="rptData" dataProvider="{currentLocalizationResource.RelatedLocalizationData}">
<mx:Label text="{(rptData.currentItem as LocalizationData).Value}" />
</mx:Repeater>
</mx:VBox>
</mx:HBox>
<mx:HRule width="100%" />
</mx:VBox>
<mx:ControlBar>
<mx:Button id="btnCreateLocalizationResource" click="OnCreate()" label="+" width="32" />
<mx:Button id="btnDeleteLocalizationResource" click="OnDelete()" enabled="{lstLocalizationResources.selectedIndex > -1}" label="-" width="32" />
</mx:ControlBar>
</mx:Panel>