package tripvisUI.infoboxes { import flash.events.Event; import mx.containers.Form; import mx.containers.FormItem; import mx.containers.HBox; import mx.controls.ComboBox; import mx.controls.TextInput; import tripvisModel.Currency; import tripvisModel.MoneyAmount; import tripvisModel.TripItem; import tripvisModel.TripVisModel; import tripvisModel.controllers.BasketController; import tripvisUI.TripItemColors; import tripvisUI.languages.LanguageDirector; public class AbstractVisualisingInfobox extends AbstractInfobox { protected var _tripItem: TripItem; private var _comboboxCurrency: ComboBox; private var _txtCost: TextInput; public function AbstractVisualisingInfobox(tripItem: TripItem) { super(); this._simpleTripItem = tripItem; this._tripItem = tripItem; } override protected function createChildren():void { super.createChildren(); this.thumbImage.width = 78; this.thumbBox.width = 78; this.thumbBox.height = 52; this.vboxName.setStyle('verticalGap', 4); // we willen een form met daarin één element: kosten // de achtergrond van die form moet het kleur zijn van het specifieke item (HOTEL, LANDMARK, ...) var form: Form = new Form(); form.percentWidth = 100; form.setStyle( "backgroundColor", TripItemColors.getTripItemColor(_tripItem.type) ); form.setStyle('backgroundAlpha', 0.5); form.setStyle('paddingLeft', 2); form.setStyle('paddingRight', 2); form.setStyle('paddingTop', 4); form.setStyle('paddingBottom', 4); var formItem: FormItem = new FormItem(); formItem.label = LanguageDirector.instance.language.infoboxCost + ":"; var hbox: HBox = new HBox(); _txtCost = new TextInput(); _txtCost.width = 81; _txtCost.text = this._tripItem.cost.amount.toString(); // amount invullen _txtCost.addEventListener(Event.CHANGE, costTxt_change); _comboboxCurrency = new ComboBox(); _comboboxCurrency.dataProvider = Currency.ALL_CURRENCIES; _comboboxCurrency.labelFunction = function(item:Object): String { return (item as Currency).longName; }; _comboboxCurrency.selectedItem = _tripItem.cost.currency; _comboboxCurrency.addEventListener(Event.CHANGE, comboboxCurrency_change); //var currencyLabel : Label = new Label(); //currencyLabel.text = "Euro"; //TODO hbox.addChild(_txtCost); //hbox.addChild(currencyLabel); hbox.addChild(_comboboxCurrency); formItem.addChild(hbox); form.addChild(formItem); this.addChild(form); } private function updateCost(): void { var amount: Number; var currency: Currency; if(!isNaN(Number(_txtCost.text))) { amount = Number(_txtCost.text); } else { _txtCost.text = "0"; amount = 0; } currency = _comboboxCurrency.selectedItem as Currency; var basketController: BasketController = TripVisModel.instance.basketController; basketController.updateTripItemCost( this._tripItem, new MoneyAmount(amount, currency) ); } private function costTxt_change(event: Event): void { updateCost(); } private function comboboxCurrency_change(event: Event): void { updateCost(); } } }