← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 3912: implemented ajax-load in add/update validationGroup

 

------------------------------------------------------------
revno: 3912
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2011-06-15 11:16:51 +0200
message:
  implemented ajax-load in add/update validationGroup
removed:
  dhis-2/dhis-web/dhis-web-validationrule/src/main/java/org/hisp/dhis/validationrule/action/validationrulegroup/GetValidationRuleGroupMembersAction.java
modified:
  dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetValidationRulesAction.java
  dhis-2/dhis-web/dhis-web-validationrule/src/main/java/org/hisp/dhis/validationrule/action/validationrulegroup/ShowUpdateValidationRuleGroupFormAction.java
  dhis-2/dhis-web/dhis-web-validationrule/src/main/resources/struts.xml
  dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/addValidationRuleGroupForm.vm
  dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/javascript/addValidationRuleGroupForm.js
  dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/javascript/updateValidationRuleGroupForm.js
  dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/updateValidationRuleGroupForm.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-commons/src/main/java/org/hisp/dhis/commons/action/GetValidationRulesAction.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetValidationRulesAction.java	2011-06-14 13:59:43 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetValidationRulesAction.java	2011-06-15 09:16:51 +0000
@@ -28,10 +28,12 @@
  */
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 
 import org.hisp.dhis.validation.ValidationRule;
 import org.hisp.dhis.validation.ValidationRuleService;
+import org.hisp.dhis.validation.comparator.ValidationRuleNameComparator;
 
 import com.opensymphony.xwork2.Action;
 
@@ -71,6 +73,8 @@
     {
         validationRules = new ArrayList<ValidationRule>( validationRuleService.getAllValidationRules() );
 
+        Collections.sort( validationRules, new ValidationRuleNameComparator() );
+
         return SUCCESS;
     }
 }

=== removed file 'dhis-2/dhis-web/dhis-web-validationrule/src/main/java/org/hisp/dhis/validationrule/action/validationrulegroup/GetValidationRuleGroupMembersAction.java'
--- dhis-2/dhis-web/dhis-web-validationrule/src/main/java/org/hisp/dhis/validationrule/action/validationrulegroup/GetValidationRuleGroupMembersAction.java	2010-04-12 21:23:33 +0000
+++ dhis-2/dhis-web/dhis-web-validationrule/src/main/java/org/hisp/dhis/validationrule/action/validationrulegroup/GetValidationRuleGroupMembersAction.java	1970-01-01 00:00:00 +0000
@@ -1,119 +0,0 @@
-package org.hisp.dhis.validationrule.action.validationrulegroup;
-
-/*
- * 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.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-import org.hisp.dhis.validation.ValidationRule;
-import org.hisp.dhis.validation.ValidationRuleGroup;
-import org.hisp.dhis.validation.ValidationRuleService;
-import org.hisp.dhis.validation.comparator.ValidationRuleNameComparator;
-
-import com.opensymphony.xwork2.Action;
-
-/**
-* @author Lars Helge Overland
-* @version $Id$
-*/
-public class GetValidationRuleGroupMembersAction
-    implements Action
-{
-    // -------------------------------------------------------------------------
-    // Dependencies
-    // -------------------------------------------------------------------------
-
-    private ValidationRuleService validationRuleService;
-
-    public void setValidationRuleService( ValidationRuleService validationRuleService )
-    {
-        this.validationRuleService = validationRuleService;
-    }
-
-    // -------------------------------------------------------------------------
-    // Input
-    // -------------------------------------------------------------------------
-
-    private Integer id;
-
-    public void setId( Integer id )
-    {
-        this.id = id;
-    }
-
-    // -------------------------------------------------------------------------
-    // Output
-    // -------------------------------------------------------------------------
-
-    private List<ValidationRule> groupMembers = new ArrayList<ValidationRule>();
-
-    public List<ValidationRule> getGroupMembers()
-    {
-        return groupMembers;
-    }
-    
-    private List<ValidationRule> availableValidationRules = new ArrayList<ValidationRule>();
-
-    public List<ValidationRule> getAvailableValidationRules()
-    {
-        return availableValidationRules;
-    }
-
-    // -------------------------------------------------------------------------
-    // Action implementation
-    // -------------------------------------------------------------------------
-
-    public String execute()
-    {
-        // ---------------------------------------------------------------------
-        // Get group members
-        // ---------------------------------------------------------------------
-
-        if ( id != null )
-        {
-            ValidationRuleGroup group = validationRuleService.getValidationRuleGroup( id );
-            
-            groupMembers = new ArrayList<ValidationRule>( group.getMembers() );
-            
-            Collections.sort( groupMembers, new ValidationRuleNameComparator() );
-        }
-
-        // ---------------------------------------------------------------------
-        // Get available ValidationRules
-        // ---------------------------------------------------------------------
-
-        availableValidationRules = new ArrayList<ValidationRule>( validationRuleService.getAllValidationRules() );
-        
-        availableValidationRules.removeAll( groupMembers );
-        
-        Collections.sort( availableValidationRules, new ValidationRuleNameComparator() );
-            
-        return SUCCESS;
-    }
-}

