← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16811: use new available/selected plugin in category combo mgmt

 

------------------------------------------------------------
revno: 16811
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2014-09-25 14:30:35 +0700
message:
  use new available/selected plugin in category combo mgmt
modified:
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/categorycombo/AddDataElementCategoryComboAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/categorycombo/UpdateDataElementCategoryComboAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/javascript/categoryOptionCombo.js
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/multidimensional/addDataElementCategoryComboForm.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/multidimensional/updateDataElementCategoryComboForm.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-datadictionary/src/main/java/org/hisp/dhis/dd/action/categorycombo/AddDataElementCategoryComboAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/categorycombo/AddDataElementCategoryComboAction.java	2014-08-15 07:40:20 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/categorycombo/AddDataElementCategoryComboAction.java	2014-09-25 07:30:35 +0000
@@ -28,20 +28,16 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.List;
-
+import com.opensymphony.xwork2.Action;
 import org.hisp.dhis.dataelement.DataElementCategory;
 import org.hisp.dhis.dataelement.DataElementCategoryCombo;
 import org.hisp.dhis.dataelement.DataElementCategoryService;
 
-import com.opensymphony.xwork2.Action;
+import java.util.ArrayList;
+import java.util.List;
 
 /**
  * @author Selamawit
- * @version $Id$
  */
 public class AddDataElementCategoryComboAction
     implements Action
@@ -76,17 +72,17 @@
     }
 
     private boolean skipTotal;
-    
+
     public void setSkipTotal( boolean skipTotal )
     {
         this.skipTotal = skipTotal;
     }
-    
-    private Collection<String> selectedList = new HashSet<>();
-
-    public void setSelectedList( Collection<String> selectedList )
+
+    private List<String> caSelected = new ArrayList<>();
+
+    public void setCaSelected( List<String> caSelected )
     {
-        this.selectedList = selectedList;
+        this.caSelected = caSelected;
     }
 
     // -------------------------------------------------------------------------
@@ -102,11 +98,9 @@
 
         List<DataElementCategory> categories = new ArrayList<>();
 
-        for ( String id : selectedList )
+        for ( String id : caSelected )
         {
-            DataElementCategory dataElementCategory = dataElementCategoryService.getDataElementCategory( 
-                Integer.parseInt( id ) );
-
+            DataElementCategory dataElementCategory = dataElementCategoryService.getDataElementCategory( id );
             categories.add( dataElementCategory );
         }
 
@@ -115,7 +109,7 @@
         dataElementCategoryService.addDataElementCategoryCombo( categoryCombo );
 
         dataElementCategoryService.generateOptionCombos( categoryCombo );
-        
+
         return SUCCESS;
     }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/categorycombo/UpdateDataElementCategoryComboAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/categorycombo/UpdateDataElementCategoryComboAction.java	2014-08-15 07:40:20 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/categorycombo/UpdateDataElementCategoryComboAction.java	2014-09-25 07:30:35 +0000
@@ -28,20 +28,16 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.List;
-
+import com.opensymphony.xwork2.Action;
 import org.hisp.dhis.dataelement.DataElementCategory;
 import org.hisp.dhis.dataelement.DataElementCategoryCombo;
 import org.hisp.dhis.dataelement.DataElementCategoryService;
 
-import com.opensymphony.xwork2.Action;
+import java.util.ArrayList;
+import java.util.List;
 
 /**
  * @author Abyot Asalefew
- * @version $Id$
  */
 public class UpdateDataElementCategoryComboAction
     implements Action
@@ -76,17 +72,17 @@
     }
 
     private boolean skipTotal;
-    
+
     public void setSkipTotal( boolean skipTotal )
     {
         this.skipTotal = skipTotal;
     }
 
-    private Collection<String> selectedList = new HashSet<>();
+    private List<String> caSelected = new ArrayList<>();
 
-    public void setSelectedList( Collection<String> selectedList )
+    public void setCaSelected( List<String> caSelected )
     {
-        this.selectedList = selectedList;
+        this.caSelected = caSelected;
     }
 
     // -------------------------------------------------------------------------
@@ -100,20 +96,18 @@
 
         categoryCombo.setName( name );
         categoryCombo.setSkipTotal( skipTotal );
-        
+
         List<DataElementCategory> updatedCategories = new ArrayList<>();
 
-        for ( String id : selectedList )
+        for ( String id : caSelected )
         {
-            DataElementCategory dataElementCategory = dataElementCategoryService.getDataElementCategory( Integer
-                .parseInt( id ) );
-
+            DataElementCategory dataElementCategory = dataElementCategoryService.getDataElementCategory( id );
             updatedCategories.add( dataElementCategory );
         }
 
         categoryCombo.setCategories( updatedCategories );
 
