You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@shindig.apache.org by al...@indt.org.br on 2008/09/13 21:40:56 UTC

Gadgets Id. How to get it?

I'm using RPC, and I want to send the container that a specified gadget
made a call, how can I send the gadgets id to the container, so he can
answer the call to the gadget?

Thanks.


Re: Gadgets Id. How to get it?

Posted by sharmishtha gupta <sh...@gmail.com>.
Ok so got your answer

On Sun, Sep 14, 2008 at 1:37 AM, sharmishtha gupta <
sharmishtha.gupta@gmail.com> wrote:

>  Hi
> I am here little confuse about whether you want to pass gadget id to make
> just a shindig call or want to play with the function in gadget.js
>
>
> gadgets.IfrGadgetService.prototype.setUserPref = function(editToken, name,
>     value) {
>   *var id = this.getGadgetIdFromModuleId(this.f);
>   var gadget = gadgets.container.getGadget(id);
> *  var prefs = gadget.getUserPrefs();
>   for (var i = 1, j = arguments.length; i < j; i += 2) {
>     prefs[arguments[i]] = arguments[i + 1];
>   }
>   gadget.setUserPrefs(prefs);
> };
>  You can set specific id for a gadget by calling the corcerned function
> from gadget.js in your application file or better to introduce one js file
> which contain the specific change and then include that js file in your
> application file.
>
> If you just want to make a shindig call then you can probably write a js
> file which is setting gadget url/ gadget id based on your database call in
> the back end:-
>
> <script type="text/javascript">
> var gServerBaseURL = '';
> var gProfileGadget = null;
> var gCanvasGadget = null;
> var gChromeIds = [ "gadget-profile-chrome", "gadget-canvas-chrome" ];
> var gOwnerId = 1; //define your suitable ownerid
> var gViewerId =  1; //define suitable viewerid
>
> function generateSecureToken( gadget, mode ) {
>   // TODO: Use a less silly mechanism of mapping a gadget URL to an appid
>   var appId = 0;
>   var appIdGeneratorUrl = gadget.specUrl + "?mode=" + mode;
>   for (var i = 0; i < appIdGeneratorUrl.length; i++) {
>     appId += appIdGeneratorUrl.charCodeAt(i);
>   }
>
>   var fields = [gOwnerId, gViewerId, appId, "shindig", gadget.specUrl,
> "0"];
>   for (var i = 0; i < fields.length; i++) {
>     // escape each field individually, for metachars in URL
>     fields[i] = escape(fields[i]);
>   }
>   return fields.join(":");
> }
> </script>
>
> <script type="text/javascript">
>
> function handleNewProfileGadget( gadgetUrl ) {
>   gProfileGadget = gadgets.container.createGadget( {'specUrl': gadgetUrl}
> );
>   gProfileGadget.setServerBase('');
>   gProfileGadget.width=170;
>   gadgets.container.addGadget( gProfileGadget );
>   gadgets.container.layoutManager.setGadgetChromeIds( gChromeIds );
> }
> function handleNewCanvasGadget( gadgetUrl ) {
>   gCanvasGadget = gadgets.container.createGadget( {'specUrl': gadgetUrl} );
>   gCanvasGadget.setServerBase('');
>   gadgets.container.addGadget( gCanvasGadget );
>   gadgets.container.layoutManager.setGadgetChromeIds( gChromeIds );
> }
>
> function handleGadgetInMode( mode ) {
>   var currGadget = null;
>
>   if (document.forms[ "profileViewGadgetForm" ].elements[ "selectGadget"
> ].selectedIndex == -1) {
>    //nothing has been selected yet!
>    return ;
>   }
>    var gadgetUrl = gServerBaseURL + document.forms[ "profileViewGadgetForm"
> ].elements[ "selectGadget" ].value;
>
>    if( mode == "profile" ) {
>     if( gProfileGadget === null ) handleNewProfileGadget( gadgetUrl );
>     currGadget = gProfileGadget;
>   } else if( mode == "canvas" ) {
>     if( gCanvasGadget === null ) handleNewCanvasGadget( gadgetUrl );
>     currGadget = gCanvasGadget;
>
>     var profileDetailsDiv=document.getElementById("profileDetails");
>     profileDetailsDiv.style.display = "none";
>   }
>
>   currGadget.specUrl = gadgetUrl;
>   currGadget.secureToken = escape(generateSecureToken( currGadget, mode ));
>
>   gadgets.container.setView( mode );
>   gadgets.container.renderGadget( currGadget );
>  }
> function initProfileGadget( ) {
>   handleGadgetInMode("profile");
>
> }
>
> gadgets.util.registerOnLoadHandler(initProfileGadget);
> </script>
>
> I hope this will help
>
> Regards
> Sharmishtha
>   On Sun, Sep 14, 2008 at 1:10 AM, <al...@indt.org.br> wrote:
>
>> I'm using RPC, and I want to send the container that a specified gadget
>> made a call, how can I send the gadgets id to the container, so he can
>> answer the call to the gadget?
>>
>> Thanks.
>>
>>
>