=== modified file 'dhis-2/dhis-web/dhis-web-validationrule/src/main/java/org/hisp/dhis/validationrule/action/validationrulegroup/ShowUpdateValidationRuleGroupFormAction.java'
--- dhis-2/dhis-web/dhis-web-validationrule/src/main/java/org/hisp/dhis/validationrule/action/validationrulegroup/ShowUpdateValidationRuleGroupFormAction.java	2011-05-31 05:38:55 +0000
+++ dhis-2/dhis-web/dhis-web-validationrule/src/main/java/org/hisp/dhis/validationrule/action/validationrulegroup/ShowUpdateValidationRuleGroupFormAction.java	2011-06-15 09:16:51 +0000
@@ -110,16 +110,6 @@
 
         Collections.sort( groupMembers, new ValidationRuleNameComparator() );
 
-        // ---------------------------------------------------------------------
-        // Get available ValidationRules
-        // ---------------------------------------------------------------------
-
-        availableValidationRules = new ArrayList<ValidationRule>( validationRuleService.getAllValidationRules() );
-
-        availableValidationRules.removeAll( groupMembers );
-
-        Collections.sort( availableValidationRules, new ValidationRuleNameComparator() );
-
         return SUCCESS;
     }
 

=== modified file 'dhis-2/dhis-web/dhis-web-validationrule/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-validationrule/src/main/resources/struts.xml	2011-06-11 23:05:27 +0000
+++ dhis-2/dhis-web/dhis-web-validationrule/src/main/resources/struts.xml	2011-06-15 09:16:51 +0000
@@ -96,7 +96,7 @@
       <param name="onExceptionReturn">plainTextError</param>
     </action>
       
-    <action name="showAddValidationRuleGroupForm" class="org.hisp.dhis.validationrule.action.validationrulegroup.GetValidationRuleGroupMembersAction">
+    <action name="showAddValidationRuleGroupForm" class="org.hisp.dhis.validationrule.action.NoAction">
       <result name="success" type="velocity">/main.vm</result>
       <param name="page">/dhis-web-validationrule/addValidationRuleGroupForm.vm</param>
       <param name="javascripts">javascript/validationRuleGroup.js, javascript/addValidationRuleGroupForm.js</param>

=== modified file 'dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/addValidationRuleGroupForm.vm'
--- dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/addValidationRuleGroupForm.vm	2011-03-29 08:15:49 +0000
+++ dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/addValidationRuleGroupForm.vm	2011-06-15 09:16:51 +0000
@@ -1,13 +1,18 @@
 <script type="text/javascript">
