← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2269: Dataset module - Dataset Assignment Editor - Improved.

 

------------------------------------------------------------
revno: 2269
committer: Hieu <hieu.hispvietnam@xxxxxxxxx>
branch nick: trunk
timestamp: Wed 2010-09-29 14:05:04 +0700
message:
  Dataset module - Dataset Assignment Editor - Improved.
  Please test it and give your comment.
added:
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/editor/MergeAssignedOrgunitsAction.java
modified:
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/DefineDataSetAssociationsAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/editor/SaveAssignMultiDataSetForOrgunitAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/resources/org/hisp/dhis/dataset/i18n_module.properties
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/resources/org/hisp/dhis/dataset/i18n_module_vi_VN.properties
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/resources/struts.xml
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/showAssignMultiDataSetForm.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-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/DefineDataSetAssociationsAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/DefineDataSetAssociationsAction.java	2010-09-14 09:03:41 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/DefineDataSetAssociationsAction.java	2010-09-29 07:05:04 +0000
@@ -34,6 +34,7 @@
 import org.hisp.dhis.dataset.DataSet;
 import org.hisp.dhis.dataset.DataSetService;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitService;
 import org.hisp.dhis.oust.manager.SelectionTreeManager;
 import org.hisp.dhis.source.Source;
 
@@ -66,6 +67,13 @@
         this.dataSetService = dataSetService;
     }
 
+    private OrganisationUnitService organisationUnitService;
+
+    public void setOrganisationUnitService( OrganisationUnitService organisationUnitService )
+    {
+        this.organisationUnitService = organisationUnitService;
+    }
+
     // -------------------------------------------------------------------------
     // Input & Output
     // -------------------------------------------------------------------------
@@ -89,18 +97,18 @@
 
         Set<OrganisationUnit> unitsInTheTree = new HashSet<OrganisationUnit>();
 
-        getUnitsInTheTree( rootUnits, unitsInTheTree );
+        organisationUnitService.getUnitsInTheTree( rootUnits, unitsInTheTree );
 
         DataSet dataSet = dataSetService.getDataSet( dataSetId );
 
         Set<Source> assignedSources = dataSet.getSources();
 
-        assignedSources.removeAll( convert( unitsInTheTree ) );
+        assignedSources.removeAll( organisationUnitService.convert( unitsInTheTree ) );
 
         Collection<OrganisationUnit> selectedOrganisationUnits = selectionTreeManager
             .getReloadedSelectedOrganisationUnits();
 
-        assignedSources.addAll( convert( selectedOrganisationUnits ) );
+        assignedSources.addAll( organisationUnitService.convert( selectedOrganisationUnits ) );
 
         dataSet.setSources( assignedSources );
 
@@ -108,26 +116,4 @@
 
         return SUCCESS;
     }
-
-    // -------------------------------------------------------------------------
-    // Supportive methods
-    // -------------------------------------------------------------------------
-
-    private Set<Source> convert( Collection<OrganisationUnit> organisationUnits )
-    {
-        Set<Source> sources = new HashSet<Source>();
-
-        sources.addAll( organisationUnits );
-
-        return sources;
-    }
-
-    private void getUnitsInTheTree( Collection<OrganisationUnit> rootUnits, Set<OrganisationUnit> unitsInTheTree )
-    {
-        for ( OrganisationUnit root : rootUnits )
-        {
-            unitsInTheTree.add( root );
-            getUnitsInTheTree( root.getChildren(), unitsInTheTree );
-        }
-    }
 }

