dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #19558
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 8576: mobile: support local storage of dataValueSets in mobile
------------------------------------------------------------
revno: 8576
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2012-10-18 12:45:26 +0200
message:
mobile: support local storage of dataValueSets in mobile
modified:
dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/data-entry.vm
dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/index.vm
dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/dhis-web-mobile-resources/js/dhis2.storage.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-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/data-entry.vm'
--- dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/data-entry.vm 2012-10-18 08:27:37 +0000
+++ dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/data-entry.vm 2012-10-18 10:45:26 +0000
@@ -129,12 +129,9 @@
return;
}
- console.log(Selected);
-
$.mobile.showPageLoadingMsg();
function renderFormTemplate(form) {
-
var tmpl = jQuery('#data-entry-template').html();
jQuery('#data-entry-page section[data-role="content"]').html(
@@ -154,13 +151,11 @@
},
dataType: 'json'
}).success(function(form) {
- console.log("rendering fresh form");
- console.log(form);
renderFormTemplate(form);
- $.mobile.hidePageLoadingMsg();
}).error(function() {
var form = fm.form(Selected.dataSet);
renderFormTemplate(form);
+ }).complete(function() {
$.mobile.hidePageLoadingMsg();
});
}
@@ -192,19 +187,10 @@
dataValueSet.dataValues = dataValues;
+ fm.saveDataValueSet( dataValueSet );
+ $.mobile.hidePageLoadingMsg();
+
console.log(dataValueSet);
-
- $.ajax({
- url: '../api/dataValueSets',
- type: 'POST',
- contentType: 'application/json',
- data: JSON.stringify(dataValueSet)
- }).success(function() {
- $.mobile.hidePageLoadingMsg();
- }).error(function() {
- console.log("error when saving datavalues")
- $.mobile.hidePageLoadingMsg();
- });
}
jQuery(document).bind('pagechange', function (event, data) {
=== modified file 'dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/index.vm'
--- dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/index.vm 2012-10-18 08:27:37 +0000
+++ dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/index.vm 2012-10-18 10:45:26 +0000
@@ -1,19 +1,24 @@
<script>
$(document).bind('pagebeforecreate',function(){
+ $.mobile.showPageLoadingMsg();
+
$.ajax({
url: '../api/currentUser/dashboard',
dataType: 'json',
- async: false
}).success(function(data) {
if( data.unreadMessageConversation > 0 ) {
$('#messages a').append("<span class='ui-li-count'>" + data.unreadMessageConversation + "</span>");
}
+
+ fm.initialize();
+ fm.uploadDataValueSets();
}).error(function() {
$('#messages a').append("<span class='ui-li-count'>Offline</span>")
+ }).complete(function() {
+ $('section[data-role="content"] ul').listview('refresh');
+ $.mobile.hidePageLoadingMsg();
});
-
- fm.initialize();
});
</script>
=== modified file 'dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/dhis-web-mobile-resources/js/dhis2.storage.js'
--- dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/dhis-web-mobile-resources/js/dhis2.storage.js 2012-10-15 12:37:39 +0000
+++ dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/dhis-web-mobile-resources/js/dhis2.storage.js 2012-10-18 10:45:26 +0000
@@ -77,6 +77,59 @@
return this.forms()[id]
};
+dhis2.storage.FormManager.prototype.dataValueSets = function() {
+ var dataValueSets = localStorage['dataValueSets'];
+
+ if(dataValueSets !== undefined )
+ {
+ dataValueSets = JSON.parse( dataValueSets );
+ } else {
+ dataValueSets = [];
+ }
+
+ return dataValueSets;
+};
+
+dhis2.storage.FormManager.prototype.saveDataValueSet = function( dataValueSet ) {
+ var dataValueSets = this.dataValueSets();
+
+ $.ajax({
+ url: '../api/dataValueSets2',
+ type: 'POST',
+ contentType: 'application/json',
+ data: JSON.stringify(dataValueSet),
+ async: false
+ }).success(function() {
+ // nop, successfully uploaded
+ }).error(function() {
+ // add to local dataValueSets
+ dataValueSets.push(dataValueSet);
+ localStorage['dataValueSets'] = JSON.stringify(dataValueSets);
+ });
+};
+
+dhis2.storage.FormManager.prototype.uploadDataValueSets = function() {
+ var dataValueSets = this.dataValueSets();
+
+ _.each(dataValueSets, function( dataValueSet, idx ) {
+ $.ajax({
+ url: '../api/dataValueSets',
+ type: 'POST',
+ contentType: 'application/json',
+ data: JSON.stringify(dataValueSet),
+ async: false
+ }).success(function() {
+ delete dataValueSets[idx];
+ }).error(function() {
+ });
+ });
+
+ // filter out undefined dataValues (successfully uploaded);
+ dataValueSets = _.filter(dataValueSets, function(dv) { return dv !== undefined; });
+
+ localStorage['dataValueSets'] = JSON.stringify( dataValueSets );
+};
+
// global storage manager instance
(function () {
window.fm = new dhis2.storage.FormManager();