All pastes #627664 Raw Edit

Stuff

public text v1 · immutable
·published 2007-07-20 13:25 UTC
rendered paste body
<?xml version="1.0" encoding="utf-8"?>
<mx:HDividedBox
	xmlns:mx="http://www.adobe.com/2006/mxml" 
	creationComplete="onCreationComplete()"
	>
	<mx:Script>
		<![CDATA[
			import mx.effects.Sequence;
			import mx.collections.SortField;
			import mx.collections.Sort;
			import mx.controls.Alert;
			import mx.rpc.Responder;
			import mx.events.CloseEvent;
			import mx.collections.ArrayCollection;
			import weborb.data.DynamicLoadEvent;
			import weborb.data.ActiveCollection;
			import Pixco.Framework.AssetManagement.Data.AssetTechnicalFormat;
			import Pixco.Framework.AssetManagement.Data.ConversionSet;
			import Pixco.Framework.AssetManagement.Data.ActiveRecords;
			import Pixco.Framework.AssetManagement.Data.ConversionSetConversion;
			import Pixco.Framework.AssetManagement.Data.Conversion;
			
			[Bindable]
			private var _conversions:ActiveCollection = null;
			
			[Bindable]
			private var _currentConversionSet:ConversionSet;
			
			[Bindable]
			private var _unrelatedConversions:ArrayCollection;
			
			private function onCreationComplete():void
			{
				_unrelatedConversions = ActiveRecords.Conversion.findAll();
				_unrelatedConversions.addEventListener(DynamicLoadEvent.LOADED, 
						function(e:DynamicLoadEvent):void
						{
							//Performance .... where??? But it helps out to avoid the famous 'Error'
							for each(var conversion:Conversion in _unrelatedConversions)
							{
								if(!conversion.RelatedConverter.IsLoaded)
								{
									//
								}
							}
							//
							_unrelatedConversions.filterFunction = filterConversions;	
						}
					);
			}
			private function filterConversions(item:Object): Boolean
			{
				for (var i:int; i < _currentConversionSet.RelatedConversionSetConversion.length; i++)
					if (_currentConversionSet.RelatedConversionSetConversion[i].ConversionID == (item as Conversion).ID)
						return false;
				return true;
			}	
			private function onCreateConversionSet():void
			{
				_currentConversionSet = new ConversionSet();
				_currentConversionSet.CreateBy = 0;
				_currentConversionSet.CreateDate = new Date();
				_currentConversionSet.ModifyBy = 0;
				_currentConversionSet.ModifyDate = new Date();
				
				lstConversionSet.selectedIndex = -1;
				ddlDestinationAssetTechnicalFormat.selectedIndex = -1;
				ddlSourceAssetTechnicalFormat.selectedIndex = -1;
				txtName.setFocus();
				
				btnDelete.enabled = false;
				
				_unrelatedConversions.refresh();
			}
			private function onDeleteConversionSet():void
			{
				if(!(lstConversionSet.selectedItem as ConversionSet).IsLocked)
				{
					var selectedConversionSet:ConversionSet = lstConversionSet.selectedItem as ConversionSet;
                
	                Alert.show("Are you sure you would like to remove ConversionSet \"" + selectedConversionSet.Name + "\" ?",
	                    "Generic",
	                    Alert.YES | Alert.NO,
	                    this,
	                    function(closeEvent:CloseEvent):void
	                    {
	                        if(closeEvent.detail == Alert.YES)
	                        {
	                            selectedConversionSet.remove();
	                            lstConversionSet.selectedIndex = -1;
	                        }
	                    });   	
				}
				else
				{
					Alert.show("The ConversionSet \""+ (lstConversionSet.selectedItem as ConversionSet).Name + "\" is locked!",
						"Generic");
				}
			}
			private function onSaveConversionSet():void
			{
				/* var conversionSet:ConversionSet = _currentConversionSet;
				conversionSet.Name = txtName.text;
				conversionSet.RelatedAssetTechnicalFormat1 = ddlSourceAssetTechnicalFormat.selectedItem as AssetTechnicalFormat;
				conversionSet.RelatedAssetTechnicalFormat = ddlDestinationAssetTechnicalFormat.selectedItem as AssetTechnicalFormat;
				conversionSet.deepSave(true,new mx.rpc.Responder(conversionSetSaved,conversionSetError));		 */	
				
				_currentConversionSet.Name = txtName.text;
				_currentConversionSet.RelatedAssetTechnicalFormat1 = ddlSourceAssetTechnicalFormat.selectedItem as AssetTechnicalFormat;
				_currentConversionSet.RelatedAssetTechnicalFormat = ddlDestinationAssetTechnicalFormat.selectedItem as AssetTechnicalFormat;
				_currentConversionSet.deepSave(true,new mx.rpc.Responder(conversionSetSaved,conversionSetError));
			}
			private function conversionSetSaved(conversionSet:ConversionSet): void
			{
				//Save ok
				Alert.show("saved");
			}
	
			private function conversionSetError(obj:Object): void
			{
				Alert.show("Error during save: " + obj.toString());
			}
			private function onChange():void
			{
				_currentConversionSet = lstConversionSet.selectedItem as ConversionSet;
				
				if(_currentConversionSet.RelatedAssetTechnicalFormat == null)
				{
					ddlDestinationAssetTechnicalFormat.selectedIndex = -1;	
				}			
				if(_currentConversionSet.RelatedAssetTechnicalFormat1 == null)
				{
					ddlSourceAssetTechnicalFormat.selectedIndex = -1;	
				}
				
				if(!_currentConversionSet.RelatedConversionSetConversion.IsLoaded)
				{
					_currentConversionSet.RelatedConversionSetConversion.addEventListener(DynamicLoadEvent.LOADED,
							function(e:DynamicLoadEvent):void
							{
								var sortConversions:Sort = new Sort();
								sortConversions.fields = [new SortField("Sequence")];	
								_currentConversionSet.RelatedConversionSetConversion.sort = sortConversions;
								_currentConversionSet.RelatedConversionSetConversion.refresh();
								_unrelatedConversions.refresh();
							}
						);
				}
				else
				{
					_unrelatedConversions.refresh();
				}
				
			}
			private function onAddConversion():void
			{
				/*conversionSetConversion.RelatedConversion = lstUnrelatedConversions.selectedItem as Conversion;
				var conv:Conversion =  lstUnrelatedConversions.selectedItem as Conversion;
				conv.RelatedConversionSetConversions.AddItem( conversionSetConversion );*/
				
				var sequence:int = 1;
				if (_currentConversionSet.RelatedConversionSetConversion.length > 0)
				{
					sequence = _currentConversionSet.RelatedConversionSetConversion[_currentConversionSet.RelatedConversionSetConversion.length-1].Sequence+1;
				}
				var conversionSetConversion:ConversionSetConversion = new ConversionSetConversion();
				conversionSetConversion.CreateBy = 0;
				conversionSetConversion.CreateDate = new Date();
				conversionSetConversion.ModifyBy = 0;
				conversionSetConversion.ModifyDate = new Date();
				conversionSetConversion.RelatedConversion = lstUnrelatedConversions.selectedItem as Conversion;
				conversionSetConversion.RelatedConversionSet = _currentConversionSet;
				conversionSetConversion.Sequence = sequence;
				
				_currentConversionSet.RelatedConversionSetConversion.addItem(conversionSetConversion);
				_unrelatedConversions.refresh();
				
				if(lstUnrelatedConversions.dataProvider.length > 0)
				{
					lstUnrelatedConversions.selectedIndex = 0;	
				}
				else
				{
					lstUnrelatedConversions.selectedIndex = -1;	
				}
				
			}
			private function onRemoveConversion():void
			{
				_currentConversionSet.removeRelatedConversionSetConversion(lstRelatedConversions.selectedItem as ConversionSetConversion);
				_unrelatedConversions.refresh();
				
				if(lstRelatedConversions.dataProvider.length > 0)
				{
					lstRelatedConversions.selectedIndex = 0;
				}
				else
				{
					lstRelatedConversions.selectedIndex = -1;	
				}
			}
			private function onClickConversionUp(): void
			{		
				var id:int = lstRelatedConversions.selectedItem.ID;
				var sequence:int = lstRelatedConversions.selectedItem.Sequence;
				for each(var conversionSetConversion:ConversionSetConversion in _currentConversionSet.RelatedConversionSetConversion)
				{
					if(conversionSetConversion.Sequence == sequence - 1)
					{
						conversionSetConversion.Sequence++;
					}
					if(conversionSetConversion.ID == id)
					{
						if(conversionSetConversion.Sequence == 1) return;
						conversionSetConversion.Sequence--;
					} 
				}
				_currentConversionSet.RelatedConversionSetConversion.refresh();
			}
			
			private function onClickConversionDown(): void
			{
				var id:int = (lstRelatedConversions.selectedItem as ConversionSetConversion).ID;
				var sequence:int = (lstRelatedConversions.selectedItem as ConversionSetConversion).Sequence;
				for each(var conversionSetConversion:ConversionSetConversion in _currentConversionSet.RelatedConversionSetConversion)
				{
					if(conversionSetConversion.Sequence == sequence + 1)
					{
						conversionSetConversion.Sequence--;
					} 
					if(conversionSetConversion.ID == id)
					{
						if(conversionSetConversion.Sequence == _currentConversionSet.RelatedConversionSetConversion.length) return;
						conversionSetConversion.Sequence++;
					}
					
				}
				_currentConversionSet.RelatedConversionSetConversion.refresh();
			}
		]]>
	</mx:Script>
	<mx:VBox width="200" height="100%">
		<mx:List id="lstConversionSet" 
			width="100%" height="100%"
			dataProvider="{ActiveRecords.ConversionSet.findAll()}"
			labelField="Name"
			change="onChange()"
			/>
		<mx:HBox width="100%" horizontalAlign="right">
			<mx:Button id="btnCreate" label="+" click="onCreateConversionSet()"/>
			<mx:Button id="btnDelete" label="-" click="onDeleteConversionSet()"/>
		</mx:HBox>
	</mx:VBox>	
	<mx:VBox height="100%" width="100%">
		<mx:Form id="frmAssetFormat" 
			width="100%"
			paddingBottom="0" paddingLeft="0" paddingTop="0" paddingRight="0"
			>
			<mx:FormItem label="Name:" width="100%">
				<mx:TextInput id="txtName" 
					width="100%" 
					text="{_currentConversionSet.Name}"
					/>			
			</mx:FormItem>
			<mx:FormItem label="Source technical format:" width="100%">
				<mx:ComboBox id="ddlSourceAssetTechnicalFormat"
					width="100%"
					prompt="Choose a technical format"
					dataProvider="{ActiveRecords.AssetTechnicalFormat.findAll()}"
					selectedItem="{_currentConversionSet.RelatedAssetTechnicalFormat1 as AssetTechnicalFormat}"
					labelField="NameResourceCode"
					/>
			</mx:FormItem>
			<mx:FormItem label="Destination technical format:" width="100%">
				<mx:ComboBox id="ddlDestinationAssetTechnicalFormat"
					width="100%"
					prompt="Choose a technical format"
					dataProvider="{ActiveRecords.AssetTechnicalFormat.findAll()}"
					selectedItem="{_currentConversionSet.RelatedAssetTechnicalFormat as AssetTechnicalFormat}"
					labelField="NameResourceCode"
					/>
			</mx:FormItem>
		</mx:Form>
		<mx:HBox width="100%" height="100%">
			<mx:VBox width="100%" height="100%">
				<mx:List id="lstRelatedConversions" 
					width="100%" height="100%" 
					dataProvider="{_currentConversionSet.RelatedConversionSetConversion}"
					>
					<mx:itemRenderer>
						<mx:Component>
							<mx:Label text="{data.RelatedConversion.Name}"/>
						</mx:Component>
					</mx:itemRenderer>
				</mx:List>
				<mx:HBox width="100%">
					<mx:Button id="btnMoveUp" label="UP" click="onClickConversionUp()" enabled="{lstRelatedConversions.selectedItem != null}" />
					<mx:Button id="btnMoveDown" label="DOWN" click="onClickConversionDown()" enabled="{lstRelatedConversions.selectedItem != null}"/>
				</mx:HBox>
			</mx:VBox>
			<mx:VBox height="100%" verticalAlign="middle">
				<mx:Button label="&lt;" click="onAddConversion()" enabled="{lstUnrelatedConversions.selectedItem != null}"/>
				<mx:Button label="&gt;" click="onRemoveConversion()" enabled="{lstRelatedConversions.selectedItem != null}"/>	
			</mx:VBox>
			<mx:List id="lstUnrelatedConversions"
				width="100%" height="100%"
				dataProvider="{_unrelatedConversions}"
				>
				<mx:itemRenderer>
					<mx:Component>
						<mx:Label text="{data.Name}" />
					</mx:Component>
				</mx:itemRenderer>
			</mx:List>
		</mx:HBox>
		<mx:HBox width="100%">
			<mx:Spacer width="100%" />
			<mx:Button id="btnSave"
				label="Save" 
				click="onSaveConversionSet()"
				enabled="{(!_currentConversionSet.IsLocked || _currentConversionSet.IsDirty)}"
				/>
		</mx:HBox>
	</mx:VBox>
</mx:HDividedBox>