-        dataElementCategoryService.updateDataElementCategoryCombo( categoryCombo );       
+        dataElementCategoryService.updateDataElementCategoryCombo( categoryCombo );
 
         return SUCCESS;
     }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/javascript/categoryOptionCombo.js'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/javascript/categoryOptionCombo.js	2013-12-20 14:15:25 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/javascript/categoryOptionCombo.js	2014-09-25 07:30:35 +0000
@@ -30,31 +30,24 @@
 
 dhis2.coc = {
     clearAndSetAjaxSelect: function( type, clearSelected ) {
-        var source = "../dhis-web-commons-ajax-json/getDataElementCategories.action";
+        var source = "../api/categories.json";
 
         if( type !== undefined ) {
-            source += "?type=" + type;
+            source += "?filter=dataDimensionType:eq:" + type;
         }
 
         if( clearSelected ) {
             $('#selectedList').children().empty();
         }
 
-        jQuery("#availableList").dhisAjaxSelect({
-            source: source,
-            iterator: 'dataElementCategories',
-            sortSelected: false,
-            connectedTo: 'selectedList',
-            handler: function( item ) {
-                var option = jQuery("<option />");
-                option.text(item.name);
-                option.attr("value", item.id);
-
-                return option;
-            }
+        $('#caAvailable').selected({
+          url: source,
+          target: $('#caSelected'),
+          search: $('#caAvailableSearch'),
+          iterator: 'categories'
         });
     },
     getType: function () {
-        return $('#dimensionType').val().toUpperCase();
+        return $('#dimensionType').val().toLowerCase();
     }
 };

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/multidimensional/addDataElementCategoryComboForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/multidimensional/addDataElementCategoryComboForm.vm	2014-03-25 08:23:36 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/multidimensional/addDataElementCategoryComboForm.vm	2014-09-25 07:30:35 +0000
@@ -10,7 +10,10 @@
         validation2( 'addDataElementCategoryComboForm', function( form ){
 			validateSelectedCategories( form );
 		}, {
-			'beforeValidateHandler': function() { listValidator( 'selectedCategories', 'selectedList' ); },
+			'beforeValidateHandler': function() {
+                $("#caSelected").find("option").attr("selected", "selected");
+                listValidator( 'caValidator', 'caSelected' );
+            },
 			'rules': getValidationRules("dateElementCategoryCombo")
 		});
 
@@ -54,53 +57,11 @@
     </tbody>
   </table>
 
-  <table id="dataElementCategorySelectionArea">
-      <colgroup>
-        <col style="width: 500px;"/>
-        <col/>
-        <col style="width: 500px;"/>
-        <col/>
-      </colgroup>
-
-    <thead>
-      <tr>        
-		<th>$i18n.getString( "available_categories" )</th>
-		<th></th>
-		<th>$i18n.getString( "selected_categories" )</th>
-      </tr>
-    </thead>
-
-    <tbody>
-      <tr>
-        <td>
-            <select id="availableList" name="availableList" multiple="multiple" style="height: 200px; width: 100%;"></select>
-        </td>
-
-        <td style="text-align:center">
-        	<input type="button" value="&gt;" title="$i18n.getString( 'move_selected' )" style="width:50px" onclick="dhisAjaxSelect_moveAllSelected( 'availableList' );"/><br/>
-            <input type="button" value="&lt;" title="$i18n.getString( 'remove_selected' )" style="width:50px" onclick="dhisAjaxSelect_moveAllSelected( 'selectedList' );"/><br/>
-			<input type="button" value="&gt;&gt;" title="$i18n.getString('move_all')" style="width:50px" onclick="dhisAjaxSelect_moveAll( 'availableList' );"/><br/>
-			<input type="button" value="&lt;&lt;" title="$i18n.getString('remove_all')" style="width:50px" onclick="dhisAjaxSelect_moveAll( 'selectedList' );"/>
-        </td>
-
-		<td>
-            <select id="selectedList" name="selectedList" multiple="multiple" style="height: 200px; width: 100%; margin-top: 22px;"></select>
-        </td>
-
-		<td>
-		  <a onclick="moveUpSelectedOption('selectedList')" title="$i18n.getString( 'move_up' )"><img src="../images/move_up.png" style="border:0;cursor:pointer" alt="$i18n.getString( 'move_up' )"/></a><br/><br/>
-		  <a onclick="moveDownSelectedOption('selectedList')" title="$i18n.getString( 'move_down' )"><img src="../images/move_down.png" style="border:0;cursor:pointer" alt="$i18n.getString( 'move_down' )"/></a>
-		</td>
-      </tr>
-
-	  <tr>
-		<td colspan="4">
-			<select id="selectedCategories" name="selectedCategories" style="display:none"></select>
-		</td>
-      </tr>
-
-    </tbody>
-  </table>
+  #jqSelected({
+    "prefix": "ca",
+    "i18n_available": "available_categories",
+    "i18n_selected": "selected_categories"
+  })
 
 	<p>
 		<input type="submit" name="add" value="$i18n.getString( 'add' )" style="width:10em" />

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/multidimensional/updateDataElementCategoryComboForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/multidimensional/updateDataElementCategoryComboForm.vm	2013-12-20 14:15:25 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/multidimensional/updateDataElementCategoryComboForm.vm	2014-09-25 07:30:35 +0000
@@ -11,8 +11,8 @@
 			validateSelectedCategories( form );
 		}, {
 			'beforeValidateHandler': function() {
-				jQuery("#selectedList option").each(function() { jQuery(this).attr("selected", "true"); });
-				listValidator( 'selectedCategories', 'selectedList' );
+                $("#caSelected").find("option").attr("selected", "selected");
+                listValidator( 'caValidator', 'caSelected' );
 			},
 			'rules': getValidationRules("dateElementCategoryCombo")
 		});
