← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 8825: (GIS) Favorite crud + legend set crud + gui (work in progress).

 

Merge authors:
  Jan Henrik Øverland (janhenrik-overland)
------------------------------------------------------------
revno: 8825 [merge]
committer: Jan Henrik Overland <janhenrik.overland@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2012-11-01 17:33:19 +0300
message:
  (GIS) Favorite crud + legend set crud + gui (work in progress).
removed:
  dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/AddMapViewAction.java
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MappingService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/mapping/DefaultMappingService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/mapping/MappingServiceTest.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/mapping/MapValueController.java
  dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetGeoJsonAction.java
  dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetGeoJsonFacilitiesAction.java
  dhis-2/dhis-web/dhis-web-mapping/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-mapping/src/main/resources/struts.xml
  dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/index.html
  dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/app.js
  dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/ext-ux/panel/LayerItemPanel.js
  dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/mapfish/core/GeoStat.js
  dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/mapfish/core/GeoStat/Boundary.js
  dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/mapfish/core/GeoStat/Thematic1.js
  dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/mapfish/core/GeoStat/Thematic2.js
  dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/mapfish/widgets/geostat/Boundary.js
  dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/mapfish/widgets/geostat/Facility.js
  dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/mapfish/widgets/geostat/Thematic1.js
  dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/mapfish/widgets/geostat/Thematic2.js
  dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/styles/style.css
  dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/jsonOrganisationUnitChildren.vm


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MappingService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MappingService.java	2012-10-25 14:58:43 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MappingService.java	2012-10-31 18:29:46 +0000
@@ -138,12 +138,6 @@
 
     int addMapView( MapView mapView );
 
-    void addMapView( String name, boolean system, String mapValueType, Integer indicatorGroupId, Integer indicatorId,
-                     Integer dataElementGroupId, Integer dataElementId, String periodTypeName, Integer periodId,
-                     Integer parentOrganisationUnitId, Integer organisationUnitLevel, String mapLegendType, Integer method,
-                     Integer classes, String bounds, String colorLow, String colorHigh, Integer mapLegendSetId, Integer radiusLow,
-                     Integer radiusHigh, String longitude, String latitude, int zoom );
-
     void updateMapView( MapView mapView );
 
     void deleteMapView( MapView view );

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/mapping/DefaultMappingService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/mapping/DefaultMappingService.java	2012-11-01 05:33:34 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/mapping/DefaultMappingService.java	2012-11-01 08:22:08 +0000
@@ -444,45 +444,7 @@
     {
         return mapViewStore.save( mapView );
     }
-
-    public void addMapView( String name, boolean system, String mapValueType, Integer indicatorGroupId,
-        Integer indicatorId, Integer dataElementGroupId, Integer dataElementId, String periodTypeName,
-        Integer periodId, Integer parentOrganisationUnitId, Integer organisationUnitLevel, String mapLegendType,
-        Integer method, Integer classes, String bounds, String colorLow, String colorHigh, Integer mapLegendSetId,
-        Integer radiusLow, Integer radiusHigh, String longitude, String latitude, int zoom )
-    {
-        IndicatorGroup indicatorGroup = null;
-
-        Indicator indicator = null;
-
-        DataElementGroup dataElementGroup = null;
-
-        DataElement dataElement = null;
-
-        if ( mapValueType.equals( MapView.VALUE_TYPE_INDICATOR ) )
-        {
-            indicatorGroup = indicatorService.getIndicatorGroup( indicatorGroupId );
-            indicator = indicatorService.getIndicator( indicatorId );
-        }
-        else
-        {
-            dataElementGroup = dataElementService.getDataElementGroup( dataElementGroupId );
-            dataElement = dataElementService.getDataElement( dataElementId );
-        }
-
-        Period period = periodId != null ? periodService.getPeriod( periodId ) : null;
-
-        OrganisationUnit parent = organisationUnitService.getOrganisationUnit( parentOrganisationUnitId );
-
-        OrganisationUnitLevel level = organisationUnitService.getOrganisationUnitLevelByLevel( organisationUnitLevel );
-
-        MapLegendSet mapLegendSet = mapLegendSetId != null ? getMapLegendSet( mapLegendSetId ) : null;
-
-        addMapView( new MapView( MapView.LAYER_THEMATIC1, name, mapValueType, indicatorGroup, indicator, dataElementGroup, dataElement,
-            period, parent, level, mapLegendType, method, classes, colorLow, colorHigh,
-            mapLegendSet, radiusLow, radiusHigh, 1.0 ) );
-    }
-
+    
     public void updateMapView( MapView mapView )
     {
         mapViewStore.update( mapView );

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java	2012-11-01 05:57:43 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java	2012-11-01 14:25:50 +0000
@@ -146,8 +146,9 @@
         executeSql( "ALTER TABLE mapview RENAME COLUMN mapvaluetype TO valuetype" );
         executeSql( "ALTER TABLE mapview RENAME COLUMN maplegendtype TO legendtype" );
         executeSql( "ALTER TABLE mapview RENAME COLUMN maplegendsetid TO legendsetid" );
+        executeSql( "ALTER TABLE mapview ALTER COLUMN opacity TYPE double precision" );
+
         executeSql( "ALTER TABLE maplegend DROP CONSTRAINT maplegend_name_key" );
-        executeSql( "ALTER TABLE mapview ALTER COLUMN opacity TYPE double precision" );
         
         executeSql( "UPDATE mapview SET layer = 'thematic1' WHERE layer IS NULL" );
         

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/mapping/MappingServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/mapping/MappingServiceTest.java	2012-11-01 05:33:34 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/mapping/MappingServiceTest.java	2012-11-01 08:22:08 +0000
@@ -256,46 +256,6 @@
         mappingService.addMapLegendSet( legendSet3 );
 
         assertTrue( mappingService.getAllMapLegendSets().containsAll( mapLegendSets ) );
-
-    }
-
-    // -------------------------------------------------------------------------
-    // MapView tests
-    // -------------------------------------------------------------------------
-
-    @Test
-    public void testAddGetMapView()
-    {
-        MapView mapView = new MapView( LAYER_THEMATIC1, "MapViewA", VALUE_TYPE_INDICATOR, indicatorGroup,
-            indicator, dataElementGroup, dataElement, period,
-            organisationUnit, organisationUnitLevel, LEGEND_TYPE_AUTOMATIC, 1, 1, "A", "B",
-            mapLegendSet, 5, 20, 1.0 );
-
-        int idA = mappingService.addMapView( mapView );
-
-        assertEquals( mapView, mappingService.getMapView( idA ) );
-        assertEquals( indicatorGroup, mappingService.getMapView( idA ).getIndicatorGroup() );
-        assertEquals( indicator, mappingService.getMapView( idA ).getIndicator() );
-        assertEquals( period, mappingService.getMapView( idA ).getPeriod() );
-    }
-
-    @Test
-    public void testGetAllMapViews()
-    {
-        MapView mapView1 = new MapView( LAYER_THEMATIC1, "MapViewA", VALUE_TYPE_INDICATOR, indicatorGroup,
-            indicator, dataElementGroup, dataElement, period,
-            organisationUnit, organisationUnitLevel, LEGEND_TYPE_AUTOMATIC, 1, 1, "A", "B",
-            mapLegendSet, 5, 20, 1.0 );
-
-        MapView mapView2 = new MapView( LAYER_THEMATIC1, "MapViewB", VALUE_TYPE_INDICATOR, indicatorGroup,
-            indicator, dataElementGroup, dataElement, period,
-            organisationUnit, organisationUnitLevel, LEGEND_TYPE_AUTOMATIC, 1, 1, "A", "B",
-            mapLegendSet, 5, 20, 1.0 );
-
-        mappingService.addMapView( mapView1 );
-        mappingService.addMapView( mapView2 );
-
-        assertEquals( 2, mappingService.getAllMapViews().size() );
     }
 
     // -------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/mapping/MapValueController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/mapping/MapValueController.java	2012-09-12 18:01:24 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/mapping/MapValueController.java	2012-10-31 12:40:43 +0000
@@ -39,6 +39,7 @@
 import org.hisp.dhis.indicator.IndicatorService;
 import org.hisp.dhis.mapping.MappingService;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitLevel;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.period.PeriodService;
@@ -79,7 +80,7 @@
         @RequestParam String in,
         @RequestParam String pe,
         @RequestParam String ou,
-        @RequestParam Integer level,
+        @RequestParam String le,
         Model model,
         HttpServletResponse response ) throws Exception
     {
@@ -109,7 +110,15 @@
             return null;            
         }
         
-        Collection<AggregatedMapValue> mapValues = mappingService.getIndicatorMapValues( indicator.getId(), period.getId(), organisationUnit.getId(), level );
+        OrganisationUnitLevel level = organisationUnitService.getOrganisationUnitLevel( le );
+        
+        if ( level == null )
+        {
+            ContextUtils.conflictResponse( response, "Invalid organisation unit level identifier" );
+            return null;            
+        }
+        
+        Collection<AggregatedMapValue> mapValues = mappingService.getIndicatorMapValues( indicator.getId(), period.getId(), organisationUnit.getId(), level.getLevel() );
         
         model.addAttribute( "model", mapValues );
         
@@ -121,7 +130,7 @@
         @RequestParam String de,
         @RequestParam String pe,
         @RequestParam String ou,
-        @RequestParam Integer level,
+        @RequestParam String le,
         Model model,
         HttpServletResponse response ) throws Exception
     {
@@ -151,7 +160,15 @@
             return null;            
         }
         
-        Collection<AggregatedMapValue> mapValues = mappingService.getDataElementMapValues( dataElement.getId(), period.getId(), organisationUnit.getId(), level );
+        OrganisationUnitLevel level = organisationUnitService.getOrganisationUnitLevel( le );
+        
+        if ( level == null )
+        {
+            ContextUtils.conflictResponse( response, "Invalid organisation unit level identifier" );
+            return null;            
+        }
+        
+        Collection<AggregatedMapValue> mapValues = mappingService.getDataElementMapValues( dataElement.getId(), period.getId(), organisationUnit.getId(), level.getLevel() );
         
         model.addAttribute( "model", mapValues );
         

=== removed file 'dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/AddMapViewAction.java'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/AddMapViewAction.java	2011-12-26 10:07:59 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/AddMapViewAction.java	1970-01-01 00:00:00 +0000
@@ -1,231 +0,0 @@
-package org.hisp.dhis.mapping.action;
-
-/*
- * Copyright (c) 2004-2012, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright notice,
- *   this list of conditions and the following disclaimer in the documentation
- *   and/or other materials provided with the distribution.
- * * Neither the name of the HISP project nor the names of its contributors may
- *   be used to endorse or promote products derived from this software without
- *   specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-import org.hisp.dhis.mapping.MappingService;
-
-import com.opensymphony.xwork2.Action;
-
-/**
- * @author Jan Henrik Overland
- * @version $Id$
- */
-public class AddMapViewAction
-    implements Action
-{
-    // -------------------------------------------------------------------------
-    // Dependencies
-    // -------------------------------------------------------------------------
-
-    private MappingService mappingService;
-
-    public void setMappingService( MappingService mappingService )
-    {
-        this.mappingService = mappingService;
-    }
-
-    // -------------------------------------------------------------------------
-    // Input
-    // -------------------------------------------------------------------------
-
-    private String name;
-
-    public void setName( String name )
-    {
-        this.name = name;
-    }
-    
-    private boolean system;
-
-    public void setSystem( boolean system )
-    {
-        this.system = system;
-    }
-
-    private String mapValueType;
-
-    public void setMapValueType( String mapValueType )
-    {
-        this.mapValueType = mapValueType;
-    }
-
-    private Integer indicatorGroupId;
-
-    public void setIndicatorGroupId( Integer indicatorGroupId )
-    {
-        this.indicatorGroupId = indicatorGroupId;
-    }
-
-    private Integer indicatorId;
-
-    public void setIndicatorId( Integer indicatorId )
-    {
-        this.indicatorId = indicatorId;
-    }
-
-    private Integer dataElementGroupId;
-
-    public void setDataElementGroupId( Integer dataElementGroupId )
-    {
-        this.dataElementGroupId = dataElementGroupId;
-    }
-
-    private Integer dataElementId;
-
-    public void setDataElementId( Integer dataElementId )
-    {
-        this.dataElementId = dataElementId;
-    }
-
-    private String periodTypeId;
-
-    public void setPeriodTypeId( String periodTypeId )
-    {
-        this.periodTypeId = periodTypeId;
-    }
-
-    private Integer periodId;
-
-    public void setPeriodId( Integer periodId )
-    {
-        this.periodId = periodId;
-    }
-
-    private Integer parentOrganisationUnitId;
-
-    public void setParentOrganisationUnitId( Integer parentOrganisationUnitId )
-    {
-        this.parentOrganisationUnitId = parentOrganisationUnitId;
-    }
-
-    private Integer organisationUnitLevel;
-
-    public void setOrganisationUnitLevel( Integer organisationUnitLevel )
-    {
-        this.organisationUnitLevel = organisationUnitLevel;
-    }
-
-    private String mapLegendType;
-
-    public void setMapLegendType( String mapLegendType )
-    {
-        this.mapLegendType = mapLegendType;
-    }
-
-    private Integer method;
-
-    public void setMethod( Integer method )
-    {
-        this.method = method;
-    }
-
-    private Integer classes;
-
-    public void setClasses( Integer classes )
-    {
-        this.classes = classes;
-    }
-
-    private String bounds;
-
-    public void setBounds( String bounds )
-    {
-        this.bounds = bounds;
-    }
-
-    private String colorLow;
-
-    public void setColorLow( String colorLow )
-    {
-        this.colorLow = colorLow;
-    }
-
-    private String colorHigh;
-
-    public void setColorHigh( String colorHigh )
-    {
-        this.colorHigh = colorHigh;
-    }
-
-    private Integer mapLegendSetId;
-
-    public void setMapLegendSetId( Integer mapLegendSetId )
-    {
-        this.mapLegendSetId = mapLegendSetId;
-    }
-
-    private Integer radiusLow;
-
-    public void setRadiusLow( Integer radiusLow )
-    {
-        this.radiusLow = radiusLow;
-    }
-
-    private Integer radiusHigh;
-
-    public void setRadiusHigh( Integer radiusHigh )
-    {
-        this.radiusHigh = radiusHigh;
-    }
-
-    private String longitude;
-
-    public void setLongitude( String longitude )
-    {
-        this.longitude = longitude;
-    }
-
-    private String latitude;
-
-    public void setLatitude( String latitude )
-    {
-        this.latitude = latitude;
-    }
-
-    private int zoom;
-
-    public void setZoom( int zoom )
-    {
-        this.zoom = zoom;
-    }
-
-    // -------------------------------------------------------------------------
-    // Action implementation
-    // -------------------------------------------------------------------------
-
-    public String execute()
-        throws Exception
-    {
-        mappingService.addMapView( name, system, mapValueType, indicatorGroupId, indicatorId,
-            dataElementGroupId, dataElementId, periodTypeId, periodId, parentOrganisationUnitId,
-            organisationUnitLevel, mapLegendType, method, classes, bounds, colorLow, colorHigh, mapLegendSetId,
-            radiusLow, radiusHigh, longitude, latitude, zoom );
-
-        return SUCCESS;
-    }
-}
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetGeoJsonAction.java'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetGeoJsonAction.java	2012-10-15 12:51:32 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetGeoJsonAction.java	2012-10-31 12:40:43 +0000
@@ -34,6 +34,7 @@
 
 import org.apache.struts2.ServletActionContext;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitLevel;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
 import org.hisp.dhis.system.filter.OrganisationUnitWithValidCoordinatesFilter;
 import org.hisp.dhis.system.util.FilterUtils;
@@ -68,9 +69,9 @@
         this.parentId = parentId;
     }
 
-    private Integer level;
+    private String level;
 
-    public void setLevel( Integer level )
+    public void setLevel( String level )
     {
         this.level = level;
     }
@@ -108,10 +109,21 @@
         {
             parent = organisationUnitService.getOrganisationUnit( Integer.parseInt( parentId ) );
         }
-
-        level = level == null ? organisationUnitService.getLevelOfOrganisationUnit( parent.getId() ) : level;
-
-        Collection<OrganisationUnit> organisationUnits = organisationUnitService.getOrganisationUnitsAtLevel( level, parent );
+        
+        OrganisationUnitLevel orgUnitLevel = organisationUnitService.getOrganisationUnitLevel( level );
+
+        if ( orgUnitLevel == null )
+        {
+            orgUnitLevel = organisationUnitService.getOrganisationUnitLevel( Integer.parseInt( level ) );
+        }
+        
+        if ( orgUnitLevel == null )
+        {
+            orgUnitLevel = organisationUnitService.getOrganisationUnitLevel( parent.getOrganisationUnitLevel() );
+        }
+
+        Collection<OrganisationUnit> organisationUnits = organisationUnitService.getOrganisationUnitsAtLevel(
+            orgUnitLevel.getLevel(), parent );
 
         FilterUtils.filter( organisationUnits, new OrganisationUnitWithValidCoordinatesFilter() );
 
@@ -136,7 +148,7 @@
             }
         }
         
-        Collection<OrganisationUnit> organisationUnitsUp = organisationUnitService.getOrganisationUnitsAtLevel( level - 1 );
+        Collection<OrganisationUnit> organisationUnitsUp = organisationUnitService.getOrganisationUnitsAtLevel( orgUnitLevel.getLevel() - 1 );
         
         FilterUtils.filter( organisationUnitsUp, new OrganisationUnitWithValidCoordinatesFilter() );
         

=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetGeoJsonFacilitiesAction.java'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetGeoJsonFacilitiesAction.java	2012-10-25 12:07:10 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetGeoJsonFacilitiesAction.java	2012-10-31 12:40:43 +0000
@@ -34,6 +34,7 @@
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitGroupService;
 import org.hisp.dhis.organisationunit.OrganisationUnitGroupSet;
+import org.hisp.dhis.organisationunit.OrganisationUnitLevel;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
 import org.hisp.dhis.system.filter.OrganisationUnitWithValidCoordinatesFilter;
 import org.hisp.dhis.system.util.FilterUtils;
@@ -76,9 +77,9 @@
         this.parentId = parentId;
     }
 
-    private Integer level;
+    private String level;
 
-    public void setLevel( Integer level )
+    public void setLevel( String level )
     {
         this.level = level;
     }
@@ -110,10 +111,25 @@
     {
         OrganisationUnit parent = organisationUnitService.getOrganisationUnit( parentId );
 
-        level = level == null ? organisationUnitService.getLevelOfOrganisationUnit( parent.getId() ) : level;
-
-        Collection<OrganisationUnit> organisationUnits = organisationUnitService.getOrganisationUnitsAtLevel( level,
-            parent );
+        if ( parent == null )
+        {
+            parent = organisationUnitService.getOrganisationUnit( Integer.parseInt( parentId ) );
+        }
+
+        OrganisationUnitLevel orgUnitLevel = organisationUnitService.getOrganisationUnitLevel( level );
+
+        if ( orgUnitLevel == null )
+        {
+            orgUnitLevel = organisationUnitService.getOrganisationUnitLevel( Integer.parseInt( level ) );
+        }
+
+        if ( orgUnitLevel == null )
+        {
+            orgUnitLevel = organisationUnitService.getOrganisationUnitLevel( parent.getOrganisationUnitLevel() );
+        }
+
+        Collection<OrganisationUnit> organisationUnits = organisationUnitService.getOrganisationUnitsAtLevel(
+            orgUnitLevel.getLevel(), parent );
 
         FilterUtils.filter( organisationUnits, new OrganisationUnitWithValidCoordinatesFilter() );
 

=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/resources/META-INF/dhis/beans.xml	2012-04-20 09:52:17 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/resources/META-INF/dhis/beans.xml	2012-10-31 18:29:46 +0000
@@ -187,11 +187,6 @@
     </bean>
 
 	<!-- MapView -->
-    
-    <bean id="org.hisp.dhis.mapping.action.AddMapViewAction"
-        class="org.hisp.dhis.mapping.action.AddMapViewAction" scope="prototype">
-        <property name="mappingService" ref="org.hisp.dhis.mapping.MappingService" />
-    </bean>
 
 	<bean id="org.hisp.dhis.mapping.action.DeleteMapViewAction" class="org.hisp.dhis.mapping.action.DeleteMapViewAction"
 		scope="prototype">

=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/resources/struts.xml	2012-08-13 10:41:31 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/resources/struts.xml	2012-10-31 18:29:46 +0000
@@ -200,12 +200,6 @@
 
 		<!-- MapView -->
 
-        <action name="addMapView"
-            class="org.hisp.dhis.mapping.action.AddMapViewAction">
-            <result name="success" type="velocity-json">/dhis-web-mapping/void.vm
-            </result>
-        </action>
-
 		<action name="deleteMapView" class="org.hisp.dhis.mapping.action.DeleteMapViewAction">
 			<result name="success" type="velocity-json">/dhis-web-mapping/void.vm
 			</result>

=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/index.html'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/index.html	2012-10-24 15:00:24 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/index.html	2012-11-01 09:34:58 +0000
@@ -32,7 +32,9 @@
 		document.getElementById('slow').innerHTML = "<a href=''>SLOW CONNECTION?</a>";
 	</script>
     
+<!--
     <script type="text/javascript" src="https://maps.google.com/maps/api/js?sensor=false";></script>
+-->
 
     <script type="text/javascript" src="../../dhis-web-commons/javascripts/ext/ext-all.js"></script>
     <script type="text/javascript">

=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/app.js'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/app.js	2012-10-30 07:26:04 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/app.js	2012-11-01 14:20:29 +0000
@@ -95,6 +95,7 @@
 GIS.mask;
 
 GIS.util = {
+	url: {},
 	google: {},
 	map: {},
 	svg: {},
@@ -193,9 +194,8 @@
 			GIS.init.onInitialize(r);	
 	
 	GIS.init.onRender = function() {
-		//GIS.base.googleStreets.layer.item.setValue(false);
 		if (!window.google) {
-			GIS.base.openStreetMap.layer.item.setValue(false);
+			GIS.base.openStreetMap.layer.item.setValue(true);
 		}
 	};
 	
@@ -235,36 +235,12 @@
 			}
 		});
 		
