How to Save User Preferences on Spaces?

Can someone explain to me how to save user preferences on Spaces or point me to some instructions

If there is a way to determine whether a gadget is on Spaces or Live, that would be good to know too so that I can hide the preference link in Spaces view mode.

I got one of my gadgets to save user preferences on Live but it's not working on Spaces.

Thanks


Answer this question

How to Save User Preferences on Spaces?

  • Kumar Venkat

    I had a simular problem.
    Although my code seem to work fine on spaces and on live.com, it threw an error on gadget.start.com

    Since preview on the gallery is in gadget.start.com the gadget would look like it is broken.

    With al little help from Chris Butler I solved the problem by using this code:

    try{m_mode = m_module.getMode();}
    catch(e){m_mode = true}
       
     if (m_mode == Web.Gadget.Mode.author)
                {
                    setupAuthor();
                }
                else
                {
                    setupViewer();
                }



  • zkhan

    Your gadget preferences are not visible in author mode until the next time you load that gadget in author mode. (refresh, etc...)


  • hammar

    Thanks, I can see that it even works better!

    still learning...



  • Raul Rodriguez

    Someone with more knowledge will be around soon I am sure, but this is the method I use

    var prefValue = m_module.getPreference("some value");

    if (prefValue == null)
    {
    m_module.setPreference("some value", "some value");
    }

    I just asked a similar question about view mode vs author mode about two threads down, but this is the answer!

    if (p_args.module.getMode() == Web.Gadget.Mode.view ) {
    }
    else

    showsettings();
    }

    I am still learning, so I hope this is correct and helpful


  • dax_kun

    The code suggested above:

    if (p_args.module.getMode() == Web.Gadget.Mode.view ) {

    causes an error ("Object doesn't support this object or method") when previewing the gadget on Live.com.

    Is there a better way to check whether you are in author or view mode




  • Alex Yakhnin - MSFT

    Not to contradict Chris, but there's a better way to do this. The problem is that p_args.module.GetMode() is not defined in the preview framework but is available everywhere. However you can use the p_args.mode variable in all environments. Thus you get code that looks like:

    var mode;
    if (m_module.getMode)
    {
    mode = m_module.getMode();
    }
    else if (p_args.mode)
    {
    mode = p_args.mode;
    }
    else
    {
    mode = Web.Gadget.Mode.author;
    }

    Or even simpler, just check p_args.mode. This method checks if the function exists and uses that, or if the variable exists and uses that, or defaults to author mode.

    To see what variables are available in what environments (live.com preview, live.com, spaces view, spaces edit, gallery preview), you can use Donavon's Gadget Platform Test Page. That page defaults to Donavon's test gadget which enumerates everything available in p_args, but you can use the same page to simultaneously run your own gadget in all environments.


  • Jeffrey Harmon

    abowman wrote:
    I think I see why I got confused.
    The preferences just aren't visible until you go to view mode.
    There is also a bug in my gadget that occurs in Firefox.

    Thanks

    Preferences should be visible in both author and view mode. You can only set the preferences when in author mode, though.


  • Bingo Boy

    I think I see why I got confused.
    The preferences just aren't visible until you go to view mode.
    There is also a bug in my gadget that occurs in Firefox.

    Thanks


  • MikePHall

    I'm sorry it took a while for me to reply back to you..

    This should work.. I didn't test it..

    Let me know if it works, I'm to tire to test it tonight. If it doesn't I'll play with it tomorrow.

    if (p_args.onDashboard == true)

    {

    //Basically, you're running on live.com. So preview mode should be view mode, so call the function that creates the

    // view mode here

    CreateViewMode();

    }

    else

    {

    if (p_args.module.getMode() == Web.Gadget.Mode.view ) {

    //your in view mode call the viewmode code.

    CreateViewMode();

    } else

    {

    //Call the author mode here.

    }


  • How to Save User Preferences on Spaces?