MySpace Open Platform

A Place For Developers

Welcome Developers!

in

Welcome!

in

Sample widget for requestNavigateTo

Last post 03-15-2008 3:00 AM by jiangtao. 31 replies.
Page 1 of 3 (32 items) 1 2 3 Next >
Sort Posts: Previous Next
  • 02-26-2008 2:01 PM

    Sample widget for requestNavigateTo

    I'm updating this post as the sample below was pretty old, this new sample is from DM and uses the new 0.7 gadgets stuff.  Note that since calling "new opensocial.Surface" was never allowed, it's now broken from the 0.6->0.7 migration, making the original sample even more deprecated.

     

    updated sample 

     

    <select id="ddl_canvas">

                    <option value="home">home</option>

                    <option value="profile">profile.left</option>

                    <option value="profile.right">profile.right</option>

                    <option value="canvas">canvas</option>

    </select>

    <br>

    Value One: <input type="text" id="txtParamOne" />

    <br>

    Value Two: <input type="text" id="txtParamTwo" />

    <br>

    <input type="button" onclick="navigate()" value="Submit" />

     

    <script type="text/javascript" id="MSOS_HOME">

                    function navigate(){

                                    var params = {};               

                                    var isPrimary = false;

                                   

                                    var surfaceName = document.getElementById('ddl_canvas').value;

                                    if (surfaceName === 'canvas')

                                                    isPrimary = true;

                                   

                                    var surfaces = gadgets.views.getSupportedViews();

                                    var surfaceRef = surfaces[surfaceName];

                                   

                                    params['param1'] = document.getElementById('txtParamOne').value;

                                    params['param2'] = document.getElementById('txtParamTwo').value;

                                    gadgets.views.requestNavigateTo(surfaceRef, params);

                                    }

                   

                    function init() {

                                    var params1 = opensocial.getEnvironment().getParams();

                                    if ('undefined'===typeof(params1) || 'undefined' === typeof(params1['param1'])){

                                                    return; 

                                    }

                                    document.getElementById('txtParamOne').value = params1['param1'];

                                    document.getElementById('txtParamTwo').value = params1['param2'];

                    }

                    init();

    </script>

     

     

     

    ----------------- old post below ----------------------- 

    See below for a sample widget that navigates between surfaces and passes arbitrary values around (thanks for the code Donny).  Note that you can't navigate from Home to anywhere at this time but all other permutations should work. Also note that right now any opt_params passed into rNT will end up on the other end under this object:

     

    opensocial.getEnvironment().getParams().appParams 

     

    This is a bug, in the future the objects will be accessed directly under getParams() as per the opensocial spec (and not under appParams).

     

     

    <select id="ddl_canvas">

          <option value="home">home</option>

          <option value="profile">profile.left</option>

          <option value="profile.right">profile.right</option>

          <option value="canvas">canvas</option>

    </select>

    <br>

    Value One: <input type="text" id="txtParamOne" />

    <br>

    Value Two: <input type="text" id="txtParamTwo" />

    <br>

    <input type="button" onclick="navigate()" value="Submit" />

     

    <script type="text/javascript" id="MSOS_HOME">

          function navigate(){

                var params = {}; 

                var isPrimary = false;

               

                var surfaceName = document.getElementById('ddl_canvas').value;

                if (surfaceName === 'canvas')

                      isPrimary = true;

               

               

                var canv = new opensocial.Surface(surfaceName, isPrimary);

               

                params['param1'] = document.getElementById('txtParamOne').value;

                params['param2'] = document.getElementById('txtParamTwo').value;

                opensocial.requestNavigateTo(canv, params);

          }

         

          function init() {

                var params1 = opensocial.getEnvironment().getParams().appParams;

                if ('undefined'===typeof(params1) || 'undefined' === typeof(params1['param1'])){

                      return;    

                }

                document.getElementById('txtParamOne').value = params1['param1'];

                document.getElementById('txtParamTwo').value = params1['param2'];

          }

          init();

    </script>

     

  • 02-26-2008 2:17 PM In reply to

    Re: Sample widget for requestNavigateTo

    Sorry, one more addendum.. according to the opensocial spec you're not supposed to directly call "new opensocial.Surface(x,y);" as it's marked as private.  I think the correct way would be to call this:

    var surfaces = opensocial.getEnvironment().getSupportedSurfaces(); 

    Then, I suppose, rattle through them looking for the one you want (seems pretty clunky to me).

    -----------

    var nav_surface; 

    for(var i = 0; i < surfaces.length; i++){

         if(surfaces[i].getName() === MyOpenSpace.Surface.Field.CANVAS) { nav_surface = surfaces[i]; break; }

    opensocial.requestNavigateTo(nav_surface, {});

    ------------ 

    Surfaces were reworked by Google as part of 0.7 and moved into the gadgets spec in order to clean some of this up.

  • 02-27-2008 9:47 AM In reply to

    Re: Sample widget for requestNavigateTo

    I have noticed that certain characters can not be passed through params this way.  For example, if you type the string "a&b" into this sample app, it will not be displayed after the navigation.  Url escaping the parameter values seems to work around the problem. 

  • 02-27-2008 4:22 PM In reply to

    Re: Sample widget for requestNavigateTo

     Thanks for the tip, I'll check it out.

  • 03-03-2008 5:06 PM In reply to

    • Mark
    • Top 50 Contributor
    • Joined on 02-05-2008
    • Posts 72

    Re: Sample widget for requestNavigateTo

     Is there a way to use requestNavigateTo to send someone to the application's profile page?  Or is there some other way to do this?  It seems like this must have been answered somewhere in the forums, but I can't find anything about it.  Basically, if a user is viewing the profile of someone who has installed the app, but they haven't installed it themselves, I want to have a link to the app profile to prompt the viewer to add it. 

  • 03-04-2008 8:40 AM In reply to

    • Marc
    • Top 100 Contributor
    • Joined on 02-11-2008
    • Posts 36

    Re: Sample widget for requestNavigateTo

    I can't get the passing parameters to work using "opensocial.getEnvironment().getParams().appParams" or "opensocial.getEnvironment().getParams()".  Is this working yet?

  • 03-04-2008 12:04 PM In reply to

    Re: Sample widget for requestNavigateTo

     I am also having issues gettig "opensocial.getEnvironment().getParams().appParams" or "opensocial.getEnvironment().getParams()" to work.  Is this working yet or a possible bug?

     Anyone else having issues with getting params to work?

  • 03-04-2008 12:27 PM In reply to

    Re: Sample widget for requestNavigateTo

     Hi,

    I've reported this so we'll have someone check into asap.

    Rhonda

     

  • 03-04-2008 2:59 PM In reply to

    • Cyn
    • Top 200 Contributor
    • Joined on 03-01-2008
    • Posts 26

    Re: Sample widget for requestNavigateTo

    Mark:

     Is there a way to use requestNavigateTo to send someone to the application's profile page?  Or is there some other way to do this?  It seems like this must have been answered somewhere in the forums, but I can't find anything about it.  Basically, if a user is viewing the profile of someone who has installed the app, but they haven't installed it themselves, I want to have a link to the app profile to prompt the viewer to add it. 

     

     No reply to this, but this is something that I've spent the last 30 minutes searching for too.  We need a way to at least provide a link that navigates the user to the app profile.. to make installation easy.

     Does myspace intend to address this need?

  • 03-04-2008 3:29 PM In reply to

    • Marc
    • Top 100 Contributor
    • Joined on 02-11-2008
    • Posts 36

    Re: Sample widget for requestNavigateTo

     As of now, I'm just using the url in a link that opens to a new window.  Works for the mean time.  So

    <a href=http://profile.myspace.com/index.cfm?fuseaction=user.viewprofile&friendid=xxxxxx target=_blank></a>.

    But having that would be nice, instead of opening it in a new window.  Also, having it redirect to the profile page to install it, if the user hasn't added the app yet.   Instead it goes to the canvas page with an error.

  • 03-04-2008 6:53 PM In reply to

    Re: Sample widget for requestNavigateTo

    I can't be totally sure if this answers your specific question, but someone asked something similar in a different forum, and the basic answer is that if a profile viewer doesn't have the App installed, there will by a link on or near your App's display surface provided by MySpace that will take them to the App's Proile page.

    Sorry if that doesn't quite answer you, or if that snwer isn't quite correct. I'm on my fourh cup of coffee and I still can't seem to concentrate for longer than 30 seconds...

  • 03-06-2008 3:34 AM In reply to

    • James
    • Top 150 Contributor
    • Joined on 02-15-2008
    • Posts 27

    Re: Sample widget for requestNavigateTo

    The example given by Chad appears to not re-populate that text fields with the passed data. The function:

         opensocial.getEnvironment().getParams().appParams;

    is returning "undefined" in all cases.

     

    Can someone  update the status of this function please? Is it working or have mods been made to how it works?

     Thanks,

     James 

  • 03-06-2008 7:49 AM In reply to

    Re: Sample widget for requestNavigateTo

    James, 

    I believe that the bug Chad alluded to in his initial post has been fixed, so now you should just access this:

        opensocial.getEnvironment().getParams()

    instead of this:

        opensocial.getEnvironment().getParams().appParams

  • 03-06-2008 7:59 AM In reply to

    • James
    • Top 150 Contributor
    • Joined on 02-15-2008
    • Posts 27

    Re: Sample widget for requestNavigateTo

    yeah I see that, but opensocial.getEnvironment().getParams() does not contain the appParams element so they remain undefined...

    ...or am i missunderstaanding? Have you got this working? 

     thanks

  • 03-06-2008 8:50 AM In reply to

    Re: Sample widget for requestNavigateTo

    James:

    yeah I see that, but opensocial.getEnvironment().getParams() does not contain the appParams element so they remain undefined...

    ...or am i missunderstaanding? Have you got this working? 

     thanks

     

    Yes, I just tested this and it works for me.  I simply copied the sample code above, but changed this line:

                var params1 = opensocial.getEnvironment().getParams().appParams;

    to this:

                var params1 = opensocial.getEnvironment().getParams();

    Is that what you are trying?

Page 1 of 3 (32 items) 1 2 3 Next >