Module: nagvis Branch: master Commit: 9e359170db0a04ea1736b83cd876c78d1d685c12 URL: http://nagvis.git.sourceforge.net/git/gitweb.cgi?p=nagvis/nagvis/commit/?id=9e359170db0a04ea1736b83cd876c78d1d685c12
Author: Andriy Skuratov <[email protected]> Date: Fri Aug 7 17:24:19 2009 +0300 Locations are now editable and deletable --- uifx/src/modules/gmap/GMapModule.as | 8 ++- uifx/src/modules/gmap/data/LocationsData.as | 37 ++++++++++++++++- uifx/src/modules/gmap/mate/GeneralEM.mxml | 8 ++++ uifx/src/modules/gmap/mate/LocationsEM.mxml | 23 +++++++++- uifx/src/modules/gmap/view/DialogLocation.mxml | 45 +++++++++++++++++++- uifx/src/modules/gmap/view/MainView.mxml | 1 - .../gmap/view/controls/GMapLocationsControl.as | 22 +++++++++- .../modules/gmap/view/controls/LocationMarker.as | 11 ++++- 8 files changed, 142 insertions(+), 13 deletions(-) diff --git a/uifx/src/modules/gmap/GMapModule.as b/uifx/src/modules/gmap/GMapModule.as index 79ecf47..b37c6be 100644 --- a/uifx/src/modules/gmap/GMapModule.as +++ b/uifx/src/modules/gmap/GMapModule.as @@ -203,6 +203,7 @@ private function addLocation_handler(event : ResultEvent) : void locationBox.setCurrentState("right-contracted"); } +/* Done private function editLocation_handler(event : ResultEvent) : void { var result : Location = event.result as Location; @@ -211,6 +212,7 @@ private function editLocation_handler(event : ResultEvent) : void locationBox.setCurrentState("right-contracted"); } +*/ private function removeLocation_handler(event : ResultEvent) : void { @@ -436,7 +438,7 @@ private function onSaveLocation() : void { if (locationBox.locID != "") { - /* TODO: reenable + /* TODO: Done rLocations.edit(locationBox.locID, (new LatLng(parseFloat(locationBox.locLat.text), parseFloat(locationBox.locLng.text)).toUrlValue(16)), locationBox.locName.text, locationBox.locAddress.text, locationBox.locDescription.text, @@ -453,13 +455,13 @@ private function onSaveLocation() : void } } +/* TODO: done private function onDeleteLocation() : void { - /* TODO: reenable if (locationBox.locID != "") rLocations.remove(locationBox.locID); - */ } +*/ /*********************************************/ /* Link dialog box diff --git a/uifx/src/modules/gmap/data/LocationsData.as b/uifx/src/modules/gmap/data/LocationsData.as index 4530bc2..d255049 100644 --- a/uifx/src/modules/gmap/data/LocationsData.as +++ b/uifx/src/modules/gmap/data/LocationsData.as @@ -16,7 +16,42 @@ package modules.gmap.data public function fill(data : Array):void { this.source = data; - } + } + + public function getItemById(id : String) : Location + { + for each(var location : Location in this) + if (location.id == id) + return location; + + return null; + } + + public function getItemByLatLng(coords : LatLng) : Location + { + for each(var location : Location in this) + if (LatLng.fromUrlValue(location.point).lat() == coords.lat() + && LatLng.fromUrlValue(location.point).lng() == coords.lng()) + { + return location; + } + + return null; + } + + public function addUpdateItem(item : Location) : void + { + var location : Location = this.getItemById(item.id); + + if (location == null) + this.addItem(item); + else + location.update(item); + } + public function removeItemById(id:String):void + { + removeItemAt(getItemIndex(getItemById(id))); + } } } \ No newline at end of file diff --git a/uifx/src/modules/gmap/mate/GeneralEM.mxml b/uifx/src/modules/gmap/mate/GeneralEM.mxml index 0586120..4a09388 100644 --- a/uifx/src/modules/gmap/mate/GeneralEM.mxml +++ b/uifx/src/modules/gmap/mate/GeneralEM.mxml @@ -5,6 +5,10 @@ > <mx:Script> <![CDATA[ + import mx.controls.Alert; + + import com.asfusion.mate.events.UnhandledFaultEvent; + import modules.gmap.events.ModeEvent; import modules.gmap.mediator.MainMD; @@ -12,6 +16,10 @@ ]]> </mx:Script> + <EventHandlers type="{UnhandledFaultEvent.FAULT}"> + <InlineInvoker method="Alert.show" arguments="{[event.fault.faultDetail, 'Error']}"/> + </EventHandlers> + <EventHandlers type="resized"> <MethodInvoker generator="{MainMD}" method="reconsiderMode"/> </EventHandlers> diff --git a/uifx/src/modules/gmap/mate/LocationsEM.mxml b/uifx/src/modules/gmap/mate/LocationsEM.mxml index 5d40cb0..8d1474d 100644 --- a/uifx/src/modules/gmap/mate/LocationsEM.mxml +++ b/uifx/src/modules/gmap/mate/LocationsEM.mxml @@ -7,6 +7,7 @@ <![CDATA[ import mx.controls.Alert; + import modules.gmap.data.LocationsData; import modules.gmap.data.LocationsExtData; import modules.gmap.events.AddressEvent; @@ -31,11 +32,29 @@ </EventHandlers> <EventHandlers type="{LocationEvent.SAVE}"> - <InlineInvoker method="Alert.show" arguments="{[event.location.label, 'Save Location']}"/> + <RemoteObjectInvoker instance="{LocationsService}" method="edit" + arguments="{[ + event.location.id, + event.location.point, + event.location.label, + event.location.address, + event.location.description, + event.location.object + ]}" + > + <resultHandlers> + <MethodInvoker generator="{LocationsData}" method="addUpdateItem" arguments="{resultObject}"/> + </resultHandlers> + </RemoteObjectInvoker> </EventHandlers> <EventHandlers type="{LocationEvent.DELETE}"> - <InlineInvoker method="Alert.show" arguments="{[event.location.label, 'Delete Location']}"/> + <InlineInvoker method="Alert.show" arguments="{[event.location.label, 'Delete Location']}"/> + <RemoteObjectInvoker instance="{LocationsService}" method="remove" arguments="{event.location.id}"> + <resultHandlers> + <MethodInvoker generator="{LocationsData}" method="removeItemById" arguments="{resultObject}"/> + </resultHandlers> + </RemoteObjectInvoker> </EventHandlers> </EventMap> diff --git a/uifx/src/modules/gmap/view/DialogLocation.mxml b/uifx/src/modules/gmap/view/DialogLocation.mxml index 180a789..ea01657 100644 --- a/uifx/src/modules/gmap/view/DialogLocation.mxml +++ b/uifx/src/modules/gmap/view/DialogLocation.mxml @@ -32,6 +32,7 @@ </mx:Metadata> <mx:Script> <![CDATA[ + import mx.events.CloseEvent; import modules.gmap.events.LocationEvent; import modules.gmap.domain.nagios.ServiceGroup; import modules.gmap.domain.nagios.HostGroup; @@ -124,6 +125,15 @@ locNObject.selectedItem = null; } } + + protected function reverseUpdate():void + { + location.point = new LatLng(parseFloat(locLat.text), parseFloat(locLng.text)).toUrlValue(16); + location.label = locName.text; + location.address = locAddress.text; + location.description = locDescription.text; + location.object = locNObject.selectedItem; + } private function objectItemClick(event : MenuEvent) : void { @@ -178,6 +188,37 @@ break; } } + + private function onSaveClicked():void + { + if(this.location) + { + reverseUpdate(); + dispatchEvent(new LocationEvent(LocationEvent.SAVE, this.location)); + } + } + + private function onDeleteClicked():void + { + if(this.location) + { + Alert.show( + 'Are you sure to delete location ' + location.label + "?", + 'Confirmation', + 3, this, + deleteConfirmation + ); + } + } + + private function deleteConfirmation(event : CloseEvent):void + { + if(event.detail == Alert.YES) + { + reverseUpdate(); + dispatchEvent(new LocationEvent(LocationEvent.DELETE, this.location)); + } + } ]]> </mx:Script> <mx:XML format="e4x" id="autoCompleteMenu"> @@ -284,11 +325,11 @@ </flexlib:HAccordion> <mx:Button label="Save" right="0" bottom="0" - click="dispatchEvent(new LocationEvent(LocationEvent.SAVE, this.location))" + click="onSaveClicked()" /> <mx:Button label="Delete" right="65" bottom="0" - click="dispatchEvent(new LocationEvent(LocationEvent.DELETE, this.location))" + click="onDeleteClicked()" /> </mx:Canvas> </EdgeBox> diff --git a/uifx/src/modules/gmap/view/MainView.mxml b/uifx/src/modules/gmap/view/MainView.mxml index 0ba1e17..71ec135 100644 --- a/uifx/src/modules/gmap/view/MainView.mxml +++ b/uifx/src/modules/gmap/view/MainView.mxml @@ -71,7 +71,6 @@ contractedWidth="35" contractedHeight="35" currentState="right-contracted" save="onSaveLocation()" - remove="onDeleteLocation()" contracted="onHideLocationBox()" /> <view:DialogSearch id="searchBox" group="{ebg}" diff --git a/uifx/src/modules/gmap/view/controls/GMapLocationsControl.as b/uifx/src/modules/gmap/view/controls/GMapLocationsControl.as index 65231f9..bc7b335 100644 --- a/uifx/src/modules/gmap/view/controls/GMapLocationsControl.as +++ b/uifx/src/modules/gmap/view/controls/GMapLocationsControl.as @@ -65,7 +65,27 @@ package modules.gmap.view.controls reinitMarkers(); //TODO: handle items addition - //TODO: handle items removal + + if(event.kind == CollectionEventKind.REMOVE) + { + for each (var removed:Location in event.items) + { + var marked : LocationMarker; + for(var i:int = _markers.length; i >=0; i--) + { + marked = _markers.shift(); + + if(marked.location.id === removed.id) + { + if(visible && _map) + _map.removeOverlay(marked); + break; + } + + _markers.push(marked); + } + } + } } public override function set visible(value:Boolean):void diff --git a/uifx/src/modules/gmap/view/controls/LocationMarker.as b/uifx/src/modules/gmap/view/controls/LocationMarker.as index 72dc4be..a2a62f5 100644 --- a/uifx/src/modules/gmap/view/controls/LocationMarker.as +++ b/uifx/src/modules/gmap/view/controls/LocationMarker.as @@ -25,7 +25,7 @@ package modules.gmap.view.controls [Embed(source="modules/gmap/img/std_small_unknown.png")] protected var unknownIcon : Class; - private var location : Location; + private var _location : Location; public function LocationMarker(location:Location) { @@ -43,7 +43,7 @@ package modules.gmap.view.controls super(point, options); - this.location = location; + _location = location; this.addEventListener(MapMouseEvent.CLICK, this.onClick); } @@ -51,9 +51,14 @@ package modules.gmap.view.controls protected function onClick(event : *):void { dispatchEvent( - new LocationEvent(LocationEvent.SELECTED, this.location, true) + new LocationEvent(LocationEvent.SELECTED, _location, true) ); } + public function get location():Location + { + return _location; + } + } } \ No newline at end of file ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ Nagvis-checkins mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/nagvis-checkins