Re: Gadgets Id. How to get it?

Posted by sharmishtha gupta <sh...@gmail.com>.
Hi
I am here little confuse about whether you want to pass gadget id to make
just a shindig call or want to play with the function in gadget.js


gadgets.IfrGadgetService.prototype.setUserPref = function(editToken, name,
    value) {
  *var id = this.getGadgetIdFromModuleId(this.f);
  var gadget = gadgets.container.getGadget(id);
*  var prefs = gadget.getUserPrefs();
  for (var i = 1, j = arguments.length; i < j; i += 2) {
    prefs[arguments[i]] = arguments[i + 1];
  }
  gadget.setUserPrefs(prefs);
};
 You can set specific id for a gadget by calling the corcerned function from
gadget.js in your application file or better to introduce one js file which
contain the specific change and then include that js file in your
application file.

If you just want to make a shindig call then you can probably write a js
file which is setting gadget url/ gadget id based on your database call in
the back end:-

<script type="text/javascript">
var gServerBaseURL = '';
var gProfileGadget = null;
var gCanvasGadget = null;
var gChromeIds = [ "gadget-profile-chrome", "gadget-canvas-chrome" ];
var gOwnerId = 1; //define your suitable ownerid
var gViewerId =  1; //define suitable viewerid

function generateSecureToken( gadget, mode ) {
  // TODO: Use a less silly mechanism of mapping a gadget URL to an appid
  var appId = 0;
  var appIdGeneratorUrl = gadget.specUrl + "?mode=" + mode;
  for (var i = 0; i < appIdGeneratorUrl.length; i++) {
    appId += appIdGeneratorUrl.charCodeAt(i);
  }

  var fields = [gOwnerId, gViewerId, appId, "shindig", gadget.specUrl, "0"];
  for (var i = 0; i < fields.length; i++) {
    // escape each field individually, for metachars in URL
    fields[i] = escape(fields[i]);
  }
  return fields.join(":");
}
</script>

<script type="text/javascript">

function handleNewProfileGadget( gadgetUrl ) {
  gProfileGadget = gadgets.container.createGadget( {'specUrl': gadgetUrl} );
  gProfileGadget.setServerBase('');
  gProfileGadget.width=170;
  gadgets.container.addGadget( gProfileGadget );
  gadgets.container.layoutManager.setGadgetChromeIds( gChromeIds );
}
function handleNewCanvasGadget( gadgetUrl ) {
  gCanvasGadget = gadgets.container.createGadget( {'specUrl': gadgetUrl} );
  gCanvasGadget.setServerBase('');
  gadgets.container.addGadget( gCanvasGadget );
  gadgets.container.layoutManager.setGadgetChromeIds( gChromeIds );
}

function handleGadgetInMode( mode ) {
  var currGadget = null;

  if (document.forms[ "profileViewGadgetForm" ].elements[ "selectGadget"
].selectedIndex == -1) {
   //nothing has been selected yet!
   return ;
  }
   var gadgetUrl = gServerBaseURL + document.forms[ "profileViewGadgetForm"
].elements[ "selectGadget" ].value;

   if( mode == "profile" ) {
    if( gProfileGadget === null ) handleNewProfileGadget( gadgetUrl );
    currGadget = gProfileGadget;
  } else if( mode == "canvas" ) {
    if( gCanvasGadget === null ) handleNewCanvasGadget( gadgetUrl );
    currGadget = gCanvasGadget;

    var profileDetailsDiv=document.getElementById("profileDetails");
    profileDetailsDiv.style.display = "none";
  }

  currGadget.specUrl = gadgetUrl;
  currGadget.secureToken = escape(generateSecureToken( currGadget, mode ));

  gadgets.container.setView( mode );
  gadgets.container.renderGadget( currGadget );
 }
function initProfileGadget( ) {
  handleGadgetInMode("profile");

}

gadgets.util.registerOnLoadHandler(initProfileGadget);
</script>

I hope this will help

Regards
Sharmishtha
On Sun, Sep 14, 2008 at 1:10 AM, <al...@indt.org.br> wrote:

> I'm using RPC, and I want to send the container that a specified gadget
> made a call, how can I send the gadgets id to the container, so he can
> answer the call to the gadget?
>
> Thanks.
>
>

RE: Gadgets Id. How to get it?

Posted by al...@indt.org.br.
I found out that I can use the this.f to get the iframeId, and that
helped a lot.

Thank you. 

-----Original Message-----
From: ext alan.castro@indt.org.br [mailto:alan.castro@indt.org.br] 
Sent: Saturday, September 13, 2008 3:41 PM
To: shindig-dev@incubator.apache.org
Subject: Gadgets Id. How to get it?

I'm using RPC, and I want to send the container that a specified gadget
made a call, how can I send the gadgets id to the container, so he can
answer the call to the gadget?

Thanks.