=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryOption.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryOption.java 2014-04-25 11:22:12 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryOption.java 2014-06-02 15:29:13 +0000 @@ -28,6 +28,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +import java.util.Date; import java.util.HashSet; import java.util.Set; @@ -59,6 +60,10 @@ public static final String DEFAULT_NAME = "default"; + private Date startDate; + + private Date endDate; + private Set categories = new HashSet(); @Scanned @@ -152,6 +157,30 @@ } @JsonProperty + @JsonView( {DetailedView.class } ) + public Date getStartDate() + { + return startDate; + } + + public void setStartDate( Date startDate ) + { + this.startDate = startDate; + } + + @JsonProperty + @JsonView( {DetailedView.class } ) + public Date getEndDate() + { + return endDate; + } + + public void setEndDate( Date endDate ) + { + this.endDate = endDate; + } + + @JsonProperty @JsonSerialize(contentAs = BaseIdentifiableObject.class) @JsonView({ DetailedView.class }) @JacksonXmlElementWrapper(localName = "categories", namespace = DxfNamespaces.DXF_2_0) === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataelement/hibernate/DataElementCategoryOption.hbm.xml' --- dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataelement/hibernate/DataElementCategoryOption.hbm.xml 2014-03-11 16:06:51 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataelement/hibernate/DataElementCategoryOption.hbm.xml 2014-06-02 15:29:13 +0000 @@ -17,6 +17,10 @@ + + + + === modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonDataElementCategoryOption.vm' --- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonDataElementCategoryOption.vm 2013-02-22 14:58:47 +0000 +++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonDataElementCategoryOption.vm 2014-06-02 15:29:13 +0000 @@ -2,6 +2,8 @@ { "id": "${dataElementCategoryOption.id}" , "name": "$!encoder.jsonEncode( ${dataElementCategoryOption.name} )", + "startDate": "$!format.formatDate( ${dataElementCategoryOption.startDate} )", + "endDate": "$!format.formatDate( ${dataElementCategoryOption.endDate} )", "concept": "$!encoder.jsonEncode(${dataElementCategoryOption.concept.name})" } } === 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 2014-02-11 15:34:53 +0000 +++ dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/struts.xml 2014-06-02 15:29:13 +0000 @@ -13,7 +13,7 @@ /main.vm /dhis-web-dataentry/select.vm /dhis-web-dataentry/menu.vm - ../dhis-web-commons/ouwt/ouwt.js,javascript/form.js,javascript/entry.js,javascript/history.js + ../dhis-web-commons/ouwt/ouwt.js,../dhis-web-commons/javascripts/ext/ext-all.js,javascript/form.js,javascript/entry.js,javascript/history.js style/dhis-web-dataentry.css ../dhis-web-commons/cacheManifest.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 2014-05-23 13:27:48 +0000 +++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js 2014-06-02 15:29:13 +0000 @@ -380,9 +380,6 @@ function addEventListeners() { - var dataSetId = $( '#selectedDataSetId' ).val(); - var formType = dhis2.de.dataSets[dataSetId].type; - $( '.entryfield' ).each( function( i ) { var id = $( this ).attr( 'id' ); @@ -692,6 +689,21 @@ return split; } +/** + * Creates an associative array with values of the current period. + */ +function currentPeriod() +{ + var period = {}; + var part = ( $( '#selectedPeriodId' ).val() || "" ).split( ',' ); + + period.iso = part[0]; + period.startDate = part[1]; + period.endDate = part[2]; + + return period; +} + function refreshZebraStripes( $tbody ) { $tbody.find( 'tr:not([colspan]):visible:even' ).find( 'td:first-child' ).removeClass( 'reg alt' ).addClass( 'alt' ); @@ -739,6 +751,9 @@ // OrganisationUnit Selection // ----------------------------------------------------------------------------- +/** + * Callback for changes in organisation unit selections. + */ function organisationUnitSelected( orgUnits, orgUnitNames, children ) { if ( dhis2.de.metaDataIsLoaded == false ) @@ -757,7 +772,7 @@ $( '#selectedDataSetId' ).removeAttr( 'disabled' ); var dataSetId = $( '#selectedDataSetId' ).val(); - var periodId = $( '#selectedPeriodId' ).val(); + var periodId = currentPeriod().iso; clearListById( 'selectedDataSetId' ); addOptionById( 'selectedDataSetId', '-1', '[ ' + i18n_select_data_set + ' ]' ); @@ -849,6 +864,9 @@ return dataSetList; } +/** + * Gets list of data sets for selected organisation units. + */ function getSortedDataSetListForOrgUnits( orgUnits ) { var dataSetList = []; @@ -886,16 +904,15 @@ // DataSet Selection // ----------------------------------------------------------------------------- +/** + * Callback for changes in data set list. + */ function dataSetSelected() { - $( '#selectedPeriodId' ).removeAttr( 'disabled' ); - $( '#prevButton' ).removeAttr( 'disabled' ); - $( '#nextButton' ).removeAttr( 'disabled' ); - var x = dhis2.de.currentDataSetId; var dataSetId = $( '#selectedDataSetId' ).val(); - var periodId = $( '#selectedPeriodId' ).val(); + var periodVal = $( '#selectedPeriodId' ).val(); var previousDataSetValid = ( dhis2.de.currentDataSetId && dhis2.de.currentDataSetId != -1 ); var previousPeriodType = previousDataSetValid ? dhis2.de.dataSets[dhis2.de.currentDataSetId].periodType : null; @@ -904,43 +921,25 @@ if ( dataSetId && dataSetId != -1 ) { - var periodType = dhis2.de.dataSets[dataSetId].periodType; - var allowFuturePeriods = dhis2.de.dataSets[dataSetId].allowFuturePeriods; - var periods = dhis2.period.generator.generateReversedPeriods(periodType, dhis2.de.currentPeriodOffset); - - if( allowFuturePeriods == false ) - { - periods = dhis2.period.generator.filterFuturePeriods(periods); - } - - clearListById( 'selectedPeriodId' ); - clearSectionFilters(); + $( '#selectedPeriodId' ).removeAttr( 'disabled' ); + $( '#prevButton' ).removeAttr( 'disabled' ); + $( '#nextButton' ).removeAttr( 'disabled' ); + + var periodType = dhis2.de.dataSets[dataSetId].periodType; + + if ( periodType != previousPeriodType ) + { + displayPeriods(); + clearSectionFilters(); + } dhis2.de.currentCategories = dhis2.de.getCategories( dataSetId ); dhis2.de.multiOrganisationUnit = !!$( '#selectedDataSetId :selected' ).data( 'multiorg' ); - var attributeMarkup = dhis2.de.getAttributesMarkup(); - $( '#attributeComboDiv' ).html( attributeMarkup ); - - if ( periods.length > 0 ) - { - addOptionById( 'selectedPeriodId', '-1', '[ ' + i18n_select_period + ' ]' ); - } - else - { - addOptionById( 'selectedPeriodId', '-1', i18n_no_periods_click_prev_year_button ); - } - - $.safeEach( periods, function( idx, item ) - { - addOptionById( 'selectedPeriodId', item.iso, item.name ); - } ); - if ( dhis2.de.inputSelected() && previousPeriodType && previousPeriodType == periodType ) { - showLoader(); - $( '#selectedPeriodId' ).val( periodId ); + showLoader(); loadForm(); } else @@ -950,24 +949,34 @@ } else { + $( '#selectedPeriodId').val( "" ); + $( '#selectedPeriodId' ).attr( 'disabled', 'disabled' ); + $( '#prevButton' ).attr( 'disabled', 'disabled' ); + $( '#nextButton' ).attr( 'disabled', 'disabled' ); + clearEntryForm(); dhis2.de.clearAttributes(); } + + dhis2.de.updateOptionsStatus(); } // ----------------------------------------------------------------------------- // Period Selection // ----------------------------------------------------------------------------- +/** + * Callback for changes in period select list. + */ function periodSelected() { var periodName = $( '#selectedPeriodId :selected' ).text(); - var dataSetId = $( '#selectedDataSetId' ).val(); $( '#currentPeriod' ).html( periodName ); - var periodId = $( '#selectedPeriodId' ).val(); - + var attributeMarkup = dhis2.de.getAttributesMarkup(); + $( '#attributeComboDiv' ).html( attributeMarkup ); + if ( dhis2.de.inputSelected() ) { showLoader(); @@ -981,24 +990,37 @@ loadForm(); } } + else + { + clearEntryForm(); + } } +/** + * Handles the onClick event for the next period button. + */ function nextPeriodsSelected() { if ( dhis2.de.currentPeriodOffset < 0 ) // Cannot display future periods { dhis2.de.currentPeriodOffset++; - displayPeriodsInternal(); + displayPeriods(); } } +/** + * Handles the onClick event for the previous period button. + */ function previousPeriodsSelected() { dhis2.de.currentPeriodOffset--; - displayPeriodsInternal(); + displayPeriods(); } -function displayPeriodsInternal() +/** + * Generates the period select list options. + */ +function displayPeriods() { var dataSetId = $( '#selectedDataSetId' ).val(); var periodType = dhis2.de.dataSets[dataSetId].periodType; @@ -1014,16 +1036,17 @@ if ( periods.length > 0 ) { - addOptionById( 'selectedPeriodId', '-1', '[ ' + i18n_select_period + ' ]' ); + addOptionById( 'selectedPeriodId', "", '[ ' + i18n_select_period + ' ]' ); } else { - addOptionById( 'selectedPeriodId', '-1', i18n_no_periods_click_prev_year_button ); + addOptionById( 'selectedPeriodId', "", i18n_no_periods_click_prev_year_button ); } $.safeEach( periods, function( idx, item ) { - addOptionById( 'selectedPeriodId', item.iso, item.name ); + var periodInfo = item.iso + ',' + item.startDate + ',' + item.endDate; + addOptionById( 'selectedPeriodId', periodInfo, item.name ); } ); } @@ -1032,8 +1055,8 @@ //------------------------------------------------------------------------------ /** -* Returns an array of category objects for the given data set identifier. Categories -* are looked up using the category combo of the data set. Null is returned if +* Returns an array of category objects for the given data set identifier. Categories +* are looked up using the category combo of the data set. Null is returned if * the given data set has the default category combo. */ dhis2.de.getCategories = function( dataSetId ) @@ -1043,7 +1066,7 @@ if ( !dataSet || !dataSet.categoryCombo || dhis2.de.defaultCategoryCombo === dataSet.categoryCombo ) { return null; } - + var categoryCombo = dhis2.de.categoryCombos[dataSet.categoryCombo]; var categories = []; @@ -1117,6 +1140,34 @@ }; /** + * Updates the options status showing options selected if any. + */ +dhis2.de.updateOptionsStatus = function() +{ + var html = ''; + + if ( dhis2.de.currentCategories && dhis2.de.currentCategories.length != 0 ) + { + var prefix = '('; + $.safeEach(dhis2.de.currentCategories, function (idx, category) { + var option = $('#category-' + category.id).val(); + + if (option && option != -1) { + var options = dhis2.de.categories[ category.id ].options; + var matching = $.grep(options, function (e) { + return e.id == option; + }); + html += prefix + matching[0].name; + prefix = ', '; + } + }); + html += html.length == 0 ? '' : ')'; + } + + $( '#currentOptionsSelection').html( html ); +}; + +/** * Returns a query param value for the currently selected category options where * each option is separated by the ; character. */ @@ -1140,14 +1191,28 @@ } /** + * Tests to see if a category option is valid during a period. + */ +dhis2.de.optionValidWithinPeriod = function( option, period ) +{ + return ( option.startDate == null || option.startDate <= period.endDate ) + && ( option.endDate == null || option.endDate >= period.startDate ) +} + +/** * Returns markup for drop down boxes to be put in the selection box for the * given categories. The empty string is returned if no categories are given. */ dhis2.de.getAttributesMarkup = function() { var html = ''; - - if ( !dhis2.de.currentCategories || dhis2.de.currentCategories.length == 0 ) { + + var period = currentPeriod(); + + var options = dhis2.de.getCurrentCategoryOptions(); + + if ( !dhis2.de.currentCategories || dhis2.de.currentCategories.length == 0 + || period.iso == "" ) { return html; } @@ -1156,9 +1221,12 @@ html += '
' + category.name + '
 '; html += ''; @@ -1191,6 +1259,12 @@ loadForm(); } } + else + { + clearEntryForm(); + } + + dhis2.de.updateOptionsStatus(); }; // ----------------------------------------------------------------------------- @@ -1203,12 +1277,12 @@ dhis2.de.inputSelected = function() { var dataSetId = $( '#selectedDataSetId' ).val(); - var periodId = $( '#selectedPeriodId' ).val(); + var periodId = currentPeriod().iso; if ( dhis2.de.currentOrganisationUnitId && dataSetId && dataSetId != -1 && - periodId && periodId != -1 && + periodId && periodId != "" && dhis2.de.categoriesSelected() ) { return true; } @@ -1230,7 +1304,7 @@ function getAndInsertDataValues() { - var periodId = $( '#selectedPeriodId' ).val(); + var periodId = currentPeriod().iso; var dataSetId = $( '#selectedDataSetId' ).val(); // Clear existing values and colors, grey disabled fields @@ -1810,7 +1884,7 @@ function viewHist( dataElementId, optionComboId ) { - var periodId = $( '#selectedPeriodId' ).val(); + var periodId = currentPeriod().iso; if ( dataElementId && optionComboId && periodId && periodId != -1 ) { @@ -2363,7 +2437,7 @@ { var params = { 'ds': $( '#selectedDataSetId' ).val(), - 'pe': $( '#selectedPeriodId' ).val(), + 'pe': currentPeriod().iso, 'ou': getCurrentOrganisationUnit(), 'multiOu': dhis2.de.multiOrganisationUnit }; @@ -2434,7 +2508,7 @@ return true; } - return false; + return false; } /** === modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/responseMetaData.vm' --- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/responseMetaData.vm 2014-02-25 05:51:59 +0000 +++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/responseMetaData.vm 2014-06-02 15:29:13 +0000 @@ -69,7 +69,7 @@ #foreach( $category in $categoryCombo.categories ) "${category.uid}"#if( $velocityCount < $size2 ),#end #end -] }#if( $velocityCount < $size1 ),#end +] }#if( $velocityCount < $size1 ),#end #end }, @@ -80,8 +80,10 @@ #set( $categoryOptions = $categoryOptionMap.get( $category.uid ) ) #set( $size2 = $categoryOptions.size() ) #foreach( $option in $categoryOptions ) -{"id":"${option.uid}","name":"$encoder.jsonEncode( ${option.displayName} )"}#if( $velocityCount < $size2 ),#end +{"id":"${option.uid}","name":"$encoder.jsonEncode( ${option.displayName} )" +#if( ${option.startDate} ),"startDate":"${option.startDate}"#end +#if( ${option.endDate} ),"endDate":"${option.endDate}"#end}#if( $velocityCount < $size2 ),#end #end -] }#if( $velocityCount < $size1 ),#end +] }#if( $velocityCount < $size1 ),#end #end } } } === 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 2014-01-23 15:36:54 +0000 +++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/select.vm 2014-06-02 15:29:13 +0000 @@ -61,7 +61,8 @@
- $i18n.getString( "no_organisationunit_selected" ) - $i18n.getString( "no_period_selected" )
+ $i18n.getString( "no_organisationunit_selected" ) - $i18n.getString( "no_period_selected" ) +
$i18n.getString( "no_dataelement_selected" )
@@ -81,13 +82,13 @@ -
$i18n.getString( "period" )
+


-


+


+


+



=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/multidimensional/updateDataElementCategoryOptionForm.vm' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/multidimensional/updateDataElementCategoryOptionForm.vm 2014-02-12 16:09:47 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/multidimensional/updateDataElementCategoryOptionForm.vm 2014-06-02 15:29:13 +0000 @@ -3,10 +3,16 @@ validation2( 'editDataElementCategoryOptionForm', function( form ){ form.submit()}, { 'beforeValidateHandler': function() { listValidator( 'memberValidator', 'categoryOptions' ); }, 'rules': getValidationRules("dateElementCategoryOption") - }); + }); + + dhis2.period.picker.createInstance('#startDate'); + dhis2.period.picker.createInstance('#endDate'); + + $('#startDate').calendarsPicker('option', 'maxDate', dhis2.period.calendar.add(dhis2.period.calendar.today(), 100, 'y')); + $('#endDate').calendarsPicker('option', 'maxDate', dhis2.period.calendar.add(dhis2.period.calendar.today(), 100, 'y')); checkValueIsExist( "name", "validateDataElementCategoryOption.action", {id: $dataElementCategoryOption.id} ); - checkValueIsExist( "code", "validateDataElementCategoryOption.action", {id: $dataElementCategoryOption.code} ); +//Error: checkValueIsExist( "code", "validateDataElementCategoryOption.action", {id: $dataElementCategoryOption.code} ); }); var i18n_confirm_delete = '$encoder.jsEscape( $i18n.getString( "confirm_delete_data_element_category_option" ) , "'")'; @@ -35,6 +41,22 @@ + + + + + + + + + + + + + + + +