Johnny6773854
Posts: 0
Joined: Mon Mar 31, 2014 7:11 am

Internet connection

Hi

I have a problem. I need to save my data (10 fields and 1 image) local when the internet connection is lost. The sync it when the internet is back.

We are not always in a "Internet zone". So all the data that is entered must be save local till the internet is available.

Can I store it in local storage? But then it must be like a array? can that work for my 10 fields and 1 image :)

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Internet connection

Hi Johnny,

Yes, you can do this. I'd recommend you this tutorial for work in offline mode:
http://docs.appery.io/tutorials/build...

Johnny6773854
Posts: 0
Joined: Mon Mar 31, 2014 7:11 am

Internet connection

Thank you! :)

Johnny6773854
Posts: 0
Joined: Mon Mar 31, 2014 7:11 am

Internet connection

Hi there

I replied also via email but do not know if you get it.

Let me explain what I want from the beginning.

I want to store 10 + fields in local storage when connection is down then sync when connection is back up!

Now i do not want to list the data nor delete the data. it must sync to database where i must keep record of every field.

I worked from that example you gave me!

Here is my code when offline. I know the code is wrong and hope you can help me!

// On offline
function onOffline() {
localStorage.setItem('_isOnline', 0);
$('[dsid="lblstatus"]').text('Offline');

Code: Select all

 var components = []; 
 components.push(Appery("txt_e_naamvan").text()); 
 components.push(Appery("txt_e_epos").text()); 
 components.push(Appery("txt_e_selfoon").text()); 
 components.push(Appery("txt_e_datum").text()); 
 components.push(Appery("txt_e_tyd").text()); 
 components.push(Appery("txtbank").text()); 
 components.push(Appery("txttakkode").text()); 
 components.push(Appery("txtrekeninghour").text()); 
 components.push(Appery("txtreknommer").text()); 
 components.push(Appery("txtrektipe").text()); 
 components.push(Appery("txtbedrag").text()); 

 var str = JSON.stringify(components); 

 localStorage.setItem("_naamvan", JSON.stringify(str)); 
 localStorage.setItem("_epos", JSON.stringify(str)); 
 localStorage.setItem("_selfoon", JSON.stringify(str)); 
 localStorage.setItem("_datum", JSON.stringify(str)); 
 localStorage.setItem("_tyd", JSON.stringify(str)); 
 localStorage.setItem("_banknaam", JSON.stringify(str)); 
 localStorage.setItem("_taknaam", JSON.stringify(str)); 
 localStorage.setItem("_rekeninghouer", JSON.stringify(str)); 
 localStorage.setItem("_rekeningnommer", JSON.stringify(str)); 
 localStorage.setItem("_rekeningtipe", JSON.stringify(str)); 
 localStorage.setItem("_bedrag", JSON.stringify(str)); 

}

Then when this part is finished I need to sort out this part:
(I am totally lost on this one!)

// Constructor of task
function TaskToSynchronize(name, id) {
this.id = id;
this.name = name;
}

// Array of tasks to be deleted when online
var tasksToDelete = [];
// Array of tasks to be creaded when online
var tasksToCreate = [];

Johnny6773854
Posts: 0
Joined: Mon Mar 31, 2014 7:11 am

Internet connection

Any update on this?

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Internet connection

Hello!

Sorry, not yet. Working on it.

Johnny6773854
Posts: 0
Joined: Mon Mar 31, 2014 7:11 am

Internet connection

Thank you for the help!

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Internet connection

Hi Johnny,

In this tutorial arrays to store 'task' are created as it is meant there will be some (arbitrary number). If you intend to store the values ​​of only 10 variables, you can dispense without the designer and without the array. You will need to write values ​​to localStorage:
prelocalStorage.setItem("_naamvan", Appery("txt_e_naamvan").text());/prefor all 10 values​​.

Then when you are connected to the Internet, call service 'Create' where these local variables will be mapped to Database fields.

Johnny6773854
Posts: 0
Joined: Mon Mar 31, 2014 7:11 am

Internet connection

thank you I will try this and let you know.

Johnny6773854
Posts: 0
Joined: Mon Mar 31, 2014 7:11 am

Internet connection

What if I want to store more than 1 value in the localstorage. because when i am offline i must be able to store more than 1 value.

Return to “Issues”