dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #08620
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2104: Fixed function next/previous periods
------------------------------------------------------------
revno: 2104
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2010-11-18 13:28:04 +0100
message:
Fixed function next/previous periods
added:
dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/LoadNextPreviousPeriodsAction.java
modified:
dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/LoadDataSetsAction.java
dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/LoadPeriodsAction.java
dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/SelectAction.java
dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/META-INF/dhis/beans.xml
dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/struts.xml
dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js
dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/responseDataSets.vm
dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/responsePeriods.vm
dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/select.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-dataentry/src/main/java/org/hisp/dhis/de/action/LoadDataSetsAction.java'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/LoadDataSetsAction.java 2010-11-18 09:42:34 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/LoadDataSetsAction.java 2010-11-18 12:28:04 +0000
@@ -44,11 +44,18 @@
return organisationUnit;
}
- private boolean selectionValid;
-
- public boolean isSelectionValid()
- {
- return selectionValid;
+ private boolean dataSetValid;
+
+ public boolean isDataSetValid()
+ {
+ return dataSetValid;
+ }
+
+ private boolean periodValid;
+
+ public boolean isPeriodValid()
+ {
+ return periodValid;
}
// -------------------------------------------------------------------------
@@ -57,26 +64,35 @@
public String execute()
{
- dataSets = selectedStateManager.loadDataSetsForSelectedOrgUnit();
-
- Collections.sort( dataSets, new DataSetNameComparator() );
-
organisationUnit = selectedStateManager.getSelectedOrganisationUnit();
- // ---------------------------------------------------------------------
- // Validate whether current data set selection is still valid
- // ---------------------------------------------------------------------
-
- DataSet selectedDataSet = selectedStateManager.getSelectedDataSet();
-
- if ( selectedDataSet != null && dataSets.contains( selectedDataSet ) )
- {
- selectionValid = true;
- }
- else
- {
- selectedStateManager.clearSelectedDataSet();
- selectedStateManager.clearSelectedPeriod();
+ if ( organisationUnit != null )
+ {
+ // -----------------------------------------------------------------
+ // Load data sets for selected org unit
+ // -----------------------------------------------------------------
+
+ dataSets = selectedStateManager.loadDataSetsForSelectedOrgUnit();
+
+ Collections.sort( dataSets, new DataSetNameComparator() );
+
+ // -----------------------------------------------------------------
+ // Check if selected data set is associated with selected org unit
+ // -----------------------------------------------------------------
+
+ DataSet selectedDataSet = selectedStateManager.getSelectedDataSet();
+
+ if ( selectedDataSet != null && dataSets.contains( selectedDataSet ) )
+ {
+ dataSetValid = true;
+
+ periodValid = selectedStateManager.getSelectedPeriod() != null;
+ }
+ else
+ {
+ selectedStateManager.clearSelectedDataSet();
+ selectedStateManager.clearSelectedPeriod();
+ }
}
return SUCCESS;
=== added file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/LoadNextPreviousPeriodsAction.java'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/LoadNextPreviousPeriodsAction.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/LoadNextPreviousPeriodsAction.java 2010-11-18 12:28:04 +0000
@@ -0,0 +1,87 @@
+package org.hisp.dhis.de.action;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.hisp.dhis.de.state.SelectedStateManager;
+import org.hisp.dhis.i18n.I18nFormat;
+import org.hisp.dhis.period.Period;
+
+import com.opensymphony.xwork2.Action;
+
+public class LoadNextPreviousPeriodsAction
+ implements Action
+{
+ // -------------------------------------------------------------------------
+ // Dependencies
+ // -------------------------------------------------------------------------
+
+ private SelectedStateManager selectedStateManager;
+
+ public void setSelectedStateManager( SelectedStateManager selectedStateManager )
+ {
+ this.selectedStateManager = selectedStateManager;
+ }
+
+ private I18nFormat format;
+
+ public void setFormat( I18nFormat format )
+ {
+ this.format = format;
+ }
+
+ // -------------------------------------------------------------------------
+ // Input
+ // -------------------------------------------------------------------------
+
+ private boolean next;
+
+ public void setNext( boolean next )
+ {
+ this.next = next;
+ }
+
+ private boolean previous;
+
+ public void setPrevious( boolean previous )
+ {
+ this.previous = previous;
+ }
+
+ // -------------------------------------------------------------------------
+ // Output
+ // -------------------------------------------------------------------------
+
+ private List<Period> periods = new ArrayList<Period>();
+
+ public Collection<Period> getPeriods()
+ {
+ return periods;
+ }
+
+ // -------------------------------------------------------------------------
+ // Action implementation
+ // -------------------------------------------------------------------------
+
+ public String execute()
+ {
+ if ( next )
+ {
+ selectedStateManager.nextPeriodSpan();
+ }
+ else if ( previous )
+ {
+ selectedStateManager.previousPeriodSpan();
+ }
+
+ periods = selectedStateManager.getPeriodList();
+
+ for ( Period period : periods )
+ {
+ period.setName( format.formatPeriod( period ) );
+ }
+
+ return SUCCESS;
+ }
+}
=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/LoadPeriodsAction.java'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/LoadPeriodsAction.java 2010-11-18 10:07:31 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/LoadPeriodsAction.java 2010-11-18 12:28:04 +0000
@@ -51,20 +51,6 @@
this.dataSetId = dataSetId;
}
- private boolean next;
-
- public void setNext( boolean next )
- {
- this.next = next;
- }
-
- private boolean previous;
-
- public void setPrevious( boolean previous )
- {
- this.previous = previous;
- }
-
// -------------------------------------------------------------------------
// Output
// -------------------------------------------------------------------------
@@ -76,11 +62,11 @@
return periods;
}
- private boolean selectionValid;
+ private boolean periodValid;
- public boolean isSelectionValid()
+ public boolean isPeriodValid()
{
- return selectionValid;
+ return periodValid;
}
// -------------------------------------------------------------------------
@@ -93,21 +79,27 @@
if ( selectedDataSet != null )
{
+ // -----------------------------------------------------------------
+ // Check if previous data set has same period type as selected
+ // -----------------------------------------------------------------
+
DataSet previousDataSet = selectedStateManager.getSelectedDataSet();
- selectionValid = previousDataSet != null && previousDataSet.getPeriodType().equals( selectedDataSet.getPeriodType() );
-
+ if ( previousDataSet != null && previousDataSet.getPeriodType().equals( selectedDataSet.getPeriodType() ) )
+ {
+ periodValid = true;
+ }
+ else
+ {
+ selectedStateManager.clearSelectedPeriod();
+ }
+
+ // -----------------------------------------------------------------
+ // Load periods for period type of selected data set
+ // -----------------------------------------------------------------
+
selectedStateManager.setSelectedDataSet( selectedDataSet );
- if ( next )
- {
- selectedStateManager.nextPeriodSpan();
- }
- else if ( previous )
- {
- selectedStateManager.previousPeriodSpan();
- }
-
periods = selectedStateManager.getPeriodList();
for ( Period period : periods )
@@ -115,7 +107,7 @@
period.setName( format.formatPeriod( period ) );
}
}
-
+
return SUCCESS;
}
}
=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/SelectAction.java'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/SelectAction.java 2010-11-17 18:26:47 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/SelectAction.java 2010-11-18 12:28:04 +0000
@@ -230,6 +230,7 @@
public String execute()
throws Exception
{
+ /*
// ---------------------------------------------------------------------
// Validate selected OrganisationUnit
// ---------------------------------------------------------------------
@@ -279,7 +280,11 @@
return SUCCESS;
}
-
+*/
+ organisationUnit = selectedStateManager.getSelectedOrganisationUnit();
+
+ DataSet selectedDataSet = selectedStateManager.getSelectedDataSet();
+
// ---------------------------------------------------------------------
// Generate Periods
// ---------------------------------------------------------------------
@@ -295,36 +300,35 @@
selectedPeriodIndex = selectedStateManager.getSelectedPeriodIndex();
}
+ if ( selectedPeriodIndex != null && selectedPeriodIndex >= 0 && selectedPeriodIndex < periods.size() )
+ {
+ selectedStateManager.setSelectedPeriodIndex( selectedPeriodIndex );
+ period = selectedStateManager.getSelectedPeriod();
+ }
+ else
+ {
+ selectedStateManager.clearSelectedPeriod();
+
+ return SUCCESS;
+ }
+
// -----------------------------------------------------------------------
// For Data Locking
// -----------------------------------------------------------------------
- if ( selectedPeriodIndex != null && selectedPeriodIndex >= 0 && selectedPeriodIndex < periods.size() )
+ if ( selectedDataSet != null )
{
- selectedStateManager.setSelectedPeriodIndex( selectedPeriodIndex );
-
- if ( selectedDataSet != null )
+ period = selectedStateManager.getSelectedPeriod();
+
+ DataSetLock dataSetLock = dataSetLockService.getDataSetLockByDataSetAndPeriod( selectedDataSet, period );
+
+ if ( dataSetLock != null && dataSetLock.getSources().contains( organisationUnit ) )
{
- period = selectedStateManager.getSelectedPeriod();
-
- DataSetLock dataSetLock = dataSetLockService.getDataSetLockByDataSetAndPeriod( selectedDataSet, period );
-
- if ( dataSetLock != null && dataSetLock.getSources().contains( organisationUnit ) )
- {
- locked = true;
- log.info( "Dataset '" + selectedDataSet.getName() + "' is locked " );
- }
+ locked = true;
+ log.info( "Dataset '" + selectedDataSet.getName() + "' is locked " );
}
}
- else
- {
- selectedStateManager.clearSelectedPeriod();
-
- return SUCCESS;
- }
-
- period = selectedStateManager.getSelectedPeriod();
-
+
// ---------------------------------------------------------------------
// Get CalculatedDataElement info
// ---------------------------------------------------------------------
=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/META-INF/dhis/beans.xml 2010-11-17 18:26:47 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/META-INF/dhis/beans.xml 2010-11-18 12:28:04 +0000
@@ -54,6 +54,10 @@
<property name="dataSetService" ref="org.hisp.dhis.dataset.DataSetService" />
</bean>
+ <bean id="org.hisp.dhis.de.action.LoadNextPreviousPeriodsAction" class="org.hisp.dhis.de.action.LoadNextPreviousPeriodsAction" scope="prototype">
+ <property name="selectedStateManager" ref="org.hisp.dhis.de.state.SelectedStateManager" />
+ </bean>
+
<bean id="org.hisp.dhis.de.action.LoadDisplayModesAction" class="org.hisp.dhis.de.action.LoadDisplayModesAction" scope="prototype">
<property name="selectedStateManager" ref="org.hisp.dhis.de.state.SelectedStateManager" />
</bean>
=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/struts.xml 2010-11-18 10:07:31 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/struts.xml 2010-11-18 12:28:04 +0000
@@ -31,6 +31,10 @@
<result name="success" type="velocity-json">/dhis-web-dataentry/responsePeriods.vm</result>
</action>
+ <action name="loadNextPreviousPeriods" class="org.hisp.dhis.de.action.LoadNextPreviousPeriodsAction">
+ <result name="success" type="velocity-json">../dhis-web-commons/ajax/jsonPeriods.vm</result>
+ </action>
+
<action name="loadDisplayModes" class="org.hisp.dhis.de.action.LoadDisplayModesAction">
<result name="success" type="velocity-json">/dhis-web-dataentry/responseDisplayModes.vm</result>
</action>
=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js 2010-11-18 10:07:31 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js 2010-11-18 12:28:04 +0000
@@ -16,22 +16,21 @@
}
}
-// -----------------------------------------------------------------------------
-// Selection
-// -----------------------------------------------------------------------------
-
-function clearDataSetAndPeriod()
-{
- clearList( document.getElementById( 'selectedDataSetId' ) );
- clearPeriod();
-}
-
function clearPeriod()
{
clearList( document.getElementById( 'selectedPeriodIndex' ) );
+ clearEntryForm();
+}
+
+function clearEntryForm()
+{
$('#entryForm').html( '' );
}
+// -----------------------------------------------------------------------------
+// OrganisationUnit Selection
+// -----------------------------------------------------------------------------
+
function organisationUnitSelected( orgUnits )
{
var dataSetId = $( '#selectedDataSetId' ).val();
@@ -41,24 +40,36 @@
var list = document.getElementById( 'selectedDataSetId' );
clearList( list );
+
addOptionToList( list, '-1', '[ Select ]' );
$.getJSON( url, function( json ) {
- $('#selectedOrganisationUnit').val( json.organisationUnit.name );
- $('#currentOrganisationUnit').html( json.organisationUnit.name );
+ $( '#selectedOrganisationUnit' ).val( json.organisationUnit.name );
+ $( '#currentOrganisationUnit' ).html( json.organisationUnit.name );
for ( i in json.dataSets ) {
addOptionToList( list, json.dataSets[i].id, json.dataSets[i].name );
}
- if ( json.selectionValid && dataSetId != null ) {
+ if ( json.dataSetValid && dataSetId != null ) {
$( '#selectedDataSetId' ).val( dataSetId );
- }
+
+ if ( json.periodValid ) {
+ displayEntryFormInternal( null );
+ }
+ }
+ else {
+ clearPeriod();
+ }
} );
}
selection.setListenerFunction( organisationUnitSelected );
+// -----------------------------------------------------------------------------
+// Next/Previous Periods Selection
+// -----------------------------------------------------------------------------
+
function nextPeriodsSelected()
{
displayPeriodsInternal( true, false );
@@ -69,24 +80,40 @@
displayPeriodsInternal( false, true );
}
+function displayPeriodsInternal( next, previous )
+{
+ var url = 'loadNextPreviousPeriods.action?next=' + next + '&previous=' + previous;
+
+ var list = document.getElementById( 'selectedPeriodIndex' );
+
+ clearList( list );
+
+ addOptionToList( list, '-1', '[ Select ]' );
+
+ $.getJSON( url, function( json ) {
+ for ( i in json.periods ) {
+ addOptionToList( list, i, json.periods[i].name );
+ }
+ } );
+}
+
+// -----------------------------------------------------------------------------
+// DataSet Selection
+// -----------------------------------------------------------------------------
+
function dataSetSelected()
{
- displayPeriodsInternal( false, false );
-}
-
-function displayPeriodsInternal( next, previous )
-{
- var dataSetId = $( '#selectedDataSetId' ).val();
-
- var periodIndex = $('#selectedPeriodIndex').val();
+ var dataSetId = $( '#selectedDataSetId' ).val();
+ var periodIndex = $( '#selectedPeriodIndex' ).val();
if ( dataSetId && dataSetId != -1 )
{
- var url = 'loadPeriods.action?dataSetId=' + dataSetId + '&next=' + next + '&previous=' + previous;
+ var url = 'loadPeriods.action?dataSetId=' + dataSetId;
var list = document.getElementById( 'selectedPeriodIndex' );
clearList( list );
+
addOptionToList( list, '-1', '[ Select ]' );
$.getJSON( url, function( json ) {
@@ -94,18 +121,30 @@
addOptionToList( list, i, json.periods[i].name );
}
- if ( json.selectionValid && periodIndex != null ) {
- $('#selectedPeriodIndex').val( periodIndex );
- }
+ if ( json.periodValid && periodIndex != null ) {
+ $( '#selectedPeriodIndex' ).val( periodIndex );
+ displayEntryFormInternal( setDisplayModes );
+ }
+ else {
+ clearEntryForm();
+ }
} );
}
}
-function displayEntryForm()
+// -----------------------------------------------------------------------------
+// DisplayMode Selection
+// -----------------------------------------------------------------------------
+
+function displayModeSelected()
{
displayEntryFormInternal( null );
}
+// -----------------------------------------------------------------------------
+// Period Selection
+// -----------------------------------------------------------------------------
+
function periodSelected()
{
displayEntryFormInternal( setDisplayModes );
@@ -113,8 +152,8 @@
function displayEntryFormInternal( callback )
{
- var dataSetId = $('#selectedDataSetId').val();
- var periodIndex = $('#selectedPeriodIndex').val();
+ var dataSetId = $( '#selectedDataSetId' ).val();
+ var periodIndex = $( '#selectedPeriodIndex' ).val();
if ( dataSetId && dataSetId != -1 && periodIndex && periodIndex != -1 )
{
@@ -122,7 +161,7 @@
'&selectedPeriodIndex=' + periodIndex +
'&displayMode=' + $("input[name='displayMode']:checked").val();
- $('#entryForm').load( url, callback );
+ $( '#entryForm' ).load( url, callback );
}
}
@@ -161,6 +200,10 @@
} );
}
+// -----------------------------------------------------------------------------
+// History
+// -----------------------------------------------------------------------------
+
function viewHistory( dataElementId, optionComboId, showComment )
{
window.open( 'viewHistory.action?dataElementId=' + dataElementId + '&optionComboId=' + optionComboId + '&showComment=' + showComment, '_blank', 'width=580,height=710,scrollbars=yes' );
=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/responseDataSets.vm'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/responseDataSets.vm 2010-11-18 09:42:34 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/responseDataSets.vm 2010-11-18 12:28:04 +0000
@@ -14,5 +14,6 @@
"name": "$!encoder.jsEncode( ${organisationUnit.name} )",
"shortName": "$!encoder.jsEncode( ${organisationUnit.shortName} )"
},
- "selectionValid": ${selectionValid}
+ "dataSetValid": ${dataSetValid},
+ "periodValid": ${periodValid}
}
\ No newline at end of file
=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/responsePeriods.vm'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/responsePeriods.vm 2010-11-18 10:07:31 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/responsePeriods.vm 2010-11-18 12:28:04 +0000
@@ -9,5 +9,5 @@
"externalId": "$!{period.externalId}"
}#if( $velocityCount < $size ),#end
#end ],
- "selectionValid": ${selectionValid}
+ "periodValid": ${periodValid}
}
=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/select.vm'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/select.vm 2010-11-17 18:26:47 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/select.vm 2010-11-18 12:28:04 +0000
@@ -13,11 +13,11 @@
<input type="button" value="$i18n.getString( 'run_validation' )" onclick="javascript:validate()" style="width:150px"/><br/>
<input type="button" id="calculateCDEs" value="$i18n.getString( 'save_calculated' )" name="calculateCDEs" onclick="calculateAndSaveCDEs()" style="width:150px"/><br/><br/>
- <input type="radio" id="displayModeCustom" name="displayMode" value="customform" disabled="disabled" onclick="displayEntryForm()">
+ <input type="radio" id="displayModeCustom" name="displayMode" value="customform" disabled="disabled" onclick="displayModeSelected()">
<label for="displayModeCustom">$i18n.getString( "use_custom_form" )</label><br/>
- <input type="radio" id="displayModeSection" name="displayMode" value="sectionform" disabled="disabled" onclick="displayEntryForm()">
+ <input type="radio" id="displayModeSection" name="displayMode" value="sectionform" disabled="disabled" onclick="displayModeSelected()">
<label for="displayModeSection">$i18n.getString( "use_section_form" )</label><br/>
- <input type="radio" id="displayModeDefault" name="displayMode" value="defaultform" onclick="displayEntryForm()">
+ <input type="radio" id="displayModeDefault" name="displayMode" value="defaultform" onclick="displayModeSelected()">
<label for="displayModeDefault">$i18n.getString( "use_default_form" )</label><br/><br/>
</div>