dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #09340
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2450: add form validation for user group/fixed javascript bug in datamart list and user list
------------------------------------------------------------
revno: 2450
committer: Tri <Tri@Tri-Laptop>
branch nick: dhis2
timestamp: Thu 2010-12-30 11:29:49 +0700
message:
add form validation for user group/fixed javascript bug in datamart list and user list
modified:
dhis-2/dhis-web/dhis-web-datamart/src/main/webapp/dhis-web-datamart/viewExportForm.vm
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/ValidateUserGroupAction.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/resources/META-INF/dhis/beans.xml
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/resources/struts.xml
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/addUserGroupForm.vm
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/updateUserGroupForm.vm
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/userGroupList.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-datamart/src/main/webapp/dhis-web-datamart/viewExportForm.vm'
--- dhis-2/dhis-web/dhis-web-datamart/src/main/webapp/dhis-web-datamart/viewExportForm.vm 2010-12-07 08:30:02 +0000
+++ dhis-2/dhis-web/dhis-web-datamart/src/main/webapp/dhis-web-datamart/viewExportForm.vm 2010-12-30 04:29:49 +0000
@@ -12,27 +12,24 @@
</table>
<table class="listTable" id="listTable">
<col/>
- <col width="20"/>
- <col width="20"/>
- <col width="20"/>
- <col width="20"/>
- <col width="20"/>
- <thead>
-
- <tr>
- <th>$i18n.getString( "name" )</th>
- <th colspan="5" class="{sorter: false}">$i18n.getString( "operations" )</th>
- </tr>
+ <col width="150"/>
+ <thead>
+ <tr>
+ <th>$i18n.getString( "name" )</th>
+ <th class="{sorter: false}">$i18n.getString( "operations" )</th>
+ </tr>
</thead>
<tbody id="list">
#foreach( $export in $exports )
<tr>
<td onclick="showDataMartExportDetails( $export.id )">$encoder.htmlEncode( $export.name )</td>
- <td style="text-align:center"><a href="exportDataMartExport.action?id=$export.id" title="$i18n.getString( 'export' )"><img src="../images/start_process.png" alt="$i18n.getString( 'export' )"/></a></td>
- <td style="text-align:center"><a href="getOptions.action?id=$export.id" title="$i18n.getString( 'edit' )"><img src="../images/edit.png" alt="$i18n.getString( 'edit' )"></a></td>
- <td style="text-align:center"><a href="javascript:removeDatamartExport( $export.id, '$encoder.jsEncode( $export.name )' )" title="$i18n.getString( 'remove' )"><img src="../images/delete.png" alt="$i18n.getString( 'remove' )"/></a></td>
- <td style="text-align:center"><a href="javascript:addToDashboard( '$export.id' )" title="$i18n.getString( 'add_to_dashboard' )"><img src="../images/add_to_dashboard.png" alt="$i18n.getString( 'add_to_dashboard' )"/></a></td>
- <td style="text-align:center"><a href="javascript:showDataMartExportDetails( $export.id )" title="$i18n.getString( 'show_details' )"><img src="../images/information.png" alt="$i18n.getString( 'show_details' )"/></a></td>
+ <td style="text-align:center">
+ <a href="exportDataMartExport.action?id=$export.id" title="$i18n.getString( 'export' )"><img src="../images/start_process.png" alt="$i18n.getString( 'export' )"/></a>
+ <a href="getOptions.action?id=$export.id" title="$i18n.getString( 'edit' )"><img src="../images/edit.png" alt="$i18n.getString( 'edit' )"></a>
+ <a href="javascript:removeDatamartExport( $export.id, '$encoder.jsEncode( $export.name )' )" title="$i18n.getString( 'remove' )"><img src="../images/delete.png" alt="$i18n.getString( 'remove' )"/></a>
+ <a href="javascript:addToDashboard( '$export.id' )" title="$i18n.getString( 'add_to_dashboard' )"><img src="../images/add_to_dashboard.png" alt="$i18n.getString( 'add_to_dashboard' )"/></a>
+ <a href="javascript:showDataMartExportDetails( $export.id )" title="$i18n.getString( 'show_details' )"><img src="../images/information.png" alt="$i18n.getString( 'show_details' )"/></a>
+ </td>
</tr>
#end
</tbody>
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/ValidateUserGroupAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/ValidateUserGroupAction.java 2010-12-26 15:38:45 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/ValidateUserGroupAction.java 2010-12-30 04:29:49 +0000
@@ -27,6 +27,8 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import org.hisp.dhis.i18n.I18n;
+import org.hisp.dhis.user.UserCredentials;
import org.hisp.dhis.user.UserGroup;
import org.hisp.dhis.user.UserGroupService;
@@ -46,14 +48,38 @@
this.userGroupService = userGroupService;
}
+ private I18n i18n;
+
+ public void setI18n( I18n i18n )
+ {
+ this.i18n = i18n;
+ }
+
// -------------------------------------------------------------------------
// Parameters
// -------------------------------------------------------------------------
private Integer id;
+ public void setId( Integer id )
+ {
+ this.id = id;
+ }
+
private String name;
+ public void setName( String name )
+ {
+ this.name = name;
+ }
+
+ private String message;
+
+ public String getMessage()
+ {
+ return message;
+ }
+
// -------------------------------------------------------------------------
// Action Implementation
// -------------------------------------------------------------------------
@@ -61,13 +87,21 @@
public String execute()
throws Exception
{
- UserGroup group = userGroupService.getUserGroupByName( name );
- if ( ( id == null && group != null ) || ( id != null && id != group.getId() ) )
+ if ( name != null )
{
- return INPUT;
+ UserGroup match = userGroupService.getUserGroupByName( name );
+
+ if ( match != null && (id == null || match.getId() != id) )
+ {
+ message = i18n.getString( "name_in_use" );
+
+ return ERROR;
+ }
}
-
+
+ message = i18n.getString( "everything_is_ok" );
+
return SUCCESS;
}
}
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/resources/META-INF/dhis/beans.xml 2010-12-23 12:27:24 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/resources/META-INF/dhis/beans.xml 2010-12-30 04:29:49 +0000
@@ -25,22 +25,21 @@
</property>
</bean>
- <bean id="org.hisp.dhis.user.action.DeleteCurrentUserAction"
- class="org.hisp.dhis.user.action.DeleteCurrentUserAction"
- scope="prototype">
- <property name="userStore">
- <ref bean="org.hisp.dhis.user.UserStore"/>
- </property>
- <property name="currentUserService">
- <ref bean="org.hisp.dhis.user.CurrentUserService"/>
- </property>
- <property name="passwordManager">
- <ref bean="org.hisp.dhis.security.PasswordManager"/>
- </property>
- <property name="userService">
- <ref bean="org.hisp.dhis.user.UserService" />
- </property>
- </bean>
+ <bean id="org.hisp.dhis.user.action.DeleteCurrentUserAction"
+ class="org.hisp.dhis.user.action.DeleteCurrentUserAction" scope="prototype">
+ <property name="userStore">
+ <ref bean="org.hisp.dhis.user.UserStore" />
+ </property>
+ <property name="currentUserService">
+ <ref bean="org.hisp.dhis.user.CurrentUserService" />
+ </property>
+ <property name="passwordManager">
+ <ref bean="org.hisp.dhis.security.PasswordManager" />
+ </property>
+ <property name="userService">
+ <ref bean="org.hisp.dhis.user.UserService" />
+ </property>
+ </bean>
<bean id="org.hisp.dhis.user.action.GetUserAction" class="org.hisp.dhis.user.action.GetUserAction"
@@ -65,9 +64,9 @@
<property name="userStore">
<ref bean="org.hisp.dhis.user.UserStore" />
</property>
- <property name="currentUserService">
- <ref bean="org.hisp.dhis.user.CurrentUserService"/>
- </property>
+ <property name="currentUserService">
+ <ref bean="org.hisp.dhis.user.CurrentUserService" />
+ </property>
</bean>
<bean id="org.hisp.dhis.user.action.RemoveUserAction" class="org.hisp.dhis.user.action.RemoveUserAction"
@@ -113,10 +112,10 @@
</property>
<property name="selectionManager">
<ref bean="org.hisp.dhis.ouwt.manager.OrganisationUnitSelectionManager" />
- </property>
+ </property>
<property name="userStore">
<ref bean="org.hisp.dhis.user.UserStore" />
- </property>
+ </property>
</bean>
<bean
@@ -211,47 +210,49 @@
</property>
</bean>
- <!-- User groups -->
-
- <bean id="org.hisp.dhis.user.action.GetUserGroupListAction" class="org.hisp.dhis.user.action.GetUserGroupListAction"
- scope="prototype">
- <property name="userGroupService" ref="org.hisp.dhis.user.UserGroupService" />
- </bean>
-
- <bean id="org.hisp.dhis.user.action.AddUserGroupFormAction" class="org.hisp.dhis.user.action.AddUserGroupFormAction"
- scope="prototype">
- <property name="userStore" ref="org.hisp.dhis.user.UserStore" />
- </bean>
-
- <bean id="org.hisp.dhis.user.action.AddUserGroupAction" class="org.hisp.dhis.user.action.AddUserGroupAction"
- scope="prototype">
- <property name="userStore" ref="org.hisp.dhis.user.UserStore" />
- <property name="userGroupService" ref="org.hisp.dhis.user.UserGroupService" />
- </bean>
-
- <bean id="org.hisp.dhis.user.action.EditUserGroupFormAction" class="org.hisp.dhis.user.action.EditUserGroupFormAction"
- scope="prototype">
- <property name="userStore" ref="org.hisp.dhis.user.UserStore" />
- <property name="userGroupService" ref="org.hisp.dhis.user.UserGroupService" />
- </bean>
-
- <bean id="org.hisp.dhis.user.action.UpdateUserGroupAction" class="org.hisp.dhis.user.action.UpdateUserGroupAction"
- scope="prototype">
- <property name="userStore" ref="org.hisp.dhis.user.UserStore" />
- <property name="userGroupService" ref="org.hisp.dhis.user.UserGroupService" />
- </bean>
-
- <bean id="org.hisp.dhis.user.action.RemoveUserGroupAction" class="org.hisp.dhis.user.action.RemoveUserGroupAction"
- scope="prototype">
- <property name="userGroupService" ref="org.hisp.dhis.user.UserGroupService" />
- </bean>
-
-
- <bean id="org.hisp.dhis.user.action.GetUserGroupAction" class="org.hisp.dhis.user.action.GetUserGroupAction"
- scope="prototype">
- <property name="userGroupService" ref="org.hisp.dhis.user.UserGroupService" />
- </bean>
-
-
+ <!-- User groups -->
+
+ <bean id="org.hisp.dhis.user.action.GetUserGroupListAction" class="org.hisp.dhis.user.action.GetUserGroupListAction"
+ scope="prototype">
+ <property name="userGroupService" ref="org.hisp.dhis.user.UserGroupService" />
+ </bean>
+
+ <bean id="org.hisp.dhis.user.action.AddUserGroupFormAction" class="org.hisp.dhis.user.action.AddUserGroupFormAction"
+ scope="prototype">
+ <property name="userStore" ref="org.hisp.dhis.user.UserStore" />
+ </bean>
+
+ <bean id="org.hisp.dhis.user.action.AddUserGroupAction" class="org.hisp.dhis.user.action.AddUserGroupAction"
+ scope="prototype">
+ <property name="userStore" ref="org.hisp.dhis.user.UserStore" />
+ <property name="userGroupService" ref="org.hisp.dhis.user.UserGroupService" />
+ </bean>
+
+ <bean id="org.hisp.dhis.user.action.EditUserGroupFormAction"
+ class="org.hisp.dhis.user.action.EditUserGroupFormAction" scope="prototype">
+ <property name="userStore" ref="org.hisp.dhis.user.UserStore" />
+ <property name="userGroupService" ref="org.hisp.dhis.user.UserGroupService" />
+ </bean>
+
+ <bean id="org.hisp.dhis.user.action.UpdateUserGroupAction" class="org.hisp.dhis.user.action.UpdateUserGroupAction"
+ scope="prototype">
+ <property name="userStore" ref="org.hisp.dhis.user.UserStore" />
+ <property name="userGroupService" ref="org.hisp.dhis.user.UserGroupService" />
+ </bean>
+
+ <bean id="org.hisp.dhis.user.action.RemoveUserGroupAction" class="org.hisp.dhis.user.action.RemoveUserGroupAction"
+ scope="prototype">
+ <property name="userGroupService" ref="org.hisp.dhis.user.UserGroupService" />
+ </bean>
+
+ <bean id="org.hisp.dhis.user.action.GetUserGroupAction" class="org.hisp.dhis.user.action.GetUserGroupAction"
+ scope="prototype">
+ <property name="userGroupService" ref="org.hisp.dhis.user.UserGroupService" />
+ </bean>
+
+ <bean id="org.hisp.dhis.user.action.ValidateUserGroupAction"
+ class="org.hisp.dhis.user.action.ValidateUserGroupAction" scope="prototype">
+ <property name="userGroupService" ref="org.hisp.dhis.user.UserGroupService" />
+ </bean>
</beans>
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/resources/struts.xml 2010-12-29 20:53:30 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/resources/struts.xml 2010-12-30 04:29:49 +0000
@@ -147,6 +147,7 @@
</action>
<!--Delete current user-->
+
<action name="deleteCurrentUser" class="org.hisp.dhis.user.action.DeleteCurrentUserAction">
<!--<result name="error" type="velocity">/dhis-web-maintenance-user/responseError.vm</result>-->
<result name="input" type="velocity">/main.vm</result>
@@ -197,13 +198,15 @@
getAllUserGroups.action</result>
</action>
- <action name="removeUserGroup" class="org.hisp.dhis.user.action.RemoveUserGroupAction">
-
- <!-- <result name="success" type="redirect">getAllUserGroups.action</result> -->
- <result name="success" type="velocity">
- /dhis-web-commons/ajax/jsonResponseSuccess.vm</result>
- <!--<param name ="javascripts">javascript/user.js</param> -->
+ <action name="removeUserGroup" class="org.hisp.dhis.user.action.RemoveUserGroupAction">
+ <result name="success" type="velocity">/dhis-web-commons/ajax/jsonResponseSuccess.vm</result>
</action>
+
+ <action name="validateUserGroup" class="org.hisp.dhis.user.action.ValidateUserGroupAction">
+ <result name="success" type="velocity-json">/dhis-web-commons/ajax/jsonResponseSuccess.vm</result>
+ <result name="error" type="velocity-json">/dhis-web-commons/ajax/jsonResponseError.vm</result>
+ <param name="onExceptionReturn">plainTextError</param>
+ </action>
</package>
</struts>
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/addUserGroupForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/addUserGroupForm.vm 2010-12-29 20:53:30 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/addUserGroupForm.vm 2010-12-30 04:29:49 +0000
@@ -1,6 +1,15 @@
+<script>
+ jQuery(document).ready( function(){
+ validation( 'addUserGroupForm', function( form ){ form.submit() }, function(){
+ listValidator( 'memberValidator','groupMembers');
+ } );
+ checkValueIsExist( "name", "validateUserGroup.action");
+ });
+</script>
+
<h3>$i18n.getString( "add_user_group" )</h3>
-<form id="addUserGroupForm" name="addUserGroupForm" action = " addUserGroup.action" method="post" onSubmit=" return addValidation()" >
+<form id="addUserGroupForm" name="addUserGroupForm" action = " addUserGroup.action" method="post" >
<table id="detailsList">
<col/>
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/updateUserGroupForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/updateUserGroupForm.vm 2010-12-29 20:53:30 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/updateUserGroupForm.vm 2010-12-30 04:29:49 +0000
@@ -1,9 +1,16 @@
-
+<script>
+ jQuery(document).ready( function(){
+ validation( 'editUserGroupForm', function( form ){ form.submit() }, function(){
+ listValidator( 'memberValidator','groupMembers');
+ } );
+ checkValueIsExist( "name", "validateUserGroup.action", {id:$group.id});
+ });
+</script>
<h3>$i18n.getString( "edit_user_group" )</h3>
-<form id="editUserGroupForm" name="editUserGroupForm" action="updateUserGroup.action" method="post" onsubmit="return editValidation();" >
+<form id="editUserGroupForm" name="editUserGroupForm" action="updateUserGroup.action" method="post">
-<input type="hidden" name="userGroupId" id="userGroupId" value="$userGroupId" />
+<input type="hidden" name="userGroupId" id="userGroupId" value="$group.id" />
<table id="detailsList">
<col/>
<col/>
@@ -15,7 +22,7 @@
<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" value ="$encoder.htmlEncode( $group.name )" onchange="nameChanged()" style="width:20em" maxlength="150" /></td>
+ <td><input type="text" id="name" name="name" value ="$encoder.htmlEncode( $group.name )" style="width:20em" maxlength="150" /></td>
</tr>
<tr><td colspan="2" style="height:15px"></td></tr>
</tbody>
@@ -24,7 +31,7 @@
<tr>
<th>$i18n.getString( "available_users" )</th><td></td>
<th>$i18n.getString( "group_members" )
- <select id="memberValidator" multiple="multiple" style="display:none"/>
+ <select id="memberValidator" multiple="multiple" style="display:none" class="{validate:{required:true}}"/>
</th>
</tr>
<tr>
@@ -66,30 +73,4 @@
<p><input type="submit" value="$i18n.getString( 'save' )" style="width:10em"/><input type="button" value="$i18n.getString( 'cancel' )" onclick="window.location.href='getAllUserGroups.action'" style="width:10em"/></p>
-</form>
-<script type="text/javascript">
- function editValidation ()
-{
- var k =0 ;
- var xyz=document.getElementById("name");
- var abc =document.getElementById("groupMembers");
- var c = abc.length ;
-
- if( xyz.value == "") {
- alert ("please select name ");alert(' xyz.value is empty');
- return false;
- }
- else if ( c <=0 ){
- alert("please select at least one member");
- return false ;
- }else{
- if (c >0 )
- {
- selectAllById("groupMembers");
- }
- }
-
- return true;
-}
-
-</script>
+</form>
\ No newline at end of file
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/userGroupList.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/userGroupList.vm 2010-12-23 12:27:24 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/userGroupList.vm 2010-12-30 04:29:49 +0000
@@ -13,14 +13,11 @@
</table>
<table class="listTable" id="listTable">
<col/>
- <col width="20"/>
- <col width="20"/>
- <col width="20"/>
-
+ <col width="100"/>
<thead>
<tr>
<th>$i18n.getString( "name" )</th>
- <th style="text-align:center" colspan="3" class="{sorter: false}">$i18n.getString( "operations" )</th>
+ <th style="text-align:center" class="{sorter: false}">$i18n.getString( "operations" )</th>
</tr>
</thead>
<tbody id="list">
@@ -28,12 +25,8 @@
<tr id="tr${userGroup.id}">
<td onclick="showUserGroupDetails( $userGroup.id )">$encoder.htmlEncode( $userGroup.name )</td>
<td style="text-align:center">
- <a href="editUserGroupForm.action?userGroupId=$userGroup.id" title="$i18n.getString( 'edit' )"><img src="../images/edit.png" alt="$i18n.getString( 'edit' )"/></a>
- </td>
- <td style="text-align:center">
- <a href="javascript:removeUserGroup( '$userGroup.id', '$encoder.jsEncode( $userGroup.name )' )" title="$i18n.getString( 'remove' )"><img src="../images/delete.png" alt="$i18n.getString( 'remove' )"/></a>
- </td>
- <td style="text-align:center">
+ <a href="editUserGroupForm.action?userGroupId=$userGroup.id" title="$i18n.getString( 'edit' )"><img src="../images/edit.png" alt="$i18n.getString( 'edit' )"/></a>
+ <a href="javascript:removeUserGroup( '$userGroup.id', '$encoder.jsEncode( $userGroup.name )' )" title="$i18n.getString( 'remove' )"><img src="../images/delete.png" alt="$i18n.getString( 'remove' )"/></a>
<a href="javascript:showUserGroupDetails( $userGroup.id )" title="$i18n.getString( 'show_details' )"><img src="../images/information.png" alt="$i18n.getString( 'show_details' )"/></a>
</td>
</tr>