Page 1 of 1

favourite

Posted: Thu Apr 17, 2014 11:24 am
by laura6372139

I'm following these two links:

https://getsatisfaction.com/apperyio/...

https://getsatisfaction.com/apperyio/...

I want to save favorites in localStorage so that only the device.

First I put in local set storage variable "myFavorist"

Image

And then I create a Generic service:

Appery.prueba = Appery.createClass(null, {

Code: Select all

 init: function(requestOptions) { 
     this.__requestOptions = $.extend({}, requestOptions); 
 }, 
 process: function(settings) { 
     if (this.__requestOptions.echo) { 
         settings.success(this.__requestOptions.echo); 
     } else { 
         var myFavorits; 
         try { 
           myFavorits = JSON.parse(localStorage.getItem("myFavorits")); 
           if ({}.toString.call(myFavorits) !== "[object Array]") { 
             myFavorits = []; 
           } 
         } catch ( e ) { 
           myFavorits = []; 
         } 
         settings.success(myFavorits); 
     } 
     settings.complete('success'); 
 } 

});

Image

And then load ivoke service.

But I get:

Image

This is my public link:

http://appery.io/app/mobile-frame?src...


favourite

Posted: Thu Apr 17, 2014 12:08 pm
by Kateryna Grynko

Hi Laura,

How do you call the service? Where can we run it? Is the array 'myFavorits' empty?


favourite

Posted: Thu Apr 17, 2014 4:14 pm
by laura6372139

The name service is "Generic Service".

Javascript is "favoritos"

And maybe that myFavorits array is empty.

I have a label "idfavoritos" connect with database:

Image

Image

And then save the label in localstorage "myFavorits"
Image

And then I create generic service.


favourite

Posted: Fri Apr 18, 2014 12:27 am
by Illya Stepanov

Hi Laura,

There is some mistakes in your app which you have to fix:
ol
liYour service called "GenericService" but in implementation you use "Appery.favoritos". You need to use "Appery.GenericService" instead./li

liIf you set local storage variable (LSV) this way: https://d2r1vs3d9006ap.cloudfront.net... in LSV will be stored just a value not a JSON.
/li/ol
So this code is not good:
precode

Code: Select all

 myFavorits = JSON.parse(localStorage.getItem("myFavorits")); 
 if ({}.toString.call(myFavorits) !== "[object Array]") { 
     myFavorits = []; 
 }/code/pre 

Please describe what this code should do.

Also please share your project with us, and describe steps to reproduce the problem.

Regards.


favourite

Posted: Tue Apr 22, 2014 9:09 am
by laura6372139

Hi Illya:

I change the fist step.

Now is:

Appery.GenericService

Image

LSV, I need that only read a value.

I change my code of GenericService but

Appery.GenericService = Appery.createClass(null, {

Code: Select all

 init: function(requestOptions) { 
     this.__requestOptions = $.extend({}, requestOptions); 
 }, 

 process: function(settings) { 
     if (this.__requestOptions.echo) { 
         settings.success(this.__requestOptions.echo); 
     } else { 

         var cdata = localStorage.getItem("myFavorits"); 

         settings.success((cdata));             
     } 
     settings.complete('success'); 
 } 

});

Image


favourite

Posted: Tue Apr 22, 2014 9:10 am
by laura6372139

My app is share whit us.

The name is "City Up"


favourite

Posted: Tue Apr 22, 2014 9:13 am
by laura6372139

I need that when the users click on the picture on the page "Tienda" is added to the page "misfavoritos"


favourite

Posted: Wed Apr 23, 2014 12:27 am
by Igor

Let's make you goals clear:

You have some list with image and "idfavoritos" label(with id of it item) inside each item.

You want when use click on image add this item to "myFavorits" localStorage variable(LSV).

Please try to follow below steps:

1 Open "mobilimage_43" click event handler. And change "myFavorits" to "myCurrentFavorite". http://prntscr.com/3ci1z8/direct

2 Add one another click event handler with action "Run Javascript" and fill it with following code: http://prntscr.com/3ci7y6/direct

pre

//Get current favorite(that's user clicked on).
var myCurrentFavorite = localStorage.getItem("myCurrentFavorite");

//Get stored favorites.
var myFavorits = localStorage.getItem("myFavorits");

//If myFavorits not exist - use simple array.
if(!myFavorits)
myFavorits = "[]";

//Parse it into the array
myFavorits = JSON.parse(myFavorits);

//Put myCurrentFavorite in the array.
myFavorits.push({id: myCurrentFavorite});

//Store modified array back to LSV.
localStorage.setItem("myFavorits", JSON.stringify(myFavorits));

//Check browser console to see what exactly is stored.
console.log(myFavorits);
/pre
3 Place your click event handler form step 2 into second position: http://prntscr.com/3ci8h7/direct

When user click on the image - id of this item will be added as new item into "myFavorits" LSV.

After that you can use this value like you need on other pages. To get current value in myFavorits LSV open console and use below code:
pre
console.log(localStorage.getItem("myFavorits"))
/pre


favourite

Posted: Tue May 06, 2014 9:42 am
by laura6372139

Hi Igor:

Thanks for your help!

I follow your steps:

Image

And then in my generic service:

Appery.GenericService = Appery.createClass(null, {

Code: Select all

 init: function(requestOptions) { 
     this.__requestOptions = $.extend({}, requestOptions); 
 }, 

 process: function(settings) { 
     if (this.__requestOptions.echo) { 
         settings.success(this.__requestOptions.echo); 
     } else { 

         var cdata = console.log(localStorage.getItem("myFavorits")); 

         settings.success((cdata));             
     } 
     settings.complete('success'); 
 } 

});

But I get:

Image


favourite

Posted: Wed May 07, 2014 9:13 am
by Evgene Karachevtsev

Hello Laura,

In file favoritos.js change "Appery.GenericService" to "Appery.favoritos"