dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #22029
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10553: upload of offline execution dates
------------------------------------------------------------
revno: 10553
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2013-04-15 19:48:18 +0700
message:
upload of offline execution dates
modified:
dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/anonymousRegistration.vm
dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/anonymousRegistration.js
dhis-2/dhis-web/dhis-web-commons/src/main/resources/i18n_global.properties
dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/org/hisp/dhis/de/i18n_module.properties
--
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-caseentry/src/main/webapp/dhis-web-caseentry/anonymousRegistration.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/anonymousRegistration.vm 2013-04-15 07:57:01 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/anonymousRegistration.vm 2013-04-15 12:48:18 +0000
@@ -217,6 +217,12 @@
var i18n_insert_a_report_date = '$encoder.jsEscape( $i18n.getString( "insert_a_report_date" ) , "'")';
var i18n_comment_added = '$encoder.jsEscape( $i18n.getString( "comment_added" ) , "'")';
+ var i18n_need_to_sync_notification = '$encoder.jsEscape( $i18n.getString( "need_to_sync_notification" ) , "'")';
+ var i18n_sync_now = '$encoder.jsEscape( $i18n.getString( "sync_now" ) , "'")';
+ var i18n_sync_success = '$encoder.jsEscape( $i18n.getString( "sync_success" ) , "'")';
+ var i18n_sync_failed = '$encoder.jsEscape( $i18n.getString( "sync_failed" ) , "'")';
+ var i18n_uploading_data_notification = '$encoder.jsEscape( $i18n.getString( "uploading_data_notification" ) , "'")';
+
isAjax = true;
contentDiv = '';
var unSave = false;
@@ -232,4 +238,4 @@
var startDateSince = jQuery.datepicker.formatDate( dateFormat, new Date(y, m, d-7) ) ;
setFieldValue('startDate', startDateSince);
-</script>
\ No newline at end of file
+</script>
=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/anonymousRegistration.js'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/anonymousRegistration.js 2013-04-15 07:57:01 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/anonymousRegistration.js 2013-04-15 12:48:18 +0000
@@ -73,10 +73,69 @@
$( "#offlineListDiv table" ).addClass( 'hidden' );
}
- $( document ).trigger('dhis2.anonymous.showOfflineEvents');
+ $( document ).trigger('dhis2.anonymous.checkOfflineEvents');
});
}
+var haveLocalData = false;
+
+function checkOfflineData() {
+ DAO.executionDates.fetchAll( function ( store, arr ) {
+ if ( arr.length > 0 ) {
+ haveLocalData = true;
+ }
+
+ $( document ).trigger('dhis2.anonymous.checkOfflineData');
+ } );
+}
+
+function uploadExecutionDate( key, programId, executionDate, organisationUnitId ) {
+ return ajaxExecutionDate(programId, "0", executionDate, organisationUnitId ).done(function(json) {
+ if ( json.response == 'success' ) {
+ // console.log( key + " turned into " + json.message );
+
+ DAO.executionDates.remove(key, function(store) {
+ showOfflineEvents();
+ });
+ }
+ } );
+}
+
+function uploadLocalData() {
+ setHeaderWaitMessage( i18n_uploading_data_notification );
+
+ DAO.executionDates.fetchAll( function ( store, arr ) {
+ if(arr.length == 0) {
+ setHeaderDelayMessage( i18n_sync_success );
+ return;
+ }
+
+ var deferred = $.Deferred();
+ var promise = deferred.promise();
+
+ $.each(arr, function(idx, item) {
+ promise = promise.pipe(function () {
+ uploadExecutionDate(item.key, item.programId, item.executionDate, item.organisationUnitId);
+ });
+ });
+
+ deferred.done(function() {
+ setHeaderDelayMessage( i18n_sync_success );
+ });
+
+ deferred.resolve();
+ } );
+}
+
+function sync_failed_button() {
+ var message = i18n_sync_failed
+ + ' <button id="sync_button" type="button">' + i18n_sync_now + '</button>';
+
+ setHeaderMessage( message );
+
+ $( '#sync_button' ).bind( 'click', uploadLocalData );
+}
+
$( document ).ready( function () {
$.ajaxSetup( {
type: 'POST',
@@ -86,6 +145,10 @@
$( "#orgUnitTree" ).one( "ouwtLoaded", function () {
$( document ).one('dhis2.anonymous.programStagesInitialized', initializePrograms);
$( document ).one('dhis2.anonymous.programsInitialized', showOfflineEvents);
+ $( document ).one( 'dhis2.anonymous.checkOfflineEvents', checkOfflineData );
+ $( document ).one( 'dhis2.anonymous.checkOfflineData', function() {
+ dhis2.availability.startAvailabilityCheck();
+ } );
initalizeProgramStages();
initializeExecutionDates();
@@ -94,7 +157,17 @@
$( document ).bind( 'dhis2.online', function ( event, loggedIn ) {
if ( loggedIn ) {
- setHeaderDelayMessage( i18n_online_notification );
+ if ( haveLocalData ) {
+ var message = i18n_need_to_sync_notification
+ + ' <button id="sync_button" type="button">' + i18n_sync_now + '</button>';
+
+ setHeaderMessage( message );
+
+ $( '#sync_button' ).bind( 'click', uploadLocalData );
+ } else {
+ setHeaderDelayMessage( i18n_online_notification );
+ }
+
enableFiltering();
searchEvents( eval( getFieldValue( 'listAll' ) ) );
$('#commentInput').removeAttr('disabled');
@@ -120,8 +193,6 @@
$('#commentInput').attr('disabled', true);
disableFiltering();
} );
-
- dhis2.availability.startAvailabilityCheck();
} );
function disableFiltering() {
@@ -755,16 +826,20 @@
searchEvents( eval( getFieldValue( "listAll" ) ) );
}
+function ajaxExecutionDate( programId, programStageInstanceId, executionDate, organisationUnitId ) {
+ return $.ajax( {
+ url: 'saveExecutionDate.action',
+ data: createExecutionDate( programId, programStageInstanceId, executionDate, organisationUnitId ),
+ type: 'POST',
+ dataType: 'json'
+ } );
+}
+
// execution date module
var service = (function () {
return {
saveExecutionDate: function( programId, programStageInstanceId, executionDate, organisationUnitId ) {
- $.ajax( {
- url: 'saveExecutionDate.action',
- data: createExecutionDate(programId, programStageInstanceId, executionDate, organisationUnitId),
- type: 'POST',
- dataType: 'json'
- } ).done(function ( json ) {
+ ajaxExecutionDate(programId, programStageInstanceId, executionDate, organisationUnitId).done(function ( json ) {
if ( json.response == 'success' ) {
jQuery( "#executionDate" ).css( 'background-color', SUCCESS_COLOR );
setFieldValue( 'programStageInstanceId', json.message );
=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/resources/i18n_global.properties'
--- dhis-2/dhis-web/dhis-web-commons/src/main/resources/i18n_global.properties 2013-04-08 05:53:22 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/resources/i18n_global.properties 2013-04-15 12:48:18 +0000
@@ -110,6 +110,8 @@
online_notification=You are online
offline_notification=You are offline, data will be stored locally
need_to_sync_notification=There is data stored locally, please upload to server
+uploading_data_notification=Uploading locally stored data to the server
+ajax_login_failed=Login failed, check your username and password and try again
sync_now=Upload
sync_success=Upload to server was successful
sync_failed=Upload to server failed, please try again later
=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/org/hisp/dhis/de/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/org/hisp/dhis/de/i18n_module.properties 2013-04-15 08:20:20 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/org/hisp/dhis/de/i18n_module.properties 2013-04-15 12:48:18 +0000
@@ -79,8 +79,6 @@
save=Save
save_comment=Save comment
operation_not_available_offline=This operation is not available in off-line mode
-uploading_data_notification=Uploading locally stored data to the server
-ajax_login_failed=Login failed, check your username and password and try again
mark_value_for_followup=Mark value for follow-up
unmark_value_for_followup=Un-mark value for follow-up
completed_by=Completed by