dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #20197
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9121: fix for adding/updating data dictionaries that only have either data elements or indicators
------------------------------------------------------------
revno: 9121
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2012-11-25 23:18:03 +0100
message:
fix for adding/updating data dictionaries that only have either data elements or indicators
modified:
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-datadictionary/src/main/java/org/hisp/dhis/dd/action/datadictionary/AddDataDictionaryAction.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/datadictionary/UpdateDataDictionaryAction.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/javascript/addDataDictionaryForm.js
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/javascript/updateDataDictionaryForm.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/validationRules.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/validationRules.js 2012-11-07 11:17:41 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/validationRules.js 2012-11-25 22:18:03 +0000
@@ -287,12 +287,6 @@
},
"region" : {
"rangelength" : [ 0, 255 ]
- },
- "memberValidator" : {
- "required" : true
- },
- "memberValidatorIn" : {
- "required" : true
}
},
"indicator" : {
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/datadictionary/AddDataDictionaryAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/datadictionary/AddDataDictionaryAction.java 2011-12-26 10:07:59 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/datadictionary/AddDataDictionaryAction.java 2012-11-25 22:18:03 +0000
@@ -27,10 +27,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Set;
-
+import com.opensymphony.xwork2.Action;
import org.hisp.dhis.datadictionary.DataDictionary;
import org.hisp.dhis.datadictionary.DataDictionaryService;
import org.hisp.dhis.dataelement.DataElement;
@@ -38,9 +35,11 @@
import org.hisp.dhis.indicator.Indicator;
import org.hisp.dhis.indicator.IndicatorService;
-import com.opensymphony.xwork2.Action;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
-import static org.hisp.dhis.system.util.TextUtils.nullIfEmpty;;
+import static org.hisp.dhis.system.util.TextUtils.nullIfEmpty;
/**
* @author Lars Helge Overland
@@ -66,7 +65,7 @@
{
this.dataElementService = dataElementService;
}
-
+
private IndicatorService indicatorService;
public void setIndicatorService( IndicatorService indicatorService )
@@ -91,7 +90,7 @@
{
this.description = description;
}
-
+
private String region;
public void setRegion( String region )
@@ -105,7 +104,7 @@
{
this.selectedDataElements = groupMembers;
}
-
+
private Collection<String> selectedIndicators;
public void setSelectedIndicators( Collection<String> indicators )
@@ -120,11 +119,11 @@
public String execute()
{
DataDictionary dictionary = new DataDictionary();
-
- dictionary.setName( name);
+
+ dictionary.setName( name );
dictionary.setDescription( nullIfEmpty( description ) );
dictionary.setRegion( nullIfEmpty( region ) );
-
+
if ( selectedDataElements != null )
{
Set<DataElement> members = new HashSet<DataElement>( selectedDataElements.size() );
@@ -136,21 +135,29 @@
dictionary.setDataElements( members );
}
-
+ else
+ {
+ dictionary.setDataElements( new HashSet<DataElement>() );
+ }
+
if ( selectedIndicators != null )
{
Set<Indicator> members = new HashSet<Indicator>( selectedIndicators.size() );
-
+
for ( String id : selectedIndicators )
{
members.add( indicatorService.getIndicator( Integer.parseInt( id ) ) );
}
-
+
dictionary.setIndicators( members );
}
+ else
+ {
+ dictionary.setIndicators( new HashSet<Indicator>() );
+ }
dataDictionaryService.saveDataDictionary( dictionary );
-
+
return SUCCESS;
}
}
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/datadictionary/UpdateDataDictionaryAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/datadictionary/UpdateDataDictionaryAction.java 2011-12-26 10:07:59 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/datadictionary/UpdateDataDictionaryAction.java 2012-11-25 22:18:03 +0000
@@ -27,10 +27,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Set;
-
+import com.opensymphony.xwork2.Action;
import org.hisp.dhis.datadictionary.DataDictionary;
import org.hisp.dhis.datadictionary.DataDictionaryService;
import org.hisp.dhis.dataelement.DataElement;
@@ -38,9 +35,11 @@
import org.hisp.dhis.indicator.Indicator;
import org.hisp.dhis.indicator.IndicatorService;
-import com.opensymphony.xwork2.Action;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
-import static org.hisp.dhis.system.util.TextUtils.nullIfEmpty;;
+import static org.hisp.dhis.system.util.TextUtils.nullIfEmpty;
/**
* @author Lars Helge Overland
@@ -66,7 +65,7 @@
{
this.dataElementService = dataElementService;
}
-
+
private IndicatorService indicatorService;
public void setIndicatorService( IndicatorService indicatorService )
@@ -98,7 +97,7 @@
{
this.description = description;
}
-
+
private String region;
public void setRegion( String region )
@@ -111,7 +110,7 @@
public void setSelectedDataElements( Collection<String> groupMembers )
{
this.selectedDataElements = groupMembers;
- }
+ }
private Collection<String> selectedIndicators;
@@ -119,7 +118,7 @@
{
this.selectedIndicators = indicators;
}
-
+
// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@@ -127,7 +126,7 @@
public String execute()
{
DataDictionary dictionary = dataDictionaryService.getDataDictionary( id );
-
+
dictionary.setName( name );
dictionary.setDescription( nullIfEmpty( description ) );
dictionary.setRegion( nullIfEmpty( region ) );
@@ -143,21 +142,29 @@
dictionary.setDataElements( members );
}
-
+ else
+ {
+ dictionary.setDataElements( new HashSet<DataElement>() );
+ }
+
if ( selectedIndicators != null )
{
Set<Indicator> members = new HashSet<Indicator>( selectedIndicators.size() );
-
+
for ( String id : selectedIndicators )
{
members.add( indicatorService.getIndicator( Integer.parseInt( id ) ) );
}
-
+
dictionary.setIndicators( members );
}
-
+ else
+ {
+ dictionary.setIndicators( new HashSet<Indicator>() );
+ }
+
dataDictionaryService.saveDataDictionary( dictionary );
-
+
return SUCCESS;
}
}
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/javascript/addDataDictionaryForm.js'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/javascript/addDataDictionaryForm.js 2011-08-19 21:33:57 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/javascript/addDataDictionaryForm.js 2012-11-25 22:18:03 +0000
@@ -1,8 +1,24 @@
jQuery( document ).ready( function()
{
+ function preSubmit() {
+ var $selectedDataElements = $('#selectedDataElements');
+ var $selectedIndicators = $('#selectedIndicators');
+
+ var hasDataElements = $selectedDataElements.val() != null && $selectedDataElements.val().length > 0;
+ var hasIndicators = $selectedIndicators.val() != null && $selectedIndicators.val().length > 0;
+
+ if( !hasDataElements && !hasIndicators )
+ {
+ setHeaderDelayMessage('Data Elements or Indicators are required.')
+ return false;
+ }
+
+ return true;
+ }
+
validation2( 'addDataDictionaryForm', function( form )
{
- form.submit();
+ preSubmit() && form.submit();
}, {
'beforeValidateHandler' : function()
{
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/javascript/updateDataDictionaryForm.js'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/javascript/updateDataDictionaryForm.js 2011-08-19 21:33:57 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/javascript/updateDataDictionaryForm.js 2012-11-25 22:18:03 +0000
@@ -1,8 +1,24 @@
jQuery( document ).ready( function()
{
+ function preSubmit() {
+ var $selectedDataElements = $('#selectedDataElements');
+ var $selectedIndicators = $('#selectedIndicators');
+
+ var hasDataElements = $selectedDataElements.val() != null && $selectedDataElements.val().length > 0;
+ var hasIndicators = $selectedIndicators.val() != null && $selectedIndicators.val().length > 0;
+
+ if( !hasDataElements && !hasIndicators )
+ {
+ setHeaderDelayMessage('Data Elements or Indicators are required.')
+ return false;
+ }
+
+ return true;
+ }
+
validation2( 'updateDataDictionaryForm', function( form )
{
- form.submit();
+ preSubmit() && form.submit();
}, {
'beforeValidateHandler' : function()
{