-    var groupMembers = new Object();
-	#foreach( $validationRule in $groupMembers )
-		groupMembers['$validationRule.id'] = '$encoder.jsEscape( $validationRule.name, "'" )';
-	#end
+	jQuery(document).ready(function() {
+		jQuery("#availableValidationRules").dhisAjaxSelect({
+			source: "../dhis-web-commons-ajax-json/getValidationRules.action",
+			iterator: "validationRules",
+			connectedTo: 'groupMembers',
+			handler: function(item) {
+				var option = jQuery("<option />");
+				option.text( item.name );
+				option.attr( "value", item.id );
 
-    var availableValidationRules = new Object();
-	#foreach( $validationRule in $availableValidationRules )
-		availableValidationRules['$validationRule.id'] = '$encoder.jsEscape( $validationRule.name, "'" )';
-	#end
+				return option;
+			}
+		});
+	});
 </script>
 
 <h3>$i18n.getString( "create_new_validation_rule_group" )</h3>
@@ -18,43 +23,50 @@
     <tr>
         <th colspan="2">$i18n.getString( "details" )</th>
     </tr>
+
     <tr>
         <td><label for="name">$i18n.getString( "name" ) <em title="$i18n.getString( "required" )" class="required">*</em></label></td>
         <td><input type="text" id="name" name="name" style="width:20em" /></td>
     </tr>
+
     <tr>
         <td><label for="description">$i18n.getString( "description" )<em title="$i18n.getString( "required" )" class="required">*</em></label></td>
         <td><input type="text" id="description" name="description" style="width:20em" /></td>
     </tr>
-    <tr>
-        <td colspan="2">&nbsp;</td>
-    </tr>
 </table>
 
-<table>
-    <tr>
-        <th>$i18n.getString( "available_validation_rules" )</th><td></td><th>$i18n.getString( "group_members" )</th>
-    </tr>
-    <tr>
-    	<td><input type="text" id="availableValidationRulesFilter" onkeyup="filterAvailableValidationRules()" style="width:25em"></td>
-        <td style="text-align:center">&lt; $i18n.getString( "filters" ) &gt;</td>
-        <td><input type="text" id="groupMembersFilter" onkeyup="filterGroupMembers()" style="width:25em"></td>        
-    </tr>
+<table style="margin-top: 15px;">
+    <col style="width: 450px"/>
+    <col/>
+    <col style="width: 450px"/>
+
+    <tr>
+        <th>$i18n.getString( "available_validation_rules" )</th>
+        <th></th>
+        <th>$i18n.getString( "group_members" )</th>
+    </tr>
+
     <tr>
     	<td>
-            <select id="availableValidationRules" size="2" multiple="multiple" style="min-width:25em; height:25em" ondblclick="addGroupMembers()">
-            </select>
+            <select id="availableValidationRules" name="availableValidationRules" multiple="multiple" style="height: 200px; width: 100%;"></select>
         </td>
+
         <td style="text-align:center">
-            <input type="button" value="&gt;" title="$i18n.getString('move_selected')" onclick="addGroupMembers()"><br><br>
-            <input type="button" value="&lt;" title="$i18n.getString('remove_selected')" onclick="removeGroupMembers()">
+        	<input type="button" value="&gt;" title="$i18n.getString( 'move_selected' )" style="width:50px" onclick="dhisAjaxSelect_moveAllSelected( 'availableValidationRules' );"/><br/>
+            <input type="button" value="&lt;" title="$i18n.getString( 'remove_selected' )" style="width:50px" onclick="dhisAjaxSelect_moveAllSelected( 'groupMembers' );"/><br/>
+			<input type="button" value="&gt;&gt;" title="$i18n.getString('move_all')" style="width:50px" onclick="dhisAjaxSelect_moveAll( 'availableValidationRules' );"/><br/>
+			<input type="button" value="&lt;&lt;" title="$i18n.getString('remove_all')" style="width:50px" onclick="dhisAjaxSelect_moveAll( 'groupMembers' );"/>
         </td>
+
         <td>
-            <select id="groupMembers" name="groupMembers" size="2" multiple="multiple" style="min-width:25em; height:25em" ondblclick="removeGroupMembers()" />
+            <select id="groupMembers" name="groupMembers" multiple="multiple" style="height: 200px; width: 100%; margin-top: 22px" />
         </td>      
     </tr>
 </table>
 
