=== 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 2011-05-31 07:54:15 +0000 +++ dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/META-INF/dhis/beans.xml 2011-06-23 08:20:44 +0000 @@ -1,142 +1,151 @@ - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + === 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 2011-05-31 07:54:15 +0000 +++ dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/struts.xml 2011-06-23 08:20:44 +0000 @@ -4,109 +4,108 @@ "http://struts.apache.org/dtds/struts-2.0.dtd"> - - - - - - displayForm.action - - - - - /main.vm - /dhis-web-dataentry/select.vm - /dhis-web-dataentry/menu.vm - 420 - ../dhis-web-commons/ouwt/ouwt.js,javascript/form.js,javascript/entry.js - style/dhis-web-dataentry.css - - - - /dhis-web-dataentry/responseDataSets.vm - - - - /dhis-web-dataentry/responsePeriods.vm - - - - ../dhis-web-commons/ajax/jsonPeriods.vm - - - - /dhis-web-dataentry/responseDisplayModes.vm - - - - /dhis-web-dataentry/customForm.vm - /dhis-web-dataentry/sectionForm.vm - /dhis-web-dataentry/defaultForm.vm - /dhis-web-dataentry/responseVoid.vm - - - - /dhis-web-dataentry/status.vm - plainTextError - F_DATAVALUE_ADD,F_DATAVALUE_UPDATE,F_DATAVALUE_DELETE - - - - /dhis-web-dataentry/status.vm - plainTextError - F_DATAVALUE_ADD,F_DATAVALUE_UPDATE,F_DATAVALUE_DELETE - - - - - 204 - - plainTextError - F_DATAELEMENT_MINMAX_ADD,F_DATAELEMENT_MINMAX_UPDATE - - - - - 204 - - plainTextError - F_DATAELEMENT_MINMAX_DELETE - - - - /popup.vm - /dhis-web-dataentry/history.vm - javascript/history.js - - - - ../dhis-web-commons/ajax/jsonResponseSuccess.vm - ../dhis-web-commons/ajax/jsonResponseInput.vm - - - - ../dhis-web-commons/ajax/jsonResponseSuccess.vm - - - - ../dhis-web-commons/ajax/jsonResponseSuccess.vm - ../dhis-web-commons/ajax/jsonResponseInput.vm - - - - /popup.vm - /popup.vm - /dhis-web-dataentry/validationResult.vm - - - - ../dhis-web-commons/ajax/jsonResponseSuccess.vm - - - - - - - + + + + + + displayForm.action + + + + + /main.vm + /dhis-web-dataentry/select.vm + /dhis-web-dataentry/menu.vm + 420 + ../dhis-web-commons/ouwt/ouwt.js,javascript/form.js,javascript/entry.js + style/dhis-web-dataentry.css + + + + /dhis-web-dataentry/responseDataSets.vm + + + + /dhis-web-dataentry/responsePeriods.vm + + + + ../dhis-web-commons/ajax/jsonPeriods.vm + + + + /dhis-web-dataentry/responseDisplayModes.vm + + + + /dhis-web-dataentry/customForm.vm + /dhis-web-dataentry/sectionForm.vm + /dhis-web-dataentry/defaultForm.vm + /dhis-web-dataentry/responseVoid.vm + + + + /dhis-web-dataentry/status.vm + plainTextError + F_DATAVALUE_ADD,F_DATAVALUE_UPDATE,F_DATAVALUE_DELETE + + + + /dhis-web-dataentry/status.vm + plainTextError + F_DATAVALUE_ADD,F_DATAVALUE_UPDATE,F_DATAVALUE_DELETE + + + + + 204 + + plainTextError + F_DATAELEMENT_MINMAX_ADD,F_DATAELEMENT_MINMAX_UPDATE + + + + + 204 + + plainTextError + F_DATAELEMENT_MINMAX_DELETE + + + + /popup.vm + /dhis-web-dataentry/history.vm + javascript/history.js + + + + ../dhis-web-commons/ajax/jsonResponseSuccess.vm + ../dhis-web-commons/ajax/jsonResponseInput.vm + + + + ../dhis-web-commons/ajax/jsonResponseSuccess.vm + + + + ../dhis-web-commons/ajax/jsonResponseSuccess.vm + ../dhis-web-commons/ajax/jsonResponseInput.vm + + + + /popup.vm + /popup.vm + /dhis-web-dataentry/validationResult.vm + + + + ../dhis-web-commons/ajax/jsonResponseSuccess.vm + + + + + + + === modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/entry.js' --- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/entry.js 2011-06-23 08:19:11 +0000 +++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/entry.js 2011-06-23 08:20:44 +0000 @@ -1,4 +1,3 @@ - // ----------------------------------------------------------------------------- // Save // ----------------------------------------------------------------------------- @@ -17,131 +16,140 @@ */ function updateIndicators() { - var entryFieldValues = getEntryFieldValues(); - - $( 'input[name="indicator"]' ).each( function( index ) { - var indicatorId = $( this ).attr( 'indicatorid' ); - - var formula = indicatorFormulas[ indicatorId ]; - - var expression = generateExpression( formula ); - - var value = eval( expression ); - - value = isNaN( value ) ? '-' : Math.round( value ); - - $( this ).attr( 'value', value ); - } ); + var entryFieldValues = getEntryFieldValues(); + + $( 'input[name="indicator"]' ).each( function( index ) + { + var indicatorId = $( this ).attr( 'indicatorid' ); + + var formula = indicatorFormulas[indicatorId]; + + var expression = generateExpression( formula ); + + var value = eval( expression ); + + value = isNaN( value ) ? '-' : Math.round( value ); + + $( this ).attr( 'value', value ); + } ); } /** * Returns an associative array with an entry for each entry input field in the - * form where the key is the input field id and the value is the input field value. + * form where the key is the input field id and the value is the input field + * value. */ function getEntryFieldValues() { - var entryFieldValues = new Array(); - - $( 'input[name="entryfield"]' ).each( function( index ) { - entryFieldValues[ $( this ).attr( 'id' ) ] = $( this ).attr( 'value' ); - } ); - - return entryFieldValues; + var entryFieldValues = new Array(); + + $( 'input[name="entryfield"]' ).each( function( index ) + { + entryFieldValues[$( this ).attr( 'id' )] = $( this ).attr( 'value' ); + } ); + + return entryFieldValues; } /** - * Parses the expression and substitues the operand identifiers with the value of - * the corresponding input entry field. + * Parses the expression and substitues the operand identifiers with the value + * of the corresponding input entry field. */ function generateExpression( expression ) { - var matcher = expression.match( FORMULA_PATTERN ); - - for ( k in matcher ) - { - var match = matcher[k]; - var operand = match.replace( /[\[\]]/g, '' ); // Remove brackets from expression to simplify extraction of identifiers - - var dataElementId = operand.substring( 0, operand.indexOf( SEPARATOR ) ); - var categoryOptionComboId = operand.substring( operand.indexOf( SEPARATOR ) + 1, operand.length ); - - var entryFieldId = 'value[' + dataElementId + '].value:value[' + categoryOptionComboId + '].value'; - var entryField = document.getElementById( entryFieldId ); - - var value = entryField && entryField.value ? entryField.value : '0'; - - expression = expression.replace( match, value ); // TODO signed numbers - } - - return expression; + var matcher = expression.match( FORMULA_PATTERN ); + + for ( k in matcher ) + { + var match = matcher[k]; + var operand = match.replace( /[\[\]]/g, '' ); // Remove brackets from + // expression to + // simplify extraction + // of identifiers + + var dataElementId = operand.substring( 0, operand.indexOf( SEPARATOR ) ); + var categoryOptionComboId = operand.substring( operand.indexOf( SEPARATOR ) + 1, operand.length ); + + var entryFieldId = 'value[' + dataElementId + '].value:value[' + categoryOptionComboId + '].value'; + var entryField = document.getElementById( entryFieldId ); + + var value = entryField && entryField.value ? entryField.value : '0'; + + expression = expression.replace( match, value ); // TODO signed + // numbers + } + + return expression; } /** -/* Used by default and section forms. -*/ + * /* Used by default and section forms. + */ function saveVal( dataElementId, optionComboId ) { - var dataElementName = document.getElementById( 'value[' + dataElementId + '].name' ).innerHTML; - - saveValueInternal( dataElementId, optionComboId, dataElementName, null ); + var dataElementName = document.getElementById( 'value[' + dataElementId + '].name' ).innerHTML; + + saveValueInternal( dataElementId, optionComboId, dataElementName, null ); } /** -/* Used by custom forms. -*/ + * /* Used by custom forms. + */ function saveValue( dataElementId, optionComboId, dataElementName ) { - saveValueInternal( dataElementId, optionComboId, dataElementName ); - updateIndicators(); + saveValueInternal( dataElementId, optionComboId, dataElementName ); + updateIndicators(); } function saveValueInternal( dataElementId, optionComboId, dataElementName ) { - var field = document.getElementById( 'value[' + dataElementId + '].value' + ':' + 'value[' + optionComboId + '].value'); + var field = document.getElementById( 'value[' + dataElementId + '].value' + ':' + 'value[' + optionComboId + + '].value' ); var type = document.getElementById( 'value[' + dataElementId + '].type' ).innerHTML; - var organisationUnitId = getFieldValue( 'organisationUnitId' ); - + var organisationUnitId = getFieldValue( 'organisationUnitId' ); + field.style.backgroundColor = COLOR_YELLOW; - + if ( field.value && field.value != '' ) { if ( type == 'int' || type == 'number' || type == 'positiveNumber' || type == 'negativeNumber' ) { - if ( field.value && field.value.length > 255 ) - { - window.alert( i18n_value_too_long + '\n\n' + dataElementName ); - return alertField( field ); - } - if ( type == 'int' && !isInt( field.value ) ) - { - window.alert( i18n_value_must_integer + '\n\n' + dataElementName ); + if ( field.value && field.value.length > 255 ) + { + window.alert( i18n_value_too_long + '\n\n' + dataElementName ); + return alertField( field ); + } + if ( type == 'int' && !isInt( field.value ) ) + { + window.alert( i18n_value_must_integer + '\n\n' + dataElementName ); return alertField( field ); } if ( type == 'number' && !isRealNumber( field.value ) ) { window.alert( i18n_value_must_number + '\n\n' + dataElementName ); return alertField( field ); - } - if ( type == 'positiveNumber' && !isPositiveInt( field.value ) ) + } + if ( type == 'positiveNumber' && !isPositiveInt( field.value ) ) { window.alert( i18n_value_must_positive_integer + '\n\n' + dataElementName ); return alertField( field ); - } - if ( type == 'negativeNumber' && !isNegativeInt( field.value ) ) + } + if ( type == 'negativeNumber' && !isNegativeInt( field.value ) ) { window.alert( i18n_value_must_negative_integer + '\n\n' + dataElementName ); return alertField( field ); } - if ( isValidZeroNumber( field.value ) ) + if ( isValidZeroNumber( field.value ) ) { - // If value is 0 and zero is not significant for data element, then skip value - if ( significantZeros.indexOf( dataElementId ) == -1 ) - { - field.style.backgroundColor = COLOR_GREEN; - return false; - } + // If value is 0 and zero is not significant for data element, + // then skip value + if ( significantZeros.indexOf( dataElementId ) == -1 ) + { + field.style.backgroundColor = COLOR_GREEN; + return false; + } } - + var minString = document.getElementById( 'value[' + dataElementId + ':' + optionComboId + '].min' ).innerHTML; var maxString = document.getElementById( 'value[' + dataElementId + ':' + optionComboId + '].max' ).innerHTML; @@ -153,24 +161,26 @@ if ( value < min ) { - var valueSaver = new ValueSaver( dataElementId, optionComboId, organisationUnitId, field.value, COLOR_ORANGE ); + var valueSaver = new ValueSaver( dataElementId, optionComboId, organisationUnitId, field.value, + COLOR_ORANGE ); valueSaver.save(); - + window.alert( i18n_value_of_data_element_less + '\n\n' + dataElementName ); - + return; } if ( value > max ) { - var valueSaver = new ValueSaver( dataElementId, optionComboId, organisationUnitId, field.value, COLOR_ORANGE ); + var valueSaver = new ValueSaver( dataElementId, optionComboId, organisationUnitId, field.value, + COLOR_ORANGE ); valueSaver.save(); - - window.alert( i18n_value_of_data_element_greater + '\n\n' + dataElementName); - + + window.alert( i18n_value_of_data_element_greater + '\n\n' + dataElementName ); + return; } - } + } } } @@ -178,38 +188,39 @@ valueSaver.save(); } -function saveBoolean( dataElementId, optionComboId, selectedOption ) -{ - var select = selectedOption.options[selectedOption.selectedIndex].value - var organisationUnitId = getFieldValue( 'organisationUnitId' ); - - selectedOption.style.backgroundColor = COLOR_YELLOW; - - var valueSaver = new ValueSaver( dataElementId, optionComboId, organisationUnitId, select, COLOR_GREEN, selectedOption ); +function saveBoolean( dataElementId, optionComboId, selectedOption ) +{ + var select = selectedOption.options[selectedOption.selectedIndex].value + var organisationUnitId = getFieldValue( 'organisationUnitId' ); + + selectedOption.style.backgroundColor = COLOR_YELLOW; + + var valueSaver = new ValueSaver( dataElementId, optionComboId, organisationUnitId, select, COLOR_GREEN, + selectedOption ); valueSaver.save(); } function saveDate( dataElementId, dataElementName ) { - var field = document.getElementById( 'value[' + dataElementId + '].date' ); + var field = document.getElementById( 'value[' + dataElementId + '].date' ); var type = document.getElementById( 'value[' + dataElementId + '].valueType' ).innerHTML; - var organisationUnitId = getFieldValue( 'organisationUnitId' ); - + var organisationUnitId = getFieldValue( 'organisationUnitId' ); + field.style.backgroundColor = COLOR_YELLOW; - + var valueSaver = new ValueSaver( dataElementId, '', organisationUnitId, field.value, COLOR_GREEN, '' ); valueSaver.save(); } function saveComment( dataElementId, optionComboId, commentValue ) { - var field = document.getElementById( 'value[' + dataElementId + ':' + optionComboId + '].comment' ); + var field = document.getElementById( 'value[' + dataElementId + ':' + optionComboId + '].comment' ); var select = document.getElementById( 'value[' + dataElementId + ':' + optionComboId + '].comments' ); - var organisationUnitId = getFieldValue( 'organisationUnitId' ); - + var organisationUnitId = getFieldValue( 'organisationUnitId' ); + field.style.backgroundColor = COLOR_YELLOW; select.style.backgroundColor = COLOR_YELLOW; - + var commentSaver = new CommentSaver( dataElementId, optionComboId, organisationUnitId, commentValue ); commentSaver.save(); } @@ -219,7 +230,7 @@ */ function alertField( field ) { - field.style.backgroundColor = COLOR_YELLOW; + field.style.backgroundColor = COLOR_YELLOW; field.select(); field.focus(); return false; @@ -237,56 +248,58 @@ var resultColor = resultColor_; var selectedOption = selectedOption_; var organisationUnitId = organisationUnitId_; - + this.save = function() { - var url = 'saveValue.action?organisationUnitId=' + organisationUnitId + '&dataElementId=' + - dataElementId + '&optionComboId=' + optionComboId + '&value=' + value; - - $.ajax( { url: url, dataType: 'json', success: handleResponse, error: handleError } ); + var url = 'saveValue.action?organisationUnitId=' + organisationUnitId + '&dataElementId=' + dataElementId + + '&optionComboId=' + optionComboId + '&value=' + value; + + $.ajax( { + url : url, + dataType : 'json', + success : handleResponse, + error : handleError + } ); }; - + function handleResponse( json ) { var code = json.code; - + if ( code == 0 ) { markValue( resultColor ); - } - else + } else { markValue( COLOR_RED ); window.alert( i18n_saving_value_failed_status_code + '\n\n' + code ); } } - + function handleError( jqXHR, textStatus, errorThrown ) { markValue( COLOR_RED ); window.alert( i18n_saving_value_failed_status_code + '\n\n' + textStatus ); - } - + } + function markValue( color ) { var type = document.getElementById( 'value[' + dataElementId + '].type' ).innerText; var element; - + if ( type == 'bool' ) { element = document.getElementById( 'value[' + dataElementId + '].boolean' ); - } - else if ( type == 'date' ) - { - element = document.getElementById( 'value[' + dataElementId + '].date' ); - } - else if ( selectedOption ) - { - element = selectedOption; - } - else - { - element = document.getElementById( 'value[' + dataElementId + '].value' + ':' + 'value[' + optionComboId + '].value'); + } else if ( type == 'date' ) + { + element = document.getElementById( 'value[' + dataElementId + '].date' ); + } else if ( selectedOption ) + { + element = selectedOption; + } else + { + element = document.getElementById( 'value[' + dataElementId + '].value' + ':' + 'value[' + optionComboId + + '].value' ); } element.style.backgroundColor = color;