Dear All,

 

In accordance with the OpenSocial Tutorials I've implemented User
Preferences saving/restoring state i.e. those that belong to the range of
pre-defined types: (ENUM, STRING. LIST, BOOL). However, I'm not currently
able to also maintain the state of the gadget's HIDDEN user preferences,
received from metadata.

 

The code below renders gadget using its preferences.

 

CommonContainer.renderGadget = function (gadget, contentHolder,
userPreference) {
    var gadgetURL = gadget.Url;
    // going to hardcode these values for width.
    var el = $(contentHolder).get(0);
    var params;
    if (userPreference == null) {
        params = { userPrefs: cacheDefaultUserPreference[gadgetURL] };
    } else {
        params = { userPrefs: userPreference };
    }
    params["view"] = "home";
    if (gadget.viewType == GadgetViewTypes.Canvas) {
        params["view"] = "canvas";
    }
    params[osapi.container.RenderParam.WIDTH] = '100%';
    var gadgetSite = CommonContainer.newGadgetSite(el);
    CommonContainer.navigateGadget(gadgetSite, gadgetURL, {}, params);
    defaultUserPreference = {};
    return gadgetSite;
};

 

Maintaining the user preferences which are not HIDDEN type works well okay
and settings are retained by the gadget. However, if I try to do a similar
action regarding HIDDEN preferences then it appears to have the effect of
replacing the default gadget's settings and saving just my values that I
maintained by catching 'set_prefs' event. My callback function looks like
this...


function setPrefs(t, name, value) {
    var info = $('#' + this.f).parent().parent();
    
    var hfGdgets = $('input[id*=hfGadgetInfo]', info).val();
    var gadgetInfo = eval("(" + hfGdgets + ")");
    var cookieUserGadget = new CookieUserGadget();
    cookieUserGadget.ID = gadgetInfo.CategoryGadgetID;
    cookieUserGadget.GadgetID = gadgetInfo.GadgetID;
    // set Pref in pref dialog
    $("#" + name, info).val(value);
    if (gadgetInfo.UserPreference.Value == null) {
        gadgetInfo.UserPreference.Value = new Object();
        gadgetInfo.UserPreference.Value[name] = value;
    } else {
        if (typeof gadgetInfo.UserPreference.Value !== 'object') {
            gadgetInfo.UserPreference.Value = eval("(" +
gadgetInfo.UserPreference.Value + ")");
        }
        gadgetInfo.UserPreference.Value[name] = value;
    }
    cookieUserGadget.UserPreference = { "Value":
JSON.stringify(gadgetInfo.UserPreference.Value) };
    $('input[id*=hfGadgetInfo]', info).val(JSON.stringify(gadgetInfo));
    var data = {
        "cookieUserGadgetPreference": JSON.stringify(cookieUserGadget)
    };
    $.ajax({
        url: '/Channel.aspx/SaveUserGadgetPreference',
        dataType: 'json',
        type: "post",
        data: JSON.stringify(data),
        contentType: "application/json; charset=utf-8",
        async: false,
        success: function (data) {
        }
    });
}

 

Examples of gadgets with internal HIDDEN preferences include:-

Google News (http://www.google.com/ig/modules/tabnews/tabnews.xml)

Date & Time (http://gadgets.blueg.com/standard/date-time/date-time.xml)

 

Examples of gadgets with user preferences include:-

Dictionary (http://www.gstatic.com/ig/modules/dictionary/dictionary_v2.xml)

Gismeteo
(http://sterno-gadgets.googlecode.com/svn/trunk/gismeteo/gismeteo.xml)

 

My question is this - how to correctly retain the internal gadget's state
between the requests and not to erase the rest of its user preference
settings?

 

Any help much appreciated.

 

Kind regards,

 

Darren

 

Reply via email to