-<p><input type="submit" value="$i18n.getString( "add" )" style="width:10em"><input type="button" value="$i18n.getString( "cancel" )" onclick="window.location.href='showValidationRuleGroupForm.action'" style="width:10em"></p>
+<p>
+	<input type="submit" value="$i18n.getString( "add" )" style="width:10em" />
+	<input type="button" value="$i18n.getString( "cancel" )" onclick="window.location.href='showValidationRuleGroupForm.action'" style="width:10em" />
+</p>
 
 </form>

=== modified file 'dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/javascript/addValidationRuleGroupForm.js'
--- dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/javascript/addValidationRuleGroupForm.js	2011-04-11 12:23:17 +0000
+++ dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/javascript/addValidationRuleGroupForm.js	2011-06-15 09:16:51 +0000
@@ -11,6 +11,4 @@
 	});
 
 	checkValueIsExist("name", "validateValidationRuleGroup.action");
-
-	initLists();
 });

=== modified file 'dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/javascript/updateValidationRuleGroupForm.js'
--- dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/javascript/updateValidationRuleGroupForm.js	2011-04-11 12:23:17 +0000
+++ dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/javascript/updateValidationRuleGroupForm.js	2011-06-15 09:16:51 +0000
@@ -1,18 +1,19 @@
-jQuery(document).ready(function() {
-	jQuery("#name").focus();
-
-	validation2('updateValidationRuleGroupForm', function(form) {
-		form.submit()
-	}, {
-		'beforeValidateHandler' : function() {
-			selectAllById('groupMembers')
-		},
-		'rules' : getValidationRules("validationRuleGroup")
-	});
-
-	checkValueIsExist("name", "validateValidationRuleGroup.action", {
-		id : getFieldValue('id')
-	});
-
-	initLists();
-});
+jQuery( document ).ready( function()
+{
+    jQuery( "#name" ).focus();
+
+    validation2( 'updateValidationRuleGroupForm', function( form )
+    {
+        form.submit()
+    }, {
+        'beforeValidateHandler' : function()
+        {
+            selectAllById( 'groupMembers' )
+        },
+        'rules' : getValidationRules( "validationRuleGroup" )
+    } );
+
+    checkValueIsExist( "name", "validateValidationRuleGroup.action", {
+        id : getFieldValue( 'id' )
+    } );
+} );

=== modified file 'dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/updateValidationRuleGroupForm.vm'
--- dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/updateValidationRuleGroupForm.vm	2011-03-29 08:15:49 +0000
+++ dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/updateValidationRuleGroupForm.vm	2011-06-15 09:16:51 +0000
@@ -1,13 +1,18 @@
 <script type="text/javascript">
-    var groupMembers = new Object();
-	#foreach( $validationRule in $groupMembers )
-		groupMembers['$validationRule.id'] = '$encoder.jsEscape( $validationRule.name, "'" )';
-	#end
+	jQuery(document).ready(function() {
+		jQuery("#availableValidationRules").dhisAjaxSelect({
+			source: "../dhis-web-commons-ajax-json/getValidationRules.action",
+			iterator: "validationRules",
+			connectedTo: 'groupMembers',
+			handler: function(item) {
+				var option = jQuery("<option />");
+				option.text( item.name );
+				option.attr( "value", item.id );
 
-    var availableValidationRules = new Object();
-	#foreach( $validationRule in $availableValidationRules )
-		availableValidationRules['$validationRule.id'] = '$encoder.jsEscape( $validationRule.name, "'" )';
-	#end
+				return option;
+			}
+		});
+	});
 </script>
 
 <h3>$i18n.getString( "edit_validation_rule_group" )</h3>
@@ -22,45 +27,56 @@
     <tr>
         <th colspan="2">$i18n.getString( "details" )</th>
     </tr>
