=== 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 2011-08-29 19:28:09 +0000 +++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js 2011-08-29 19:29:19 +0000 @@ -25,6 +25,9 @@ // Indicates whether any data entry form has been loaded var dataEntryFormIsLoaded = false; +// Indicates whether meta data is loaded +var metaDataIsLoaded = false; + // Currently selected organisation unit identifier var currentOrganisationUnitId = null; @@ -155,6 +158,7 @@ dataSetAssociationSets = metaData.dataSetAssociationSets; organisationUnitAssociationSetMap = metaData.organisationUnitAssociationSetMap; + metaDataIsLoaded = true; selection.responseReceived(); // Notify that meta data is loaded $( '#loaderSpan' ).hide(); log( 'Meta-data loaded' ); @@ -437,6 +441,11 @@ function organisationUnitSelected( orgUnits, orgUnitNames ) { + if ( metaDataIsLoaded == false ) + { + return false; + } + currentOrganisationUnitId = orgUnits[0]; var organisationUnitName = orgUnitNames[0]; @@ -445,42 +454,39 @@ var dataSetList = getSortedDataSetList(); - if ( dataSetList.length ) - { - $( '#selectedDataSetId' ).removeAttr( 'disabled' ); - - var dataSetId = $( '#selectedDataSetId' ).val(); - var periodId = $( '#selectedPeriodId' ).val(); + $( '#selectedDataSetId' ).removeAttr( 'disabled' ); - clearListById( 'selectedDataSetId' ); - addOptionById( 'selectedDataSetId', '-1', '[ ' + i18n_select_data_set + ' ]' ); - - var dataSetValid = false; - - for ( i in dataSetList ) - { - addOptionById( 'selectedDataSetId', dataSetList[i].id, dataSetList[i].name ); - - if ( dataSetId == dataSetList[i].id ) - { - dataSetValid = true; - } - } - - if ( dataSetValid && dataSetId != null ) - { - $( '#selectedDataSetId' ).val( dataSetId ); - - if ( periodId && periodId != -1 && dataEntryFormIsLoaded ) - { - showLoader(); - loadDataValues(); - } - } - else - { - clearPeriod(); - } + var dataSetId = $( '#selectedDataSetId' ).val(); + var periodId = $( '#selectedPeriodId' ).val(); + + clearListById( 'selectedDataSetId' ); + addOptionById( 'selectedDataSetId', '-1', '[ ' + i18n_select_data_set + ' ]' ); + + var dataSetValid = false; + + for ( i in dataSetList ) + { + addOptionById( 'selectedDataSetId', dataSetList[i].id, dataSetList[i].name ); + + if ( dataSetId == dataSetList[i].id ) + { + dataSetValid = true; + } + } + + if ( dataSetValid && dataSetId != null ) + { + $( '#selectedDataSetId' ).val( dataSetId ); + + if ( periodId && periodId != -1 && dataEntryFormIsLoaded ) + { + showLoader(); + loadDataValues(); + } + } + else + { + clearPeriod(); } }