dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #11589
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 3336: WIP: validation rules
------------------------------------------------------------
revno: 3336
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2011-04-11 11:51:38 +0200
message:
WIP: validation rules
modified:
dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/commons.js
dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/useraccount/updateUserAccountForm.js
dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/validationRules.js
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/javascript/addUserForm.js
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/javascript/updateUserForm.js
--
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-resources/src/main/webapp/dhis-web-commons/javascripts/commons.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/commons.js 2011-04-01 10:19:39 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/commons.js 2011-04-11 09:51:38 +0000
@@ -1099,27 +1099,39 @@
var rules = kwargs["rules"];
var validator = jQuery("#" + formId ).validate({
- meta:"validate"
- ,errorElement:"span"
- ,beforeValidateHandler:beforeValidateHandler
- ,submitHandler: submitHandler
- ,rules: rules
+ meta:"validate",
+ errorElement:"span",
+ beforeValidateHandler: beforeValidateHandler,
+ submitHandler: submitHandler,
+ rules: rules
+ });
+
+ $("#" + formId + " input").each(function(n) {
+ try {
+ $(this).attr("maxlength", rules[this.id].rangelength[1]);
+ } catch(e) {}
});
var nameField = jQuery('#' + formId + ' :input')[0];
-
+
if ( nameField )
{
nameField.focus();
}
-
+
return validator;
}
/**
- * @return A dictionary containing the default validation rules.
+ * @param form Get validation rules for this form
+ *
+ * @return Validation rules for a given form
*/
-function getValidationRules() {
+function getValidationRules(form) {
+ if( form !== undefined ) {
+ return validationRules[form];
+ }
+
return validationRules;
}
=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/useraccount/updateUserAccountForm.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/useraccount/updateUserAccountForm.js 2011-03-28 15:28:36 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/useraccount/updateUserAccountForm.js 2011-04-11 09:51:38 +0000
@@ -1,51 +1,17 @@
jQuery( document ).ready( function()
{
- var r = getValidationRules();
+ var rules = getValidationRules("user");
- /* validation */
- var rules = {
- oldPassword : {
- required : true
- },
- rawPassword : {
- required : false,
- password : true,
- rangelength : r.user.password.rangelength,
- notequalto : '#username'
- },
- retypePassword : {
- required : false,
- equalTo : '#rawPassword'
- },
- surname : {
- required : true,
- rangelength : r.user.name.rangelength
- },
- firstName : {
- required : true,
- rangelength : r.user.name.rangelength
- },
- email : {
- email : true,
- rangelength : r.user.email.rangelength
- },
- phoneNumber : {
- rangelength : r.user.phone.rangelength
- }
+ /* some customization is needed for the updateUserAccount validation rules */
+ rules["rawPassword"].required = false;
+ rules["oldPassword"] = {
+ required: true
}
validation2( 'updateUserinforForm', updateUser, {
'rules' : rules
} );
- jQuery( "#rawPassword" ).attr( "maxlength", r.user.password.rangelength[1] );
- jQuery( "#retypePassword" ).attr( "maxlength", r.user.password.rangelength[1] );
- jQuery( "#surname" ).attr( "maxlength", r.user.name.rangelength[1] );
- jQuery( "#firstName" ).attr( "maxlength", r.user.name.rangelength[1] );
- jQuery( "#email" ).attr( "maxlength", r.user.email.rangelength[1] );
- jQuery( "#phoneNumber" ).attr( "maxlength", r.user.phone.rangelength[1] );
- /* end validation */
-
var oldPassword = byId( 'oldPassword' );
oldPassword.select();
oldPassword.focus();
=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/validationRules.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/validationRules.js 2011-04-08 12:48:37 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/validationRules.js 2011-04-11 09:51:38 +0000
@@ -1,22 +1,44 @@
var validationRules = {
/* dhis-web-maintenance-user */
"user" : {
- "name" : {
- "rangelength" : [ 2, 140 ]
- },
"username" : {
+ "required" : true,
"rangelength" : [ 2, 140 ],
"firstletteralphabet" : true,
"alphanumeric" : true
},
+ "firstName" : {
+ "required" : true,
+ "rangelength" : [ 2, 140 ]
+ },
+ "surname" : {
+ "required" : true,
+ "rangelength" : [ 2, 140 ]
+ },
"password" : {
- "rangelength" : [ 8, 35 ]
+ "required" : true,
+ "password" : true,
+ "notequalto" : "#username",
+ "rangelength" : [ 8, 35 ]
+ },
+ "rawPassword" : {
+ "required" : true,
+ "password" : true,
+ "rangelength" : [ 8, 35 ]
+ },
+ "retypePassword" : {
+ "required" : true,
+ "equalTo" : "#rawPassword"
},
"email" : {
+ "email" : true,
"rangelength" : [ 0, 160 ]
},
- "phone" : {
+ "phoneNumber" : {
"rangelength" : [ 0, 80 ]
+ },
+ "roleValidator" : {
+ "required" : true
}
},
"role" : {
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/javascript/addUserForm.js'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/javascript/addUserForm.js 2011-04-01 20:21:05 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/javascript/addUserForm.js 2011-04-11 09:51:38 +0000
@@ -1,44 +1,5 @@
jQuery( document ).ready( function()
{
- var r = getValidationRules();
-
- var rules = {
- username : {
- required : true,
- firstletteralphabet : r.user.username.firstletteralphabet,
- alphanumeric : r.user.username.alphanumeric,
- rangelength : r.user.username.rangelength
- },
- rawPassword : {
- required : true,
- password : true,
- notequalto : '#username',
- rangelength : r.user.password.rangelength
- },
- retypePassword : {
- required : true,
- equalTo : '#rawPassword'
- },
- surname : {
- required : true,
- rangelength : r.user.name.rangelength
- },
- firstName : {
- required : true,
- rangelength : r.user.name.rangelength
- },
- email : {
- email : true,
- rangelength : r.user.email.rangelength
- },
- phoneNumber : {
- rangelength : r.user.phone.rangelength
- },
- roleValidator : {
- required : true
- }
- };
-
validation2( 'addUserForm', function( form )
{
form.submit()
@@ -47,21 +8,13 @@
{
listValidator( 'roleValidator', 'selectedList' );
},
- 'rules' : rules
+ 'rules' : getValidationRules("user")
} );
-
- jQuery( "#username" ).attr( "maxlength", r.user.username.rangelength[1] );
- jQuery( "#rawPassword" ).attr( "maxlength", r.user.password.rangelength[1] );
- jQuery( "#retypePassword" ).attr( "maxlength", r.user.password.rangelength[1] );
- jQuery( "#surname" ).attr( "maxlength", r.user.name.rangelength[1] );
- jQuery( "#firstName" ).attr( "maxlength", r.user.name.rangelength[1] );
- jQuery( "#email" ).attr( "maxlength", r.user.email.rangelength[1] );
- jQuery( "#phoneNumber" ).attr( "maxlength", r.user.phone.rangelength[1] );
-
+
/* remote validation */
checkValueIsExist( "username", "validateUser.action" );
jQuery("#cancel").click(function() {
referrerBack( "alluser.action" );
});
-} );
+});
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/javascript/updateUserForm.js'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/javascript/updateUserForm.js 2011-03-24 13:32:53 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/javascript/updateUserForm.js 2011-04-11 09:51:38 +0000
@@ -1,38 +1,5 @@
jQuery( document ).ready( function()
{
- var r = getValidationRules();
-
- var rules = {
- rawPassword : {
- password : true,
- notequalto : '#username',
- rangelength : r.user.password.rangelength
- },
- retypePassword : {
- required : false,
- equalTo : '#rawPassword',
- rangelength : r.user.password.rangelength
- },
- surname : {
- required : true,
- rangelength : r.user.name.rangelength
- },
- firstName : {
- required : true,
- rangelength : r.user.name.rangelength
- },
- email : {
- email : true,
- rangelength : r.user.email.rangelength
- },
- phoneNumber : {
- rangelength : r.user.phone.rangelength
- },
- roleValidator : {
- required : true
- }
- };
-
validation2( 'updateUserForm', function( form )
{
form.submit()
@@ -41,16 +8,9 @@
{
listValidator( 'roleValidator', 'selectedList' );
},
- 'rules' : rules
+ 'rules' : getValidationRules("user")
} );
- jQuery( "#rawPassword" ).attr( "maxlength", r.user.password.rangelength[1] );
- jQuery( "#retypePassword" ).attr( "maxlength", r.user.password.rangelength[1] );
- jQuery( "#surname" ).attr( "maxlength", r.user.name.rangelength[1] );
- jQuery( "#firstName" ).attr( "maxlength", r.user.name.rangelength[1] );
- jQuery( "#email" ).attr( "maxlength", r.user.email.rangelength[1] );
- jQuery( "#phoneNumber" ).attr( "maxlength", r.user.phone.rangelength[1] );
-
jQuery("#cancel").click(function() {
referrerBack( "alluser.action" );
});