=== 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-08-15 10:35:59 +0000 +++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/entry.js 2011-08-15 12:44:50 +0000 @@ -204,6 +204,31 @@ return false; } +$(document).ready(function() { + $("#orgUnitTree").one("ouwtLoaded", function() { + saveDataValuesInLocalStorage(); + }); +}) + +function saveDataValuesInLocalStorage() { + var dataValues = storageManager.getAllDataValues(); + + for(var dataValueKey in dataValues) { + var dataValue = dataValues[dataValueKey]; + console.log(dataValue); + + $.ajax( { + url : "saveValue.action", + data : dataValue, + dataType : 'json', + success : function( json ) { + storageManager.clearDataValueJSON( dataValue ); + console.log("Successfully saved dataValue with value " + dataValue.value); + } + } ); + } +} + // ----------------------------------------------------------------------------- // Saver objects // ----------------------------------------------------------------------------- @@ -222,13 +247,16 @@ this.save = function() { - storageManager.saveDataValueJSON( dataValue ); + storageManager.saveDataValue( dataValue ); $.ajax( { url : "saveValue.action", data : dataValue, dataType : 'json', - success : handleResponse, + success : function( json ) { + storageManager.clearDataValueJSON( dataValue ); + handleResponse( json ); + }, error : handleError } ); }; === 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-15 10:48:36 +0000 +++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js 2011-08-15 12:44:50 +0000 @@ -1005,25 +1005,11 @@ /** * Saves a data value. * - * @param dataValue The datavalue and identifiers in json format. - */ - this.saveDataValueJSON = function( dataValue ) - { - this.saveDataValue( dataValue.dataElementId, dataValue.optionComboId, dataValue.periodId, dataValue.organisationUnitId, dataValue.value ); - } - - /** - * Saves a data value. - * - * @param dataElementId the data element identifier. - * @param categoryOptionComboId the category option combo identifier. - * @param periodId the period identifier. - * @param organisationUnitId the organisation unit identifier. - * @param value the value. - */ - this.saveDataValue = function( dataElementId, categoryOptionComboId, periodId, organisationUnitId, value ) - { - var id = this.getDataValueIdentifier( dataElementId, categoryOptionComboId, periodId, organisationUnitId ); + * @param dataValue The datavalue and identifiers in json format. + */ + this.saveDataValue = function( dataValue ) + { + var id = this.getDataValueIdentifier( dataValue.dataElementId, dataValue.optionComboId, dataValue.periodId, dataValue.organisationUnitId ); var dataValues = {}; @@ -1032,7 +1018,7 @@ dataValues = JSON.parse( localStorage[KEY_DATAVALUES] ); } - dataValues[id] = value; + dataValues[id] = dataValue; try { @@ -1059,16 +1045,45 @@ this.getDataValue = function( dataElementId, categoryOptionComboId, periodId, organisationUnitId ) { var id = this.getDataValueIdentifier( dataElementId, categoryOptionComboId, periodId, organisationUnitId ); - + if ( localStorage[KEY_DATAVALUES] != null ) { var dataValues = JSON.parse( localStorage[KEY_DATAVALUES] ); return dataValues[id]; } - + return null; } + + /** + * Removes the wanted dataValue from localStorage. + * + * @param dataValue The datavalue and identifiers in json format. + */ + this.clearDataValueJSON = function( dataValue ) + { + this.clearDataValue( dataValue.dataElementId, dataValue.optionComboId, dataValue.periodId, dataValue.organisationUnitId ); + } + + /** + * Removes the wanted dataValue from localStorage. + * + * @param dataElementId the data element identifier. + * @param categoryOptionComboId the category option combo identifier. + * @param periodId the period identifier. + * @param organisationUnitId the organisation unit identifier. + */ + this.clearDataValue = function( dataElementId, categoryOptionComboId, periodId, organisationUnitId ) + { + var id = this.getDataValueIdentifier( dataElementId, categoryOptionComboId, periodId, organisationUnitId ); + var dataValues = this.getAllDataValues(); + + console.log("deleting with id " + id); + + delete dataValues[id]; + localStorage[KEY_DATAVALUES] = JSON.stringify( dataValues ); + } /** * Returns a JSON associative array where the keys are on the form