Module: nagvis
Branch: master
Commit: 60490c722fa682601d4b113f407f73b61c77b352
URL:    
http://nagvis.git.sourceforge.net/git/gitweb.cgi?p=nagvis/nagvis/commit/?id=60490c722fa682601d4b113f407f73b61c77b352

Author: Andriy Skuratov <[email protected]>
Date:   Thu Aug 27 11:54:35 2009 +0300

gmap:Viewpoints deletion functionality added.

---

 share/netmap/ViewpointService.php               |   35 +++++++++++++
 uifx/src/modules/gmap/data/ViewpointsData.as    |   13 +++++-
 uifx/src/modules/gmap/events/ViewpointEvent.as  |    1 +
 uifx/src/modules/gmap/mate/ViewpointsEM.mxml    |    7 +++
 uifx/src/modules/gmap/view/DialogViewpoint.mxml |   60 +++++++++++++++++------
 5 files changed, 99 insertions(+), 17 deletions(-)

diff --git a/share/netmap/ViewpointService.php 
b/share/netmap/ViewpointService.php
index 4eb8a06..76d33cf 100644
--- a/share/netmap/ViewpointService.php
+++ b/share/netmap/ViewpointService.php
@@ -73,6 +73,41 @@ class ViewpointService
                else
                        throw new Exception('Could not write viewpoints.xml');
     }
+    
+       private function removeNodeByLabel(&$xml, $label)
+       {
+               $index = 0;
+               foreach ($xml->viewpoint as $node)
+               {
+                       if ($node['label'] == $label)
+                       {
+                               // Note: unset($node) won't work thus the need 
for $index
+                               unset($xml->viewpoint[$index]);
+                               $success = true;
+                               break;
+                       }
+                       $index++;
+               }
+               if (!isset($success))
+                       throw new Exception('View Point does not exist');
+       }
+       
+       /**
+        * @param  string $label
+        * @return string
+        */
+       public function remove($label)
+       {
+               if (($xml = @simplexml_load_file(CONFIG_PATH . 
'viewpoints.xml')) === FALSE)
+                       throw new Exception('Could not read viewpoints.xml');
+
+               self::removeNodeByLabel($xml, $label);
+
+               if (file_put_contents(CONFIG_PATH . 'viewpoints.xml', 
$xml->asXML()) !== FALSE)
+                       return $label;
+               else
+                       throw new Exception('Could not write viewpoints.xml');
+    }  
 }
 
 ?>
diff --git a/uifx/src/modules/gmap/data/ViewpointsData.as 
b/uifx/src/modules/gmap/data/ViewpointsData.as
index bd14cda..e762ea6 100644
--- a/uifx/src/modules/gmap/data/ViewpointsData.as
+++ b/uifx/src/modules/gmap/data/ViewpointsData.as
@@ -22,7 +22,7 @@
 package modules.gmap.data
 {
        import modules.gmap.domain.Viewpoint;
-
+       
        import mx.collections.ArrayCollection;
 
        public class ViewpointsData extends ArrayCollection
@@ -37,5 +37,16 @@ package modules.gmap.data
                        this.source = data;
                }
 
+               public function removeItemByLabel(label:String):void
+               {
+                       for(var i:int = this.length - 1; i >= 0; --i)
+                       {
+                               if ((getItemAt(i) as Viewpoint).label == label)
+                               {
+                                       removeItemAt(i);
+                                       return;                                 
+                               }
+                       }
+               }
        }
 }
diff --git a/uifx/src/modules/gmap/events/ViewpointEvent.as 
b/uifx/src/modules/gmap/events/ViewpointEvent.as
index c709d22..99c29e3 100644
--- a/uifx/src/modules/gmap/events/ViewpointEvent.as
+++ b/uifx/src/modules/gmap/events/ViewpointEvent.as
@@ -31,6 +31,7 @@ package modules.gmap.events
                public static const CREATE : String = "ViewpointCreate";
                public static const CREATED : String = "ViewpointCreated";
                public static const SAVE : String = "ViewpointSave";
+               public static const DELETE : String = "ViewpointDelete";
 
                public var viewpoint : Viewpoint;
 
