dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #28980
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 14565: Approval, validation
------------------------------------------------------------
revno: 14565
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2014-03-31 13:43:23 +0200
message:
Approval, validation
added:
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/java/org/hisp/dhis/settings/action/system/ValidateApprovalLevelAction.java
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataapproval/DataApprovalLevelService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DefaultDataApprovalLevelService.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/java/org/hisp/dhis/settings/action/system/AddApprovalLevelAction.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/resources/META-INF/dhis/beans.xml
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/resources/struts.xml
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/webapp/dhis-web-maintenance-settings/addApprovalLevel.vm
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/webapp/dhis-web-maintenance-settings/javascripts/addApprovalLevel.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-api/src/main/java/org/hisp/dhis/dataapproval/DataApprovalLevelService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataapproval/DataApprovalLevelService.java 2014-03-28 10:13:01 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataapproval/DataApprovalLevelService.java 2014-03-31 11:43:23 +0000
@@ -83,10 +83,10 @@
* unit level and category option group set (but not necessarily the
* same level number.)
*
- * @param testLevel Data approval level to test for existence.
+ * @param level Data approval level to test for existence.
* @return true if it exists, otherwise false.
*/
- public boolean dataApprovalLevelExists ( DataApprovalLevel testLevel );
+ public boolean dataApprovalLevelExists ( DataApprovalLevel level );
/**
* Adds a new data approval level. Adds the new level at the highest
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DefaultDataApprovalLevelService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DefaultDataApprovalLevelService.java 2014-03-31 10:53:08 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DefaultDataApprovalLevelService.java 2014-03-31 11:43:23 +0000
@@ -166,14 +166,14 @@
}
}
- public boolean dataApprovalLevelExists( DataApprovalLevel testLevel )
+ public boolean dataApprovalLevelExists( DataApprovalLevel level )
{
List<DataApprovalLevel> dataApprovalLevels = getAllDataApprovalLevels();
for ( DataApprovalLevel dataApprovalLevel : dataApprovalLevels )
{
- if ( testLevel.getOrgUnitLevel() == dataApprovalLevel.getOrgUnitLevel()
- && testLevel.getCategoryOptionGroupSet() == dataApprovalLevel.getCategoryOptionGroupSet() )
+ if ( level.getOrgUnitLevel() == dataApprovalLevel.getOrgUnitLevel()
+ && level.getCategoryOptionGroupSet() == dataApprovalLevel.getCategoryOptionGroupSet() )
{
return true;
}
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/java/org/hisp/dhis/settings/action/system/AddApprovalLevelAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/java/org/hisp/dhis/settings/action/system/AddApprovalLevelAction.java 2014-03-30 22:00:52 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/java/org/hisp/dhis/settings/action/system/AddApprovalLevelAction.java 2014-03-31 11:43:23 +0000
@@ -32,7 +32,6 @@
import org.hisp.dhis.dataapproval.DataApprovalLevelService;
import org.hisp.dhis.dataelement.CategoryOptionGroupSet;
import org.hisp.dhis.dataelement.DataElementCategoryService;
-import org.hisp.dhis.i18n.I18n;
import com.opensymphony.xwork2.Action;
@@ -60,13 +59,6 @@
this.categoryService = categoryService;
}
- private I18n i18n;
-
- public void setI18n( I18n i18n )
- {
- this.i18n = i18n;
- }
-
// -------------------------------------------------------------------------
// Input
// -------------------------------------------------------------------------
@@ -86,17 +78,6 @@
}
// -------------------------------------------------------------------------
- // Output
- // -------------------------------------------------------------------------
-
- private String message;
-
- public String getMessage()
- {
- return message;
- }
-
- // -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@@ -111,14 +92,7 @@
DataApprovalLevel dataApprovalLevel = new DataApprovalLevel( organisationUnitLevel, catOptGroupSet );
- boolean added = dataApprovalLevelService.addDataApprovalLevel( dataApprovalLevel );
-
- if ( !added )
- {
- message = i18n.getString( "approval_level_is_already_defined" );
-
- return INPUT;
- }
+ dataApprovalLevelService.addDataApprovalLevel( dataApprovalLevel );
return SUCCESS;
}
=== added file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/java/org/hisp/dhis/settings/action/system/ValidateApprovalLevelAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/java/org/hisp/dhis/settings/action/system/ValidateApprovalLevelAction.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/java/org/hisp/dhis/settings/action/system/ValidateApprovalLevelAction.java 2014-03-31 11:43:23 +0000
@@ -0,0 +1,82 @@
+package org.hisp.dhis.settings.action.system;
+
+import org.hisp.dhis.dataapproval.DataApprovalLevel;
+import org.hisp.dhis.dataapproval.DataApprovalLevelService;
+import org.hisp.dhis.dataelement.CategoryOptionGroupSet;
+import org.hisp.dhis.dataelement.DataElementCategoryService;
+import org.hisp.dhis.i18n.I18n;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import com.opensymphony.xwork2.Action;
+
+public class ValidateApprovalLevelAction
+ implements Action
+{
+ @Autowired
+ private DataApprovalLevelService dataApprovalLevelService;
+
+ @Autowired
+ private DataElementCategoryService categoryService;
+
+ private I18n i18n;
+
+ public void setI18n( I18n i18n )
+ {
+ this.i18n = i18n;
+ }
+
+ // -------------------------------------------------------------------------
+ // Input
+ // -------------------------------------------------------------------------
+
+ private int organisationUnitLevel;
+
+ public void setOrganisationUnitLevel( int organisationUnitLevel )
+ {
+ this.organisationUnitLevel = organisationUnitLevel;
+ }
+
+ private int categoryOptionGroupSet;
+
+ public void setCategoryOptionGroupSet( int categoryOptionGroupSet )
+ {
+ this.categoryOptionGroupSet = categoryOptionGroupSet;
+ }
+
+ // -------------------------------------------------------------------------
+ // Output
+ // -------------------------------------------------------------------------
+
+ private String message;
+
+ public String getMessage()
+ {
+ return message;
+ }
+
+ // -------------------------------------------------------------------------
+ // Action implementation
+ // -------------------------------------------------------------------------
+
+ @Override
+ public String execute()
+ throws Exception
+ {
+ CategoryOptionGroupSet catOptGroupSet = categoryService.getCategoryOptionGroupSet( categoryOptionGroupSet );
+
+ DataApprovalLevel level = new DataApprovalLevel( organisationUnitLevel, catOptGroupSet );
+
+ boolean exists = dataApprovalLevelService.dataApprovalLevelExists( level );
+
+ if ( exists )
+ {
+ message = i18n.getString( "approval_level_is_already_defined" );
+
+ return ERROR;
+ }
+
+ message = "ok";
+
+ return SUCCESS;
+ }
+}
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/resources/META-INF/dhis/beans.xml 2014-03-30 22:00:52 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/resources/META-INF/dhis/beans.xml 2014-03-31 11:43:23 +0000
@@ -59,6 +59,14 @@
<property name="systemSettingManager" ref="org.hisp.dhis.setting.SystemSettingManager" />
</bean>
+ <bean id="org.hisp.dhis.settings.action.system.GetAccessSettingsAction"
+ class="org.hisp.dhis.settings.action.system.GetAccessSettingsAction"
+ scope="prototype" />
+
+ <bean id="org.hisp.dhis.settings.action.system.SetAccessSettingsAction"
+ class="org.hisp.dhis.settings.action.system.SetAccessSettingsAction"
+ scope="prototype" />
+
<bean id="org.hisp.dhis.settings.action.system.GetApprovalSettingsAction"
class="org.hisp.dhis.settings.action.system.GetApprovalSettingsAction"
scope="prototype">
@@ -79,15 +87,9 @@
<property name="categoryService" ref="org.hisp.dhis.dataelement.DataElementCategoryService" />
</bean>
- <!--
<bean id="org.hisp.dhis.settings.action.system.ValidateApprovalLevelAction"
class="org.hisp.dhis.settings.action.system.ValidateApprovalLevelAction"
- scope="prototype">
- <property name="dataApprovalLevelService" ref="org.hisp.dhis.dataapproval.DataApprovalLevelService" />
- <property name="organisationUnitService" ref="org.hisp.dhis.organisationunit.OrganisationUnitService" />
- <property name="dataElementCategoryService" ref="org.hisp.dhis.dataelement.DataElementCategoryService" />
- </bean>
- -->
+ scope="prototype"/>
<bean id="org.hisp.dhis.settings.action.system.MoveApprovalLevelDownAction"
class="org.hisp.dhis.settings.action.system.MoveApprovalLevelDownAction"
@@ -107,12 +109,4 @@
<property name="dataApprovalLevelService" ref="org.hisp.dhis.dataapproval.DataApprovalLevelService" />
</bean>
- <bean id="org.hisp.dhis.settings.action.system.GetAccessSettingsAction"
- class="org.hisp.dhis.settings.action.system.GetAccessSettingsAction"
- scope="prototype" />
-
- <bean id="org.hisp.dhis.settings.action.system.SetAccessSettingsAction"
- class="org.hisp.dhis.settings.action.system.SetAccessSettingsAction"
- scope="prototype" />
-
</beans>
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/resources/struts.xml 2014-03-30 22:10:43 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/resources/struts.xml 2014-03-31 11:43:23 +0000
@@ -67,6 +67,22 @@
<param name="requiredAuthorities">F_SYSTEM_SETTING</param>
</action>
+ <!-- Access settings -->
+
+ <action name="systemAccessSettings" class="org.hisp.dhis.settings.action.system.GetAccessSettingsAction">
+ <result name="success" type="velocity">/main.vm</result>
+ <param name="page">/dhis-web-maintenance-settings/systemAccessSettings.vm</param>
+ <param name="menu">/dhis-web-maintenance-settings/settingsMenu.vm</param>
+ <param name="requiredAuthorities">F_SYSTEM_SETTING</param>
+ </action>
+
+ <action name="setSystemAccessSettings" class="org.hisp.dhis.settings.action.system.SetAccessSettingsAction">
+ <result name="success" type="velocity-json">
+ /dhis-web-commons/ajax/jsonResponseSuccess.vm</result>
+ <param name="onExceptionReturn">plainTextError</param>
+ <param name="requiredAuthorities">F_SYSTEM_SETTING</param>
+ </action>
+
<!-- Approval settings -->
<action name="systemApprovalSettings" class="org.hisp.dhis.settings.action.system.GetApprovalSettingsAction">
@@ -87,7 +103,6 @@
<action name="addApprovalLevel" class="org.hisp.dhis.settings.action.system.AddApprovalLevelAction">
<result name="success" type="redirect">systemApprovalSettings.action</result>
- <result name="input" type="velocity-json">/dhis-web-commons/ajax/jsonResponseInput.vm</result>
<param name="requiredAuthorities">F_SYSTEM_SETTING</param>
</action>
@@ -111,21 +126,11 @@
<param name="onExceptionReturn">plainTextError</param>
<param name="requiredAuthorities">F_SYSTEM_SETTING</param>
</action>
-
- <!-- Access settings -->
-
- <action name="systemAccessSettings" class="org.hisp.dhis.settings.action.system.GetAccessSettingsAction">
- <result name="success" type="velocity">/main.vm</result>
- <param name="page">/dhis-web-maintenance-settings/systemAccessSettings.vm</param>
- <param name="menu">/dhis-web-maintenance-settings/settingsMenu.vm</param>
- <param name="requiredAuthorities">F_SYSTEM_SETTING</param>
- </action>
-
- <action name="setSystemAccessSettings" class="org.hisp.dhis.settings.action.system.SetAccessSettingsAction">
- <result name="success" type="velocity-json">
- /dhis-web-commons/ajax/jsonResponseSuccess.vm</result>
- <param name="onExceptionReturn">plainTextError</param>
- <param name="requiredAuthorities">F_SYSTEM_SETTING</param>
+
+ <action name="validateApprovalLevel" class="org.hisp.dhis.settings.action.system.ValidateApprovalLevelAction">
+ <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>
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/webapp/dhis-web-maintenance-settings/addApprovalLevel.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/webapp/dhis-web-maintenance-settings/addApprovalLevel.vm 2014-03-28 17:12:58 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/webapp/dhis-web-maintenance-settings/addApprovalLevel.vm 2014-03-31 11:43:23 +0000
@@ -30,7 +30,7 @@
<tr>
<td></td>
<td>
- <input type="submit" value="$i18n.getString( "add" )" style="width:10em" />
+ <input type="button" value="$i18n.getString( "add" )" onclick="javascript:validateApprovalLevel()" style="width:10em" />
<input type="button" value="$i18n.getString( "cancel" )" onclick="window.location.href='systemApprovalSettings.action'" style="width:10em" />
</td>
</tr>
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/webapp/dhis-web-maintenance-settings/javascripts/addApprovalLevel.js'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/webapp/dhis-web-maintenance-settings/javascripts/addApprovalLevel.js 2014-02-19 04:19:40 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/webapp/dhis-web-maintenance-settings/javascripts/addApprovalLevel.js 2014-03-31 11:43:23 +0000
@@ -1,7 +1,5 @@
jQuery( document ).ready( function()
{
- jQuery( "#name" ).focus();
-
validation2( 'addApprovalLevelForm', function( form )
{
form.submit();
@@ -9,3 +7,19 @@
'rules' : getValidationRules( "dataApprovalLevel" )
} );
} );
+
+function validateApprovalLevel()
+{
+ jQuery.getJSON( "validateApprovalLevel.action", {
+ "organisationUnitLevel": jQuery( "#organisationUnitLevel" ).val(),
+ "categoryOptionGroupSet": jQuery( "#categoryOptionGroupSet" ).val()
+ }, function( json ) {
+ if ( json.response == "error" ) {
+ setHeaderDelayMessage( json.message );
+ return false;
+ }
+ else {
+ $( "#addApprovalLevelForm" ).submit();
+ }
+ } );
+}
\ No newline at end of file