Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Refined Server Sync

The app no longer tried to sync changes to the server unless something was actually changed in the array.  This helps for initial setup of the checked tasks from the server.  It doesn't need to save them because they just came from the server.
  • Loading branch information...
commit 8d420a442a6774c50bad5cd971f3ccb32c848b51 1 parent e4f37c2
@kcalmes kcalmes authored
Showing with 18 additions and 12 deletions.
  1. +18 −12 public/myguide_asset/js/application.js
View
30 public/myguide_asset/js/application.js
@@ -189,23 +189,29 @@ function updateUserData(task_id, add){
task_id = parseInt(task_id);
index_of_task_id = user_data.tasks.indexOf(task_id);
+ is_change_to_sync = false;
+
if(add){
if(index_of_task_id < 0){
user_data.tasks.push(task_id);
+ is_change_to_sync = true;
}
} else {
user_data.tasks.splice(index_of_task_id,1);
+ is_change_to_sync = false;
+ }
+ if(is_change_to_sync){
+ $.ajax({
+ url: '/users/' + user_data.user_id + '/tasks.json',
+ data: user_data,
+ dataType: 'json',
+ success: function(){
+
+ },
+ error: function(){
+ alert("Could not sync changes with the server, check your internet connection and try again.");
+ //TO FIX: the user doesnt know how to 'try again'
+ }
+ });
}
- $.ajax({
- url: '/users/' + user_data.user_id + '/tasks.json',
- data: user_data,
- dataType: 'json',
- success: function(){
-
- },
- error: function(){
- alert("Could not sync changes with the server, check your internet connection and try again.");
- //TO FIX: the user doesnt know how to 'try again'
- }
- });
}
Please sign in to comment.
Something went wrong with that request. Please try again.