Permalink
Browse files

Sachin: Fixed sync issues. Now all things are synced except images

  • Loading branch information...
1 parent 0f445df commit a4cf6d710daa297c71b70fe9d017013b86772396 Sachin Dharmapurikar committed Apr 15, 2011
@@ -103,4 +103,16 @@ function Common(){
}
return devtrac.user.name;
}
+
+ this.findPlaceType = function(site){
+ if (site.offline) {
+ for (var index in devtrac.places) {
+ var place = devtrac.places[index];
+ if (site.type == place.name) {
+ return place.id;
+ }
+ }
+ }
+ return site.placeTaxonomy[0].id;
+ }
}
@@ -51,7 +51,8 @@ DataPush.prototype.uploadData = function(progressCallback, callback, errorCallba
navigator.log.debug('Received response from service: ' + JSON.stringify(response));
// TODO: Remove before pushing out.
alert("Received response from service: " + JSON.stringify(response));
- callback('Data uploaded successfully.');
+ callback('Data uploaded successfully. Trip will be re-downloaded.');
+ devtrac.dataPush.clearAndResync();
}, function(srvErr){
navigator.log.log('Error in sync service call.');
navigator.log.log(srvErr);
@@ -65,6 +66,14 @@ DataPush.prototype.uploadData = function(progressCallback, callback, errorCallba
});
}
+DataPush.prototype.clearAndResync = function(){
+ devtrac.dataStore.removeFieldTrip(function(){
+ devtrac.fieldTrip = new FieldTrip();
+ devtrac.currentSite = "";
+ devtrac.dataPull.tripDetails(fieldTripController.showTripReports);
+ });
+}
+
DataPush.prototype.createActionItem = function(tripItemId, callback, errorCallBack){
var params = devtrac.dataPush.createActionItemNode(tripItemId, 0, actionItem);
devtrac.dataPush._callService(params, callback, errorCallBack);
@@ -90,8 +99,8 @@ DataPush.prototype.createActionItemNode = function(tripItemId, placeId, actionIt
var userName = devtrac.user.name;
var timestamp = Math.round(new Date() / 1000);
var actionitemDueDate = devtrac.common.getOneMonthLaterDate();
- var assignedTo = devtrac.common.validateAssignedTo(actionItem.assignedTo);
- var node = {
+ var assignedTo = devtrac.common.validateAssignedTo(actionItem.assignedTo);
+ var node = {
nid: actionItem.id,
uid: userId,
name: userName,
@@ -145,6 +154,7 @@ DataPush.prototype.createUpdatePlaceNode = function(site){
var userId = devtrac.user.uid;
var userName = devtrac.user.name;
var timestamp = Math.round(new Date().getTime() / 1000);
+ var placeTypeId = devtrac.common.findPlaceType(site);
var node = {
nid: placeId,
uid: userId,
@@ -161,7 +171,10 @@ DataPush.prototype.createUpdatePlaceNode = function(site){
}],
field_place_website: [{
url: ''
- }]
+ }],
+ taxonomy: {
+ 1: placeTypeId
+ }
};
if (placeId == 0) {
@@ -24,7 +24,7 @@ DataStore.prototype.init = function(callback){
DataStore.prototype.retrieveFieldTrip = function(callback){
navigator.log.debug("Trying to retreive a field trip for user: " + devtrac.user.name);
- function portOldImages(){
+ function portOldImages(){
$.each(devtrac.fieldTrip.sites, function(index, site){
if (site.photos && site.photos.length) {
var photos = {};
@@ -55,8 +55,22 @@ DataStore.prototype.retrieveFieldTrip = function(callback){
}, devtrac.user.name);
}
+DataStore.prototype.removeFieldTrip = function(callback){
+ navigator.store.remove(function(response){
+ navigator.log.debug("Removed current user field trip from datastore.");
+ if (callback) {
+ callback();
+ }
+ }, function(error){
+ devtrac.common.logAndShowGenericError("Offline storage error: " + error);
+ if (callback) {
+ callback();
+ }
+ }, devtrac.user.name);
+}
+
DataStore.prototype.saveFieldTrip = function(callback){
- navigator.log.debug("Storing field trip: " + devtrac.fieldTrip.title);
+ navigator.log.debug("Storing field trip: " + devtrac.fieldTrip.title);
navigator.store.put(function(){
callback();
}, function(error){

0 comments on commit a4cf6d7

Please sign in to comment.