You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@shindig.apache.org by Henk de Vries <he...@hinttech.com> on 2014/06/30 17:43:06 UTC

How to store gadget preferences in a database

Dear all,

we are creating a Proof of Concept Gadget for our customer.
We want to be able to store and retrieve user preferences for this gadget,
actually the same as was discusses in the thread "Data Persistence of
Google Gadgets (e.g. TODO List)". However I found no clear answer in that
thread.

So let me try to explain what is the issue here. The gadget we created has
a UserPref defined and requires the feature setprefs, here is a snippet:

<Module>
    <ModulePrefs title="hello world example">
        <Require feature="setprefs"/>
    </ModulePrefs>
    <UserPref name="picture_format" display_name="Picture Format"
              datatype="hidden" required="true" default_value="CIRCLE"/>

We create a prefs instance and we try to set the pref.

       <script type="text/javascript">

           var prefs = new gadgets.Prefs(1000);
           var pictureFormat = prefs.getString("picture_format");

           var div = document.getElementById("pfDisplay");
           div.innerHTML=pictureFormat;

           $("input[name='radio']").click(function(){
                var value=$('input[name=radio]:checked').val();

                console.log(value);
                div.innerHTML=value;

                prefs.set("picture_format", value);

           });
        </script>

1. First of when we change the value of the radio button control  the
prefs.set call ends with an error that is not clear to me:

No relay set (used as window.postMessage targetOrigin), cannot send
cross-domain message

Googling around tells me that I should set an identifier somewhere, but I
do not have a clue what identifier that would be. This is because I call
the gadget as follows:

http://localhost:8080/gadgets/ifr?url=http://localhost:8080/gadget.xml&debug=1&up_picture_format=SQUARE

(I found this link that is giving me the impression I am missing some
things on the gadget :
http://comments.gmane.org/gmane.comp.web.shindig.devel/2488)

2. Second, if this is the good call (prefs.set(x,y)), how should we make
sure the picture format parameter ends up in our database? and how do we
connect it to the same user? With this I mean, that while at the moment I
have no authenticated user, I will have somewhere in my session a UUID of
the user with which I want to store his/her prefs.

Any help will be very much appreciated.

kind regards,

Henk de Vries
Consultant
Hinttech

Re: How to store gadget preferences in a database

Posted by Ryan Baxter <rb...@apache.org>.
On Mon, Jun 30, 2014 at 11:43 AM, Henk de Vries
<he...@hinttech.com> wrote:
> Dear all,
>
> we are creating a Proof of Concept Gadget for our customer.
> We want to be able to store and retrieve user preferences for this gadget,
> actually the same as was discusses in the thread "Data Persistence of
> Google Gadgets (e.g. TODO List)". However I found no clear answer in that
> thread.
>
> So let me try to explain what is the issue here. The gadget we created has
> a UserPref defined and requires the feature setprefs, here is a snippet:
>
> <Module>
>     <ModulePrefs title="hello world example">
>         <Require feature="setprefs"/>
>     </ModulePrefs>
>     <UserPref name="picture_format" display_name="Picture Format"
>               datatype="hidden" required="true" default_value="CIRCLE"/>
>
> We create a prefs instance and we try to set the pref.
>
>        <script type="text/javascript">
>
>            var prefs = new gadgets.Prefs(1000);
>            var pictureFormat = prefs.getString("picture_format");
>
>            var div = document.getElementById("pfDisplay");
>            div.innerHTML=pictureFormat;
>
>            $("input[name='radio']").click(function(){
>                 var value=$('input[name=radio]:checked').val();
>
>                 console.log(value);
>                 div.innerHTML=value;
>
>                 prefs.set("picture_format", value);
>
>            });
>         </script>
>
> 1. First of when we change the value of the radio button control  the
> prefs.set call ends with an error that is not clear to me:
>
> No relay set (used as window.postMessage targetOrigin), cannot send
> cross-domain message
>
> Googling around tells me that I should set an identifier somewhere, but I
> do not have a clue what identifier that would be. This is because I call
> the gadget as follows:
>
> http://localhost:8080/gadgets/ifr?url=http://localhost:8080/gadget.xml&debug=1&up_picture_format=SQUARE
>
> (I found this link that is giving me the impression I am missing some
> things on the gadget :
> http://comments.gmane.org/gmane.comp.web.shindig.devel/2488)
Sounds like you are running into some cross-domain browser
restriction.  When prefs.set is called it is making and RPC request
from the gadget iframe to the container page which is rendering the
gadget.  Typically the RPC layer would use window.postMessage to send
the request from the iframe to the container if you are using a modern
browser.  What browser are you using and which container are you
using?  What domains are they rendered on?

>
> 2. Second, if this is the good call (prefs.set(x,y)), how should we make
> sure the picture format parameter ends up in our database? and how do we
> connect it to the same user? With this I mean, that while at the moment I
> have no authenticated user, I will have somewhere in my session a UUID of
> the user with which I want to store his/her prefs.
Are you using the common container?  If so the information in this
thread [1] might be useful to you.  If not I suggest you look into
transitioning over to the common container, unless you are using an
earlier version of Shindig.

[1] http://markmail.org/message/4xg6tqscatokhlx7

>
> Any help will be very much appreciated.
>
> kind regards,
>
> Henk de Vries
> Consultant
> Hinttech