=== 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 2013-09-18 09:45:24 +0000 +++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js 2013-09-18 13:51:51 +0000 @@ -1037,6 +1037,79 @@ displayEntryFormCompleted(); } +function insertOfflineDataValues(dataSetId, periodId, dataValueMap){ + var formType = dataSets[dataSetId].type; + + $( '[name="entryfield"]' ).each( function( i ) + { + var id = $( this ).attr( 'id' ); + + var split = splitFieldId( id ); + var dataElementId = split.dataElementId; + var optionComboId = split.optionComboId; + currentOrganisationUnitId = split.organisationUnitId; + + var elem = storageManager.getDataValue( dataElementId, optionComboId, periodId, currentOrganisationUnitId ); + if (elem != null) + { + var fieldId = '#' + elem.dataElementId + '-' + elem.optionComboId + '-val'; + + if ( $( fieldId ).length > 0 ) // Insert for fixed input fields + { + if ( $( fieldId ).attr( 'name' ) == 'entrytrueonly' ) { + $( fieldId ).attr('checked', true); + } else { + $( fieldId ).val( elem.value ); + } + } + else // Insert for potential dynamic input fields + { + var dataElementId = elem.dataElementId; + var optionComboId = elem.optionComboId; + + var selectElementId = '#' + getDynamicSelectElementId( dataElementId ); + + if ( $( selectElementId ).length == 0 ) + { + log( 'Could not find dynamic select element for data element: ' + dataElementId ); + return true; + } + + var code = $( selectElementId ).attr( 'id' ).split( '-' )[0]; + + if ( !isDefined( code ) ) + { + log( 'Could not find code on select element: ' + selectElementId ); + return true; + } + + var dynamicInputId = '#' + code + '-' + optionComboId + '-dyninput'; + + if ( $( dynamicInputId ).length == 0 ) + { + log( 'Could not find find dynamic input element for option combo: ' + optionComboId ); + return true; + } + + // Set data element in select list + + $( selectElementId ).val( dataElementId ); + + // Enable input fields and set value + + $( 'input[code="' + code + '"]' ).prop( 'disabled', false ); + $( 'input[code="' + code + '"]' ).css( 'background-color', COLOR_WHITE ); + + $( dynamicInputId ).val( elem.val ); + } + + dataValueMap[elem.dataElementId+'-'+elem.optionComboId] = elem.val + } + } + ); +} + + function insertDataValues() { var dataValueMap = []; @@ -1062,132 +1135,172 @@ $( '.entryfield' ).filter( ':disabled' ).css( 'background-color', COLOR_GREY ); - $.ajax( { - url: 'getDataValues.action', - data: - { - periodId : periodId, - dataSetId : dataSetId, - organisationUnitId : getCurrentOrganisationUnit(), - multiOrganisationUnit: multiOrganisationUnit - }, - dataType: 'json', - error: function() // offline - { - $( '#contentDiv' ).show(); - $( '#completenessDiv' ).show(); - $( '#infoDiv' ).hide(); - }, - success: function( json ) // online - { - if ( json.locked ) - { - $( '#contentDiv input').attr( 'readonly', 'readonly' ); - $( '.entryoptionset').autocomplete( 'disable' ); - $( '.sectionFilter').removeAttr( 'disabled' ); - $( '#completenessDiv' ).hide(); - setHeaderDelayMessage( i18n_dataset_is_locked ); - } - else - { - $( '.entryoptionset' ).autocomplete( 'enable' ); - $( '#contentDiv input' ).removeAttr( 'readonly' ); - $( '#completenessDiv' ).show(); - } - - // Set data values, works for selects too as data value=select value - - $.safeEach( json.dataValues, function( i, value ) - { - var fieldId = '#' + value.id + '-val'; - var commentId = '#' + value.id + '-comment'; - - if ( $( fieldId ).length > 0 ) // Set values - { - if ( $( fieldId ).attr( 'name' ) == 'entrytrueonly' && 'true' == value.val ) - { - $( fieldId ).attr( 'checked', true ); - } - else - { - $( fieldId ).val( value.val ); - } - } - - if ( 'true' == value.com ) // Set active comments - { - if ( $( commentId ).length > 0 ) - { - $( commentId ).attr( 'src', '../images/comment_active.png' ); + //Validation if user is Online or Offline + if(!dhis2.availability._isAvailable){ + insertOfflineDataValues(dataSetId, periodId, dataValueMap); + } else{ + + $.ajax( { + url: 'getDataValues.action', + data: + { + periodId : periodId, + dataSetId : dataSetId, + organisationUnitId : getCurrentOrganisationUnit(), + multiOrganisationUnit: multiOrganisationUnit + }, + dataType: 'json', + error: function() // offline + { + $( '#contentDiv' ).show(); + $( '#completenessDiv' ).show(); + $( '#infoDiv' ).hide(); + }, + success: function( json ) // online + { + if ( json.locked ) + { + $( '#contentDiv input').attr( 'readonly', 'readonly' ); + $( '.entryoptionset').autocomplete( 'disable' ); + $( '.sectionFilter').removeAttr( 'disabled' ); + $( '#completenessDiv' ).hide(); + setHeaderDelayMessage( i18n_dataset_is_locked ); + } + else + { + $( '.entryoptionset' ).autocomplete( 'enable' ); + $( '#contentDiv input' ).removeAttr( 'readonly' ); + $( '#completenessDiv' ).show(); + } + + // Set data values, works for selects too as data value=select value + + $.safeEach( json.dataValues, function( i, value ) + { + var fieldId = '#' + value.id + '-val'; + var commentId = '#' + value.id + '-comment'; + + if ( $( fieldId ).length > 0 ) // Set values + { + if ( $( fieldId ).attr( 'name' ) == 'entrytrueonly' && 'true' == value.val ) + { + $( fieldId ).attr( 'checked', true ); + } + else + { + $( fieldId ).val( value.val ); + } } - else if ( $( fieldId ).length > 0 ) + + if ( 'true' == value.com ) // Set active comments + { + if ( $( commentId ).length > 0 ) + { + $( commentId ).attr( 'src', '../images/comment_active.png' ); + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + } + else if ( $( fieldId ).length > 0 ) + { + $( fieldId ).css( 'border-color', COLOR_BORDER_ACTIVE ) + } + } + + dataValueMap[value.id] = value.val; + } ); + + // Set min-max values and colorize violation fields + + if( !json.locked ) + { + $.safeEach( json.minMaxDataElements, function( i, value ) { - $( fieldId ).css( 'border-color', COLOR_BORDER_ACTIVE ) - } + var minId = value.id + '-min'; + var maxId = value.id + '-max'; + + var valFieldId = '#' + value.id + '-val'; + + var dataValue = dataValueMap[value.id]; + + if ( dataValue && ( ( value.min && new Number( dataValue ) < new Number( + value.min ) ) || ( value.max && new Number( dataValue ) > new Number( value.max ) ) ) ) + { + $( valFieldId ).css( 'background-color', COLOR_ORANGE ); + } + + currentMinMaxValueMap[minId] = value.min; + currentMinMaxValueMap[maxId] = value.max; + } ); } - - dataValueMap[value.id] = value.val; - } ); - - // Set min-max values and colorize violation fields - - if( !json.locked ) - { - $.safeEach( json.minMaxDataElements, function( i, value ) - { - var minId = value.id + '-min'; - var maxId = value.id + '-max'; - - var valFieldId = '#' + value.id + '-val'; - - var dataValue = dataValueMap[value.id]; - - if ( dataValue && ( ( value.min && new Number( dataValue ) < new Number( - value.min ) ) || ( value.max && new Number( dataValue ) > new Number( value.max ) ) ) ) - { - $( valFieldId ).css( 'background-color', COLOR_ORANGE ); - } - - currentMinMaxValueMap[minId] = value.min; - currentMinMaxValueMap[maxId] = value.max; - } ); - } - - // Update indicator values in form - - updateIndicators(); - updateDataElementTotals(); - - // Set completeness button - - if ( json.complete && !json.locked) - { - $( '#completeButton' ).attr( 'disabled', 'disabled' ); - $( '#undoButton' ).removeAttr( 'disabled' ); - - if ( json.storedBy ) + + // Update indicator values in form + + updateIndicators(); + updateDataElementTotals(); + + // Set completeness button + + if ( json.complete && !json.locked) + { + $( '#completeButton' ).attr( 'disabled', 'disabled' ); + $( '#undoButton' ).removeAttr( 'disabled' ); + + if ( json.storedBy ) + { + $( '#infoDiv' ).show(); + $( '#completedBy' ).html( json.storedBy ); + $( '#completedDate' ).html( json.date ); + + currentCompletedByUser = json.storedBy; + } + } + else + { + $( '#completeButton' ).removeAttr( 'disabled' ); + $( '#undoButton' ).attr( 'disabled', 'disabled' ); + $( '#infoDiv' ).hide(); + } + + if ( json.locked ) { - $( '#infoDiv' ).show(); - $( '#completedBy' ).html( json.storedBy ); - $( '#completedDate' ).html( json.date ); - - currentCompletedByUser = json.storedBy; + $( '#contentDiv input' ).css( 'backgroundColor', '#eee' ); + $( '.sectionFilter' ).css( 'backgroundColor', '#fff' ); } } - else - { - $( '#completeButton' ).removeAttr( 'disabled' ); - $( '#undoButton' ).attr( 'disabled', 'disabled' ); - $( '#infoDiv' ).hide(); - } - - if ( json.locked ) - { - $( '#contentDiv input' ).css( 'backgroundColor', '#eee' ); - $( '.sectionFilter' ).css( 'backgroundColor', '#fff' ); - } - } - } ); + } ); + } } function displayEntryFormCompleted()