@@ -56,63 +56,16 @@
     </tbody>
   </table>
 
- <table id="dataElementCategorySelectionArea">
-     <colgroup>
-       <col style="width: 500px;"/>
-       <col/>
-       <col style="width: 500px;"/>
-       <col/>
-     </colgroup>
-
-    <thead>
-        <tr>        
-		<th>$i18n.getString( "available_categories" )</th>
-		<th></th>        
-		<th>$i18n.getString( "selected_categories" )</th>
-      </tr>
-    </thead>
-  
-    <tbody>
-      <tr>       
-		<td>
-          <select id="availableList" name="availableList" multiple="multiple" style="height: 200px; width: 100%;"></select>
-        </td>
-       </td>
-
-        <td style="text-align:center">
-        	<input type="button" value="&gt;" title="$i18n.getString( 'move_selected' )" style="width:50px" onclick="dhisAjaxSelect_moveAllSelected( 'availableList' );"/><br/>
-            <input type="button" value="&lt;" title="$i18n.getString( 'remove_selected' )" style="width:50px" onclick="dhisAjaxSelect_moveAllSelected( 'selectedList' );"/><br/>
-			<input type="button" value="&gt;&gt;" title="$i18n.getString('move_all')" style="width:50px" onclick="dhisAjaxSelect_moveAll( 'availableList' );"/><br/>
-			<input type="button" value="&lt;&lt;" title="$i18n.getString('remove_all')" style="width:50px" onclick="dhisAjaxSelect_moveAll( 'selectedList' );"/>
-        </td>
-
-		<td>
-          <select id="selectedList" name="selectedList" multiple="multiple" style="height: 200px; width: 100%; margin-top: 22px;">
-            #foreach ( $dataElementCategory in $dataElementCategories )
-              <option value="$dataElementCategory.id">$encoder.htmlEncode( $dataElementCategory.name )</option>
-            #end
-          </select>
-        </td>
-        
-		<td>
-		  <a onclick="moveUpSelectedOption('selectedList')" title="$i18n.getString( 'move_up' )"><img src="../images/move_up.png" style="border:0;cursor:pointer" alt="$i18n.getString( 'move_up' )"/></a><br/><br/>
-		  <a onclick="moveDownSelectedOption('selectedList')" title="$i18n.getString( 'move_down' )"><img src="../images/move_down.png" style="border:0;cursor:pointer" alt="$i18n.getString( 'move_down' )"/></a>		  
-        </td> 
-            
-      </tr>
-
-	  <tr>
-		<td colspan="4">
-			<select id="selectedCategories" name="selectedCategories" style="display:none"></select>
-		</td>
-      </tr>
-
-    </tbody>
-  </table>
-
-<p>
+  #jqSelected({
+    "prefix": "ca",
+    "i18n_available": "available_categories",
+    "i18n_selected": "selected_categories",
+    "objects": $dataElementCategories
+  })
+
+  <p>
 	<input type="submit" name="update" value="$i18n.getString( 'update' )" style="width:10em" />
 	<input type="button" name="cancel" onclick="dhis2.commons.redirectCurrentPage( 'categoryCombo.action' )" value="$i18n.getString( 'cancel' )" style="width:10em" />
-</p>
-       
+  </p>
+
 </form>