diff --git a/uifx/src/modules/gmap/mate/ViewpointsEM.mxml 
b/uifx/src/modules/gmap/mate/ViewpointsEM.mxml
index 9de51a3..40c74dc 100644
--- a/uifx/src/modules/gmap/mate/ViewpointsEM.mxml
+++ b/uifx/src/modules/gmap/mate/ViewpointsEM.mxml
@@ -47,4 +47,11 @@
                />
        </EventHandlers>
 
+       <EventHandlers type="{ViewpointEvent.DELETE}">
+               <MethodInvoker generator="{ViewpointsData}" 
method="removeItemByLabel" arguments="{event.viewpoint.label}"/>
+               <RemoteObjectInvoker instance="{ViewpointsService}" 
method="remove"
+                       arguments="{event.viewpoint.label}"
+               />
+       </EventHandlers>
+
 </EventMap>
diff --git a/uifx/src/modules/gmap/view/DialogViewpoint.mxml 
b/uifx/src/modules/gmap/view/DialogViewpoint.mxml
index a633899..afe1151 100644
--- a/uifx/src/modules/gmap/view/DialogViewpoint.mxml
+++ b/uifx/src/modules/gmap/view/DialogViewpoint.mxml
@@ -39,6 +39,7 @@
 
                public function onListSelectChange() : void
                {
+                       preName.text = (list.selectedItem as Viewpoint).label;
                        dispatchEvent(new 
ViewpointEvent(ViewpointEvent.SELECTED, list.selectedItem as Viewpoint));
                }
 
@@ -50,30 +51,53 @@
                            return str.substring(i, j+1);
                        }
 
-               public function onSaveButtonClick() : void
+                       private function nameExist(name:String):Boolean
+                       {
+                               for each(var v:Viewpoint in dataProvider)
+                                       if(v.label == name)
+                                               return true;
+
+                               return false;                   
+                       }
+
+               public function onSaveButtonClick():void
                {
                        var name:String = trim(preName.text);
                        
                        if(name.length == 0)
-                       {
-                               Alert.show('Please, select a name for a View 
Point', 'Error');
                                return; 
-                       }
-                       
-                               for each(var v:Viewpoint in dataProvider)
+
+                               if(nameExist(name))
                                {
-                                       if(v.label == name)
-                                       {
-                                               Alert.show('View Point named ' 
+ name + ' already exists.', 'Error');
-                                               return;
-                                       }
-                               }
+                                       Alert.show('View Point "' + name + '" 
already exists.', 'Error');
+                                       return;
+                               }                       
                                        
                        var vp : Viewpoint = new Viewpoint;
                        vp.label = name;
 
                        dispatchEvent(new ViewpointEvent(ViewpointEvent.CREATE, 
vp));
                }
+               
+               public function onDeleteButtonClick():void
+               {
+                       var name:String = trim(preName.text);
+                       
+                       if(name.length == 0)
+                               return; 
+
+                               if(!nameExist(name))
+                               {
+                                       Alert.show('View Point "' + name + '" 
does not exist.', 'Error');
+                                       return;
+                               }                       
+                                       
+                       var vp : Viewpoint = new Viewpoint;
+                       vp.label = name;
+
+                       dispatchEvent(new ViewpointEvent(ViewpointEvent.DELETE, 
vp));
+                       preName.text = '';
+               }
        ]]>
     </mx:Script>
        <mx:HBox left="10" right="15" top="10" height="20">
@@ -87,17 +111,21 @@
        </mx:HBox>
        <mx:Canvas left="10" right="15" top="40" bottom="10">
                <mx:List id="list"
-                       top="0" left="0" right="0" height="138"
+                       top="0" left="0" right="0" bottom="30"
                        dataProvider="{dataProvider}"
                        change="onListSelectChange()"
-               />
+                />
                <flexlib:PromptingTextInput id="preName"
-                       left="0" right="62" bottom="0" height="22"
+                       left="0" right="136" bottom="0"
                        prompt="viewpoint name"
                />
                <mx:Button label="Save"
-                       right="0" bottom="0" height="22"
+                       right="68" bottom="0" height="22" width="64"
                        click="onSaveButtonClick()"
+                />
+               <mx:Button label="Delete" 
+                       bottom="0" right="0" width="64"
+                       click="onDeleteButtonClick()"
                />
        </mx:Canvas>
 </EdgeBox>


------------------------------------------------------------------------------
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

Reply via email to