+
     <tr>
         <td><label for="name">$i18n.getString( "name" ) <em title="$i18n.getString( "required" )" class="required">*</em></label></td>
         <td><input type="text" id="name" name="name" value="$encoder.htmlEncode( $validationRuleGroup.name )" style="width:20em"></td>
     </tr>
+
     <tr>
         <td><label for="description">$i18n.getString( "description" )<em title="$i18n.getString( "required" )" class="required">*</em></label></td>
         <td><input type="text" id="description" name="description" value="$encoder.htmlEncode( $validationRuleGroup.description )" style="width:20em"></td>
     </tr>
-    <tr>
-        <td colspan="2">&nbsp;</td>
-    </tr>
+
 </table>
 
-<table>
+<table style="margin-top: 15px;">
+    <col style="width: 450px"/>
+    <col/>
+    <col style="width: 450px"/>
+
     <tr>
-        <th>$i18n.getString( "available_validation_rules" )</th><td></td><th>$i18n.getString( "group_members" )</th>
-    </tr>
-    <tr>    	
-        <td><input type="text" id="availableValidationRulesFilter" onkeyup="filterAvailableValidationRules()" style="width:25em"></td>
-        <td style="text-align:center">&lt; $i18n.getString( "filters" ) &gt;</td>
-        <td><input type="text" id="groupMembersFilter" onkeyup="filterGroupMembers()" style="width:25em"></td>        
-    </tr>
+        <th>$i18n.getString( "available_validation_rules" )</th>
+        <th></th>
+        <th>$i18n.getString( "group_members" )</th>
+    </tr>
+
     <tr>
         <td>
-            <select id="availableValidationRules" size="2" multiple="multiple" style="min-width:25em; height:25em" ondblclick="addGroupMembers()">
-            </select>
+            <select id="availableValidationRules" name="availableValidationRules" multiple="multiple" style="height: 200px; width: 100%;"></select>
         </td>
+
         <td style="text-align:center">
-            <input type="button" value="&gt;" title="$i18n.getString('move_selected')" onclick="addGroupMembers()"><br><br>
-            <input type="button" value="&lt;" title="$i18n.getString('remove_selected')" onclick="removeGroupMembers()">
-        </td>        
+        	<input type="button" value="&gt;" title="$i18n.getString( 'move_selected' )" style="width:50px" onclick="dhisAjaxSelect_moveAllSelected( 'availableValidationRules' );"/><br/>
+            <input type="button" value="&lt;" title="$i18n.getString( 'remove_selected' )" style="width:50px" onclick="dhisAjaxSelect_moveAllSelected( 'groupMembers' );"/><br/>
+			<input type="button" value="&gt;&gt;" title="$i18n.getString('move_all')" style="width:50px" onclick="dhisAjaxSelect_moveAll( 'availableValidationRules' );"/><br/>
+			<input type="button" value="&lt;&lt;" title="$i18n.getString('remove_all')" style="width:50px" onclick="dhisAjaxSelect_moveAll( 'groupMembers' );"/>
+        </td>
+
         <td>
-            <select id="groupMembers" name="groupMembers" size="2" multiple="multiple" style="min-width:25em; height:25em" ondblclick="removeGroupMembers()">
+            <select id="groupMembers" name="groupMembers" multiple="multiple" style="height: 200px; width: 100%; margin-top: 22px">
+			#foreach( $validationRule in $groupMembers )
+				<option value="$validationRule.id">$encoder.htmlEncode( $validationRule.name )</option>
+			#end
             </select>
-        </td>
+        </td>      
     </tr>
 </table>
 
-<p><input type="submit" value="$i18n.getString( "save" )" style="width:10em"><input type="button" value="$i18n.getString( "cancel" )" onclick="window.location.href='showValidationRuleGroupForm.action'" style="width:10em"></p>
+<p>
+	<input type="submit" value="$i18n.getString( "save" )" style="width:10em" />
+	<input type="button" value="$i18n.getString( "cancel" )" onclick="window.location.href='showValidationRuleGroupForm.action'" style="width:10em" />
+</p>
 
 </form>