dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #13494
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4351: moved complete methods into storageManager, and fixed some bugs
------------------------------------------------------------
revno: 4351
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2011-08-18 13:51:03 +0200
message:
moved complete methods into storageManager, and fixed some bugs
modified:
dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== 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-18 10:30:26 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js 2011-08-18 11:51:03 +0000
@@ -66,7 +66,7 @@
$( document ).bind( 'dhis2.online', function( event, loggedIn ) {
if ( loggedIn ) {
- if( haveLocalData()) {
+ if( storageManager.haveLocalData()) {
var message = i18n_need_to_sync_notification + '<button id="sync_button" type="button">' + i18n_sync_now + '</button>';
if(isHeaderMessageVisible())
@@ -126,28 +126,15 @@
} );
}
-function haveLocalData()
-{
- var dataValues = storageManager.getAllDataValues();
- var completeDataSets = getCompleteDataSetsLocalVariable();
-
- if(dataValues != null || completeDataSets != null)
- {
- return true;
- }
-
- return false;
-}
-
function uploadLocalData()
{
- if(!haveLocalData())
+ if(!storageManager.haveLocalData())
{
return;
}
var dataValues = storageManager.getAllDataValues();
- var completeDataSets = getCompleteDataSetsLocalVariable();
+ var completeDataSets = storageManager.getCompleteDataSetsLocalVariable();
setHeaderWaitMessage( i18n_uploading_data_notification );
@@ -746,65 +733,14 @@
// Data completeness
// -----------------------------------------------------------------------------
-var KEY_COMPLETEDATASETS = 'completedatasets';
-
-function getCompleteDataSetId(json)
-{
- return json.periodId + "-" + json.dataSetId + "-" + json.organisationUnitId;
-}
-
-function getCurrentCompleteDataSetParams() {
- var params = {
- 'periodId': $( '#selectedPeriodId' ).val(),
- 'dataSetId': $( '#selectedDataSetId' ).val(),
- 'organisationUnitId': currentOrganisationUnitId
- };
-
- return params;
-}
-
-function getCompleteDataSetsLocalVariable()
-{
- var completeDataSets;
-
- if( localStorage[KEY_COMPLETEDATASETS] == null )
- {
- return null;
- } else {
- completeDataSets = JSON.parse( localStorage[KEY_COMPLETEDATASETS] );
- }
-
- return completeDataSets;
-}
-
-function storeCompleteDataSetLocally(json)
-{
- var completeDataSets = getCompleteDataSetsLocalVariable();
- var completeDataSetId = getCompleteDataSetId(json);
-
- completeDataSets[completeDataSetId] = json;
-
- localStorage[KEY_COMPLETEDATASETS] = JSON.stringify( completeDataSets );
-}
-
-function clearCompleteDataSetLocally(json)
-{
- var completeDataSets = getCompleteDataSetsLocalVariable();
- var completeDataSetId = getCompleteDataSetId(json);
-
- delete completeDataSets[completeDataSetId];
-
- localStorage[KEY_COMPLETEDATASETS] = JSON.stringify( completeDataSets );
-}
-
function validateCompleteDataSet()
{
var confirmed = confirm( i18n_confirm_complete );
if ( confirmed )
{
- var params = getCurrentCompleteDataSetParams();
-
+ var params = storageManager.getCurrentCompleteDataSetParams();
+
disableCompleteButton();
$.getJSON( 'getValidationViolations.action', params).success( function( data ) {
@@ -820,14 +756,14 @@
function registerCompleteDataSet( json )
{
- var params = getCurrentCompleteDataSetParams();
+ var params = storageManager.getCurrentCompleteDataSetParams();
if ( json.response == 'success' )
{
- storeCompleteDataSetLocally(params);
+ storageManager.storeCompleteDataSetLocally(params);
$.getJSON( 'registerCompleteDataSet.action', params).success(function() {
- clearCompleteDataSetLocally(params);
+ storageManager.clearCompleteDataSetLocally(params);
} ).error( function() {
} );
}
@@ -842,17 +778,17 @@
function undoCompleteDataSet()
{
var confirmed = confirm( i18n_confirm_undo );
- var params = getCurrentCompleteDataSetParams();
+ var params = storageManager.getCurrentCompleteDataSetParams();
if ( confirmed )
{
disableUndoButton();
$.getJSON( 'undoCompleteDataSet.action', params).success(function() {
- clearCompleteDataSetLocally(params);
+ storageManager.clearCompleteDataSetLocally(params);
} ).error( function()
{
- clearCompleteDataSetLocally(params);
+ storageManager.clearCompleteDataSetLocally(params);
} );
}
}
@@ -1031,6 +967,7 @@
var KEY_FORM_PREFIX = 'form-';
var KEY_FORM_VERSIONS = 'formversions';
var KEY_DATAVALUES = 'datavalues';
+ var KEY_COMPLETEDATASETS = 'completedatasets';
/**
* Returns the total number of characters currently in the local storage.
@@ -1363,4 +1300,86 @@
{
return dataElementId + "-" + categoryOptionComboId + "-" + periodId + "-" + organisationUnitId;
};
+
+ this.getCompleteDataSetId = function (json)
+ {
+ return json.periodId + "-" + json.dataSetId + "-" + json.organisationUnitId;
+ };
+
+ this.getCurrentCompleteDataSetParams = function () {
+ var params = {
+ 'periodId': $( '#selectedPeriodId' ).val(),
+ 'dataSetId': $( '#selectedDataSetId' ).val(),
+ 'organisationUnitId': currentOrganisationUnitId
+ };
+
+ return params;
+ };
+
+ this.getCompleteDataSetsLocalVariable = function ()
+ {
+ var completeDataSets;
+
+ if( localStorage[KEY_COMPLETEDATASETS] == null )
+ {
+ return null;
+ }
+ else
+ {
+ completeDataSets = JSON.parse( localStorage[KEY_COMPLETEDATASETS] );
+ }
+
+ return completeDataSets;
+ };
+
+ this.storeCompleteDataSetLocally = function (json)
+ {
+ var completeDataSets = this.getCompleteDataSetsLocalVariable();
+ var completeDataSetId = this.getCompleteDataSetId(json);
+
+ if(completeDataSets != null)
+ {
+ completeDataSets[completeDataSetId] = json;
+ }
+ else
+ {
+ completeDataSets = {};
+ completeDataSets[completeDataSetId] = json;
+ }
+
+ localStorage[KEY_COMPLETEDATASETS] = JSON.stringify( completeDataSets );
+ };
+
+ this.clearCompleteDataSetLocally = function (json)
+ {
+ var completeDataSets = this.getCompleteDataSetsLocalVariable();
+ var completeDataSetId = this.getCompleteDataSetId(json);
+
+ if(completeDataSets != null)
+ {
+ delete completeDataSets[completeDataSetId];
+
+ if(completeDataSets.length > 0)
+ {
+ localStorage.remoteItem(KEY_COMPLETEDATASETS);
+ }
+ else
+ {
+ localStorage[KEY_COMPLETEDATASETS] = JSON.stringify( completeDataSets );
+ }
+ }
+ };
+
+ this.haveLocalData = function ()
+ {
+ var dataValues = this.getAllDataValues();
+ var completeDataSets = this.getCompleteDataSetsLocalVariable();
+
+ if(dataValues != null || completeDataSets != null)
+ {
+ return true;
+ }
+
+ return false;
+ };
}