=== added file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/editor/MergeAssignedOrgunitsAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/editor/MergeAssignedOrgunitsAction.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/editor/MergeAssignedOrgunitsAction.java	2010-09-29 07:05:04 +0000
@@ -0,0 +1,129 @@
+package org.hisp.dhis.dataset.action.editor;
+
+/*
+ * Copyright (c) 2004-2010, 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 java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import org.hisp.dhis.dataset.DataSet;
+import org.hisp.dhis.dataset.DataSetService;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.oust.manager.SelectionTreeManager;
+
+import com.opensymphony.xwork2.Action;
+
+/**
+ * @author Dang Duy Hieu
+ * @version $Id$
+ */
+public class MergeAssignedOrgunitsAction
+    implements Action
+{
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
+    private SelectionTreeManager selectionTreeManager;
+
+    public void setSelectionTreeManager( SelectionTreeManager selectionTreeManager )
+    {
+        this.selectionTreeManager = selectionTreeManager;
+    }
+
+    private DataSetService dataSetService;
+
+    public void setDataSetService( DataSetService dataSetService )
+    {
+        this.dataSetService = dataSetService;
+    }
+
+    // -------------------------------------------------------------------------
+    // Input
+    // -------------------------------------------------------------------------
+
+    private Collection<String> selectedDataSets = new HashSet<String>();
+
+    public void setSelectedDataSets( Collection<String> selectedDataSets )
+    {
+        this.selectedDataSets = selectedDataSets;
+    }
+
+    // -------------------------------------------------------------------------
+    // Output
+    // -------------------------------------------------------------------------
+
+    private Set<OrganisationUnit> selectedUnits = new HashSet<OrganisationUnit>();
+
+    public Set<OrganisationUnit> getSelectedUnits()
+    {
+        return selectedUnits;
+    }
+
+    // -------------------------------------------------------------------------
+    // Action
+    // -------------------------------------------------------------------------
+
+    public String execute()
+        throws Exception
+    {
+        Set<OrganisationUnit> tempUnits = new HashSet<OrganisationUnit>();
+
+        if ( selectedDataSets.size() >= 1 )
+        {
+            Iterator<String> iterator = selectedDataSets.iterator();
+
+            if ( iterator.hasNext() )
+            {
+                DataSet dataSet = dataSetService.getDataSet( Integer.valueOf( iterator.next() ) );
+                selectedUnits.addAll( dataSet.getOrganisationUnis() );
+
+                iterator.remove();
+            }
+        }
+
+        for ( String dataSetId : selectedDataSets )
+        {
+            DataSet dataSet = dataSetService.getDataSet( Integer.parseInt( dataSetId ) );
+            tempUnits = dataSet.getOrganisationUnis();
+
+            if ( !(tempUnits.size() == selectedUnits.size() && tempUnits.containsAll( selectedUnits )) )
+            {
+                selectedUnits.clear();
+                selectionTreeManager.setSelectedOrganisationUnits( selectedUnits );
+
+                return SUCCESS;
+            }
+        }
+
+        selectionTreeManager.setSelectedOrganisationUnits( selectedUnits );
+
+        return SUCCESS;
+    }
+}

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/editor/SaveAssignMultiDataSetForOrgunitAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/editor/SaveAssignMultiDataSetForOrgunitAction.java	2010-09-27 08:17:04 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/editor/SaveAssignMultiDataSetForOrgunitAction.java	2010-09-29 07:05:04 +0000
@@ -34,6 +34,7 @@
 import org.hisp.dhis.dataset.DataSet;
 import org.hisp.dhis.dataset.DataSetService;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitService;
 import org.hisp.dhis.oust.manager.SelectionTreeManager;
 import org.hisp.dhis.source.Source;
 
@@ -64,8 +65,15 @@
         this.dataSetService = dataSetService;
     }
 
+    private OrganisationUnitService organisationUnitService;
+
+    public void setOrganisationUnitService( OrganisationUnitService organisationUnitService )
+    {
+        this.organisationUnitService = organisationUnitService;
+    }
+
     // -------------------------------------------------------------------------
-    // Input & Output
+    // Input
     // -------------------------------------------------------------------------
 
     private Collection<String> selectedDataSets = new HashSet<String>();
@@ -75,6 +83,13 @@
         this.selectedDataSets = selectedDataSets;
     }
 