-		// Load favorite //todo
-		//var config = {
-			//classes: 5,
-			//colorHigh: "ffff00",
-			//colorLow: "0000ff",
-			//dataElement: null,
-			//dataElementGroup: null,
-			//indicator: "Uvn6LCg7dVU",
-			//indicatorGroup: "AoTB60phSOH",
-			//legendSet: null,
-			//legendType: "automatic",
-			//level: 3,
-			//levelName: "Chiefdom",
-			//method: 2,
-			//parentId: "fdc6uOvgoji",
-			//parentLevel: 2,
-			//parentName: "Bombali",
-			//parentPath: "/ImspTQPwCqd/fdc6uOvgoji",
-			//period: "2012",
-			//periodType: "Yearly",
-			//radiusHigh: 15,
-			//radiusLow: 5,
-			//updateData: false,
-			//updateLegend: false,
-			//updateOrganisationUnit: true,
-			//valueType: "indicator"
-		//};
+		// Favorite
 		
-		//GIS.base.thematic1.widget.setConfig(config);
-		//GIS.base.thematic1.widget.execute();
+		var id = GIS.util.url.getUrlParam('id');
+		if (id) {
+			GIS.util.map.getMap(id, true);
+		}
 	};
 	
 	// Mask
@@ -279,6 +255,25 @@
 		window.open('http://www.google.com/intl/en-US_US/help/terms_maps.html', '_blank');
 	};
 	
