shindig-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bruce Godden (JIRA)" <>
Subject [jira] Created: (SHINDIG-1248) UserPref problems in example container code: gadgets.js and cookiebaseduserprefstore.js
Date Wed, 16 Dec 2009 11:46:18 GMT
UserPref problems in example container code: gadgets.js and cookiebaseduserprefstore.js

                 Key: SHINDIG-1248
             Project: Shindig
          Issue Type: Bug
          Components: Javascript 
            Reporter: Bruce Godden
            Priority: Minor

I was trying to create a simple test container which supported user preferences based on the
pubsub example but I encountered a number of bugs in the example container javascript files.

In gadgets.js the setUserPref function appears to be setting the preference in the GadgetService
object instead of the Gadget object. Also the ways it runs the loop processing the function
arguments might give an unwanted effect if no value was specified for the last name argument.
The fixed function is:

gadgets.IfrGadgetService.prototype.setUserPref = function(editToken, name, value) {
  var id = gadgets.container.gadgetService.getGadgetIdFromModuleId(this.f);
  var gadget = gadgets.container.getGadget(id);
  for (var i = 2, j = arguments.length; i < j; i += 2) {      // *** run loop using the
value argument to detect the end ***
    gadget.userPrefs[arguments[i - 1]] = arguments[i];      // *** argument accesses changed
  gadget.saveUserPrefs();      // *** use gadget instead of this ***

In gadgets.js the getUserPrefValue and handleSaveUserPrefs  functions fail to fetch/store
the value for a preference because they seem to think that it is stored as a value attribute;
it isn't according to the rest of the code. The fixed functions are:

gadgets.Gadget.prototype.getUserPrefValue = function(name) {
  var pref = this.userPrefs[name];
  return typeof(pref) != 'undefined' && pref != null ?      // *** .value deleted
from this line twice ***
      pref : this.userPrefs['default'];        // *** .value deleted from this line ***

(Actually in the above is there really any point in fetching a global default value for a
preference that doesn't have a value set? This probably isn't going to be the correct default
value as given by the gadget specification.)

gadgets.IfrGadget.prototype.handleSaveUserPrefs = function() {

  var numFields = document.getElementById('m_' + +
  for (var i = 0; i < numFields; i++) {
    var input = document.getElementById('m_' + + '_' + i);
    var userPrefNamePrefix = 'm_' + + '_up_';
    var userPrefName =;
    var userPrefValue = input.value;
    this.userPrefs[userPrefName] = userPrefValue;      // *** .value deleted from this line


The current settings of the user preferences are not loaded into the gadget during its creation.
I added a comment to SHINDIG-181 about this but here is the fixed function anyway:

gadgets.Container.prototype.addGadget = function(gadget)
{ = this.getNextGadgetInstanceId();
  this.gadgets_[this.getGadgetKey_(] = gadget;
  gadget.userPrefs = this.userPrefStore.getPrefs(gadget);      // *** new line ***

In cookiebaseduserprefstore.js the savePrefs function is trying to fetch a preference value
by calling getUserPref on the gadget but the function is should be calling is getUserPrefValue.
However, it would be neater to simple use the userPrefs object it fetched to find the preference
names directly. The fixed function is:

gadgets.CookieBasedUserPrefStore.prototype.savePrefs = function(gadget) {
  var pairs = [];
  var prefs = gadget.getUserPrefs();       // *** new line ***
  for (var name in prefs) {       // *** use the fetched prefs ***
    var pair = encodeURIComponent(name) + '=' + encodeURIComponent(prefs[name]);       //
*** access the fetched prefs directly ***

  var cookieName = this.USER_PREFS_PREFIX +;
  var cookieValue = pairs.join('&');
  shindig.cookies.set(cookieName, cookieValue);

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

View raw message