+    private boolean assignStatus;
+
+    public void setAssignStatus( boolean assignStatus )
+    {
+        this.assignStatus = assignStatus;
+    }
+
     // -------------------------------------------------------------------------
     // Action
     // -------------------------------------------------------------------------
@@ -82,15 +97,26 @@
     public String execute()
         throws Exception
     {
-        Set<Source> selectedOrganisationUnits = convert( selectionTreeManager
+        Collection<OrganisationUnit> rootUnits = selectionTreeManager.getRootOrganisationUnits();
+
+        Set<OrganisationUnit> unitsInTheTree = new HashSet<OrganisationUnit>();
+
+        organisationUnitService.getUnitsInTheTree( rootUnits, unitsInTheTree );
+
+        Set<Source> selectedOrganisationUnits = organisationUnitService.convert( selectionTreeManager
             .getReloadedSelectedOrganisationUnits() );
 
         for ( String dataSetId : selectedDataSets )
         {
-            DataSet dataSet = dataSetService.getDataSet( Integer.parseInt( dataSetId ) );
+            DataSet dataSet = dataSetService.getDataSet( Integer.valueOf( dataSetId ) );
 
             Set<Source> assignedSources = dataSet.getSources();
 
+            if ( !assignStatus )
+            {
+                assignedSources.removeAll( organisationUnitService.convert( unitsInTheTree ) );
+            }
+
             assignedSources.addAll( selectedOrganisationUnits );
 
             dataSet.setSources( assignedSources );
@@ -100,17 +126,4 @@
 
         return SUCCESS;
     }
-
-    // -------------------------------------------------------------------------
-    // Supportive methods
-    // -------------------------------------------------------------------------
-
-    private Set<Source> convert( Collection<OrganisationUnit> organisationUnits )
-    {
-        Set<Source> sources = new HashSet<Source>();
-
-        sources.addAll( organisationUnits );
-
-        return sources;
-    }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/resources/META-INF/dhis/beans.xml	2010-09-16 05:35:12 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/resources/META-INF/dhis/beans.xml	2010-09-29 07:05:04 +0000
@@ -148,6 +148,9 @@
 		<property name="dataSetService">
 			<ref bean="org.hisp.dhis.dataset.DataSetService"/>
 		</property>
+		<property name="organisationUnitService">
+			<ref bean="org.hisp.dhis.organisationunit.OrganisationUnitService"/>
+		</property>
 	</bean>		
 	
 	<bean id="org.hisp.dhis.dataset.action.GetDataSetListSortOrderAction"
@@ -429,8 +432,7 @@
 			<ref bean="org.hisp.dhis.organisationunit.OrganisationUnitService"/>
 		</property>
 		<property name="organisationUnitGroupService">
-			<ref
-				bean="org.hisp.dhis.organisationunit.OrganisationUnitGroupService"/>
+			<ref bean="org.hisp.dhis.organisationunit.OrganisationUnitGroupService"/>
 		</property>
 	</bean>
 	
@@ -494,4 +496,18 @@
 		</property>
 	</bean>
 	
+	<bean id="org.hisp.dhis.dataset.action.editor.MergeAssignedOrgunitsAction"
+		class="org.hisp.dhis.dataset.action.editor.MergeAssignedOrgunitsAction"
+		scope="prototype">
+		<property name="dataSetService">
+			<ref bean="org.hisp.dhis.dataset.DataSetService"/>
+		</property>
+		<property name="selectionTreeManager">
+			<ref bean="org.hisp.dhis.oust.manager.SelectionTreeManager"/>
+		</property>
+		<property name="organisationUnitService">
+			<ref bean="org.hisp.dhis.organisationunit.OrganisationUnitService"/>
+		</property>
+	</bean>
+	
 </beans>
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/resources/org/hisp/dhis/dataset/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/resources/org/hisp/dhis/dataset/i18n_module.properties	2010-09-28 04:02:31 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/resources/org/hisp/dhis/dataset/i18n_module.properties	2010-09-29 07:05:04 +0000
@@ -148,4 +148,7 @@
 org_units													= Organisation Units
 data														= Data
 pivot														= Pivot
-please_select_dataset_or_categorycombo                      = Please select a dataset/category combo
\ No newline at end of file
+please_select_dataset_or_categorycombo                      = Please select a dataset/category combo
+confirm_save                                                = This operation will change the old orgunits assigned to these datasets.\nAre you sure to save this?
+not_change_old_but_assign_new_only                          = Do not change the old assignment but assign new only.
+datasets_different_orgunitlist                              = These selected datasets are not the same the list of organsation unit.
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/resources/org/hisp/dhis/dataset/i18n_module_vi_VN.properties'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/resources/org/hisp/dhis/dataset/i18n_module_vi_VN.properties	2010-09-07 05:24:21 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/resources/org/hisp/dhis/dataset/i18n_module_vi_VN.properties	2010-09-29 07:05:04 +0000
@@ -81,4 +81,7 @@
 delete_success                  = X\u00f3a th\u00e0nh c\u00f4ng
 rename_success                  = \u0110\u1ed5i t\u00ean th\u00e0nh c\u00f4ng
 rename_failed                   = \u0110\u1ed5i t\u00ean kh\u00f4ng th\u00e0nh c\u00f4ng
-please_select_dataset_or_categorycombo = H\u00e3y ch\u1ecdn t\u1eadp d\u1eef li\u1ec7u v\u00e0 category combo t\u01b0\u01a1ng \u1ee9ng
\ No newline at end of file
+please_select_dataset_or_categorycombo = H\u00e3y ch\u1ecdn t\u1eadp d\u1eef li\u1ec7u v\u00e0 category combo t\u01b0\u01a1ng \u1ee9ng
+confirm_save                           = H\u00e0nh \u0111\u1ed9ng n\u00e0y s\u1ebd thay \u0111\u1ed5i nh\u1eefng \u0111\u01a1n v\u1ecb \u0111\u00e3 \u0111\u01b0\u1ee3c g\u00e1n tr\u01b0\u1edbc \u0111\u00f3 cho c\u00e1c t\u1eadp d\u1eef li\u1ec7u l\u1ef1a ch\u1ecdn tr\u00ean.\nB\u1ea1n c\u00f3 mu\u1ed1n ti\u1ebfp t\u1ee5c?
+not_change_old_but_assign_new_only     = Kh\u00f4ng thay \u0111\u1ed5i vi\u1ec7c g\u00e1n c\u0169 ch\u1ec9 g\u00e1n th\u00eam m\u1edbi.
+datasets_different_orgunitlist         = C\u00e1c t\u1eadp d\u1eef li\u1ec7u \u0111\u01b0\u1ee3c ch\u1ecdn tr\u00ean kh\u00e1c nhau v\u1ec1 danh s\u00e1ch c\u00e1c \u0111\u01a1n v\u1ecb g\u00e1n.
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/resources/struts.xml	2010-09-14 09:03:41 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/resources/struts.xml	2010-09-29 07:05:04 +0000
@@ -311,11 +311,7 @@
 	  <result name="success" type="velocity">/main.vm</result>
 	  <param name="page">/dhis-web-maintenance-dataset/showAssignMultiDataSetForm.vm</param>
 	  <param name="menu">/dhis-web-maintenance-dataset/menu.vm</param>
-	  <param name="javascripts">../dhis-web-commons/oust/oust.js,
-	  		javascript/shortName.js,
-	  		javascript/dataSet.js,
-	  		javascript/multiDataSet.js
-     </param>
+	  <param name="javascripts">../dhis-web-commons/oust/oust.js</param>
 	</action>
 	
 	<action name="saveAssignMultiDataSetForOrgunit"
@@ -354,6 +350,13 @@
       <result name="success" type="velocity-xml">/dhis-web-maintenance-dataset/responseSuccess.vm</result>
       <param name="requiredAuthorities">F_DATASET_DELETE</param>
     </action>
+	
+	<action name="mergeAssignedOrgunits"
+		class="org.hisp.dhis.dataset.action.editor.MergeAssignedOrgunitsAction">
+		<result name="success" type="velocity-xml">
+			/dhis-web-commons/ouwt/responseSelect.vm</result>
+		<param name="onExceptionReturn">plainTextError</param>
+	</action>
 
 	 <!-- PivotDataSetAssociationTableService -->
     

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/showAssignMultiDataSetForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/showAssignMultiDataSetForm.vm	2010-09-25 20:13:04 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/showAssignMultiDataSetForm.vm	2010-09-29 07:05:04 +0000
@@ -1,7 +1,15 @@
+<script>
+
+	jQuery(document).ready(	function()
+	{
+		validation( 'assignMultiDataSetForm', confirmToSumbit );
+	});
+
+</script>
+
 <h3>$i18n.getString( "dataset_assignment_editor" )</h3>
 
-<form id="assignMultiDataSetForm" action="saveAssignMultiDataSetForOrgunit.action" method="post" onsubmit="selectAllById('selectedDataSets')">
-
+<form id="assignMultiDataSetForm" action="saveAssignMultiDataSetForOrgunit.action" method="POST">
 <table>
 	<tr>
 		<th>$i18n.getString( "available_datasets" )</th><td></td><th>$i18n.getString( "selected_datasets" )</th>
@@ -13,7 +21,7 @@
 	</tr>
 	<tr>
 		<td>
-			<select id="availableDataSets" size="2" multiple="multiple" style="min-width:25em; height:25em" ondblclick="moveSelectedById( 'availableDataSets', 'selectedDataSets' )">
+			<select id="availableDataSets" size="2" multiple="multiple" style="min-width:25em; height:25em" ondblclick="reloadTree( 'availableDataSets', 'selectedDataSets' )">
 			#foreach( $dataSet in $availableDataSets )
 				<option value="$dataSet.id">$dataSet.name</option>
 			#end
@@ -21,19 +29,29 @@
 		</td>
 		
 		<td style="text-align:center">			
-			<input type="button" value="&gt;" title="$i18n.getString('move_selected')" style="width:50px" onclick="moveSelectedById( 'availableDataSets', 'selectedDataSets' )" /><br/>
-			<input type="button" value="&lt;" title="$i18n.getString('remove_selected')" style="width:50px" onclick="moveSelectedById( 'selectedDataSets', 'availableDataSets' )" /><br/>
-			<input type="button" value="&gt;&gt;" title="$i18n.getString('move_all')" style="width:50px" onclick="moveAllById( 'availableDataSets', 'selectedDataSets' )"/><br/>
-			<input type="button" value="&lt;&lt;" title="$i18n.getString('remove_all')" style="width:50px" onclick="moveAllById( 'selectedDataSets', 'availableDataSets' )"/>			
+			<input type="button" value="&gt;" title="$i18n.getString('move_selected')" style="width:50px" onclick="reloadTree( 'availableDataSets', 'selectedDataSets' )" /><br/>
+			<input type="button" value="&lt;" title="$i18n.getString('remove_selected')" style="width:50px" onclick="reloadTree( 'selectedDataSets', 'availableDataSets' )" /><br/>
+			<input type="button" value="&gt;&gt;" title="$i18n.getString('move_all')" style="width:50px" onclick="reloadTree( 'availableDataSets', 'selectedDataSets', 'ALL' )"/><br/>
+			<input type="button" value="&lt;&lt;" title="$i18n.getString('remove_all')" style="width:50px" onclick="reloadTree( 'selectedDataSets', 'availableDataSets', 'ALL' )"/>			
 		</td>	
 		<td>
-			<select id="selectedDataSets" name="selectedDataSets" size="2" multiple="multiple" style="min-width:25em; height:25em" ondblclick="moveSelectedById( 'selectedDataSets', 'availableDataSets' )" />
+			<select id="selectedDataSets" name="selectedDataSets" size="2" multiple="multiple" style="min-width:25em; height:25em" ondblclick="reloadTree( 'selectedDataSets', 'availableDataSets' )" class="{validate:{required:true}}"/>
 		</td>
 	</tr>	
 </table>
 
 <div><br/></div>
-#organisationUnitSelectionTree( true, true, false)
+#organisationUnitSelectionTree( true, true, false )
+<br/>
+
+<table>
+	<tr>
+		<th>$i18n.getString( "optional" )</th>
+	</tr>
+	<tr><td>
+		<input type="checkbox" id="assignStatus" name="assignStatus" value="true"/>$i18n.getString( "not_change_old_but_assign_new_only" )
+	</td></tr>
+</table>
 
 <p>
 	<input type="submit" value="$i18n.getString( 'save' )" style="width:10em"/>
@@ -41,71 +59,6 @@
 </p>
 </form>
 
-<!-- Add new Div -->
-
-<div id="addDataSetEditorDiv" style="position:fixed;display:none;width:350px;z-index:11;background-color: white;border: medium solid silver;height:220px;padding:20px;">
-<div id="close" style="position:absolute;top:2px;right:2px;cursor: pointer;color:red;" onclick="javascript: closeDiv('addDataSetEditorDiv')">[x]</div>
-
-<h4 align="center">$i18n.getString( "add_dataset" )</h4>
-
-<form id="addDataSetEditorForm" name="addDataSetEditorForm" action="addDataSetEditor.action" method="post" >
-	<table id="detailsList">
-		<col/> ## Labels
-		<col/> ## Input
-		<thead>
-			<tr>
-				<th colspan="2">$i18n.getString( "dataset_details" )</th>
-			</tr>
-		</thead>
-		<tbody>
-		<tr>
-			<td><label>$i18n.getString( "name" ) <em title="$i18n.getString( 'required' )" class="required">*</em></label></td>
-			<td><input type="text" id="name" name="name" onchange="nameChanged()" style="width:20em" maxlength="150" class="{validate:{required:true,minlength:2}}"/></td>
-		</tr>
-		<tr>
-			<td><label>$i18n.getString( "short_name" ) <em title="$i18n.getString( 'required' )" class="required">*</em></label></td>
-			<td><input type="text" id="shortName" name="shortName" style="width:20em" maxlength="20" class="{validate:{required:true,minlength:2}}"/></td>
-		</tr>
-		<tr>
-			<td><label>$i18n.getString( "code" )</label></td>
-			<td><input type="text" id="code" name="code" style="width:20em" maxlength="40"/></td>
-		</tr>
-		<tr>
-			<td><label>$i18n.getString( "frequency" ) <em title="$i18n.getString( 'required' )" class="required">*</em></label></td>
-			<td>
-				<select id="frequencySelect" name="frequencySelect" style="min-width:20em" class="{validate:{required:true}}">
-				</select>
-			</td>
-		</tr>
-		<tr><td>&nbsp;</td><td>&nbsp;</td></tr>
-	    <tr>
-			<td colspan="3" align="center">
-				<input type="submit" value="$i18n.getString( 'save' )" style="width:13em"/>
-				<input type="button" onclick="javascript: closeDiv('addDataSetEditorDiv')" value="$i18n.getString( 'cancel' )" style="width:12em"/>
-			</td>
-		</tr>
-		<tr><td>&nbsp;</td><td>&nbsp;</td></tr>
-		</tbody>
-	</table>
-</form>
-</div>
-
-<!-- Rename Div -->
-<div id="renameDataSetEditorDiv" style="position:fixed;display:none;width:550px;z-index:11;background-color: white;border: medium solid silver;height:50px;padding:10px;">
-<div id="close" style="position:absolute;top:2px;right:2px;cursor: pointer;color:red;" onclick="javascript: closeDiv('renameDataSetEditorDiv')">[x]</div>
-<table width="100%" height="100%" border="0" cellpadding="2" cellspacing="2">
-		<tr align="center">
-			<td>$i18n.getString( "name" ): </td>
-			<td><input type="text" id="dateSetNameField" style="width:30em" onkeyup="javascript: checkKeyCodeAndValidateRenameField(event);"/></td>
-			<td>
-				<input id="addRenameDataSetButton" type="button" value="$i18n.getString( 'ok' )"/>
-				<input type="button" onclick="javascript: closeDiv( 'renameDataSetEditorDiv' );" value="$i18n.getString( 'cancel' )"/>
-			</td>
-		</tr>	  
-	</table>
-	
-</div>
-
 <div id="warningArea" style="position:fixed;right:10px;top:200px;display:none">
 	<div style="float:right">
 		<a href="javascript:hideWarning()" title="$i18n.getString( 'hide_warning' )"><img src="../images/close.png" alt="$i18n.getString( 'hide_warning' )"/></a>
@@ -121,11 +74,73 @@
 		setMessage( '$i18n.getString( "$message" )' + '<br/><br/>[<strong>' + '$i18n.getString( "$name" ) </strong>]' );
 	#end
 	
-	var previousName = '';
-
+	var confirmStatus = '';
 	var i18n_add_success = '$encoder.jsEscape( $i18n.getString( "add_success" ) , "'")';
 	var i18n_rename_success = '$encoder.jsEscape( $i18n.getString( "rename_success" ) , "'")';
 	var i18n_confirm_delete = '$encoder.jsEscape( $i18n.getString( "confirm_delete" ) , "'")';
+	var i18n_confirm_save = '$encoder.jsEscape( $i18n.getString( "confirm_save" ) , "'")';
 	var i18n_dataset_unselected = '$encoder.jsEscape( $i18n.getString( "choose_dataset" ) , "'")';
+	var i18n_datasets_different_orgunitlist = '$encoder.jsEscape( $i18n.getString( "datasets_different_orgunitlist" ) , "'")';
+	
+	// --------------------------------------------------------------
+	// Methods
+	// --------------------------------------------------------------
+	
+	function reloadTree( sourceListId, targetListId, typeMove )
+	{
+		if ( typeMove == undefined ) {
+			moveSelectedById( sourceListId, targetListId );
+		}
+		else {
+			moveAllById( sourceListId, targetListId );
+		}
+		reload();
+	}
+	
+	function reload()
+	{
+		jQuery.post( "mergeAssignedOrgunits.action",
+		{ selectedDataSets: getArrayValueOfListById( 'selectedDataSets' )
+		},
+		function( xml ){
+			var responseLen = jQuery( xml ).find('unitId').length;
+			var selectedListLen = byId('selectedDataSets').options.length;
+			
+			if ( responseLen == 0 )
+			{
+				confirmStatus = 'required';
+				if ( selectedListLen != 0 )
+				{
+					setHeaderDelayMessage( i18n_datasets_different_orgunitlist );
+				}
+			}
+			else
+			{
+				confirmStatus = '';
+			}
+			selectedOrganisationUnitXMLABCDEF( xml );
+		});	
+	}
+	
+	function confirmToSumbit()
+	{
+		var assignStatus = $("#assignStatus").is(':checked');
+		
+		if ( (confirmStatus != '') && !assignStatus ) {
+		
+			if ( window.confirm( i18n_confirm_save ) )
+			{
+				submitForm();
+			}
+			else return;
+		}
+		submitForm();
+	}
+	
+	function submitForm()
+	{
+		selectAllById('selectedDataSets');
+		byId('assignMultiDataSetForm').submit();
+	}
 	
 </script>