+	GIS.util.url.getUrlParam = function(s) {
+		var output = '';
+		var href = window.location.href;
+		if (href.indexOf('?') > -1 ) {
+			var query = href.substr(href.indexOf('?') + 1);
+			var query = query.split('&');
+			for (var i = 0; i < query.length; i++) {
+				if (query[i].indexOf('=') > -1) {
+					var a = query[i].split('=');
+					if (a[0].toLowerCase() === s) {
+						output = a[1];
+						break;
+					}
+				}
+			}
+		}
+		return unescape(output);
+	};
+	
 	GIS.util.map.getVisibleVectorLayers = function() {
 		var a = [];
 		for (var i = 0; i < GIS.map.layers.length; i++) {
@@ -339,7 +334,56 @@
 		return new OpenLayers.LonLat(point.x, point.y);
 	};
 	
-    GIS.util.svg.merge = function(str, strArray) {
+	GIS.util.map.getMap = function(id, setMap) {
+		if (!id) {
+			alert('No favorite id provided');
+			return;
+		}
+		if (!Ext.isString(id)) {
+			alert('Favorite id must be a string');
+			return;
+		}
+		
+		Ext.Ajax.request({
+			url: GIS.conf.url.path_api + 'maps/' + id + '.json?links=false',
+			success: function(r) {
+				var map = Ext.decode(r.responseText);
+				
+				if (setMap) {
+					GIS.util.map.setMap(map);
+				}
+			}
+		});
+	};
+	
+	GIS.util.map.setMap = function(map) {
+		var views = map.mapViews,
+			view,
+			center,
+			lonLat;
+			
+		GIS.map.map = map;
+			
+		GIS.util.map.closeAllLayers();
+		
+		for (var i = 0; i < views.length; i++) {
+			view = views[i];
+			
+			GIS.base[view.layer].widget.execute(view);
+		}
+		
+		lonLat = new OpenLayers.LonLat(map.longitude, map.latitude);
+        GIS.map.setCenter(lonLat, map.zoom);
+	};
+	
+	GIS.util.map.closeAllLayers = function() {
+		GIS.base.boundary.widget.reset();
+		GIS.base.thematic1.widget.reset();
+		GIS.base.thematic2.widget.reset();
+		GIS.base.facility.widget.reset();
+	};
+	
+	GIS.util.svg.merge = function(str, strArray) {
         if (strArray.length) {
             str = str || '<svg></svg>';
             for (var i = 0; i < strArray.length; i++) {
@@ -386,7 +430,7 @@
 			var layer = layers[i],
 				id = layer.base.id,
 				legendConfig = layer.base.widget.getLegendConfig(),
-				legendData = layer.base.widget.model.imageLegend,
+				imageLegendConfig = layer.base.widget.view.extended.imageLegendConfig,
 				what,
 				when,
 				where,
@@ -417,16 +461,16 @@
 				
 				legend = '<g>';
 				
-				for (var j = 0; j < legendData.length; j++) {
+				for (var j = 0; j < imageLegendConfig.length; j++) {
 					if (j !== 0) {
 						y += 15;
 					}
 					
 					legend += '<rect x="' + x + '" y="' + y + '" height="15" width="30" ' +
-							  'fill="' + legendData[j].color + '" stroke="#000000" stroke-width="1"/>';
+							  'fill="' + imageLegendConfig[j].color + '" stroke="#000000" stroke-width="1"/>';
 							  
 					legend += '<text id="label" x="' + (x + 40) + '" y="' + (y + 12) + '" font-size="12">' +
-							  '<tspan>' + legendData[j].label + '</tspan></text>';
+							  '<tspan>' + imageLegendConfig[j].label + '</tspan></text>';
 				}
 				
 				legend += '</g>';
@@ -476,7 +520,7 @@
         }
         
         if (widget) {
-			widget.tmpModel.hasCoordinatesUp = doc.properties.hasCoordinatesUp;
+			widget.tmpView.extended.hasCoordinatesUp = doc.properties.hasCoordinatesUp;
 		}
 			
         return geojson;
@@ -627,6 +671,9 @@
 				this.load(fn);
 			}
 		},
+		getRecordByLevel: function(level) {
+			return this.getAt(this.findExact('level', level));
+		},
 		listeners: {
 			load: function() {
 				if (!this.isLoaded) {
@@ -721,7 +768,7 @@
 	});
 	
 	GIS.store.legendSets = Ext.create('Ext.data.Store', {
-		fields: ['id', 'name', 'edit', 'del'],
+		fields: ['id', 'name'],
 		proxy: {
 			type: 'ajax',
 			url: GIS.conf.url.path_api + 'mapLegendSets.json?links=false&paging=false',
@@ -750,16 +797,28 @@
 	});
 	
 	GIS.store.maps = Ext.create('Ext.data.Store', {
-		fields: ['id', 'name', 'lastUpdated'],
+		fields: ['id', 'name', 'lastUpdated', 'system'],
 		proxy: {
 			type: 'ajax',
-			url: GIS.conf.url.path_api + 'indicators.json?links=false',
 			reader: {
 				type: 'json',
-				root: 'indicators'
+				root: 'maps'
 			}
 		},
 		isLoaded: false,
+		pageSize: 10,
+		page: 1,
+		defaultUrl: GIS.conf.url.path_api + 'maps.json?links=false',
+		loadStore: function(url) {
+			this.proxy.url = url || this.defaultUrl;
+			
+			this.load({
+				params: {
+					pageSize: this.pageSize,
+					page: this.page
+				}
+			});
+		},
 		loadFn: function(fn) {
 			if (this.isLoaded) {
 				fn.call();
@@ -769,10 +828,6 @@
 			}
 		},
 		listeners: {
-			beforeload: function() {
-				//console.log(this.getProxy());
-				//this.getProxy().setExtraParam('pageSize', GIS.cmp.region.center.getHeight() - 155);
-			},
 			load: function() {
 				if (!this.isLoaded) {
 					this.isLoaded = true;
@@ -980,19 +1035,23 @@
 			layer,
 			items = [],
 			item,
-			panel;
+			panel,
+			visibleLayer;
+			
+		visibleLayerId = window.google ? GIS.base.googleStreets.id : GIS.base.openStreetMap.id;
 		
 		for (var i = 0; i < layers.length; i++) {
 			layer = layers[i];
+			
 			item = Ext.create('Ext.ux.panel.LayerItemPanel', {
 				cls: 'gis-container-inner',
 				height: 23,
 				layer: layer,
 				text: layer.base.name,
 				imageUrl: 'images/' + layer.base.id + '_14.png',
-				value: layer.base.id === GIS.base.googleStreets.id ? true : false,
+				value: layer.base.id === visibleLayerId ? true : false,
 				opacity: layer.layerOpacity,
-				numberFieldDisabled: layer.base.id !== GIS.base.googleStreets.id
+				numberFieldDisabled: layer.base.id !== visibleLayerId
 			});
 			layer.item = item;
 			items.push(layer.item);
@@ -1026,6 +1085,7 @@
 				{
 					text: 'Update', //i18n
 					handler: function() {
+						GIS.map.map = null;
 						base.widget.execute();
 					}
 				}
@@ -1066,6 +1126,7 @@
 			iconCls: 'gis-window-title-icon-search',
 			cls: 'gis-container-default',
 			width: GIS.conf.layout.tool.window_width,
+			resizable: false,
 			height: 400,
 			items: [
 				{
@@ -1245,6 +1306,7 @@
 			iconCls: 'gis-window-title-icon-filter',
 			cls: 'gis-container-default',
 			width: GIS.conf.layout.tool.window_width,
+			resizable: false,
 			filter: filter,
 			items: {
 				layout: 'fit',
@@ -1385,6 +1447,7 @@
 			iconCls: 'gis-window-title-icon-labels',
 			cls: 'gis-container-default',
 			width: GIS.conf.layout.tool.window_width,
+			resizable: false,
 			closeAction: 'hide',
 			items: {
 				layout: 'fit',
@@ -1493,10 +1556,10 @@
 	GIS.obj.MapWindow = function() {
 		
 		// Objects
-		var UpdateWindow,
+		var NameWindow,
 		
 		// Instances
-			updateWindow,
+			nameWindow,
 			
 		// Components
 			addButton,
@@ -1507,17 +1570,156 @@
 			tbar,
 			bbar,
 			
-			nameTextfied,
+			nameTextfield,
 			systemCheckbox,
 			createButton,
 			updateButton,
-			
-			window;
+			cancelButton,
+			
+			mapWindow;
+			
+		NameWindow = function(id) {
+			var window;
+			
+			nameTextfield = Ext.create('Ext.form.field.Text', {
+				height: 26,
+				width: 300,
+				labelWidth: 70,
+				fieldStyle: 'padding-left: 6px; border-radius: 1px; border-color: #bbb',
+				fieldLabel: 'Name', //i18n
+				value: id ? GIS.store.maps.getById(id).data.name : '',
+				listeners: {
+					afterrender: function() {
+						this.focus();
+					}
+				}
+			});
+			
+			systemCheckbox = Ext.create('Ext.form.field.Checkbox', {
+				labelWidth: 70,
+				fieldLabel: 'System', //i18n
+				style: 'margin-bottom: 0',
+				value: id ? GIS.store.maps.getById(id).data.system : false
+			});
+			
+			createButton = Ext.create('Ext.button.Button', {
+				text: 'Create', //i18n
+				handler: function() {
+					var name = nameTextfield.getValue(),
+						system = systemCheckbox.getValue(),
+						layers = GIS.util.map.getVisibleVectorLayers(),
+						layer,
+						lonlat = GIS.map.getCenter(),
+						views = [],
+						view,
+						map;
+						
+					if (name && layers.length) {
+						for (var i = 0; i < layers.length; i++) {
+							layer = layers[i];
+							view = layer.base.widget.getView();
+							
+							// add
+							view.layer = layer.base.id;
+							
+							// remove
+							delete view.periodType;
+							views.push(view);
+						}
+						
+						map = {
+							name: name,
+							longitude: lonlat.lon,
+							latitude: lonlat.lat,
+							zoom: GIS.map.getZoom(),
+							mapViews: views
+						};
+						
+						if (!system) {
+							map.user = {
+								id: 'currentUser'
+							};
+						}
+					
+						Ext.Ajax.request({
+							url: GIS.conf.url.path_api + 'maps/',
+							method: 'POST',
+							headers: {'Content-Type': 'application/json'},
+							params: Ext.encode(map),
+							success: function() {								
+								GIS.store.maps.loadStore();
+								
+								window.close();
+							}
+						});
+					}
+				}
+			});
+			
+			updateButton = Ext.create('Ext.button.Button', {
+				text: 'Update', //i18n
+				handler: function() {
+					var name = nameTextfield.getValue(),
+						system = systemCheckbox.getValue(),
+						map = {};
+						
+					map.name = name;
+					
+					if (!system) {
+						map.user = {
+							id: 'currentUser'
+						};
+					}
+					
+					Ext.Ajax.request({
+						url: GIS.conf.url.path_api + 'maps/' + id,
+						method: 'PUT',
+						headers: {'Content-Type': 'application/json'},
+						params: Ext.encode(map),
+						success: function() {								
+							GIS.store.maps.loadStore();
+							
+							window.close();
+						}
+					});
+				}
+			});
+			
+			cancelButton = Ext.create('Ext.button.Button', {
+				text: 'Cancel', //i18n
+				handler: function() {
+					console.log('hide + load');
+				}
+			});
+			
+			window = Ext.create('Ext.window.Window', {
+				title: id ? 'Edit favorite' : 'Create new favorite',
+				iconCls: 'gis-window-title-icon-favorite',
+				cls: 'gis-container-default',
+				resizable: false,
+				modal: true,
+				items: [
+					nameTextfield,
+					systemCheckbox
+				],
+				bbar: [
+					cancelButton,
+					'->',
+					id ? updateButton : createButton
+				],
+				listeners: {
+					show: function() {
+						this.setPosition(this.getPosition()[0], 100);
+					}
+				}
+			});
+			
+			return window;
+		};
 			
 		searchTextfield = Ext.create('Ext.form.field.Text', {
-			width: 354,
+			width: 353,
 			height: 26,
-			style: 'margin-right: 4px',
 			fieldStyle: 'padding-left: 6px; border-radius: 1px; border-color: #bbb',
 			emptyText: 'Search for favorites..', //i18n
 			enableKeyEvents: true,
@@ -1525,8 +1727,14 @@
 			listeners: {
 				keyup: function() {
 					if (this.getValue() !== this.currentValue) {
-						console.log('Request ' + this.getValue());
 						this.currentValue = this.getValue();
+						
+						var value = this.getValue(),
+							url = value ? GIS.conf.url.path_api +  'maps/query/' + value + '.json?links=false' : null,
+							store = GIS.store.maps;
+							
+						store.page = 1;
+						store.loadStore(url);
 					}
 				}
 			}
@@ -1535,27 +1743,40 @@
 		addButton = Ext.create('Ext.button.Button', {
 			text: 'Add new', //i18n
 			height: 26,
-			style: 'border-radius: 1px',
+			style: 'border-radius: 1px; margin-right: 5px',
 			menu: {},
 			handler: function() {
+				nameWindow = new NameWindow();
+				nameWindow.show();
 			}
 		});
 		
 		prevButton = Ext.create('Ext.button.Button', {
 			text: 'Prev', //i18n
 			handler: function() {
+				var value = searchTextfield.getValue(),
+					url = value ? GIS.conf.url.path_api +  'maps/query/' + value + '.json?links=false' : null,
+					store = GIS.store.maps;
+					
+				store.page = store.page <= 1 ? 1 : store.page - 1;
+				store.loadStore(url);
 			}
 		});
 		
 		nextButton = Ext.create('Ext.button.Button', {
 			text: 'Next', //i18n
 			handler: function() {
+				var value = searchTextfield.getValue(),
+					url = value ? GIS.conf.url.path_api +  'maps/query/' + value + '.json?links=false' : null,
+					store = GIS.store.maps;
+					
+				store.page = store.page + 1;
+				store.loadStore(url);
 			}
 		});
 		
 		grid = Ext.create('Ext.grid.Panel', {
 			cls: 'gis-grid',
-			bodyStyle: 'border-top-color: red !important, border-bottom: 0 none',
 			scroll: false,
 			hideHeaders: true,
 			columns: [						
@@ -1565,22 +1786,14 @@
 					width: 355,
 					renderer: function(value, metaData, record) {
 						var fn = function() {
-							var span = Ext.get(record.data.id),
-								div = span.parent('div'),
-								td = span.parent('td'),
-								currentElement,
-								clickHandler = function(id) {
-									alert(id);
-									console.log(record.data.id);
-								};
-								
-							td.addClsOnOver('text-link');
-							td.addListener('click', clickHandler(td.id));
+							var el = Ext.get(record.data.id).parent('td');
+							el.addClsOnOver('link');
+							el.dom.setAttribute('onclick', 'GIS.cmp.mapWindow.destroy(); GIS.util.map.getMap("' + record.data.id + '", true)');
 						};
 						
 						Ext.defer(fn, 100);
 						
-						return '<span id="' + record.data.id + '">' + value + '</span>';
+						return '<div id="' + record.data.id + '">' + value + '</div>';
 					}
 				},
 				{
@@ -1591,19 +1804,76 @@
 						{
 							iconCls: 'gis-grid-row-icon-edit',
 							handler: function(grid, rowIndex, colIndex, col, event) {
-								//var id = this.up('grid').store.getAt(rowIndex).data.id;
+								var id = this.up('grid').store.getAt(rowIndex).data.id;
+								nameWindow = new NameWindow(id);
+								nameWindow.show();
 							}
 						},
 						{
 							iconCls: 'gis-grid-row-icon-overwrite',
 							handler: function(grid, rowIndex, colIndex, col, event) {
-								//var id = this.up('grid').store.getAt(rowIndex).data.id;
+								var record = this.up('grid').store.getAt(rowIndex),
+									id = record.data.id,
+									name = record.data.name,
+									layers = GIS.util.map.getVisibleVectorLayers(),
+									layer,
+									lonlat = GIS.map.getCenter(),
+									views = [],
+									view,
+									map,
+									message = 'Overwrite the following favorite?\n\n' + name;
+								
+								if (confirm(message)) {
+									if (layers.length) {
+										for (var i = 0; i < layers.length; i++) {
+											layer = layers[i];
+											view = layer.base.widget.getView();
+											
+											// add
+											view.layer = layer.base.id;
+											
+											// remove
+											delete view.periodType;
+											views.push(view);
+										}
+										
+										map = {
+											longitude: lonlat.lon,
+											latitude: lonlat.lat,
+											zoom: GIS.map.getZoom(),
+											mapViews: views
+										};
+									
+										Ext.Ajax.request({
+											url: GIS.conf.url.path_api + 'maps/' + id,
+											method: 'PUT',
+											headers: {'Content-Type': 'application/json'},
+											params: Ext.encode(map),
+											success: function() {								
+												GIS.store.maps.loadStore();
+												
+												window.close();
+											}
+										});
+									}
+								}
 							}
 						},
 						{
 							iconCls: 'gis-grid-row-icon-delete',
 							handler: function(grid, rowIndex, colIndex, col, event) {
-								//var id = this.up('grid').store.getAt(rowIndex).data.id;
+								var id = this.up('grid').store.getAt(rowIndex).data.id,
+									message = 'Delete the following favorite?\n\n' + name;
+									
+								if (confirm(message)) {								
+									Ext.Ajax.request({
+										url: GIS.conf.url.path_api + 'maps/' + id,
+										method: 'DELETE',
+										success: function() {
+											GIS.store.maps.loadStore();
+										}
+									});
+								}
 							}
 						}
 					]
@@ -1621,11 +1891,9 @@
 				},
 				render: function() {
 					var size = Math.floor((GIS.cmp.region.center.getHeight() - 155) / GIS.conf.layout.grid.row_height);
-					this.store.load({
-						params: {
-							pageSize: size
-						}
-					});
+					this.store.pageSize = size;
+					this.store.page = 1;
+					this.store.loadStore();
 				},
 				itemmouseenter: function(grid, record, item) {
 					this.currentItem = Ext.get(item);
@@ -1640,28 +1908,21 @@
 			}
 		});
 		
-		window = Ext.create('Ext.window.Window', {
+		mapWindow = Ext.create('Ext.window.Window', {
 			title: 'Manage favorites',
 			iconCls: 'gis-window-title-icon-favorite',
 			cls: 'gis-container-default',
+			resizable: false,
+			modal: true,
 			width: 450,
-			onmouseover: function(id) { // mapgrid
-				//Ext.get(id).addCls('gis-grid-icon-link');
-			},
-			onmouseout: function(id) {
-				//Ext.get(id).removeCls('gis-grid-icon-link');
-			},
-			onclick: function(id) {
-				//alert(id);
-			},
 			items: [
 				{
 					xtype: 'panel',
 					layout: 'hbox',
 					cls: 'gis-container-inner',
 					items: [
-						searchTextfield,
-						addButton
+						addButton,
+						searchTextfield
 					]
 				},
 				grid
@@ -1673,7 +1934,7 @@
 			}
 		});
 		
-		return window;
+		return mapWindow;
 	};
 	
 	GIS.obj.LegendSetWindow = function() {
@@ -1684,11 +1945,11 @@
 			tmpLegendStore,
 			
 		// Objects
-			LegendSetGrid,
+			LegendSetPanel,
 			LegendPanel,
 			
 		// Instances
-			legendSetGrid,
+			legendSetPanel,
 			legendPanel,
 			
 		// Components
@@ -1729,6 +1990,8 @@
 					this.sort('name', 'ASC');
 					
 					info.setText(records.length + ' legend sets available');
+					
+					//window.setHeight(110 + (this.getCount() * GIS.conf.layout.grid.row_height));
 				}
 			}
 		});
@@ -1764,23 +2027,22 @@
 			}
 		});
 		
-		LegendSetGrid = function() {
-			var tbar = Ext.create('Ext.toolbar.Toolbar', {
-				items: [
-					'->',
-					{
-						text: 'Add new..',
-						handler: function() {
-							showUpdateLegendSet();
-						}
-					}
-				]
+		LegendSetPanel = function() {
+			var items,
+				addButton;
+				
+			addButton = Ext.create('Ext.button.Button', {
+				text: 'Add new', //i18n
+				height: 26,
+				style: 'border-radius: 1px',
+				menu: {},
+				handler: function() {
+					showUpdateLegendSet();
+				}
 			});
 			
 			legendSetGrid = Ext.create('Ext.grid.Panel', {
 				cls: 'gis-grid',
-				bodyStyle: 'border-top: 0 none',
-				width: GIS.conf.layout.widget.item_width,
 				scroll: 'vertical',
 				hideHeaders: true,
 				currentItem: null,
@@ -1788,12 +2050,12 @@
 					{
 						dataIndex: 'name',
 						sortable: false,
-						width: GIS.conf.layout.widget.item_width - 62
+						width: 355
 					},
 					{
 						xtype: 'actioncolumn',
 						sortable: false,
-						width: 40,
+						width: 45,
 						items: [
 							{
 								iconCls: 'gis-grid-row-icon-edit',
@@ -1817,11 +2079,17 @@
 					}
 				],
 				store: legendSetStore,
-				tbar: tbar,
 				listeners: {
 					render: function() {
 						this.store.load();
 					},
+					resize: function() {
+						var maxHeight = GIS.cmp.region.center.getHeight() - 155;
+												
+						if (this.getHeight() > maxHeight) {
+							this.setHeight(maxHeight);
+						}
+					},
 					itemmouseenter: function(grid, record, item) {
 						this.currentItem = Ext.get(item);
 						this.currentItem.removeCls('x-grid-row-over');
@@ -1835,7 +2103,20 @@
 				}
 			});
 			
-			return legendSetGrid;
+			items = [
+				{
+					xtype: 'panel',
+					layout: 'hbox',
+					cls: 'gis-container-inner',
+					style: 'margin-bottom: 5px',
+					items: [
+						addButton
+					]
+				},
+				legendSetGrid
+			];
+			
+			return items;
 		};
 		
 		LegendPanel = function(id) {
@@ -1850,37 +2131,49 @@
 			
 			legendSetName = Ext.create('Ext.form.field.Text', {
 				cls: 'gis-textfield',
-				width: GIS.conf.layout.widget.item_width,
+				width: 422,
+				height: 25,
+				fieldStyle: 'padding-left: 6px; border-color: #bbb',
 				fieldLabel: 'Legend set name' //i18n
 			});
 			
 			legendName = Ext.create('Ext.form.field.Text', {
 				cls: 'gis-textfield',
-				width: GIS.conf.layout.widget.item_width - 12,
+				fieldStyle: 'padding-left: 6px',
+				width: 404,
+				height: 23,
 				fieldLabel: 'Legend name' //i18n
 			});
 			
 			startValue = Ext.create('Ext.form.field.Number', {
-				width: 71,
+				width: 148,
+				height: 23,
 				allowDecimals: false,
+				fieldStyle: 'padding-left: 6px; border-radius: 1px',
 				value: 0
 			});
 			
 			endValue = Ext.create('Ext.form.field.Number', {
-				width: 71,
+				width: 148,
+				height: 23,
 				allowDecimals: false,
+				fieldStyle: 'padding-left: 6px; border-radius: 1px',
 				value: 0,
-				style: 'padding-left: 2px'
+				style: 'padding-left: 3px'
 			});
 			
 			color = Ext.create('Ext.ux.button.ColorButton', {
-				width: GIS.conf.layout.widget.item_width - GIS.conf.layout.widget.itemlabel_width - 10 - 12,
+				width: 299,
+				height: 23,
 				fieldLabel: 'Symbolizer', //i18n
+				style: 'border-radius: 1px',
 				value: 'e1e1e1'
 			});
 			
 			addLegend = Ext.create('Ext.button.Button', {
 				text: 'Add legend', //i18n
+				height: 26,
+				style: 'border-radius: 1px',
 				handler: function() {
 					var date = new Date(),
 						id = date.toISOString(),
@@ -1922,7 +2215,7 @@
 			legendGrid = Ext.create('Ext.grid.Panel', {
 				cls: 'gis-grid',
 				bodyStyle: 'border-top: 0 none',
-				width: GIS.conf.layout.widget.item_width,
+				width: 422,
 				height: 235,
 				scroll: 'vertical',
 				hideHeaders: true,
@@ -1931,11 +2224,11 @@
 					{
 						dataIndex: 'name',
 						sortable: false,
-						width: GIS.conf.layout.widget.item_width - 156
+						width: 247
 					},
 					{
 						sortable: false,
-						width: 40,
+						width: 45,
 						renderer: function(value, metaData, record) {
 							return '<span style="color:' + record.data.color + '">Color</span>';
 						}
@@ -1943,12 +2236,12 @@
 					{
 						dataIndex: 'startValue',
 						sortable: false,
-						width: 37
+						width: 45
 					},
 					{
 						dataIndex: 'endValue',
 						sortable: false,
-						width: 37
+						width: 45
 					},
 					{
 						xtype: 'actioncolumn',
@@ -2000,7 +2293,7 @@
 						cls: 'gis-panel-html-separator'
 					},
 					{
-						bodyStyle: 'background-color: #f1f1f1; border: 1px solid #ccc; border-radius: 2px; padding: 5px',
+						bodyStyle: 'background-color: #f1f1f1; border: 1px solid #ccc; border-radius: 1px; padding: 8px',
 						items: [
 							legendName,
 							{
@@ -2038,7 +2331,7 @@
 					{
 						cls: 'gis-container-inner',
 						bodyStyle: 'text-align: right',
-						width: GIS.conf.layout.widget.item_width,
+						width: 422,
 						items: addLegend
 					},
 					{
@@ -2118,9 +2411,9 @@
 		
 		reset = function() {
 			legendPanel.destroy();
-			legendSetGrid = new LegendSetGrid();
+			legendSetPanel = new LegendSetPanel();
 			window.removeAll();
-			window.add(legendSetGrid);
+			window.add(legendSetPanel);
 			
 			info.show();
 			cancel.hide();
@@ -2178,6 +2471,7 @@
 						headers: {'Content-Type': 'application/json'},
 						params: body,
 						success: function() {
+							GIS.store.legendSets.load();
 							reset();
 						}
 					});
@@ -2224,14 +2518,12 @@
 		
 		window = Ext.create('Ext.window.Window', {
 			title: 'Legend sets', //i18n
-			layout: 'fit',
 			iconCls: 'gis-window-title-icon-legendset', //todo
 			cls: 'gis-container-default',
-			width: GIS.conf.layout.widget.window_width,
-			height: 500,
 			resizable: false,
+			width: 450,
 			modal: true,
-			items: new LegendSetGrid(),
+			items: new LegendSetPanel(),
 			bbar: {
 				height: 27,
 				items: [
@@ -2242,10 +2534,9 @@
 					update
 				]
 			},
-			listeners: {
+			listeners: {					
 				show: function() {
-					var x = this.getPosition()[0];
-					this.setPosition(x, 50);
+					this.setPosition(this.getPosition()[0], 40);
 				}
 			}
 		});
@@ -2270,6 +2561,7 @@
 			width: 28,
 			height: 28,
 			iconCls: 'gis-btn-icon-download',
+			style: 'border-radius: 1px',
 			handler: function() {
 				var title = textfield.getValue(),
 					svg = GIS.util.svg.getString(title, GIS.util.map.getVisibleVectorLayers()),
@@ -2473,21 +2765,39 @@
                         contentEl: 'thematic1Legend',
                         bodyStyle: 'padding: 6px; border: 0 none',
                         collapsible: true,
-                        animCollapse: false
+                        collapsed: true,
+                        animCollapse: false,
+                        listeners: {
+							added: function() {
+								GIS.base.thematic1.layer.legend = this;
+							}
+						}
                     },
                     {
                         title: 'Thematic layer 2 legend', //i18n
                         contentEl: 'thematic2Legend',
                         bodyStyle: 'padding: 6px; border: 0 none',
                         collapsible: true,
-                        animCollapse: false
+                        collapsed: true,
+                        animCollapse: false,
+                        listeners: {
+							added: function() {
+								GIS.base.thematic2.layer.legend = this;
+							}
+						}
                     },
                     {
                         title: 'Facility layer legend', //i18n
                         contentEl: 'facilityLegend',
                         bodyStyle: 'padding: 6px; border: 0 none',
                         collapsible: true,
-                        animCollapse: false
+                        collapsed: true,
+                        animCollapse: false,
+                        listeners: {
+							added: function() {
+								GIS.base.facility.layer.legend = this;
+							}
+						}
                     }
 				],
 				listeners: {
@@ -2560,84 +2870,21 @@
 							}
 						},
 						{
+							xtype: 'tbseparator',
+							height: 18,
+							style: 'border-color: transparent #d1d1d1 transparent transparent; margin-right: 4px',
+						},
+						{
 							text: 'Download', //i18n
 							menu: new GIS.obj.DownloadMenu()
 						},
+						{
+							text: 'Share', //i18n
+							menu: {},
+							disabled: true
+						},
 						'->',
 						{
-							text: 'fav1()', //i18n
-							handler: function() {
-								var config = {
-									classes: 5,
-									colorHigh: "00ff00",
-									colorLow: "ff0000",
-									dataElement: null,
-									dataElementGroup: null,
-									indicator: "Uvn6LCg7dVU",
-									indicatorGroup: "AoTB60phSOH",
-									legendSet: null,
-									legendType: "automatic",
-									level: 3,
-									levelName: "Chiefdom",
-									method: 2,
-									parentId: "fdc6uOvgoji",
-									parentLevel: 2,
-									parentName: "Bombali",
-									parentPath: "/ImspTQPwCqd/fdc6uOvgoji",
-									period: "2012",
-									periodType: "Yearly",
-									radiusHigh: 15,
-									radiusLow: 5,
-									updateData: false,
-									updateLegend: false,
-									updateOrganisationUnit: true,
-									valueType: "indicator"
-								};
-								
-								GIS.base.thematic1.widget.setConfig(config);
-								GIS.base.thematic1.widget.execute();
-							}
-						},
-						{
-							text: 'fav2()', //i18n
-							handler: function() {
-								var config = {
-									classes: 5,
-									colorHigh: "ffff00",
-									colorLow: "0000ff",
-									dataElement: null,
-									dataElementGroup: null,
-									indicator: "Uvn6LCg7dVU",
-									indicatorGroup: "AoTB60phSOH",
-									legendSet: null,
-									legendType: "automatic",
-									level: 3,
-									levelName: "Chiefdom",
-									method: 2,
-									parentId: "Vth0fbpFcsO",
-									parentLevel: 2,
-									parentName: "Kono",
-									parentPath: "/ImspTQPwCqd/Vth0fbpFcsO",
-									period: "2012",
-									periodType: "Yearly",
-									radiusHigh: 15,
-									radiusLow: 5,
-									updateData: false,
-									updateLegend: false,
-									updateOrganisationUnit: true,
-									valueType: "indicator"
-								};
-								
-								GIS.base.thematic2.widget.setConfig(config);
-								GIS.base.thematic2.widget.execute();
-							}
-						},
-						{
-							text: 'log()', //i18n
-							handler: function() {
-							}
-						},
-						{
 							text: 'Exit', //i18n
 							handler: function() {
 								alert('Exit');

=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/ext-ux/panel/LayerItemPanel.js'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/ext-ux/panel/LayerItemPanel.js	2012-10-11 23:24:07 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/ext-ux/panel/LayerItemPanel.js	2012-10-31 15:54:48 +0000
@@ -15,16 +15,38 @@
 		return this.checkbox.getValue();
 	},
 	setValue: function(value, opacity) {
-		opacity = opacity || this.opacity;
 		this.checkbox.setValue(value);
-		this.numberField.setValue(opacity * 100);
 		this.numberField.setDisabled(!value);
 		this.layer.setVisibility(value);
-		this.setOpacity(opacity);
+		
+		if (opacity === 0) {
+			this.numberField.setValue(0);
+			this.setOpacity(0.01);
+		}
+		else if (opacity > 0) {
+			this.numberField.setValue(opacity * 100);
+			this.setOpacity(opacity);
+		}
+		else {
+			this.numberField.setValue(this.opacity * 100);
+			this.setOpacity(this.opacity);
+		}
+			
+		
+		
+		//opacity = opacity === 0 ? 0.01 : (opacity || this.opacity);
+		//this.checkbox.setValue(value);
+		//this.numberField.setValue(opacity * 100);
+		//this.numberField.setDisabled(!value);
+		//this.layer.setVisibility(value);
+		//this.setOpacity(opacity);
+	},
+	getOpacity: function() {
+		return this.opacity;
 	},
 	setOpacity: function(opacity) {
-		this.opacity = opacity;
-		this.layer.setLayerOpacity(opacity);
+		this.opacity = opacity === 0 ? 0.01 : opacity;
+		this.layer.setLayerOpacity(this.opacity);
 	},
 	disableItem: function() {
 		this.checkbox.setValue(false);
@@ -78,7 +100,7 @@
 			listeners: {
 				change: function() {
 					var value = this.getValue(),
-						opacity = value === 0 ? 0 : value/100;
+						opacity = value === 0 ? 0.01 : value/100;
 					
 					that.setOpacity(opacity);
 				}

=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/mapfish/core/GeoStat.js'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/mapfish/core/GeoStat.js	2012-10-22 18:38:37 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/mapfish/core/GeoStat.js	2012-10-31 18:29:46 +0000
@@ -251,19 +251,19 @@
     },
 	
     classify: function(method, nbBins, bounds, that) {
-		if (that.tmpModel.legendType === GIS.conf.finals.widget.legendtype_predefined) {
-			bounds = that.tmpModel.bounds;
+		if (that.tmpView.legendType === GIS.conf.finals.widget.legendtype_predefined) {
+			bounds = that.tmpView.extended.bounds;
 
 			if (bounds[0] > this.minVal) {
 				bounds.unshift(this.minVal);        
                 //if (this.widget == centroid) { this.widget.symbolizerInterpolation.unshift('blank');
-				that.tmpModel.colorInterpolation.unshift(new mapfish.ColorRgb(240,240,240));
+				that.tmpView.extended.colorInterpolation.unshift(new mapfish.ColorRgb(240,240,240));
 			}
 
 			if (bounds[bounds.length-1] < this.maxVal) {
 				bounds.push(this.maxVal);
                 //todo if (this.widget == centroid) { G.vars.activeWidget.symbolizerInterpolation.push('blank');
-				that.tmpModel.colorInterpolation.push(new mapfish.ColorRgb(240,240,240));
+				that.tmpView.extended.colorInterpolation.push(new mapfish.ColorRgb(240,240,240));
 			}
 			
 			method = mapfish.GeoStat.Distribution.CLASSIFY_WITH_BOUNDS;

=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/mapfish/core/GeoStat/Boundary.js'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/mapfish/core/GeoStat/Boundary.js	2012-10-16 13:33:23 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/mapfish/core/GeoStat/Boundary.js	2012-11-01 09:34:58 +0000
@@ -61,13 +61,15 @@
     },
     
     createColorInterpolation: function() {
-        var numColors = this.classification.bins.length;
-        this.widget.imageLegend = [];
+        var numColors = this.classification.bins.length,
+			tmpView = this.widget.tmpView;
+        
+        tmpView.extended.imageLegendConfig = [];
 			
 		this.colorInterpolation = mapfish.ColorRgb.getColorsArrayByRgbInterpolation(this.colors[0], this.colors[1], numColors);
             
         for (var i = 0; i < this.classification.bins.length; i++) {
-            this.widget.imageLegend.push({
+            tmpView.extended.imageLegendConfig.push({
                 label: this.classification.bins[i].label.replace('&nbsp;&nbsp;', ' '),
                 color: this.colorInterpolation[i].toHexString()
             });
@@ -136,7 +138,8 @@
         }
         
         var config = this.widget.getLegendConfig(),
-			element;
+			element,
+			legendNames = this.widget.tmpView.extended.legendNames;
 			
         this.legendDiv.update("");
         
@@ -158,45 +161,23 @@
         element.style.height = "5px";
         this.legendDiv.appendChild(element);
         
-        if (this.widget.tmpModel.legendType === GIS.conf.finals.widget.legendtype_automatic) {
-            for (var i = 0; i < this.classification.bins.length; i++) {
-                var element = document.createElement("div");
-                element.style.backgroundColor = this.colorInterpolation[i].toHexString();
-                element.style.width = "30px";
-                element.style.height = "15px";
-                element.style.cssFloat = "left";
-                element.style.marginRight = "8px";
-                this.legendDiv.appendChild(element);
-
-                element = document.createElement("div");
-                element.innerHTML = this.classification.bins[i].label;
-                this.legendDiv.appendChild(element);
-
-                element = document.createElement("div");
-                element.style.clear = "left";
-                this.legendDiv.appendChild(element);
-            }
-        }
-        else if (this.widget.tmpModel.legendType === GIS.conf.finals.widget.legendtype_predefined) {
-            //for (var i = 0; i < this.classification.bins.length; i++) {
-                //var element = document.createElement("div");
-                //element.style.backgroundColor = this.colorInterpolation[i].toHexString();
-                //element.style.width = "30px";
-                //element.style.height = this.widget.legendNames[i] ? "25px" : "20px";
-                //element.style.cssFloat = "left";
-                //element.style.marginRight = "8px";
-                //this.legendDiv.appendChild(element);
-
-                //element = document.createElement("div");
-                //element.style.lineHeight = this.widget.legendNames[i] ? "12px" : "7px";
-                //element.innerHTML = '<b style="color:#222">' + (this.widget.legendNames[i] || '') + '</b><br/>' + this.classification.bins[i].label;
-                //this.legendDiv.appendChild(element);
-
-                //element = document.createElement("div");
-                //element.style.clear = "left";
-                //this.legendDiv.appendChild(element);
-            //}
-        }
+		for (var i = 0; i < this.classification.bins.length; i++) {
+			var element = document.createElement("div");
+			element.style.backgroundColor = this.colorInterpolation[i].toHexString();
+			element.style.width = "30px";
+			element.style.height = "15px";
+			element.style.cssFloat = "left";
+			element.style.marginRight = "8px";
+			this.legendDiv.appendChild(element);
+
+			element = document.createElement("div");
+			element.innerHTML = this.classification.bins[i].label;
+			this.legendDiv.appendChild(element);
+
+			element = document.createElement("div");
+			element.style.clear = "left";
+			this.legendDiv.appendChild(element);
+		}
     },
 
     CLASS_NAME: "mapfish.GeoStat.Boundary"

=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/mapfish/core/GeoStat/Thematic1.js'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/mapfish/core/GeoStat/Thematic1.js	2012-10-22 18:38:37 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/mapfish/core/GeoStat/Thematic1.js	2012-10-31 18:29:46 +0000
@@ -62,19 +62,20 @@
     
     createColorInterpolation: function() {
         var numColors = this.classification.bins.length,
-			legendType = this.widget.tmpModel.legendType;
+			tmpView = this.widget.tmpView,
+			legendType = tmpView.legendType;
         
-        this.widget.tmpModel.imageLegend = [];
+        tmpView.extended.imageLegendConfig = [];
         
         if (legendType === GIS.conf.finals.widget.legendtype_automatic) {
 			this.colorInterpolation = mapfish.ColorRgb.getColorsArrayByRgbInterpolation(this.colors[0], this.colors[1], numColors);
 		}
 		else {
-			this.colorInterpolation = this.widget.tmpModel.colorInterpolation;
+			this.colorInterpolation = tmpView.extended.colorInterpolation;
 		}
             
         for (var i = 0; i < this.classification.bins.length; i++) {
-            this.widget.tmpModel.imageLegend.push({
+            tmpView.extended.imageLegendConfig.push({
                 label: this.classification.bins[i].label.replace('&nbsp;&nbsp;', ' '),
                 color: this.colorInterpolation[i].toHexString()
             });
@@ -144,10 +145,10 @@
         
         var config = this.widget.getLegendConfig(),
 			element,
-			legendType = this.widget.tmpModel.legendType,
+			legendType = this.widget.tmpView.legendType,
 			automatic = GIS.conf.finals.widget.legendtype_automatic,
 			predefined = GIS.conf.finals.widget.legendtype_predefined,
-			legendNames = this.widget.tmpModel.legendNames;
+			legendNames = this.widget.tmpView.extended.legendNames;
 			
         this.legendDiv.update("");
         

=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/mapfish/core/GeoStat/Thematic2.js'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/mapfish/core/GeoStat/Thematic2.js	2012-10-22 18:38:37 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/mapfish/core/GeoStat/Thematic2.js	2012-11-01 09:03:39 +0000
@@ -62,19 +62,20 @@
     
     createColorInterpolation: function() {
         var numColors = this.classification.bins.length,
-			legendType = this.widget.tmpModel.legendType;
+			tmpView = this.widget.tmpView,
+			legendType = tmpView.legendType;
         
-        this.widget.tmpModel.imageLegend = [];
+        tmpView.extended.imageLegendConfig = [];
         
         if (legendType === GIS.conf.finals.widget.legendtype_automatic) {
 			this.colorInterpolation = mapfish.ColorRgb.getColorsArrayByRgbInterpolation(this.colors[0], this.colors[1], numColors);
 		}
 		else {
-			this.colorInterpolation = this.widget.tmpModel.colorInterpolation;
+			this.colorInterpolation = tmpView.extended.colorInterpolation;
 		}
             
         for (var i = 0; i < this.classification.bins.length; i++) {
-            this.widget.tmpModel.imageLegend.push({
+            tmpView.extended.imageLegendConfig.push({
                 label: this.classification.bins[i].label.replace('&nbsp;&nbsp;', ' '),
                 color: this.colorInterpolation[i].toHexString()
             });
@@ -144,10 +145,10 @@
         
         var config = this.widget.getLegendConfig(),
 			element,
-			legendType = this.widget.tmpModel.legendType,
+			legendType = this.widget.tmpView.legendType,
 			automatic = GIS.conf.finals.widget.legendtype_automatic,
 			predefined = GIS.conf.finals.widget.legendtype_predefined,
-			legendNames = this.widget.tmpModel.legendNames;
+			legendNames = this.widget.tmpView.extended.legendNames;
 			
         this.legendDiv.update("");
         

=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/mapfish/widgets/geostat/Boundary.js'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/mapfish/widgets/geostat/Boundary.js	2012-10-25 12:21:55 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/mapfish/widgets/geostat/Boundary.js	2012-11-01 14:19:06 +0000
@@ -42,11 +42,13 @@
     
     // Properties
     
-    config: {},
-    
-    tmpModel: {},
-    
-    model: {},
+    config: {
+		extended: {}
+	},
+    
+    tmpView: {},
+    
+    view: {},
     
     cmp: {},
     
@@ -145,7 +147,7 @@
         this.cmp.level = Ext.create('Ext.form.field.ComboBox', {
             fieldLabel: GIS.i18n.level,
             editable: false,
-            valueField: 'level',
+            valueField: 'id',
             displayField: 'name',
             mode: 'remote',
             forceSelection: true,
@@ -201,7 +203,7 @@
 				select: {
 					scope: this,
 					fn: function() {
-						this.config.updateOrganisationUnit = true;
+						this.config.extended.updateOrganisationUnit = true;
 					}
 				},
 				afterrender: function() {					
@@ -334,26 +336,39 @@
 					var store = GIS.store.organisationUnitLevels;
 					
 					if (direction === 'up') {
-						var rootNode = GIS.init.rootNodes[0];
+						var rootNode = GIS.init.rootNodes[0],
+							level = store.getAt(store.find('level', that.view.organisationUnitLevel.level - 1));
 						
-						that.config.level = that.model.level - 1;
-						that.config.levelName = store.getAt(store.find('level', that.config.level)).data.name;
-						that.config.parentId = rootNode.id;
-						that.config.parentName = rootNode.text;
-						that.config.parentLevel = rootNode.level;
-						that.config.parentPath = '/' + GIS.init.rootNodes[0].id;
+						that.config.organisationUnitLevel = {
+							id: level.data.id,
+							name: level.data.name,
+							level: level.data.level
+						};
+						that.config.parentOrganisationUnit = {
+							id: rootNode.id,
+							name: rootNode.text,
+							level: rootNode.level
+						};
+						that.config.parentGraph = '/' + GIS.init.rootNodes[0].id;
 					}
 					else if (direction === 'down') {
-						that.config.level = that.model.level + 1;
-						that.config.levelName = store.getAt(store.find('level', that.config.level)).data.name;
-						that.config.parentId = feature.attributes.id;
-						that.config.parentName = feature.attributes.name;
-						that.config.parentLevel = that.model.level;
-						that.config.parentPath = feature.attributes.path;
+						var level = store.getAt(store.find('level', that.view.organisationUnitLevel.level + 1));
+						
+						that.config.organisationUnitLevel = {
+							id: level.data.id,
+							name: level.data.name,
+							level: level.data.level
+						};
+						that.config.parentOrganisationUnit = {
+							id: feature.attributes.id,
+							name: feature.attributes.name,
+							level: that.view.organisationUnitLevel.level
+						};
+						that.config.parentGraph = feature.attributes.path;
 					}
 					
-					that.config.updateOrganisationUnit = true;
-					that.config.updateGui = true;
+					that.config.extended.updateOrganisationUnit = true;
+					that.config.extended.updateGui = true;
 					
 					that.execute();
 				});
@@ -364,7 +379,7 @@
 				Ext.create('Ext.menu.Item', {
 					text: 'Float up',
 					iconCls: 'gis-menu-item-icon-float',
-					disabled: !that.model.hasCoordinatesUp,
+					disabled: !that.view.extended.hasCoordinatesUp,
 					scope: this,
 					handler: function() {
 						drill('up');
@@ -432,20 +447,12 @@
 	
 	getLegendConfig: function() {
 		return {
-			where: this.tmpModel.levelName + ' / ' + this.tmpModel.parentName
+			where: this.tmpView.levelName + ' / ' + this.tmpView.parentName
 		};
 	},
-        //,
-        
-        //getImageExportValues: function() {
-			//return {
-				//mapValueTypeValue: this.cmp.valueType.getValue() == GIS.conf.map_value_type_indicator ?
-					//this.cmp.indicator.getRawValue() : this.cmp.dataElement.getRawValue(),
-				//dateValue: this.cmp.period.getRawValue()
-			//};
-		//},
-		
+	
 	reset: function() {
+		
 		// Components
 		this.cmp.level.clearValue();
 		this.cmp.parent.reset();
@@ -458,10 +465,12 @@
 			this.cmp.labelWindow.destroy();
 		}
 		
-		// Model
-		this.config = {};
-		this.tmpModel = {};
-		this.model = {};
+		// View
+		this.config = {
+			extended: {}
+		};
+		this.tmpView = {};
+		this.view = {};
 		
 		// Layer
 		this.layer.destroyFeatures();
@@ -473,100 +482,108 @@
 		//document.getElementById(this.legendDiv).innerHTML = '';
 	},
 	
-	setConfig: function(config) {
-		this.config.level = config.level;
-		this.config.levelName = config.levelName;
-		this.config.parentId = config.parentId;
-		this.config.parentName = config.parentName;
-		this.config.parentLevel = config.parentLevel;
-		this.config.parentPath = config.parentPath;
-		this.config.updateOrganisationUnit = true;
-		this.config.updateLegend = true;
-		this.config.updateGui = true;
-	},
-	
 	setGui: function() {
-		var model = this.tmpModel;
+		var view = this.tmpView,
+			that = this;
 		
 		// Level and parent
-		var levelView = this.cmp.level;
 		GIS.store.organisationUnitLevels.loadFn( function() {
-			levelView.setValue(model.level);
+			that.cmp.level.setValue(view.organisationUnitLevel.id);
 		});
 		
-		this.cmp.parent.selectTreePath('/root' + model.parentPath);
+		this.cmp.parent.selectTreePath('/root' + view.parentGraph);
 	},
     	
-	getModel: function() {
+	getView: function() {
 		var level = this.cmp.level,
-			parent = this.cmp.parent.getSelectionModel().getSelection();
+			parent = this.cmp.parent.getSelectionModel().getSelection(),
+			view;
+				
 		parent = parent.length ? parent : [{raw: GIS.init.rootNodes[0]}];
 		
-		var model = {
-			level: level.getValue(),
-			levelName: level.getRawValue(),
-			parentId: parent[0].raw.id,
-			parentName: parent[0].raw.text,
+		view = {
+			organisationUnitLevel: {
+				id: level.getValue(),
+				name: level.getRawValue(),
+				level: GIS.store.organisationUnitLevels.getById(level.getValue()).data.level
+			},
+			parentOrganisationUnit: {
+				id: parent[0].raw.id,
+				name: parent[0].raw.text
+			},
 			parentLevel: parent[0].raw.level,
-			parentPath: parent[0].raw.path,
-			updateOrganisationUnit: false,
-			updateLegend: false,
-			updateGui: false
-		};
-		
-		model.level = this.config.level || model.level;
-		model.levelName = this.config.levelName || model.levelName;
-		model.parentId = this.config.parentId || model.parentId;
-		model.parentName = this.config.parentName || model.parentName;
-		model.parentLevel = this.config.parentLevel || model.parentLevel;
-		model.parentPath = this.config.parentPath || null;
-		model.updateOrganisationUnit = Ext.isDefined(this.config.updateOrganisationUnit) ? this.config.updateOrganisationUnit : false;
-		model.updateLegend = Ext.isDefined(this.config.updateLegend) ? this.config.updateLegend : false;
-		model.updateGui = Ext.isDefined(this.config.updateGui) ? this.config.updateGui : false;
-		
-		return model;
-	},
-	
-	validateModel: function(model) {
-		if (!model.level || !Ext.isNumber(model.level)) {
-			GIS.logg.push([model.level, this.xtype + '.level: number']);
+			parentGraph: parent[0].raw.path,
+			opacity: this.layer.item.getOpacity()
+		};
+		
+		return view;
+	},
+	
+	extendView: function(view) {
+		var conf = this.config;
+		view = view || {};
+
+		view.organisationUnitLevel = conf.organisationUnitLevel || view.organisationUnitLevel;
+		view.parentOrganisationUnit = conf.parentOrganisationUnit || view.parentOrganisationUnit;
+		view.parentLevel = conf.parentLevel || view.parentLevel;
+		view.parentGraph = conf.parentGraph || view.parentGraph;
+		view.opacity = conf.opacity || view.opacity;
+		
+		view.extended = {
+			updateOrganisationUnit: Ext.isDefined(conf.extended.updateOrganisationUnit) ? conf.extended.updateOrganisationUnit : false,
+			updateData: Ext.isDefined(conf.extended.updateData) ? conf.extended.updateData : false,
+			updateLegend: Ext.isDefined(conf.extended.updateLegend) ? conf.extended.updateLegend : false,
+			updateGui: Ext.isDefined(conf.extended.updateGui) ? conf.extended.updateGui : false
+		};
+		
+		return view;
+	},
+	
+	validateView: function(view) {
+		if (!view.organisationUnitLevel.id || !Ext.isString(view.organisationUnitLevel.id)) {
+			GIS.logg.push([view.organisationUnitLevel.id, this.xtype + '.organisationUnitLevel.id: string']);
 				alert('No level selected'); //todo
 			return false;
 		}
-		if (!model.levelName || !Ext.isString(model.levelName)) {
-			GIS.logg.push([model.levelName, this.xtype + '.levelName: string']);
-				//alert("validation failed"); //todo
-			return false;
-		}
-		if (!model.parentId || !Ext.isString(model.parentId)) {
-			GIS.logg.push([model.parentId, this.xtype + '.parentId: string']);
+		if (!view.organisationUnitLevel.name || !Ext.isString(view.organisationUnitLevel.name)) {
+			GIS.logg.push([view.organisationUnitLevel.name, this.xtype + '.organisationUnitLevel.name: string']);
+				//alert("validation failed"); //todo
+			return false;
+		}
+		if (!view.organisationUnitLevel.level || !Ext.isNumber(view.organisationUnitLevel.level)) {
+			GIS.logg.push([view.organisationUnitLevel.level, this.xtype + '.organisationUnitLevel.level: number']);
+				//alert("validation failed"); //todo
+			return false;
+		}
+		if (!view.parentOrganisationUnit.id || !Ext.isString(view.parentOrganisationUnit.id)) {
+			GIS.logg.push([view.parentOrganisationUnit.id, this.xtype + '.parentOrganisationUnit.id: string']);
 				alert('No parent organisation unit selected'); //todo
 			return false;
 		}
-		if (!model.parentName || !Ext.isString(model.parentName)) {
-			GIS.logg.push([model.parentName, this.xtype + '.parentName: string']);
-				//alert("validation failed"); //todo
-			return false;
-		}
-		if (!model.parentLevel || !Ext.isNumber(model.parentLevel)) {
-			GIS.logg.push([model.parentLevel, this.xtype + '.parentLevel: number']);
-				//alert("validation failed"); //todo
-			return false;
-		}
-		if (model.parentLevel > model.level) {
-			GIS.logg.push([model.parentLevel, model.level, this.xtype + '.parentLevel: number <= ' + this.xtype + '.level']);
-				alert('Level cannot be higher than parent level'); //todo
-			return false;
-		}
-		
-		if (!model.parentPath && model.updateGui) {
-			GIS.logg.push([model.parentpath, this.xtype + '.parentpath: string']);
-				//alert("validation failed"); //todo
-			return false;
-		}
-		
-		if (!model.updateOrganisationUnit && !model.updateLegend) {
-			GIS.logg.push([model.updateOrganisationUnit, model.updateLegend, this.xtype + '.update ou/legend: true||true']);
+		if (!view.parentOrganisationUnit.name || !Ext.isString(view.parentOrganisationUnit.name)) {
+			GIS.logg.push([view.parentOrganisationUnit.name, this.xtype + '.parentOrganisationUnit.name: string']);
+				//alert("validation failed"); //todo
+			return false;
+		}
+		if (!view.parentLevel || !Ext.isNumber(view.parentLevel)) {
+			GIS.logg.push([view.parentLevel, this.xtype + '.parentLevel: number']);
+				//alert("validation failed"); //todo
+			return false;
+		}
+		if (!view.parentGraph || !Ext.isString(view.parentGraph)) {
+			GIS.logg.push([view.parentGraph, this.xtype + '.parentGraph: string']);
+				//alert("validation failed"); //todo
+			return false;
+		}
+		
+		if (view.parentOrganisationUnit.level > view.organisationUnitLevel.level) {
+			GIS.logg.push([view.parentOrganisationUnit.level, view.organisationUnitLevel.level, this.xtype + '.parentOrganisationUnit.level: number <= ' + this.xtype + '.organisationUnitLevel.level']);
+				alert('Orgunit level cannot be higher than parent level'); //todo
+			return false;
+		}
+				
+		if (!view.extended.updateOrganisationUnit && !view.extended.updateData && !view.extended.updateLegend) {
+			GIS.logg.push([view.extended.updateOrganisationUnit, view.extended.updateData, view.extended.updateLegend, this.xtype + '.extended.update ou/data/legend: true||true||true']);
 			return false;
 		}
 		
@@ -575,8 +592,8 @@
 	
     loadOrganisationUnits: function() {
         var url = GIS.conf.url.path_gis + 'getGeoJson.action?' +
-            'parentId=' + this.tmpModel.parentId +
-            '&level=' + this.tmpModel.level;
+            'parentId=' + this.tmpView.parentOrganisationUnit.id +
+            '&level=' + this.tmpView.organisationUnitLevel.id;
         this.setUrl(url);
     },
     
@@ -591,7 +608,13 @@
 	},
 	
 	loadLegend: function() {
-		var options = {
+		var options;
+		
+		this.tmpView.extended.legendConfig = {
+			where: this.tmpView.organisationUnitLevel.name + ' / ' + this.tmpView.parentOrganisationUnit.name
+		};
+		
+		options = {
             indicator: GIS.conf.finals.widget.value,
             method: 2,
             numClasses: 5,
@@ -606,34 +629,47 @@
         this.afterLoad();		
 	},
 	
-    execute: function() {
-		this.tmpModel = this.getModel();
-		
-		if (!this.validateModel(this.tmpModel)) {
+    execute: function(view) {
+		if (view) {
+			this.config.extended.updateOrganisationUnit = true;
+			this.config.extended.updateGui = true;
+		}
+		else {
+			view = this.getView();
+		}
+		
+		this.tmpView = this.extendView(view);
+		
+		if (!this.validateView(this.tmpView)) {
 			return;
 		}
-				
+		
 		GIS.mask.msg = GIS.i18n.loading;
 		GIS.mask.show();
 		
-		if (this.tmpModel.updateGui) {
+		if (this.tmpView.extended.updateGui) {
 			this.setGui();
 		}
 		
-		if (this.tmpModel.updateOrganisationUnit) {
+		if (this.tmpView.extended.updateOrganisationUnit) {
 			this.loadOrganisationUnits();
 		}
+		else if (this.tmpView.extended.updateData) {
+			this.loadData();
+		}
 		else {
 			this.loadLegend();
 		}
 	},
 	
 	afterLoad: function() {
-		this.model = this.tmpModel;
-		this.config = {};
+		this.view = this.tmpView;
+		this.config = {
+			extended: {}
+		};
 		
 		// Layer item
-		this.layer.item.setValue(true);
+		this.layer.item.setValue(true, this.view.opacity);
 		
 		// Layer menu
 		this.menu.enableItems();
@@ -642,22 +678,18 @@
 		this.store.features.loadFeatures(this.layer.features); 
 		
 		// Update filter window
-		if (this.cmp.filterWindow && this.cmp.filterWindow.isVisible()) {
+		if (this.cmp.filterWindow && this.cmp.filterWindow.isVisible()) { 
 			this.cmp.filterWindow.filter();
 		}
+		
+		// Legend
+		GIS.cmp.region.east.doLayout();
         
-        // Set favorite position, else zoom to visible extent
-        if (this.model.longitude && this.model.latitude && this.model.zoom) {
-			var lonLat = GIS.util.map.getLonLatByXY(this.model.longitude, this.model.latitude);
-			GIS.map.setCenter(lonLat, this.model.zoom);
-		}
-		else if (this.model.updateOrganisationUnit) {
+        // Zoom to visible extent if not loading a favorite
+        if (!GIS.map.map) {
 			GIS.util.map.zoomToVisibleExtent();
 		}
 		
-		// Legend
-		GIS.cmp.region.east.doLayout();
-		
         GIS.mask.hide();
 	},
     

=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/mapfish/widgets/geostat/Facility.js'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/mapfish/widgets/geostat/Facility.js	2012-10-25 12:23:33 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/mapfish/widgets/geostat/Facility.js	2012-11-01 13:24:45 +0000
@@ -42,11 +42,13 @@
     
     // Properties
     
-    config: {},
-    
-    tmpModel: {},
-    
-    model: {},
+    config: {
+		extended: {}
+	},
+    
+    tmpView: {},
+    
+    view: {},
     
     cmp: {},
     
@@ -212,27 +214,27 @@
             width: GIS.conf.layout.widget.item_width,
             labelWidth: GIS.conf.layout.widget.itemlabel_width,
             currentValue: false,
+            scope: this,
             store: GIS.store.groupSets, //todo
             listeners: {
-                select: {
-                    scope: this,
-                    fn: function(cb) {
-                        var store = GIS.store.groupsByGroupSet;
-                        store.proxy.url = GIS.conf.url.path_api +  'organisationUnitGroupSets/' + cb.getValue() + '.json?links=false&paging=false';
-                        store.load({
-							scope: this,
-							callback: function() {
-								if (this.tmpModel.updateGui) { // If favorite, load store and continue execution
-									if (this.tmpModel.updateOrganisationUnit) {
-										this.loadOrganisationUnits();
-									}
-									else {
-										this.loadLegend();
-									}
-								}	
-							}
-						});
-                    }
+                select: function() {
+					var store = GIS.store.groupsByGroupSet,
+						value = this.getValue();
+					
+					store.proxy.url = GIS.conf.url.path_api +  'organisationUnitGroupSets/' + value + '.json?links=false&paging=false';
+					store.load({
+						scope: this.scope,
+						callback: function() {
+							if (this.config.extended.updateGui) { // If favorite, load store and continue execution
+								if (this.config.extended.updateOrganisationUnit) {
+									this.loadOrganisationUnits();
+								}
+								else {
+									this.loadLegend();
+								}
+							}	
+						}
+					});
                 }
             }
         });
@@ -242,7 +244,7 @@
         this.cmp.level = Ext.create('Ext.form.field.ComboBox', {
             fieldLabel: GIS.i18n.level,
             editable: false,
-            valueField: 'level',
+            valueField: 'id',
             displayField: 'name',
             mode: 'remote',
             forceSelection: true,
@@ -257,7 +259,7 @@
 				select: {
 					scope: this,
 					fn: function() {
-						this.config.updateOrganisationUnit = true;
+						this.config.extended.updateOrganisationUnit = true;
 					}
 				}
 			}
@@ -298,7 +300,7 @@
 				select: {
 					scope: this,
 					fn: function() {
-						this.config.updateOrganisationUnit = true;
+						this.config.extended.updateOrganisationUnit = true;
 					}
 				},
 				afterrender: function() {					
@@ -334,7 +336,8 @@
 					this.cmp.groupSet,
 					{
 						html: 'Organisation unit level / parent', //i18n
-						cls: 'gis-form-subtitle'
+						cls: 'gis-form-subtitle',
+						bodyStyle: 'padding-top: 4px'
 					},
 					this.cmp.level,
 					this.cmp.parent
@@ -689,20 +692,13 @@
 	
 	getLegendConfig: function() {
 		return {
-			where: this.tmpModel.levelName + ' / ' + this.tmpModel.parentName
+			where: this.tmpView.organisationUnitLevel.name + ' / ' + this.tmpView.parentOrganisationUnit.name
 		};
 	},
-        //,
-        
-        //getImageExportValues: function() {
-			//return {
-				//mapValueTypeValue: this.cmp.valueType.getValue() == GIS.conf.map_value_type_indicator ?
-					//this.cmp.indicator.getRawValue() : this.cmp.dataElement.getRawValue(),
-				//dateValue: this.cmp.period.getRawValue()
-			//};
-		//},
 		
 	reset: function() {
+		
+		// Components
 		this.cmp.groupSet.clearValue();
 		
 		this.cmp.level.clearValue();
@@ -719,10 +715,12 @@
 			this.cmp.labelWindow.destroy();
 		}
 		
-		// Model
-		this.config = {};
-		this.tmpModel = {};
-		this.model = {};
+		// View
+		this.config = {
+			extended: {}
+		};
+		this.tmpView = {};
+		this.view = {};
 		
 		// Layer
 		this.layer.destroyFeatures();
@@ -734,114 +732,130 @@
 		document.getElementById(this.legendDiv).innerHTML = '';
 	},
 	
-	setConfig: function(config) {
-		this.config.groupSet = config.groupSet;
-		this.config.level = config.level;
-		this.config.levelName = config.levelName;
-		this.config.parentId = config.parentId;
-		this.config.parentName = config.parentName;
-		this.config.parentLevel = config.parentLevel;
-		this.config.parentPath = config.parentPath;
-		this.config.updateOrganisationUnit = true;
-		this.config.updateLegend = false;
-		this.config.updateGui = true;
-	},
-	
 	setGui: function() {
-		var model = this.tmpModel;
+		var view = this.tmpView,
+			that = this;
 		
-		// Group set		
-		this.cmp.groupSet.setValue(model.groupSet);
+		// Group set
+		GIS.store.groupSets.load({
+			callback: function() {
+				that.cmp.groupSet.setValue(view.organisationUnitGroupSet.id);
+				that.cmp.groupSet.fireEvent('select');
+			}
+		});
+
+		this.cmp.groupSet.setValue(view.organisationUnitGroupSet.id);
 		this.cmp.groupSet.fireEvent('select');
 		
 		// Level and parent
-		var levelView = this.cmp.level;
 		GIS.store.organisationUnitLevels.loadFn( function() {
-			levelView.setValue(model.level);
+			that.cmp.level.setValue(view.organisationUnitLevel.id);
 		});
 		
-		this.cmp.parent.selectTreePath('/root' + model.parentPath);
+		this.cmp.parent.selectTreePath('/root' + view.parentGraph);
 	},
     	
-	getModel: function() {
+	getView: function() {
 		var level = this.cmp.level,
-			parent = this.cmp.parent.getSelectionModel().getSelection();
+			parent = this.cmp.parent.getSelectionModel().getSelection(),
+			view;
+				
 		parent = parent.length ? parent : [{raw: GIS.init.rootNodes[0]}];
 		
-		var model = {
-			groupSet: this.cmp.groupSet.getValue(),
-			level: level.getValue(),
-			levelName: level.getRawValue(),
-			parentId: parent[0].raw.id,
-			parentName: parent[0].raw.text,
+		view = {
+			organisationUnitGroupSet: {
+				id: this.cmp.groupSet.getValue(),
+				name: this.cmp.groupSet.getRawValue()
+			},
+			organisationUnitLevel: {
+				id: level.getValue(),
+				name: level.getRawValue(),
+				level: GIS.store.organisationUnitLevels.getById(level.getValue()).data.level
+			},
+			parentOrganisationUnit: {
+				id: parent[0].raw.id,
+				name: parent[0].raw.text
+			},
 			parentLevel: parent[0].raw.level,
-			parentPath: parent[0].raw.path,
-			updateOrganisationUnit: false,
-			updateData: false,
-			updateLegend: false,
-			updateGui: false
-		};
-		
-		model.groupSet = this.config.groupSet || model.groupSet;
-		model.level = this.config.level || model.level;
-		model.levelName = this.config.levelName || model.levelName;
-		model.parentId = this.config.parentId || model.parentId;
-		model.parentName = this.config.parentName || model.parentName;
-		model.parentLevel = this.config.parentLevel || model.parentLevel;
-		model.parentPath = this.config.parentPath || null;
-		model.updateOrganisationUnit = Ext.isDefined(this.config.updateOrganisationUnit) ? this.config.updateOrganisationUnit : false;
-		model.updateLegend = Ext.isDefined(this.config.updateLegend) ? this.config.updateLegend : false;
-		model.updateGui = Ext.isDefined(this.config.updateGui) ? this.config.updateGui : false;
-		
-		return model;
-	},
-	
-	validateModel: function(model) {
-		if (!model.groupSet || !Ext.isString(model.groupSet)) {
-			GIS.logg.push([model.groupSet, this.xtype + '.parentId: string']);
+			parentGraph: parent[0].raw.path,
+			opacity: this.layer.item.getOpacity()
+		};
+		
+		return view;
+	},
+	
+	extendView: function(view) {
+		var conf = this.config;
+		view = view || {};
+		
+		view.organisationUnitGroupSet = conf.organisationUnitGroupSet || view.organisationUnitGroupSet;
+		view.organisationUnitLevel = conf.organisationUnitLevel || view.organisationUnitLevel;
+		view.parentOrganisationUnit = conf.parentOrganisationUnit || view.parentOrganisationUnit;
+		view.parentLevel = conf.parentLevel || view.parentLevel;
+		view.parentGraph = conf.parentGraph || view.parentGraph;
+		view.opacity = conf.opacity || view.opacity;
+		
+		view.extended = {
+			updateOrganisationUnit: Ext.isDefined(conf.extended.updateOrganisationUnit) ? conf.extended.updateOrganisationUnit : false,
+			updateData: Ext.isDefined(conf.extended.updateData) ? conf.extended.updateData : false,
+			updateLegend: Ext.isDefined(conf.extended.updateLegend) ? conf.extended.updateLegend : false,
+			updateGui: Ext.isDefined(conf.extended.updateGui) ? conf.extended.updateGui : false
+		};
+		
+		return view;
+	},
+	
+	validateView: function(view) {
+		if (!view.organisationUnitGroupSet.id || !Ext.isString(view.organisationUnitGroupSet.id)) {
+			GIS.logg.push([view.organisationUnitGroupSet.id, this.xtype + '.organisationUnitGroupSet.id: string']);
 				alert('No group set selected'); //todo //i18n
 			return false;
 		}
 		
-		if (!model.level || !Ext.isNumber(model.level)) {
-			GIS.logg.push([model.level, this.xtype + '.level: number']);
+		if (!view.organisationUnitLevel.id || !Ext.isString(view.organisationUnitLevel.id)) {
+			GIS.logg.push([view.organisationUnitLevel.id, this.xtype + '.organisationUnitLevel.id: string']);
 				alert('No level selected'); //todo
 			return false;
 		}
-		if (!model.levelName || !Ext.isString(model.levelName)) {
-			GIS.logg.push([model.levelName, this.xtype + '.levelName: string']);
-				//alert("validation failed"); //todo
-			return false;
-		}
-		if (!model.parentId || !Ext.isString(model.parentId)) {
-			GIS.logg.push([model.parentId, this.xtype + '.parentId: string']);
+		if (!view.organisationUnitLevel.name || !Ext.isString(view.organisationUnitLevel.name)) {
+			GIS.logg.push([view.organisationUnitLevel.name, this.xtype + '.organisationUnitLevel.name: string']);
+				//alert("validation failed"); //todo
+			return false;
+		}
+		if (!view.organisationUnitLevel.level || !Ext.isNumber(view.organisationUnitLevel.level)) {
+			GIS.logg.push([view.organisationUnitLevel.level, this.xtype + '.organisationUnitLevel.level: number']);
+				//alert("validation failed"); //todo
+			return false;
+		}
+		if (!view.parentOrganisationUnit.id || !Ext.isString(view.parentOrganisationUnit.id)) {
+			GIS.logg.push([view.parentOrganisationUnit.id, this.xtype + '.parentOrganisationUnit.id: string']);
 				alert('No parent organisation unit selected'); //todo
 			return false;
 		}
-		if (!model.parentName || !Ext.isString(model.parentName)) {
-			GIS.logg.push([model.parentName, this.xtype + '.parentName: string']);
-				//alert("validation failed"); //todo
-			return false;
-		}
-		if (!model.parentLevel || !Ext.isNumber(model.parentLevel)) {
-			GIS.logg.push([model.parentLevel, this.xtype + '.parentLevel: number']);
-				//alert("validation failed"); //todo
-			return false;
-		}
-		if (model.parentLevel > model.level) {
-			GIS.logg.push([model.parentLevel, model.level, this.xtype + '.parentLevel: number <= ' + this.xtype + '.level']);
-				alert('Level cannot be higher than parent level'); //todo
-			return false;
-		}
-		
-		if (!model.parentPath && model.updateGui) {
-			GIS.logg.push([model.parentpath, this.xtype + '.parentpath: string']);
-				//alert("validation failed"); //todo
-			return false;
-		}
-		
-		if (!model.updateOrganisationUnit && !model.updateLegend) {
-			GIS.logg.push([model.updateOrganisationUnit, model.updateLegend, this.xtype + '.update ou/legend: true||true']);
+		if (!view.parentOrganisationUnit.name || !Ext.isString(view.parentOrganisationUnit.name)) {
+			GIS.logg.push([view.parentOrganisationUnit.name, this.xtype + '.parentOrganisationUnit.name: string']);
+				//alert("validation failed"); //todo
+			return false;
+		}
+		if (!view.parentLevel || !Ext.isNumber(view.parentLevel)) {
+			GIS.logg.push([view.parentLevel, this.xtype + '.parentLevel: number']);
+				//alert("validation failed"); //todo
+			return false;
+		}
+		if (!view.parentGraph || !Ext.isString(view.parentGraph)) {
+			GIS.logg.push([view.parentGraph, this.xtype + '.parentGraph: string']);
+				//alert("validation failed"); //todo
+			return false;
+		}
+		
+		if (view.parentOrganisationUnit.level > view.organisationUnitLevel.level) {
+			GIS.logg.push([view.parentOrganisationUnit.level, view.organisationUnitLevel.level, this.xtype + '.parentOrganisationUnit.level: number <= ' + this.xtype + '.organisationUnitLevel.level']);
+				alert('Orgunit level cannot be higher than parent level'); //todo
+			return false;
+		}
+				
+		if (!view.extended.updateOrganisationUnit && !view.extended.updateData && !view.extended.updateLegend) {
+			GIS.logg.push([view.extended.updateOrganisationUnit, view.extended.updateData, view.extended.updateLegend, this.xtype + '.extended.update ou/data/legend: true||true||true']);
 			return false;
 		}
 		
@@ -850,8 +864,8 @@
 	
     loadOrganisationUnits: function() {
         var url = GIS.conf.url.path_gis + 'getGeoJsonFacilities.action?' +
-            'parentId=' + this.tmpModel.parentId +
-            '&level=' + this.tmpModel.level;
+            'parentId=' + this.tmpView.parentOrganisationUnit.id +
+            '&level=' + this.tmpView.organisationUnitLevel.id;
         this.setUrl(url);
     },
     
@@ -866,30 +880,38 @@
 	
 	loadLegend: function() {
 		var options = {
-            indicator: this.cmp.groupSet.getRawValue()
+            indicator: this.tmpView.organisationUnitGroupSet.name
 		};
 
         this.coreComp.applyClassification(options);
         this.classificationApplied = true;
         
         this.afterLoad();
-	},
+	},	
 	
-    execute: function() {
-		this.tmpModel = this.getModel();
-		
-		if (!this.validateModel(this.tmpModel)) {
+    execute: function(view) {
+		if (view) {
+			this.config.extended.updateOrganisationUnit = true;
+			this.config.extended.updateGui = true;
+		}
+		else {
+			view = this.getView();
+		}
+		
+		this.tmpView = this.extendView(view);
+		
+		if (!this.validateView(this.tmpView)) {
 			return;
 		}
 				
 		GIS.mask.msg = GIS.i18n.loading;
 		GIS.mask.show();
 		
-		if (this.tmpModel.updateGui) { // If favorite, wait for groups store callback
+		if (this.tmpView.extended.updateGui) { // If favorite, wait for groups store callback 
 			this.setGui();
 		}
 		else {
-			if (this.tmpModel.updateOrganisationUnit) {
+			if (this.tmpView.extended.updateOrganisationUnit) {
 				this.loadOrganisationUnits();
 			}
 			else {
@@ -899,8 +921,10 @@
 	},
 	
 	afterLoad: function() {
-		this.model = this.tmpModel;
-		this.config = {};
+		this.view = this.tmpView;
+		this.config = {
+			extended: {}
+		};
 		
 		// Layer item
 		this.layer.item.setValue(true);
@@ -915,19 +939,16 @@
 		if (this.cmp.filterWindow && this.cmp.filterWindow.isVisible()) {
 			this.cmp.filterWindow.filter();
 		}
+		
+		// Legend
+		GIS.cmp.region.east.doLayout();
+		this.layer.legend.expand();
         
-        // Set favorite position, else zoom to visible extent
-        if (this.model.longitude && this.model.latitude && this.model.zoom) {
-			var lonLat = GIS.util.map.getLonLatByXY(this.model.longitude, this.model.latitude);
-			GIS.map.setCenter(lonLat, this.model.zoom);
-		}
-		else if (this.model.updateOrganisationUnit) {
+        // Zoom to visible extent if not loading a favorite
+        if (!GIS.map.map) {
 			GIS.util.map.zoomToVisibleExtent();
 		}
 		
-		// Legend
-		GIS.cmp.region.east.doLayout();
-		
         GIS.mask.hide();
 	},
     

=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/mapfish/widgets/geostat/Thematic1.js'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/mapfish/widgets/geostat/Thematic1.js	2012-10-25 15:26:14 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/mapfish/widgets/geostat/Thematic1.js	2012-11-01 12:20:39 +0000
@@ -42,11 +42,13 @@
     
     // Properties
     
-    config: {},
-    
-    tmpModel: {},
-    
-    model: {},
+    config: {
+		extended: {}
+	},
+    
+    tmpView: {},
+    
+    view: {},
     
     cmp: {},
     
@@ -323,7 +325,7 @@
                 select: {
                     scope: this,
                     fn: function(cb) {
-						this.config.updateData = true;
+						this.config.extended.updateData = true;
 						this.toggler.valueType(cb.getValue());
                     }
                 }
@@ -346,7 +348,7 @@
                 select: {
                     scope: this,
                     fn: function(cb) {
-						this.config.updateData = true;
+						this.config.extended.updateData = true;
                         this.cmp.indicator.clearValue();
                         
                         var store = this.cmp.indicator.store;
@@ -377,12 +379,12 @@
 				if (this.store.getCount() > 0) {
 					this.setValue(this.store.getAt(0).data.id);
 				}
-				this.scope.config.updateData = true;
+				this.scope.config.extended.updateData = true;
 			},
             store: this.store.indicatorsByGroup,
             listeners: {
                 select: function() {
-					this.scope.config.updateData = true;
+					this.scope.config.extended.updateData = true;
                 }
             }
         });
@@ -435,12 +437,12 @@
 				if (this.store.getCount() > 0) {
 					this.setValue(this.store.getAt(0).data.id);
 				}
-				this.scope.config.updateData = true;
+				this.scope.config.extended.updateData = true;
 			},
             store: this.store.dataElementsByGroup,
             listeners: {
                 select: function() {
-					this.scope.config.updateData = true;
+					this.scope.config.extended.updateData = true;
                 }
 			}
         });
@@ -489,13 +491,13 @@
             scope: this,
             selectFirst: function() {
 				this.setValue(this.store.getAt(0).data.id);
-				this.scope.config.updateData = true;
+				this.scope.config.extended.updateData = true;
 			},
 			listeners: {
 				select: {
 					scope: this,
 					fn: function() {
-						this.config.updateData = true;
+						this.config.extended.updateData = true;
 					}
 				}
 			}	
@@ -553,7 +555,7 @@
                     fn: function(cb) {
 						this.toggler.legendType(cb.getValue());
 						
-						this.config.updateLegend = true;
+						this.config.extended.updateLegend = true;
                     }
                 }
             }
@@ -572,7 +574,7 @@
 				select: {
 					scope: this,
 					fn: function() {
-						this.config.updateLegend = true;
+						this.config.extended.updateLegend = true;
 					}
 				}
 			}
@@ -596,7 +598,7 @@
 				change: {
 					scope: this,
 					fn: function() {
-						this.config.updateLegend = true;
+						this.config.extended.updateLegend = true;
 					}
 				}
 			}
@@ -620,7 +622,7 @@
 				select: {
 					scope: this,
 					fn: function() {
-						this.config.updateLegend = true;
+						this.config.extended.updateLegend = true;
 					}
 				}
 			}
@@ -631,7 +633,7 @@
 			value: 'ff0000',
 			scope: this,
 			menuHandler: function() {
-				this.scope.config.updateLegend = true;
+				this.scope.config.extended.updateLegend = true;
 			}
 		});
         
@@ -640,7 +642,7 @@
 			value: '00ff00',
 			scope: this,
 			menuHandler: function() {
-				this.scope.config.updateLegend = true;
+				this.scope.config.extended.updateLegend = true;
 			}
 		});
         
@@ -653,7 +655,7 @@
 				change: {
 					scope: this,
 					fn: function() {
-						this.config.updateLegend = true;
+						this.config.extended.updateLegend = true;
 					}
 				}
 			}
@@ -668,7 +670,7 @@
 				change: {
 					scope: this,
 					fn: function() {
-						this.config.updateLegend = true;
+						this.config.extended.updateLegend = true;
 					}
 				}
 			}
@@ -679,7 +681,7 @@
         this.cmp.level = Ext.create('Ext.form.field.ComboBox', {
             fieldLabel: GIS.i18n.level,
             editable: false,
-            valueField: 'level',
+            valueField: 'id',
             displayField: 'name',
             mode: 'remote',
             forceSelection: true,
@@ -694,7 +696,7 @@
 				select: {
 					scope: this,
 					fn: function() {
-						this.config.updateOrganisationUnit = true;
+						this.config.extended.updateOrganisationUnit = true;
 					}
 				}
 			}
@@ -735,7 +737,7 @@
 				select: {
 					scope: this,
 					fn: function() {
-						this.config.updateOrganisationUnit = true;
+						this.config.extended.updateOrganisationUnit = true;
 					}
 				},
 				afterrender: function() {					
@@ -1140,26 +1142,39 @@
 					var store = GIS.store.organisationUnitLevels;
 					
 					if (direction === 'up') {
-						var rootNode = GIS.init.rootNodes[0];
+						var rootNode = GIS.init.rootNodes[0],
+							level = store.getAt(store.find('level', that.view.organisationUnitLevel.level - 1));
 						
-						that.config.level = that.model.level - 1;
-						that.config.levelName = store.getAt(store.find('level', that.config.level)).data.name;
-						that.config.parentId = rootNode.id;
-						that.config.parentName = rootNode.text;
-						that.config.parentLevel = rootNode.level;
-						that.config.parentPath = '/' + GIS.init.rootNodes[0].id;
+						that.config.organisationUnitLevel = {
+							id: level.data.id,
+							name: level.data.name,
+							level: level.data.level
+						};
+						that.config.parentOrganisationUnit = {
+							id: rootNode.id,
+							name: rootNode.text,
+							level: rootNode.level
+						};
+						that.config.parentGraph = '/' + GIS.init.rootNodes[0].id;
 					}
 					else if (direction === 'down') {
-						that.config.level = that.model.level + 1;
-						that.config.levelName = store.getAt(store.find('level', that.config.level)).data.name;
-						that.config.parentId = feature.attributes.id;
-						that.config.parentName = feature.attributes.name;
-						that.config.parentLevel = that.model.level;
-						that.config.parentPath = feature.attributes.path;
+						var level = store.getAt(store.find('level', that.view.organisationUnitLevel.level + 1));
+						
+						that.config.organisationUnitLevel = {
+							id: level.data.id,
+							name: level.data.name,
+							level: level.data.level
+						};
+						that.config.parentOrganisationUnit = {
+							id: feature.attributes.id,
+							name: feature.attributes.name,
+							level: that.view.organisationUnitLevel.level
+						};
+						that.config.parentGraph = feature.attributes.path;
 					}
 					
-					that.config.updateOrganisationUnit = true;
-					that.config.updateGui = true;
+					that.config.extended.updateOrganisationUnit = true;
+					that.config.extended.updateGui = true;
 					
 					that.execute();
 				});
@@ -1170,7 +1185,7 @@
 				Ext.create('Ext.menu.Item', {
 					text: 'Float up',
 					iconCls: 'gis-menu-item-icon-float',
-					disabled: !that.model.hasCoordinatesUp,
+					disabled: !that.view.extended.hasCoordinatesUp,
 					scope: this,
 					handler: function() {
 						drill('up');
@@ -1264,7 +1279,7 @@
 			legends;
 		
 		Ext.Ajax.request({
-			url: GIS.conf.url.path_api + 'mapLegendSets/' + this.tmpModel.legendSet + '.json?links=false&paging=false',
+			url: GIS.conf.url.path_api + 'mapLegendSets/' + this.tmpView.legendSet.id + '.json?links=false&paging=false',
 			scope: this,
 			success: function(r) {
 				legends = Ext.decode(r.responseText).mapLegends;
@@ -1283,9 +1298,9 @@
 					bounds.push(legends[i].endValue);
 				}
 
-				this.tmpModel.colorInterpolation = colors;
-				this.tmpModel.bounds = bounds;
-                this.tmpModel.legendNames = names;
+				this.tmpView.extended.colorInterpolation = colors;
+				this.tmpView.extended.bounds = bounds;
+                this.tmpView.extended.legendNames = names;
 
 				if (fn) {
 					fn.call(this);
@@ -1296,20 +1311,11 @@
 	
 	getLegendConfig: function() {
 		return {
-			what: this.tmpModel.valueType === 'indicator' ? this.cmp.indicator.getRawValue() : this.cmp.dataElement.getRawValue(),
-			when: this.cmp.period.getRawValue(),
-			where: this.tmpModel.levelName + ' / ' + this.tmpModel.parentName
+			what: this.tmpView.valueType === 'indicator' ? this.tmpView.indicator.name : this.tmpView.dataElement.name,
+			when: this.tmpView.period.id, //todo name
+			where: this.tmpView.organisationUnitLevel.name + ' / ' + this.tmpView.parentOrganisationUnit.name
 		};
 	},
-        //,
-        
-        //getImageExportValues: function() {
-			//return {
-				//mapValueTypeValue: this.cmp.valueType.getValue() == GIS.conf.map_value_type_indicator ?
-					//this.cmp.indicator.getRawValue() : this.cmp.dataElement.getRawValue(),
-				//dateValue: this.cmp.period.getRawValue()
-			//};
-		//},
 		
 	reset: function() {
 		
@@ -1348,10 +1354,12 @@
 			this.cmp.labelWindow.destroy();
 		}
 		
-		// Model
-		this.config = {};
-		this.tmpModel = {};
-		this.model = {};
+		// View
+		this.config = {
+			extended: {}
+		};
+		this.tmpView = {};
+		this.view = {};
 		
 		// Layer
 		this.layer.destroyFeatures();
@@ -1361,274 +1369,281 @@
 		
 		// Legend
 		document.getElementById(this.legendDiv).innerHTML = '';
-	},
-	
-	setConfig: function(config) {
-		this.config.valueType = config.valueType;
-		this.config.indicatorGroup = config.indicatorGroup;
-		this.config.indicator = config.indicator;
-		this.config.dataElementGroup = config.dataElementGroup;
-		this.config.dataElement = config.dataElement;
-		this.config.periodType = config.periodType;
-		this.config.period = config.period;
-		this.config.legendType = config.legendType;
-		this.config.legendSet = config.legendSet;
-		this.config.classes = config.classes;
-		this.config.method = config.method;
-		this.config.colorLow = config.colorLow;
-		this.config.colorHigh = config.colorHigh;
-		this.config.radiusLow = config.radiusLow;
-		this.config.radiusHigh = config.radiusHigh;
-		this.config.level = config.level;
-		this.config.levelName = config.levelName;
-		this.config.parentId = config.parentId;
-		this.config.parentName = config.parentName;
-		this.config.parentLevel = config.parentLevel;
-		this.config.parentPath = config.parentPath;
-		this.config.updateOrganisationUnit = true;
-		this.config.updateData = false;
-		this.config.updateLegend = false;
-		this.config.updateGui = true;
+		this.layer.legend.collapse();
 	},
 	
 	setGui: function() {
-		var model = this.tmpModel,
+		var view = this.tmpView,
 			that = this;
 		
 		// Value type
-		this.cmp.valueType.setValue(model.valueType);
+		this.cmp.valueType.setValue(view.valueType);
 		
 		// Indicator and data element
-		this.toggler.valueType(model.valueType);
+		this.toggler.valueType(view.valueType);
 		
-		var	indeGroupView = model.valueType === GIS.conf.finals.dimension.indicator.id ? this.cmp.indicatorGroup : this.cmp.dataElementGroup,
+		var	indeGroupView = view.valueType === GIS.conf.finals.dimension.indicator.id ? this.cmp.indicatorGroup : this.cmp.dataElementGroup,
 			indeGroupStore = indeGroupView.store,
-			indeGroupValue = model.valueType === GIS.conf.finals.dimension.indicator.id ? model.indicatorGroup : model.dataElementGroup,
+			indeGroupValue = view.valueType === GIS.conf.finals.dimension.indicator.id ? view.indicatorGroup.id : view.dataElementGroup.id,
 			
-			indeStore = model.valueType === GIS.conf.finals.dimension.indicator.id ? this.store.indicatorsByGroup : this.store.dataElementsByGroup,
-			indeView = model.valueType === GIS.conf.finals.dimension.indicator.id ? this.cmp.indicator : this.cmp.dataElement,
-			indeValue = model.valueType === GIS.conf.finals.dimension.indicator.id ? model.indicator : model.dataElement;
+			indeStore = view.valueType === GIS.conf.finals.dimension.indicator.id ? this.store.indicatorsByGroup : this.store.dataElementsByGroup,
+			indeView = view.valueType === GIS.conf.finals.dimension.indicator.id ? this.cmp.indicator : this.cmp.dataElement,
+			indeValue = view.valueType === GIS.conf.finals.dimension.indicator.id ? view.indicator.id : view.dataElement.id;
 			
 		indeGroupStore.loadFn( function() {
 			indeGroupView.setValue(indeGroupValue);
 		});
 		
-		indeStore.proxy.url = GIS.conf.url.path_api + model.valueType + 'Groups/' + indeGroupValue + '.json?links=false&paging=false';
+		indeStore.proxy.url = GIS.conf.url.path_api + view.valueType + 'Groups/' + indeGroupValue + '.json?links=false&paging=false';
 		indeStore.loadFn( function() {
 			indeView.setValue(indeValue);
 		});
 		
 		// Period
-		this.cmp.periodType.setValue(model.periodType);
+		this.cmp.periodType.setValue(view.periodType);
 		this.cmp.periodType.fireEvent('select');
-		this.cmp.period.setValue(model.period);
+		this.cmp.period.setValue(view.period.id);
 		
 		// Legend
-		this.cmp.legendType.setValue(model.legendType);
-		this.toggler.legendType(model.legendType);
+		this.cmp.legendType.setValue(view.legendType);
+		this.toggler.legendType(view.legendType);
 		
-		if (model.legendType === GIS.conf.finals.widget.legendtype_automatic) {
-			this.cmp.classes.setValue(model.classes);
-			this.cmp.method.setValue(model.method);
-			this.cmp.colorLow.setValue(model.colorLow);
-			this.cmp.colorHigh.setValue(model.colorHigh);
-			this.cmp.radiusLow.setValue(model.radiusLow);
-			this.cmp.radiusHigh.setValue(model.radiusHigh);
+		if (view.legendType === GIS.conf.finals.widget.legendtype_automatic) {
+			this.cmp.classes.setValue(view.classes);
+			this.cmp.method.setValue(view.method);
+			this.cmp.colorLow.setValue(view.colorLow);
+			this.cmp.colorHigh.setValue(view.colorHigh);
+			this.cmp.radiusLow.setValue(view.radiusLow);
+			this.cmp.radiusHigh.setValue(view.radiusHigh);
 		}
-		else if (model.legendType === GIS.conf.finals.widget.legendtype_predefined) {
+		else if (view.legendType === GIS.conf.finals.widget.legendtype_predefined) {
 			GIS.store.legendSets.loadFn( function() {
-				that.cmp.legendSet.setValue(model.legendSet);
+				that.cmp.legendSet.setValue(view.legendSet.id);
 			});
 		}
 		
 		// Level and parent
 		GIS.store.organisationUnitLevels.loadFn( function() {
-			that.cmp.level.setValue(model.level);
+			that.cmp.level.setValue(view.organisationUnitLevel.id);
 		});
 		
-		this.cmp.parent.selectTreePath('/root' + model.parentPath);
+		this.cmp.parent.selectTreePath('/root' + view.parentGraph);
 	},
     	
-	getModel: function() {
+	getView: function() {
 		var level = this.cmp.level,
-			parent = this.cmp.parent.getSelectionModel().getSelection();
+			parent = this.cmp.parent.getSelectionModel().getSelection(),
+			view;
+				
 		parent = parent.length ? parent : [{raw: GIS.init.rootNodes[0]}];
 		
-		var model = {
+		view = {
 			valueType: this.cmp.valueType.getValue(),
-			indicatorGroup: this.cmp.indicatorGroup.getValue(),
-			indicator: this.cmp.indicator.getValue(),
-			dataElementGroup: this.cmp.dataElementGroup.getValue(),
-			dataElement: this.cmp.dataElement.getValue(),
+			indicatorGroup: {
+				id: this.cmp.indicatorGroup.getValue(),
+				name: this.cmp.indicatorGroup.getRawValue()
+			},
+			indicator: {
+				id: this.cmp.indicator.getValue(),
+				name: this.cmp.indicator.getRawValue()
+			},
+			dataElementGroup: {
+				id: this.cmp.dataElementGroup.getValue(),
+				name: this.cmp.dataElementGroup.getRawValue()
+			},
+			dataElement: {
+				id: this.cmp.dataElement.getValue(),
+				name: this.cmp.dataElement.getRawValue()
+			},
 			periodType: this.cmp.periodType.getValue(),
-			period: this.cmp.period.getValue(),
+			period: {
+				id: this.cmp.period.getValue()
+			},
 			legendType: this.cmp.legendType.getValue(),
-			legendSet: this.cmp.legendSet.getValue(),
-			classes: this.cmp.classes.getValue(),
-			method: this.cmp.method.getValue(),
+			legendSet: {
+				id: this.cmp.legendSet.getValue(),
+				name: this.cmp.legendSet.getRawValue()
+			},
+			classes: parseInt(this.cmp.classes.getValue()),
+			method: parseInt(this.cmp.method.getValue()),
 			colorLow: this.cmp.colorLow.getValue(),
 			colorHigh: this.cmp.colorHigh.getValue(),
-			colors: this.getColors(),
 			radiusLow: parseInt(this.cmp.radiusLow.getValue()),
 			radiusHigh: parseInt(this.cmp.radiusHigh.getValue()),
-			level: level.getValue(),
-			levelName: level.getRawValue(),
-			parentId: parent[0].raw.id,
-			parentName: parent[0].raw.text,
+			organisationUnitLevel: {
+				id: level.getValue(),
+				name: level.getRawValue(),
+				level: GIS.store.organisationUnitLevels.getById(level.getValue()).data.level
+			},
+			parentOrganisationUnit: {
+				id: parent[0].raw.id,
+				name: parent[0].raw.text
+			},
 			parentLevel: parent[0].raw.level,
-			parentPath: parent[0].raw.path,
-			updateOrganisationUnit: false,
-			updateData: false,
-			updateLegend: false,
-			updateGui: false
-		};
-		
-		model.valueType = this.config.valueType || model.valueType;
-		model.indicatorGroup = this.config.indicatorGroup || model.indicatorGroup;
-		model.indicator = this.config.indicator || model.indicator;
-		model.dataElementGroup = this.config.dataElementGroup || model.dataElementGroup;
-		model.dataElement = this.config.dataElement || model.dataElement;
-		model.periodType = this.config.periodType || model.periodType;
-		model.period = this.config.period || model.period;
-		model.legendType = this.config.legendType || model.legendType;
-		model.legendSet = this.config.legendSet || model.legendSet;
-		model.classes = this.config.classes || model.classes;
-		model.method = this.config.method || model.method;
-		model.colorLow = this.config.colorLow || model.colorLow;
-		model.colorHigh = this.config.colorHigh || model.colorHigh;
-		model.colors = this.getColors(model.colorLow, model.colorHigh);
-		model.radiusLow = this.config.radiusLow || model.radiusLow;
-		model.radiusHigh = this.config.radiusHigh || model.radiusHigh;
-		model.level = this.config.level || model.level;
-		model.levelName = this.config.levelName || model.levelName;
-		model.parentId = this.config.parentId || model.parentId;
-		model.parentName = this.config.parentName || model.parentName;
-		model.parentLevel = this.config.parentLevel || model.parentLevel;
-		model.parentPath = this.config.parentPath || null;
-		model.updateOrganisationUnit = Ext.isDefined(this.config.updateOrganisationUnit) ? this.config.updateOrganisationUnit : false;
-		model.updateData = Ext.isDefined(this.config.updateData) ? this.config.updateData : false;
-		model.updateLegend = Ext.isDefined(this.config.updateLegend) ? this.config.updateLegend : false;
-		model.updateGui = Ext.isDefined(this.config.updateGui) ? this.config.updateGui : false;
-		
-		return model;
-	},
-	
-	validateModel: function(model) {
-		if (model.valueType === GIS.conf.finals.dimension.indicator.id) {
-			if (!model.indicatorGroup || !Ext.isString(model.indicatorGroup)) {
-				GIS.logg.push([model.indicatorGroup, this.xtype + '.indicatorGroup: string']);
+			parentGraph: parent[0].raw.path,
+			opacity: this.layer.item.getOpacity()
+		};
+		
+		return view;
+	},
+	
+	extendView: function(view) {
+		var conf = this.config;
+		view = view || {};
+
+		view.valueType = conf.valueType || view.valueType;
+		view.indicatorGroup = conf.indicatorGroup || view.indicatorGroup;
+		view.indicator = conf.indicator || view.indicator;
+		view.dataElementGroup = conf.dataElementGroup || view.dataElementGroup;
+		view.dataElement = conf.dataElement || view.dataElement;
+		view.periodType = conf.periodType || view.periodType;
+		view.period = conf.period || view.period;
+		view.legendType = conf.legendType || view.legendType;
+		view.legendSet = conf.legendSet || view.legendSet;
+		view.classes = conf.classes || view.classes;
+		view.method = conf.method || view.method;
+		view.colorLow = conf.colorLow || view.colorLow;
+		view.colorHigh = conf.colorHigh || view.colorHigh;
+		view.radiusLow = conf.radiusLow || view.radiusLow;
+		view.radiusHigh = conf.radiusHigh || view.radiusHigh;
+		view.organisationUnitLevel = conf.organisationUnitLevel || view.organisationUnitLevel;
+		view.parentOrganisationUnit = conf.parentOrganisationUnit || view.parentOrganisationUnit;
+		view.parentLevel = conf.parentLevel || view.parentLevel;
+		view.parentGraph = conf.parentGraph || view.parentGraph;
+		view.opacity = conf.opacity || view.opacity;
+		
+		view.extended = {
+			colors: this.getColors(view.colorLow, view.colorHigh),
+			updateOrganisationUnit: Ext.isDefined(conf.extended.updateOrganisationUnit) ? conf.extended.updateOrganisationUnit : false,
+			updateData: Ext.isDefined(conf.extended.updateData) ? conf.extended.updateData : false,
+			updateLegend: Ext.isDefined(conf.extended.updateLegend) ? conf.extended.updateLegend : false,
+			updateGui: Ext.isDefined(conf.extended.updateGui) ? conf.extended.updateGui : false
+		};
+		
+		return view;
+	},
+	
+	validateView: function(view) {
+		if (view.valueType === GIS.conf.finals.dimension.indicator.id) {
+			if (!view.indicatorGroup.id || !Ext.isString(view.indicatorGroup.id)) {
+				GIS.logg.push([view.indicatorGroup.id, this.xtype + '.indicatorGroup.id: string']);
 				//alert("validation failed"); //todo
 				return false;
 			}
-			if (!model.indicator || !Ext.isString(model.indicator)) {
-				GIS.logg.push([model.indicator, this.xtype + '.indicator: string']);
+			if (!view.indicator.id || !Ext.isString(view.indicator.id)) {
+				GIS.logg.push([view.indicator.id, this.xtype + '.indicator.id: string']);
 				alert('No indicator selected'); //todo //i18n
 				return false;
 			}
 		}
-		else if (model.valueType === GIS.conf.finals.dimension.dataElement.id) {
-			if (!model.dataElementGroup || !Ext.isString(model.dataElementGroup)) {
-				GIS.logg.push([model.dataElementGroup, this.xtype + '.dataElementGroup: string']);
+		else if (view.valueType === GIS.conf.finals.dimension.dataElement.id) {
+			if (!view.dataElementGroup.id || !Ext.isString(view.dataElementGroup.id)) {
+				GIS.logg.push([view.dataElementGroup.id, this.xtype + '.dataElementGroup.id: string']);
 				//alert("validation failed"); //todo
 				return false;
 			}
-			if (!model.dataElement || !Ext.isString(model.dataElement)) {
-				GIS.logg.push([model.dataElement, this.xtype + '.dataElement: string']);
+			if (!view.dataElement.id || !Ext.isString(view.dataElement.id)) {
+				GIS.logg.push([view.dataElement.id, this.xtype + '.dataElement.id: string']);
 				alert('No data element selected'); //todo //i18n
 				return false;
 			}
 		}
 		
-		if (!model.periodType || !Ext.isString(model.periodType)) {
-			GIS.logg.push([model.periodType, this.xtype + '.periodType: string']);
+		if (!view.periodType || !Ext.isString(view.periodType)) {
+			GIS.logg.push([view.periodType, this.xtype + '.periodType: string']);
 				//alert("validation failed"); //todo
 			return false;
 		}
-		if (!model.period || !Ext.isString(model.period)) {
-			GIS.logg.push([model.period, this.xtype + '.period: string']);
+		if (!view.period.id || !Ext.isString(view.period.id)) {
+			GIS.logg.push([view.period.id, this.xtype + '.period.id: string']);
 				alert('No period selected'); //todo //i18n
 			return false;
 		}
 		
-		if (model.legendType === GIS.conf.finals.widget.legendtype_automatic) {
-			if (!model.classes || !Ext.isNumber(model.classes)) {
-				GIS.logg.push([model.classes, this.xtype + '.classes: number']);
-				//alert("validation failed"); //todo
-				return false;
-			}
-			if (!model.method || !Ext.isNumber(model.method)) {
-				GIS.logg.push([model.method, this.xtype + '.method: number']);
-				//alert("validation failed"); //todo
-				return false;
-			}
-			if (!model.colorLow || !Ext.isString(model.colorLow)) {
-				GIS.logg.push([model.colorLow, this.xtype + '.colorLow: string']);
-				//alert("validation failed"); //todo
-				return false;
-			}
-			if (!model.radiusLow || !Ext.isNumber(model.radiusLow)) {
-				GIS.logg.push([model.radiusLow, this.xtype + '.radiusLow: number']);
-				//alert("validation failed"); //todo
-				return false;
-			}
-			if (!model.colorHigh || !Ext.isString(model.colorHigh)) {
-				GIS.logg.push([model.colorHigh, this.xtype + '.colorHigh: string']);
-				//alert("validation failed"); //todo
-				return false;
-			}
-			if (!model.radiusHigh || !Ext.isNumber(model.radiusHigh)) {
-				GIS.logg.push([model.radiusHigh, this.xtype + '.radiusHigh: number']);
+		if (view.legendType === GIS.conf.finals.widget.legendtype_automatic) {
+			if (!view.classes || !Ext.isNumber(view.classes)) {
+				GIS.logg.push([view.classes, this.xtype + '.classes: number']);
+				//alert("validation failed"); //todo
+				return false;
+			}
+			if (!view.method || !Ext.isNumber(view.method)) {
+				GIS.logg.push([view.method, this.xtype + '.method: number']);
+				//alert("validation failed"); //todo
+				return false;
+			}
+			if (!view.colorLow || !Ext.isString(view.colorLow)) {
+				GIS.logg.push([view.colorLow, this.xtype + '.colorLow: string']);
+				//alert("validation failed"); //todo
+				return false;
+			}
+			if (!view.radiusLow || !Ext.isNumber(view.radiusLow)) {
+				GIS.logg.push([view.radiusLow, this.xtype + '.radiusLow: number']);
+				//alert("validation failed"); //todo
+				return false;
+			}
+			if (!view.colorHigh || !Ext.isString(view.colorHigh)) {
+				GIS.logg.push([view.colorHigh, this.xtype + '.colorHigh: string']);
+				//alert("validation failed"); //todo
+				return false;
+			}
+			if (!view.radiusHigh || !Ext.isNumber(view.radiusHigh)) {
+				GIS.logg.push([view.radiusHigh, this.xtype + '.radiusHigh: number']);
 				//alert("validation failed"); //todo
 				return false;
 			}
 		}
-		else if (model.legendType === GIS.conf.finals.widget.legendtype_predefined) {			
-			if (!model.legendSet || !Ext.isString(model.legendSet)) {
-				GIS.logg.push([model.legendSet, this.xtype + '.legendSet: string']);
+		else if (view.legendType === GIS.conf.finals.widget.legendtype_predefined) {
+			if (!view.legendSet.id || !Ext.isString(view.legendSet.id)) {
+				GIS.logg.push([view.legendSet.id, this.xtype + '.legendSet.id: string']);
 				alert('No legend set selected'); //todo //i18n
 				return false;
 			}
 		}
 		
-		if (!model.level || !Ext.isNumber(model.level)) {
-			GIS.logg.push([model.level, this.xtype + '.level: number']);
+		if (!view.organisationUnitLevel.id || !Ext.isString(view.organisationUnitLevel.id)) {
+			GIS.logg.push([view.organisationUnitLevel.id, this.xtype + '.organisationUnitLevel.id: string']);
 				alert('No level selected'); //todo
 			return false;
 		}
-		if (!model.levelName || !Ext.isString(model.levelName)) {
-			GIS.logg.push([model.levelName, this.xtype + '.levelName: string']);
-				//alert("validation failed"); //todo
-			return false;
-		}
-		if (!model.parentId || !Ext.isString(model.parentId)) {
-			GIS.logg.push([model.parentId, this.xtype + '.parentId: string']);
+		if (!view.organisationUnitLevel.name || !Ext.isString(view.organisationUnitLevel.name)) {
+			GIS.logg.push([view.organisationUnitLevel.name, this.xtype + '.organisationUnitLevel.name: string']);
+				//alert("validation failed"); //todo
+			return false;
+		}
+		if (!view.organisationUnitLevel.level || !Ext.isNumber(view.organisationUnitLevel.level)) {
+			GIS.logg.push([view.organisationUnitLevel.level, this.xtype + '.organisationUnitLevel.level: number']);
+				//alert("validation failed"); //todo
+			return false;
+		}
+		if (!view.parentOrganisationUnit.id || !Ext.isString(view.parentOrganisationUnit.id)) {
+			GIS.logg.push([view.parentOrganisationUnit.id, this.xtype + '.parentOrganisationUnit.id: string']);
 				alert('No parent organisation unit selected'); //todo
 			return false;
 		}
-		if (!model.parentName || !Ext.isString(model.parentName)) {
-			GIS.logg.push([model.parentName, this.xtype + '.parentName: string']);
-				//alert("validation failed"); //todo
-			return false;
-		}
-		if (!model.parentLevel || !Ext.isNumber(model.parentLevel)) {
-			GIS.logg.push([model.parentLevel, this.xtype + '.parentLevel: number']);
-				//alert("validation failed"); //todo
-			return false;
-		}
-		if (model.parentLevel > model.level) {
-			GIS.logg.push([model.parentLevel, model.level, this.xtype + '.parentLevel: number <= ' + this.xtype + '.level']);
-				alert('Level cannot be higher than parent level'); //todo
-			return false;
-		}
-		
-		if (!model.parentPath && model.updateGui) {
-			GIS.logg.push([model.parentpath, this.xtype + '.parentpath: string']);
-				//alert("validation failed"); //todo
-			return false;
-		}
-		
-		if (!model.updateOrganisationUnit && !model.updateData && !model.updateLegend) {
-			GIS.logg.push([model.updateOrganisationUnit, model.updateData, model.updateLegend, this.xtype + '.update ou/data/legend: true||true||true']);
+		if (!view.parentOrganisationUnit.name || !Ext.isString(view.parentOrganisationUnit.name)) {
+			GIS.logg.push([view.parentOrganisationUnit.name, this.xtype + '.parentOrganisationUnit.name: string']);
+				//alert("validation failed"); //todo
+			return false;
+		}
+		if (!view.parentLevel || !Ext.isNumber(view.parentLevel)) {
+			GIS.logg.push([view.parentLevel, this.xtype + '.parentLevel: number']);
+				//alert("validation failed"); //todo
+			return false;
+		}
+		if (!view.parentGraph || !Ext.isString(view.parentGraph)) {
+			GIS.logg.push([view.parentGraph, this.xtype + '.parentGraph: string']);
+				//alert("validation failed"); //todo
+			return false;
+		}
+		
+		if (view.parentOrganisationUnit.level > view.organisationUnitLevel.level) {
+			GIS.logg.push([view.parentOrganisationUnit.level, view.organisationUnitLevel.level, this.xtype + '.parentOrganisationUnit.level: number <= ' + this.xtype + '.organisationUnitLevel.level']);
+				alert('Orgunit level cannot be higher than parent level'); //todo
+			return false;
+		}
+				
+		if (!view.extended.updateOrganisationUnit && !view.extended.updateData && !view.extended.updateLegend) {
+			GIS.logg.push([view.extended.updateOrganisationUnit, view.extended.updateData, view.extended.updateLegend, this.xtype + '.extended.update ou/data/legend: true||true||true']);
 			return false;
 		}
 		
@@ -1637,27 +1652,27 @@
 	
     loadOrganisationUnits: function() {
         var url = GIS.conf.url.path_gis + 'getGeoJson.action?' +
-            'parentId=' + this.tmpModel.parentId +
-            '&level=' + this.tmpModel.level;
+            'parentId=' + this.tmpView.parentOrganisationUnit.id +
+            '&level=' + this.tmpView.organisationUnitLevel.id;
         this.setUrl(url);
     },
     
     loadData: function() {
-		var type = this.tmpModel.valueType,
-			dataUrl = '../api/mapValues/' + GIS.conf.finals.dimension[type].param + '.json',
+		var type = this.tmpView.valueType,
+			dataUrl = 'mapValues/' + GIS.conf.finals.dimension[type].param + '.json',
 			indicator = GIS.conf.finals.dimension.indicator,
 			dataElement = GIS.conf.finals.dimension.dataElement,
 			period = GIS.conf.finals.dimension.period,
 			organisationUnit = GIS.conf.finals.dimension.organisationUnit,
 			params = {};
 		
-		params[type === indicator.id ? indicator.param : dataElement.param] = this.tmpModel[type];
-		params[period.param] = this.tmpModel.period;
-		params[organisationUnit.param] = this.tmpModel.parentId;
-		params.level = this.tmpModel.level;
+		params[type === indicator.id ? indicator.param : dataElement.param] = this.tmpView[type].id;
+		params[period.param] = this.tmpView.period.id;
+		params[organisationUnit.param] = this.tmpView.parentOrganisationUnit.id;
+		params.le = this.tmpView.organisationUnitLevel.id;
 		
 		Ext.Ajax.request({
-			url: GIS.conf.url.path_gis + dataUrl,
+			url: GIS.conf.url.path_api + dataUrl,
 			params: params,
 			disableCaching: false,
 			scope: this,
@@ -1668,7 +1683,7 @@
 					features = [];
 					
 				if (values.length === 0) {
-					alert('No aggregated data values found'); //todo Ext.message.msg(false, GIS.i18n.current_selection_no_data);
+					alert('No aggregated data values found'); //todo
 					GIS.mask.hide();
 					return;
 				}
@@ -1707,11 +1722,11 @@
 			fn = function() {
 				options = {
 					indicator: GIS.conf.finals.widget.value,
-					method: that.tmpModel.method,
-					numClasses: that.tmpModel.classes,
-					colors: that.tmpModel.colors,
-					minSize: that.tmpModel.radiusLow,
-					maxSize: that.tmpModel.radiusHigh
+					method: that.tmpView.method,
+					numClasses: that.tmpView.classes,
+					colors: that.tmpView.extended.colors,
+					minSize: that.tmpView.radiusLow,
+					maxSize: that.tmpView.radiusHigh
 				};
 
 				that.coreComp.applyClassification(options);
@@ -1719,8 +1734,14 @@
 				
 				that.afterLoad();
 			};
+			
+		this.tmpView.extended.legendConfig = {
+			what: this.tmpView.valueType === 'indicator' ? this.tmpView.indicator.name : this.tmpView.dataElement.name,
+			when: this.tmpView.period.id, //todo name
+			where: this.tmpView.organisationUnitLevel.name + ' / ' + this.tmpView.parentOrganisationUnit.name
+		};
 		
-		if (this.tmpModel.legendType === GIS.conf.finals.widget.legendtype_predefined) {
+		if (this.tmpView.legendType === GIS.conf.finals.widget.legendtype_predefined) {
 			this.setPredefinedLegend(fn);
 		}
 		else {
@@ -1728,24 +1749,32 @@
 		}
 	},
 	
-    execute: function() {
-		this.tmpModel = this.getModel();
-		
-		if (!this.validateModel(this.tmpModel)) {
+    execute: function(view) {
+		if (view) {
+			this.config.extended.updateOrganisationUnit = true;
+			this.config.extended.updateGui = true;
+		}
+		else {
+			view = this.getView();
+		}
+		
+		this.tmpView = this.extendView(view);
+		
+		if (!this.validateView(this.tmpView)) {
 			return;
 		}
-				
+		
 		GIS.mask.msg = GIS.i18n.loading;
 		GIS.mask.show();
 		
-		if (this.tmpModel.updateGui) {
+		if (this.tmpView.extended.updateGui) {
 			this.setGui();
 		}
 		
-		if (this.tmpModel.updateOrganisationUnit) {
+		if (this.tmpView.extended.updateOrganisationUnit) {
 			this.loadOrganisationUnits();
 		}
-		else if (this.tmpModel.updateData) {
+		else if (this.tmpView.extended.updateData) {
 			this.loadData();
 		}
 		else {
@@ -1754,11 +1783,13 @@
 	},
 	
 	afterLoad: function() {
-		this.model = this.tmpModel;
-		this.config = {};
+		this.view = this.tmpView;
+		this.config = {
+			extended: {}
+		};
 		
 		// Layer item
-		this.layer.item.setValue(true);
+		this.layer.item.setValue(true, this.view.opacity);
 		
 		// Layer menu
 		this.menu.enableItems();
@@ -1770,19 +1801,16 @@
 		if (this.cmp.filterWindow && this.cmp.filterWindow.isVisible()) { 
 			this.cmp.filterWindow.filter();
 		}
+		
+		// Legend
+		GIS.cmp.region.east.doLayout();
+		this.layer.legend.expand();
         
-        // Set favorite position, else zoom to visible extent
-        if (this.model.longitude && this.model.latitude && this.model.zoom) {
-			var lonLat = GIS.util.map.getLonLatByXY(this.model.longitude, this.model.latitude);
-			GIS.map.setCenter(lonLat, this.model.zoom);
-		}
-		else if (this.model.updateOrganisationUnit) {
+        // Zoom to visible extent if not loading a favorite
+        if (!GIS.map.map) {
 			GIS.util.map.zoomToVisibleExtent();
 		}
 		
-		// Legend
-		GIS.cmp.region.east.doLayout();
-		
         GIS.mask.hide();
 	},
     

=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/mapfish/widgets/geostat/Thematic2.js'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/mapfish/widgets/geostat/Thematic2.js	2012-10-25 12:21:55 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/mapfish/widgets/geostat/Thematic2.js	2012-11-01 12:20:39 +0000
@@ -42,11 +42,13 @@
     
     // Properties
     
-    config: {},
-    
-    tmpModel: {},
-    
-    model: {},
+    config: {
+		extended: {}
+	},
+    
+    tmpView: {},
+    
+    view: {},
     
     cmp: {},
     
@@ -323,7 +325,7 @@
                 select: {
                     scope: this,
                     fn: function(cb) {
-						this.config.updateData = true;
+						this.config.extended.updateData = true;
 						this.toggler.valueType(cb.getValue());
                     }
                 }
@@ -346,7 +348,7 @@
                 select: {
                     scope: this,
                     fn: function(cb) {
-						this.config.updateData = true;
+						this.config.extended.updateData = true;
                         this.cmp.indicator.clearValue();
                         
                         var store = this.cmp.indicator.store;
@@ -377,12 +379,12 @@
 				if (this.store.getCount() > 0) {
 					this.setValue(this.store.getAt(0).data.id);
 				}
-				this.scope.config.updateData = true;
+				this.scope.config.extended.updateData = true;
 			},
             store: this.store.indicatorsByGroup,
             listeners: {
                 select: function() {
-					this.scope.config.updateData = true;
+					this.scope.config.extended.updateData = true;
                 }
             }
         });
@@ -435,16 +437,16 @@
 				if (this.store.getCount() > 0) {
 					this.setValue(this.store.getAt(0).data.id);
 				}
-				this.scope.config.updateData = true;
+				this.scope.config.extended.updateData = true;
 			},
             store: this.store.dataElementsByGroup,
             listeners: {
                 select: function() {
-					this.scope.config.updateData = true;
+					this.scope.config.extended.updateData = true;
                 }
 			}
         });
-        
+                
         this.cmp.periodType = Ext.create('Ext.form.field.ComboBox', {
             editable: false,
             valueField: 'id',
@@ -489,13 +491,13 @@
             scope: this,
             selectFirst: function() {
 				this.setValue(this.store.getAt(0).data.id);
-				this.scope.config.updateData = true;
+				this.scope.config.extended.updateData = true;
 			},
 			listeners: {
 				select: {
 					scope: this,
 					fn: function() {
-						this.config.updateData = true;
+						this.config.extended.updateData = true;
 					}
 				}
 			}	
@@ -553,7 +555,7 @@
                     fn: function(cb) {
 						this.toggler.legendType(cb.getValue());
 						
-						this.config.updateLegend = true;
+						this.config.extended.updateLegend = true;
                     }
                 }
             }
@@ -572,7 +574,7 @@
 				select: {
 					scope: this,
 					fn: function() {
-						this.config.updateLegend = true;
+						this.config.extended.updateLegend = true;
 					}
 				}
 			}
@@ -596,7 +598,7 @@
 				change: {
 					scope: this,
 					fn: function() {
-						this.config.updateLegend = true;
+						this.config.extended.updateLegend = true;
 					}
 				}
 			}
@@ -620,7 +622,7 @@
 				select: {
 					scope: this,
 					fn: function() {
-						this.config.updateLegend = true;
+						this.config.extended.updateLegend = true;
 					}
 				}
 			}
@@ -631,7 +633,7 @@
 			value: 'ff0000',
 			scope: this,
 			menuHandler: function() {
-				this.scope.config.updateLegend = true;
+				this.scope.config.extended.updateLegend = true;
 			}
 		});
         
@@ -640,7 +642,7 @@
 			value: '00ff00',
 			scope: this,
 			menuHandler: function() {
-				this.scope.config.updateLegend = true;
+				this.scope.config.extended.updateLegend = true;
 			}
 		});
         
@@ -653,7 +655,7 @@
 				change: {
 					scope: this,
 					fn: function() {
-						this.config.updateLegend = true;
+						this.config.extended.updateLegend = true;
 					}
 				}
 			}
@@ -668,7 +670,7 @@
 				change: {
 					scope: this,
 					fn: function() {
-						this.config.updateLegend = true;
+						this.config.extended.updateLegend = true;
 					}
 				}
 			}
@@ -679,7 +681,7 @@
         this.cmp.level = Ext.create('Ext.form.field.ComboBox', {
             fieldLabel: GIS.i18n.level,
             editable: false,
-            valueField: 'level',
+            valueField: 'id',
             displayField: 'name',
             mode: 'remote',
             forceSelection: true,
@@ -694,7 +696,7 @@
 				select: {
 					scope: this,
 					fn: function() {
-						this.config.updateOrganisationUnit = true;
+						this.config.extended.updateOrganisationUnit = true;
 					}
 				}
 			}
@@ -735,7 +737,7 @@
 				select: {
 					scope: this,
 					fn: function() {
-						this.config.updateOrganisationUnit = true;
+						this.config.extended.updateOrganisationUnit = true;
 					}
 				},
 				afterrender: function() {					
@@ -1140,26 +1142,39 @@
 					var store = GIS.store.organisationUnitLevels;
 					
 					if (direction === 'up') {
-						var rootNode = GIS.init.rootNodes[0];
+						var rootNode = GIS.init.rootNodes[0],
+							level = store.getAt(store.find('level', that.view.organisationUnitLevel.level - 1));
 						
-						that.config.level = that.model.level - 1;
-						that.config.levelName = store.getAt(store.find('level', that.config.level)).data.name;
-						that.config.parentId = rootNode.id;
-						that.config.parentName = rootNode.text;
-						that.config.parentLevel = rootNode.level;
-						that.config.parentPath = '/' + GIS.init.rootNodes[0].id;
+						that.config.organisationUnitLevel = {
+							id: level.data.id,
+							name: level.data.name,
+							level: level.data.level
+						};
+						that.config.parentOrganisationUnit = {
+							id: rootNode.id,
+							name: rootNode.text,
+							level: rootNode.level
+						};
+						that.config.parentGraph = '/' + GIS.init.rootNodes[0].id;
 					}
 					else if (direction === 'down') {
-						that.config.level = that.model.level + 1;
-						that.config.levelName = store.getAt(store.find('level', that.config.level)).data.name;
-						that.config.parentId = feature.attributes.id;
-						that.config.parentName = feature.attributes.name;
-						that.config.parentLevel = that.model.level;
-						that.config.parentPath = feature.attributes.path;
+						var level = store.getAt(store.find('level', that.view.organisationUnitLevel.level + 1));
+						
+						that.config.organisationUnitLevel = {
+							id: level.data.id,
+							name: level.data.name,
+							level: level.data.level
+						};
+						that.config.parentOrganisationUnit = {
+							id: feature.attributes.id,
+							name: feature.attributes.name,
+							level: that.view.organisationUnitLevel.level
+						};
+						that.config.parentGraph = feature.attributes.path;
 					}
 					
-					that.config.updateOrganisationUnit = true;
-					that.config.updateGui = true;
+					that.config.extended.updateOrganisationUnit = true;
+					that.config.extended.updateGui = true;
 					
 					that.execute();
 				});
@@ -1170,7 +1185,7 @@
 				Ext.create('Ext.menu.Item', {
 					text: 'Float up',
 					iconCls: 'gis-menu-item-icon-float',
-					disabled: !that.model.hasCoordinatesUp,
+					disabled: !that.view.extended.hasCoordinatesUp,
 					scope: this,
 					handler: function() {
 						drill('up');
@@ -1264,7 +1279,7 @@
 			legends;
 		
 		Ext.Ajax.request({
-			url: GIS.conf.url.path_api + 'mapLegendSets/' + this.tmpModel.legendSet + '.json?links=false&paging=false',
+			url: GIS.conf.url.path_api + 'mapLegendSets/' + this.tmpView.legendSet.id + '.json?links=false&paging=false',
 			scope: this,
 			success: function(r) {
 				legends = Ext.decode(r.responseText).mapLegends;
@@ -1283,9 +1298,9 @@
 					bounds.push(legends[i].endValue);
 				}
 
-				this.tmpModel.colorInterpolation = colors;
-				this.tmpModel.bounds = bounds;
-                this.tmpModel.legendNames = names;
+				this.tmpView.extended.colorInterpolation = colors;
+				this.tmpView.extended.bounds = bounds;
+                this.tmpView.extended.legendNames = names;
 
 				if (fn) {
 					fn.call(this);
@@ -1296,20 +1311,11 @@
 	
 	getLegendConfig: function() {
 		return {
-			what: this.tmpModel.valueType === 'indicator' ? this.cmp.indicator.getRawValue() : this.cmp.dataElement.getRawValue(),
-			when: this.cmp.period.getRawValue(),
-			where: this.tmpModel.levelName + ' / ' + this.tmpModel.parentName
+			what: this.tmpView.valueType === 'indicator' ? this.tmpView.indicator.name : this.tmpView.dataElement.name,
+			when: this.tmpView.period.id, //todo name
+			where: this.tmpView.organisationUnitLevel.name + ' / ' + this.tmpView.parentOrganisationUnit.name
 		};
 	},
-        //,
-        
-        //getImageExportValues: function() {
-			//return {
-				//mapValueTypeValue: this.cmp.valueType.getValue() == GIS.conf.map_value_type_indicator ?
-					//this.cmp.indicator.getRawValue() : this.cmp.dataElement.getRawValue(),
-				//dateValue: this.cmp.period.getRawValue()
-			//};
-		//},
 		
 	reset: function() {
 		
@@ -1348,10 +1354,12 @@
 			this.cmp.labelWindow.destroy();
 		}
 		
-		// Model
-		this.config = {};
-		this.tmpModel = {};
-		this.model = {};
+		// View
+		this.config = {
+			extended: {}
+		};
+		this.tmpView = {};
+		this.view = {};
 		
 		// Layer
 		this.layer.destroyFeatures();
@@ -1361,274 +1369,281 @@
 		
 		// Legend
 		document.getElementById(this.legendDiv).innerHTML = '';
-	},
-	
-	setConfig: function(config) {
-		this.config.valueType = config.valueType;
-		this.config.indicatorGroup = config.indicatorGroup;
-		this.config.indicator = config.indicator;
-		this.config.dataElementGroup = config.dataElementGroup;
-		this.config.dataElement = config.dataElement;
-		this.config.periodType = config.periodType;
-		this.config.period = config.period;
-		this.config.legendType = config.legendType;
-		this.config.legendSet = config.legendSet;
-		this.config.classes = config.classes;
-		this.config.method = config.method;
-		this.config.colorLow = config.colorLow;
-		this.config.colorHigh = config.colorHigh;
-		this.config.radiusLow = config.radiusLow;
-		this.config.radiusHigh = config.radiusHigh;
-		this.config.level = config.level;
-		this.config.levelName = config.levelName;
-		this.config.parentId = config.parentId;
-		this.config.parentName = config.parentName;
-		this.config.parentLevel = config.parentLevel;
-		this.config.parentPath = config.parentPath;
-		this.config.updateOrganisationUnit = true;
-		this.config.updateData = false;
-		this.config.updateLegend = false;
-		this.config.updateGui = true;
+		this.layer.legend.collapse();
 	},
 	
 	setGui: function() {
-		var model = this.tmpModel,
+		var view = this.tmpView,
 			that = this;
 		
 		// Value type
-		this.cmp.valueType.setValue(model.valueType);
+		this.cmp.valueType.setValue(view.valueType);
 		
 		// Indicator and data element
-		this.toggler.valueType(model.valueType);
+		this.toggler.valueType(view.valueType);
 		
-		var	indeGroupView = model.valueType === GIS.conf.finals.dimension.indicator.id ? this.cmp.indicatorGroup : this.cmp.dataElementGroup,
+		var	indeGroupView = view.valueType === GIS.conf.finals.dimension.indicator.id ? this.cmp.indicatorGroup : this.cmp.dataElementGroup,
 			indeGroupStore = indeGroupView.store,
-			indeGroupValue = model.valueType === GIS.conf.finals.dimension.indicator.id ? model.indicatorGroup : model.dataElementGroup,
+			indeGroupValue = view.valueType === GIS.conf.finals.dimension.indicator.id ? view.indicatorGroup.id : view.dataElementGroup.id,
 			
-			indeStore = model.valueType === GIS.conf.finals.dimension.indicator.id ? this.store.indicatorsByGroup : this.store.dataElementsByGroup,
-			indeView = model.valueType === GIS.conf.finals.dimension.indicator.id ? this.cmp.indicator : this.cmp.dataElement,
-			indeValue = model.valueType === GIS.conf.finals.dimension.indicator.id ? model.indicator : model.dataElement;
+			indeStore = view.valueType === GIS.conf.finals.dimension.indicator.id ? this.store.indicatorsByGroup : this.store.dataElementsByGroup,
+			indeView = view.valueType === GIS.conf.finals.dimension.indicator.id ? this.cmp.indicator : this.cmp.dataElement,
+			indeValue = view.valueType === GIS.conf.finals.dimension.indicator.id ? view.indicator.id : view.dataElement.id;
 			
 		indeGroupStore.loadFn( function() {
 			indeGroupView.setValue(indeGroupValue);
 		});
 		
-		indeStore.proxy.url = GIS.conf.url.path_api + model.valueType + 'Groups/' + indeGroupValue + '.json?links=false&paging=false';
+		indeStore.proxy.url = GIS.conf.url.path_api + view.valueType + 'Groups/' + indeGroupValue + '.json?links=false&paging=false';
 		indeStore.loadFn( function() {
 			indeView.setValue(indeValue);
 		});
 		
 		// Period
-		this.cmp.periodType.setValue(model.periodType);
+		this.cmp.periodType.setValue(view.periodType);
 		this.cmp.periodType.fireEvent('select');
-		this.cmp.period.setValue(model.period);
+		this.cmp.period.setValue(view.period.id);
 		
 		// Legend
-		this.cmp.legendType.setValue(model.legendType);
-		this.toggler.legendType(model.legendType);
+		this.cmp.legendType.setValue(view.legendType);
+		this.toggler.legendType(view.legendType);
 		
-		if (model.legendType === GIS.conf.finals.widget.legendtype_automatic) {
-			this.cmp.classes.setValue(model.classes);
-			this.cmp.method.setValue(model.method);
-			this.cmp.colorLow.setValue(model.colorLow);
-			this.cmp.colorHigh.setValue(model.colorHigh);
-			this.cmp.radiusLow.setValue(model.radiusLow);
-			this.cmp.radiusHigh.setValue(model.radiusHigh);
+		if (view.legendType === GIS.conf.finals.widget.legendtype_automatic) {
+			this.cmp.classes.setValue(view.classes);
+			this.cmp.method.setValue(view.method);
+			this.cmp.colorLow.setValue(view.colorLow);
+			this.cmp.colorHigh.setValue(view.colorHigh);
+			this.cmp.radiusLow.setValue(view.radiusLow);
+			this.cmp.radiusHigh.setValue(view.radiusHigh);
 		}
-		else if (model.legendType === GIS.conf.finals.widget.legendtype_predefined) {
+		else if (view.legendType === GIS.conf.finals.widget.legendtype_predefined) {
 			GIS.store.legendSets.loadFn( function() {
-				that.cmp.legendSet.setValue(model.legendSet);
+				that.cmp.legendSet.setValue(view.legendSet.id);
 			});
 		}
 		
 		// Level and parent
 		GIS.store.organisationUnitLevels.loadFn( function() {
-			that.cmp.level.setValue(model.level);
+			that.cmp.level.setValue(view.organisationUnitLevel.id);
 		});
 		
-		this.cmp.parent.selectTreePath('/root' + model.parentPath);
+		this.cmp.parent.selectTreePath('/root' + view.parentGraph);
 	},
     	
-	getModel: function() {
+	getView: function() {
 		var level = this.cmp.level,
-			parent = this.cmp.parent.getSelectionModel().getSelection();
+			parent = this.cmp.parent.getSelectionModel().getSelection(),
+			view;
+				
 		parent = parent.length ? parent : [{raw: GIS.init.rootNodes[0]}];
 		
-		var model = {
+		view = {
 			valueType: this.cmp.valueType.getValue(),
-			indicatorGroup: this.cmp.indicatorGroup.getValue(),
-			indicator: this.cmp.indicator.getValue(),
-			dataElementGroup: this.cmp.dataElementGroup.getValue(),
-			dataElement: this.cmp.dataElement.getValue(),
+			indicatorGroup: {
+				id: this.cmp.indicatorGroup.getValue(),
+				name: this.cmp.indicatorGroup.getRawValue()
+			},
+			indicator: {
+				id: this.cmp.indicator.getValue(),
+				name: this.cmp.indicator.getRawValue()
+			},
+			dataElementGroup: {
+				id: this.cmp.dataElementGroup.getValue(),
+				name: this.cmp.dataElementGroup.getRawValue()
+			},
+			dataElement: {
+				id: this.cmp.dataElement.getValue(),
+				name: this.cmp.dataElement.getRawValue()
+			},
 			periodType: this.cmp.periodType.getValue(),
-			period: this.cmp.period.getValue(),
+			period: {
+				id: this.cmp.period.getValue()
+			},
 			legendType: this.cmp.legendType.getValue(),
-			legendSet: this.cmp.legendSet.getValue(),
-			classes: this.cmp.classes.getValue(),
-			method: this.cmp.method.getValue(),
+			legendSet: {
+				id: this.cmp.legendSet.getValue(),
+				name: this.cmp.legendSet.getRawValue()
+			},
+			classes: parseInt(this.cmp.classes.getValue()),
+			method: parseInt(this.cmp.method.getValue()),
 			colorLow: this.cmp.colorLow.getValue(),
 			colorHigh: this.cmp.colorHigh.getValue(),
-			colors: this.getColors(),
 			radiusLow: parseInt(this.cmp.radiusLow.getValue()),
 			radiusHigh: parseInt(this.cmp.radiusHigh.getValue()),
-			level: level.getValue(),
-			levelName: level.getRawValue(),
-			parentId: parent[0].raw.id,
-			parentName: parent[0].raw.text,
+			organisationUnitLevel: {
+				id: level.getValue(),
+				name: level.getRawValue(),
+				level: GIS.store.organisationUnitLevels.getById(level.getValue()).data.level
+			},
+			parentOrganisationUnit: {
+				id: parent[0].raw.id,
+				name: parent[0].raw.text
+			},
 			parentLevel: parent[0].raw.level,
-			parentPath: parent[0].raw.path,
-			updateOrganisationUnit: false,
-			updateData: false,
-			updateLegend: false,
-			updateGui: false
-		};
-		
-		model.valueType = this.config.valueType || model.valueType;
-		model.indicatorGroup = this.config.indicatorGroup || model.indicatorGroup;
-		model.indicator = this.config.indicator || model.indicator;
-		model.dataElementGroup = this.config.dataElementGroup || model.dataElementGroup;
-		model.dataElement = this.config.dataElement || model.dataElement;
-		model.periodType = this.config.periodType || model.periodType;
-		model.period = this.config.period || model.period;
-		model.legendType = this.config.legendType || model.legendType;
-		model.legendSet = this.config.legendSet || model.legendSet;
-		model.classes = this.config.classes || model.classes;
-		model.method = this.config.method || model.method;
-		model.colorLow = this.config.colorLow || model.colorLow;
-		model.colorHigh = this.config.colorHigh || model.colorHigh;
-		model.colors = this.getColors(model.colorLow, model.colorHigh);
-		model.radiusLow = this.config.radiusLow || model.radiusLow;
-		model.radiusHigh = this.config.radiusHigh || model.radiusHigh;
-		model.level = this.config.level || model.level;
-		model.levelName = this.config.levelName || model.levelName;
-		model.parentId = this.config.parentId || model.parentId;
-		model.parentName = this.config.parentName || model.parentName;
-		model.parentLevel = this.config.parentLevel || model.parentLevel;
-		model.parentPath = this.config.parentPath || null;
-		model.updateOrganisationUnit = Ext.isDefined(this.config.updateOrganisationUnit) ? this.config.updateOrganisationUnit : false;
-		model.updateData = Ext.isDefined(this.config.updateData) ? this.config.updateData : false;
-		model.updateLegend = Ext.isDefined(this.config.updateLegend) ? this.config.updateLegend : false;
-		model.updateGui = Ext.isDefined(this.config.updateGui) ? this.config.updateGui : false;
-		
-		return model;
-	},
-	
-	validateModel: function(model) {
-		if (model.valueType === GIS.conf.finals.dimension.indicator.id) {
-			if (!model.indicatorGroup || !Ext.isString(model.indicatorGroup)) {
-				GIS.logg.push([model.indicatorGroup, this.xtype + '.indicatorGroup: string']);
+			parentGraph: parent[0].raw.path,
+			opacity: this.layer.item.getOpacity()
+		};
+		
+		return view;
+	},
+	
+	extendView: function(view) {
+		var conf = this.config;
+		view = view || {};
+
+		view.valueType = conf.valueType || view.valueType;
+		view.indicatorGroup = conf.indicatorGroup || view.indicatorGroup;
+		view.indicator = conf.indicator || view.indicator;
+		view.dataElementGroup = conf.dataElementGroup || view.dataElementGroup;
+		view.dataElement = conf.dataElement || view.dataElement;
+		view.periodType = conf.periodType || view.periodType;
+		view.period = conf.period || view.period;
+		view.legendType = conf.legendType || view.legendType;
+		view.legendSet = conf.legendSet || view.legendSet;
+		view.classes = conf.classes || view.classes;
+		view.method = conf.method || view.method;
+		view.colorLow = conf.colorLow || view.colorLow;
+		view.colorHigh = conf.colorHigh || view.colorHigh;
+		view.radiusLow = conf.radiusLow || view.radiusLow;
+		view.radiusHigh = conf.radiusHigh || view.radiusHigh;
+		view.organisationUnitLevel = conf.organisationUnitLevel || view.organisationUnitLevel;
+		view.parentOrganisationUnit = conf.parentOrganisationUnit || view.parentOrganisationUnit;
+		view.parentLevel = conf.parentLevel || view.parentLevel;
+		view.parentGraph = conf.parentGraph || view.parentGraph;
+		view.opacity = conf.opacity || view.opacity;
+		
+		view.extended = {
+			colors: this.getColors(view.colorLow, view.colorHigh),
+			updateOrganisationUnit: Ext.isDefined(conf.extended.updateOrganisationUnit) ? conf.extended.updateOrganisationUnit : false,
+			updateData: Ext.isDefined(conf.extended.updateData) ? conf.extended.updateData : false,
+			updateLegend: Ext.isDefined(conf.extended.updateLegend) ? conf.extended.updateLegend : false,
+			updateGui: Ext.isDefined(conf.extended.updateGui) ? conf.extended.updateGui : false
+		};
+		
+		return view;
+	},
+	
+	validateView: function(view) {
+		if (view.valueType === GIS.conf.finals.dimension.indicator.id) {
+			if (!view.indicatorGroup.id || !Ext.isString(view.indicatorGroup.id)) {
+				GIS.logg.push([view.indicatorGroup.id, this.xtype + '.indicatorGroup.id: string']);
 				//alert("validation failed"); //todo
 				return false;
 			}
-			if (!model.indicator || !Ext.isString(model.indicator)) {
-				GIS.logg.push([model.indicator, this.xtype + '.indicator: string']);
+			if (!view.indicator.id || !Ext.isString(view.indicator.id)) {
+				GIS.logg.push([view.indicator.id, this.xtype + '.indicator.id: string']);
 				alert('No indicator selected'); //todo //i18n
 				return false;
 			}
 		}
-		else if (model.valueType === GIS.conf.finals.dimension.dataElement.id) {
-			if (!model.dataElementGroup || !Ext.isString(model.dataElementGroup)) {
-				GIS.logg.push([model.dataElementGroup, this.xtype + '.dataElementGroup: string']);
+		else if (view.valueType === GIS.conf.finals.dimension.dataElement.id) {
+			if (!view.dataElementGroup.id || !Ext.isString(view.dataElementGroup.id)) {
+				GIS.logg.push([view.dataElementGroup.id, this.xtype + '.dataElementGroup.id: string']);
 				//alert("validation failed"); //todo
 				return false;
 			}
-			if (!model.dataElement || !Ext.isString(model.dataElement)) {
-				GIS.logg.push([model.dataElement, this.xtype + '.dataElement: string']);
+			if (!view.dataElement.id || !Ext.isString(view.dataElement.id)) {
+				GIS.logg.push([view.dataElement.id, this.xtype + '.dataElement.id: string']);
 				alert('No data element selected'); //todo //i18n
 				return false;
 			}
 		}
 		
-		if (!model.periodType || !Ext.isString(model.periodType)) {
-			GIS.logg.push([model.periodType, this.xtype + '.periodType: string']);
+		if (!view.periodType || !Ext.isString(view.periodType)) {
+			GIS.logg.push([view.periodType, this.xtype + '.periodType: string']);
 				//alert("validation failed"); //todo
 			return false;
 		}
-		if (!model.period || !Ext.isString(model.period)) {
-			GIS.logg.push([model.period, this.xtype + '.period: string']);
+		if (!view.period.id || !Ext.isString(view.period.id)) {
+			GIS.logg.push([view.period.id, this.xtype + '.period.id: string']);
 				alert('No period selected'); //todo //i18n
 			return false;
 		}
 		
-		if (model.legendType === GIS.conf.finals.widget.legendtype_automatic) {
-			if (!model.classes || !Ext.isNumber(model.classes)) {
-				GIS.logg.push([model.classes, this.xtype + '.classes: number']);
-				//alert("validation failed"); //todo
-				return false;
-			}
-			if (!model.method || !Ext.isNumber(model.method)) {
-				GIS.logg.push([model.method, this.xtype + '.method: number']);
-				//alert("validation failed"); //todo
-				return false;
-			}
-			if (!model.colorLow || !Ext.isString(model.colorLow)) {
-				GIS.logg.push([model.colorLow, this.xtype + '.colorLow: string']);
-				//alert("validation failed"); //todo
-				return false;
-			}
-			if (!model.radiusLow || !Ext.isNumber(model.radiusLow)) {
-				GIS.logg.push([model.radiusLow, this.xtype + '.radiusLow: number']);
-				//alert("validation failed"); //todo
-				return false;
-			}
-			if (!model.colorHigh || !Ext.isString(model.colorHigh)) {
-				GIS.logg.push([model.colorHigh, this.xtype + '.colorHigh: string']);
-				//alert("validation failed"); //todo
-				return false;
-			}
-			if (!model.radiusHigh || !Ext.isNumber(model.radiusHigh)) {
-				GIS.logg.push([model.radiusHigh, this.xtype + '.radiusHigh: number']);
+		if (view.legendType === GIS.conf.finals.widget.legendtype_automatic) {
+			if (!view.classes || !Ext.isNumber(view.classes)) {
+				GIS.logg.push([view.classes, this.xtype + '.classes: number']);
+				//alert("validation failed"); //todo
+				return false;
+			}
+			if (!view.method || !Ext.isNumber(view.method)) {
+				GIS.logg.push([view.method, this.xtype + '.method: number']);
+				//alert("validation failed"); //todo
+				return false;
+			}
+			if (!view.colorLow || !Ext.isString(view.colorLow)) {
+				GIS.logg.push([view.colorLow, this.xtype + '.colorLow: string']);
+				//alert("validation failed"); //todo
+				return false;
+			}
+			if (!view.radiusLow || !Ext.isNumber(view.radiusLow)) {
+				GIS.logg.push([view.radiusLow, this.xtype + '.radiusLow: number']);
+				//alert("validation failed"); //todo
+				return false;
+			}
+			if (!view.colorHigh || !Ext.isString(view.colorHigh)) {
+				GIS.logg.push([view.colorHigh, this.xtype + '.colorHigh: string']);
+				//alert("validation failed"); //todo
+				return false;
+			}
+			if (!view.radiusHigh || !Ext.isNumber(view.radiusHigh)) {
+				GIS.logg.push([view.radiusHigh, this.xtype + '.radiusHigh: number']);
 				//alert("validation failed"); //todo
 				return false;
 			}
 		}
-		else if (model.legendType === GIS.conf.finals.widget.legendtype_predefined) {			
-			if (!model.legendSet || !Ext.isString(model.legendSet)) {
-				GIS.logg.push([model.legendSet, this.xtype + '.legendSet: string']);
+		else if (view.legendType === GIS.conf.finals.widget.legendtype_predefined) {
+			if (!view.legendSet.id || !Ext.isString(view.legendSet.id)) {
+				GIS.logg.push([view.legendSet.id, this.xtype + '.legendSet.id: string']);
 				alert('No legend set selected'); //todo //i18n
 				return false;
 			}
 		}
 		
-		if (!model.level || !Ext.isNumber(model.level)) {
-			GIS.logg.push([model.level, this.xtype + '.level: number']);
+		if (!view.organisationUnitLevel.id || !Ext.isString(view.organisationUnitLevel.id)) {
+			GIS.logg.push([view.organisationUnitLevel.id, this.xtype + '.organisationUnitLevel.id: string']);
 				alert('No level selected'); //todo
 			return false;
 		}
-		if (!model.levelName || !Ext.isString(model.levelName)) {
-			GIS.logg.push([model.levelName, this.xtype + '.levelName: string']);
-				//alert("validation failed"); //todo
-			return false;
-		}
-		if (!model.parentId || !Ext.isString(model.parentId)) {
-			GIS.logg.push([model.parentId, this.xtype + '.parentId: string']);
+		if (!view.organisationUnitLevel.name || !Ext.isString(view.organisationUnitLevel.name)) {
+			GIS.logg.push([view.organisationUnitLevel.name, this.xtype + '.organisationUnitLevel.name: string']);
+				//alert("validation failed"); //todo
+			return false;
+		}
+		if (!view.organisationUnitLevel.level || !Ext.isNumber(view.organisationUnitLevel.level)) {
+			GIS.logg.push([view.organisationUnitLevel.level, this.xtype + '.organisationUnitLevel.level: number']);
+				//alert("validation failed"); //todo
+			return false;
+		}
+		if (!view.parentOrganisationUnit.id || !Ext.isString(view.parentOrganisationUnit.id)) {
+			GIS.logg.push([view.parentOrganisationUnit.id, this.xtype + '.parentOrganisationUnit.id: string']);
 				alert('No parent organisation unit selected'); //todo
 			return false;
 		}
-		if (!model.parentName || !Ext.isString(model.parentName)) {
-			GIS.logg.push([model.parentName, this.xtype + '.parentName: string']);
-				//alert("validation failed"); //todo
-			return false;
-		}
-		if (!model.parentLevel || !Ext.isNumber(model.parentLevel)) {
-			GIS.logg.push([model.parentLevel, this.xtype + '.parentLevel: number']);
-				//alert("validation failed"); //todo
-			return false;
-		}
-		if (model.parentLevel > model.level) {
-			GIS.logg.push([model.parentLevel, model.level, this.xtype + '.parentLevel: number <= ' + this.xtype + '.level']);
-				alert('Level cannot be higher than parent level'); //todo
-			return false;
-		}
-		
-		if (!model.parentPath && model.updateGui) {
-			GIS.logg.push([model.parentpath, this.xtype + '.parentpath: string']);
-				//alert("validation failed"); //todo
-			return false;
-		}
-		
-		if (!model.updateOrganisationUnit && !model.updateData && !model.updateLegend) {
-			GIS.logg.push([model.updateOrganisationUnit, model.updateData, model.updateLegend, this.xtype + '.update ou/data/legend: true||true||true']);
+		if (!view.parentOrganisationUnit.name || !Ext.isString(view.parentOrganisationUnit.name)) {
+			GIS.logg.push([view.parentOrganisationUnit.name, this.xtype + '.parentOrganisationUnit.name: string']);
+				//alert("validation failed"); //todo
+			return false;
+		}
+		if (!view.parentLevel || !Ext.isNumber(view.parentLevel)) {
+			GIS.logg.push([view.parentLevel, this.xtype + '.parentLevel: number']);
+				//alert("validation failed"); //todo
+			return false;
+		}
+		if (!view.parentGraph || !Ext.isString(view.parentGraph)) {
+			GIS.logg.push([view.parentGraph, this.xtype + '.parentGraph: string']);
+				//alert("validation failed"); //todo
+			return false;
+		}
+		
+		if (view.parentOrganisationUnit.level > view.organisationUnitLevel.level) {
+			GIS.logg.push([view.parentOrganisationUnit.level, view.organisationUnitLevel.level, this.xtype + '.parentOrganisationUnit.level: number <= ' + this.xtype + '.organisationUnitLevel.level']);
+				alert('Orgunit level cannot be higher than parent level'); //todo
+			return false;
+		}
+				
+		if (!view.extended.updateOrganisationUnit && !view.extended.updateData && !view.extended.updateLegend) {
+			GIS.logg.push([view.extended.updateOrganisationUnit, view.extended.updateData, view.extended.updateLegend, this.xtype + '.extended.update ou/data/legend: true||true||true']);
 			return false;
 		}
 		
@@ -1637,27 +1652,27 @@
 	
     loadOrganisationUnits: function() {
         var url = GIS.conf.url.path_gis + 'getGeoJson.action?' +
-            'parentId=' + this.tmpModel.parentId +
-            '&level=' + this.tmpModel.level;
+            'parentId=' + this.tmpView.parentOrganisationUnit.id +
+            '&level=' + this.tmpView.organisationUnitLevel.id;
         this.setUrl(url);
     },
     
     loadData: function() {
-		var type = this.tmpModel.valueType,
-			dataUrl = '../api/mapValues/' + GIS.conf.finals.dimension[type].param + '.json',
+		var type = this.tmpView.valueType,
+			dataUrl = 'mapValues/' + GIS.conf.finals.dimension[type].param + '.json',
 			indicator = GIS.conf.finals.dimension.indicator,
 			dataElement = GIS.conf.finals.dimension.dataElement,
 			period = GIS.conf.finals.dimension.period,
 			organisationUnit = GIS.conf.finals.dimension.organisationUnit,
 			params = {};
 		
-		params[type === indicator.id ? indicator.param : dataElement.param] = this.tmpModel[type];
-		params[period.param] = this.tmpModel.period;
-		params[organisationUnit.param] = this.tmpModel.parentId;
-		params.level = this.tmpModel.level;
+		params[type === indicator.id ? indicator.param : dataElement.param] = this.tmpView[type].id;
+		params[period.param] = this.tmpView.period.id;
+		params[organisationUnit.param] = this.tmpView.parentOrganisationUnit.id;
+		params.le = this.tmpView.organisationUnitLevel.id;
 		
 		Ext.Ajax.request({
-			url: GIS.conf.url.path_gis + dataUrl,
+			url: GIS.conf.url.path_api + dataUrl,
 			params: params,
 			disableCaching: false,
 			scope: this,
@@ -1668,7 +1683,7 @@
 					features = [];
 					
 				if (values.length === 0) {
-					alert('No aggregated data values found'); //todo Ext.message.msg(false, GIS.i18n.current_selection_no_data);
+					alert('No aggregated data values found'); //todo
 					GIS.mask.hide();
 					return;
 				}
@@ -1707,11 +1722,11 @@
 			fn = function() {
 				options = {
 					indicator: GIS.conf.finals.widget.value,
-					method: that.tmpModel.method,
-					numClasses: that.tmpModel.classes,
-					colors: that.tmpModel.colors,
-					minSize: that.tmpModel.radiusLow,
-					maxSize: that.tmpModel.radiusHigh
+					method: that.tmpView.method,
+					numClasses: that.tmpView.classes,
+					colors: that.tmpView.extended.colors,
+					minSize: that.tmpView.radiusLow,
+					maxSize: that.tmpView.radiusHigh
 				};
 
 				that.coreComp.applyClassification(options);
@@ -1719,8 +1734,14 @@
 				
 				that.afterLoad();
 			};
+			
+		this.tmpView.extended.legendConfig = {
+			what: this.tmpView.valueType === 'indicator' ? this.tmpView.indicator.name : this.tmpView.dataElement.name,
+			when: this.tmpView.period.id, //todo name
+			where: this.tmpView.organisationUnitLevel.name + ' / ' + this.tmpView.parentOrganisationUnit.name
+		};
 		
-		if (this.tmpModel.legendType === GIS.conf.finals.widget.legendtype_predefined) {
+		if (this.tmpView.legendType === GIS.conf.finals.widget.legendtype_predefined) {
 			this.setPredefinedLegend(fn);
 		}
 		else {
@@ -1728,24 +1749,32 @@
 		}
 	},
 	
-    execute: function() {
-		this.tmpModel = this.getModel();
-		
-		if (!this.validateModel(this.tmpModel)) {
+    execute: function(view) {
+		if (view) {
+			this.config.extended.updateOrganisationUnit = true;
+			this.config.extended.updateGui = true;
+		}
+		else {
+			view = this.getView();
+		}
+		
+		this.tmpView = this.extendView(view);
+		
+		if (!this.validateView(this.tmpView)) {
 			return;
 		}
-				
+		
 		GIS.mask.msg = GIS.i18n.loading;
 		GIS.mask.show();
 		
-		if (this.tmpModel.updateGui) {
+		if (this.tmpView.extended.updateGui) {
 			this.setGui();
 		}
 		
-		if (this.tmpModel.updateOrganisationUnit) {
+		if (this.tmpView.extended.updateOrganisationUnit) {
 			this.loadOrganisationUnits();
 		}
-		else if (this.tmpModel.updateData) {
+		else if (this.tmpView.extended.updateData) {
 			this.loadData();
 		}
 		else {
@@ -1754,11 +1783,13 @@
 	},
 	
 	afterLoad: function() {
-		this.model = this.tmpModel;
-		this.config = {};
+		this.view = this.tmpView;
+		this.config = {
+			extended: {}
+		};
 		
 		// Layer item
-		this.layer.item.setValue(true);
+		this.layer.item.setValue(true, this.view.opacity);
 		
 		// Layer menu
 		this.menu.enableItems();
@@ -1770,19 +1801,16 @@
 		if (this.cmp.filterWindow && this.cmp.filterWindow.isVisible()) { 
 			this.cmp.filterWindow.filter();
 		}
+		
+		// Legend
+		GIS.cmp.region.east.doLayout();
+		this.layer.legend.expand();
         
-        // Set favorite position, else zoom to visible extent
-        if (this.model.longitude && this.model.latitude && this.model.zoom) {
-			var lonLat = GIS.util.map.getLonLatByXY(this.model.longitude, this.model.latitude);
-			GIS.map.setCenter(lonLat, this.model.zoom);
-		}
-		else if (this.model.updateOrganisationUnit) {
+        // Zoom to visible extent if not loading a favorite
+        if (!GIS.map.map) {
 			GIS.util.map.zoomToVisibleExtent();
 		}
 		
-		// Legend
-		GIS.cmp.region.east.doLayout();
-		
         GIS.mask.hide();
 	},
     

=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/styles/style.css'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/styles/style.css	2012-10-30 07:26:04 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/styles/style.css	2012-10-30 17:51:51 +0000
@@ -172,7 +172,7 @@
 }
 
 .gis-form-widget .x-btn-default-small { /* Button */
-	border-radius: 2px;
+	border-radius: 1px;
 }
 
 /* Button */
@@ -484,13 +484,10 @@
 	vertical-align: middle;
 }
 
-.gis-grid td.text-link,
-.gis-grid td.text-link div,
-.gis-grid td.text-link span  {
+.gis-grid .link,
+.gis-grid .link * {
 	cursor: pointer;
 	cursor: hand;
-}
-.gis-grid td.text-link span {
 	color: blue;
 	text-decoration: underline;
 }
@@ -498,7 +495,7 @@
 /* TextField */
 
 .gis-textfield input.x-form-text {
-	border-radius: 2px;
+	border-radius: 1px;
 }
 
 /* Checkbox */

=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/jsonOrganisationUnitChildren.vm'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/jsonOrganisationUnitChildren.vm	2012-09-24 14:16:43 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/jsonOrganisationUnitChildren.vm	2012-10-31 13:41:50 +0000
@@ -6,6 +6,7 @@
   "level": ${unit.level},
   "text": "$encoder.jsonEncode( ${unit.name} )",
   "hasChildrenWithCoordinates": $!{unit.hasChildrenWithCoordinates()},
+  "path":"#foreach($anc in $unit.getAncestors())/${anc.uid}#end/${unit.uid}",
   "leaf":#if( $unit.hasChild() ) false#else true#end
 }#if( $velocityCount < $size ),#end
 #end