Class Index | File Index

Classes


Namespace Sfdc.canvas.client

Sfdc.canvas.client
Defined in: client.js.

Namespace Summary
Constructor Attributes Constructor Name and Description
 
Method Summary
Method Attributes Method Name and Description
 
ajax(url, settings)
Perform a cross-domain, asynchronous HTTP request.
 
ctx(clientscb, token)
Get the context for the current user and organization
Namespace Detail
Sfdc.canvas.client
Method Detail
ajax(url, settings)
Perform a cross-domain, asynchronous HTTP request.
Note: this should not be used for same domain requests.
//Posting To a Chatter Feed:
var sr = JSON.parse('<%=signedRequestJson%>');
var url = sr.context.links.chatterFeedsUrl+"/news/"
                                  +sr.context.user.userId+"/feed-items";
var body = {body : {messageSegments : [{type: "Text", text: "Some Chatter Post"}]}};
connect.client.ajax(url,
  {client : sr.client,
    method: 'POST',
    contentType: "application/json",
    data: JSON.stringify(body),
    success : function(data) {
    if (201 === data.status) {
         alert("Success"
         } 
    }
  });
// Gets a List of Chatter Users:
// Paste the signed request string into a JavaScript object for easy access.
var sr = JSON.parse('<%=signedRequestJson%>');
// Reference the Chatter user's URL from Context.Links object.
var chatterUsersUrl = sr.context.links.chatterUsersUrl;

// Make an XHR call back to salesforce through the supplied browser proxy.
connect.client.ajax(chatterUsersUrl,
  {client : sr.client,
  success : function(data){
  // Make sure the status code is OK.
  if (data.status === 200) {
    // Alert with how many Chatter users were returned.
    alert("Got back "  + data.payload.users.length +
    " users"); // Returned 2 users
   }
})};
Parameters:
{String} url
The URL to which the request is sent
{Object} settings
A set of key/value pairs to configure the request.
The success setting is required at minimum and should be a callback function
{String} settings.client Optional
required client context {oauthToken: "", targetOrigin : "", instanceId : ""}
{String} settings.contentType Optional
"application/json"
{String} settings.data Optional
request body
{String} settings.headers Optional
request headers
{String} settings.method Optional, Default: "GET"
The type of Ajax Request to make
{Function} settings.success Optional
Callback for all responses from server (failure and success) . Signature: success(response); intersting fields: [response.data, response.responseHeaders, response.status, response.statusText}
{Boolean} settings.async Optional, Default: true
Asyncronous: true is only supported at this time.
Throws:
illegalArgumentException if the URL is missing or the settings object does not contain a success callback function.

ctx(clientscb, token)
Get the context for the current user and organization
// Gets context in the canvas app.

function callback(msg) {
  if (msg.status !== 200) {
    alert("Error: " + msg.status);
    return;
  }
  alert("Payload: ", msg.payload);
}
var ctxlink = connect.byId("ctxlink");
var oauthtoken = connect.oauth.token();
ctxlink.onclick=function() {
  connect.client.ctx(callback, oauthtoken)};
}
Parameters:
{Function} clientscb
Callback function to run when the call to ctx is complete
{String} token
OAuth token to send.

Documentation generated by JsDoc Toolkit 2.3.0 on Fri Jan 11 2013 16:00:16 GMT-0000 (GMT)