Javascript API

From Contensive Wiki
Revision as of 22:47, 12 April 2016 by Admin (Talk | contribs) (cj Methods)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

The Contensive javascript api includes a few methods to simplify ajax interaction.

cj Methods

cj.setSpinner

arguments:
--

// sample
// call server addon (configured as remoteMethod) myAccountFrameHandler
// store the response directly into html element with id myAccountFrame

cj.setSpinner();

cj.remote

arguments:
'method': string - addonname
'formId': string - html Id of form to be submitted
'callback': function - function to call on completion, two arguments, response and callbackArg
'callbackArg': object - passed direction to the callback function
'destinationId': string - html Id of an element to set innerHtml
'onEmptyHideId': string - if return is empty, hide this element
'onEmptyShowId': string - if return is empty, show this element
'queryString': string - queryString formatted name=value pairs added to post
'url': string - link to hit if not addon name provided

// sample
// call server addon myRemoteMethodAddon
// when the server responses, call function myCallback( response )

cj.remote({
     'method':'myRemoteMethodAddon'
     ,'callback':myCallback
});

cj.frame Methods

Used to execute server methods remotely. (requires admin framework)

cj.frame.submitForm

arguments:
remoteMethodName: string - the name of the addon to call
frameHtmlId: string - html Id of frame that will receive the html results from the addon
formHtmlId: string - the Html Id of the form that will be submitted to the remoteMethod

// Submit <form id="formToSubmitId">
// to server addon (configured as remoteMethod) myAccountFrameHandler
// store the response directly into html element with id myAccountFrame

cj.frame.submitForm('myAccountFrameHandler','myAccountFrame','formToSubmitId');

cj.frame.update

arguments:
remoteMethodName: string - the name of the addon to call
frameHtmlId: string - html Id of frame that will receive the html results from the addon
queryString: string - Anything else to be passed to the remoteMethod

// call server addon (configured as remoteMethod) myAccountFrameHandler
// store the response directly into html element with id myAccountFrame
// add formId=10 to the resulting querystring

cj.frame.update('myAccountFrameHandler','myAccountFrame','formId=10');

cj.xml

4. cj.ajax

The ajax object has methods to simplify common ajax calls and provide a framework to simplify interaction with server-side methods.
For instance, to display a current list of visitors you could:
1. Write the code yourself - create an addon that the content manager could drop on any page. The addon includes an ajax call back to the server for data. Then create a remote method (addon) that responds to the request with the data formatted appropriately.
2. Use cj.ajax - Within your same page addon, call the createRemoteQuery() method with the query needed on your page. Then do your ajax call with cj.ajax.data(). It runs your query and returns a javascript object with your data in a simple results object.
cj.ajax.data
cj.ajax.data(handler,queryKey,args,pageSize,pageNumber,responseFormat,ajaxMethod)
Arguments
handler - the javascript function (event handler) to be called when the ajax call returns. The response from the ajax call is passed to the handler as it's single argument. For example, if your handler is
function myHandler( resultSet ) {}
then the handler would be 'myHandler'
queryKey - a string that uniquely identifies the query record in the Remote Query content. If you need to run a query on a client-side event, you can create the query in the Remote Query content table and add a unique key to the record. To execute this query, include the key in the queryKey argument of this call. To programmatically create a query and get a key, see the Contensive webclient reference, GetAjaxQueryKey method.
args - A list of arguments to be passed to the server for processing with the query. They are in 'name=value&name=value' format. Each name and each value must be individually escaped before assembling the string. Depending on the QueryType setup for this key, the args can be used differently.
QueryType argument setup in the Remote Query content table:
1. SQLQuery - args are replacement name=value pairs
2. ContentInsert - args are fieldname=value pairs, but all fieldnames must be in the fieldnamelist
3. ContentUpdate - args are fieldname=value pairs, but all fieldnames must be in the fieldnamelist
pageSize - records to be returned
pageNumber - the page where the records begin
responseFormat
1. "table" - Google Visualization format
When the hander is called, the single argument will be a javascript object with rows and columns. The row labels are accessed by the 'id' property of each row. For example, if your hander is:
myHander( results ) {
rows[0].id='fieldname'
rows[0].c[0].v='value'
2. "namearray" - returns arrays named for each field
dataadded[0]='value'
name[0]='value'
3. "namevalue" - returns only the first row of a table, with no arrays
dateadded='value'
ajaxMethod - the method used for this query
"data" - use the remote query table as the source for update details
"setvisitproperty" - run serverside SetVisitProperty
"getvisitproperty" - run serverside GetVisitProperty
Return
When the ajax call returns, it calls your handler (a callback) with the result set as it's argument. The format of the results depends on the responseFormat and ajaxMethod arguments and is described there.
Example
In your server-side code:
v
remoteQueryKey = cp.setRemoteQuery( "select top 1 name from ccMembers order by id desc" )
bind a hotspot to cj.ajax.data('showLastUser',(the string remoteQueryKey) ,,1,1,'namevalue','data')
cp.doc.addHeadJavascript( "function showLastUser(results) {alert('Last user was '+results.name)}" );
cj.ajax.getTable
cj.ajax.getTable(handler,queryKey,args,pageSize,pageNumber)
Arguments
handler - the javascript function (event handler) to be called when the ajax call returns. The response from the ajax call is passed to the handler as it's single argument. For example, if your handler is
function myHandler( resultSet ) {}
then the handler would be 'myHandler'
queryKey - a string that uniquely identifies the query record in the Remote Query content. If you need to run a query on a client-side event, you can create the query in the Remote Query content table and add a unique key to the record. To execute this query, include the key in the queryKey argument of this call. To programmatically create a query and get a key, see the Contensive webclient reference, GetAjaxQueryKey method.
args - A list of arguments to be passed to the server for processing with the query. They are in 'name=value&name=value' format. Each name and each value must be individually escaped before assembling the string. Depending on the QueryType setup for this key, the args can be used differently.
QueryType argument setup in the Remote Query content table:
1. SQLQuery - args are replacement name=value pairs
2. ContentInsert - args are fieldname=value pairs, but all fieldnames must be in the fieldnamelist
3. ContentUpdate - args are fieldname=value pairs, but all fieldnames must be in the fieldnamelist
pageSize - records to be returned
pageNumber - the page where the records begin
cj.ajax.getNameArray
cj.ajax.getNameArray(handler,queryKey,args,pageSize,pageNumber)
Arguments
handler - the javascript function (event handler) to be called when the ajax call returns. The response from the ajax call is passed to the handler as it's single argument. For example, if your handler is
function myHandler( resultSet ) {}
then the handler would be 'myHandler'
queryKey - a string that uniquely identifies the query record in the Remote Query content. If you need to run a query on a client-side event, you can create the query in the Remote Query content table and add a unique key to the record. To execute this query, include the key in the queryKey argument of this call. To programmatically create a query and get a key, see the Contensive webclient reference, GetAjaxQueryKey method.
args - A list of arguments to be passed to the server for processing with the query. They are in 'name=value&name=value' format. Each name and each value must be individually escaped before assembling the string. Depending on the QueryType setup for this key, the args can be used differently.
QueryType argument setup in the Remote Query content table:
1. SQLQuery - args are replacement name=value pairs
2. ContentInsert - args are fieldname=value pairs, but all fieldnames must be in the fieldnamelist
3. ContentUpdate - args are fieldname=value pairs, but all fieldnames must be in the fieldnamelist
pageSize - records to be returned
pageNumber - the page where the records begin
cj.ajax.getNameValue
cj.ajax.getNameValue(handler,queryKey,args)
Arguments
handler - the javascript function (event handler) to be called when the ajax call returns. The response from the ajax call is passed to the handler as it's single argument. For example, if your handler is
function myHandler( resultSet ) {}
then the handler would be 'myHandler'
queryKey - a string that uniquely identifies the query record in the Remote Query content. If you need to run a query on a client-side event, you can create the query in the Remote Query content table and add a unique key to the record. To execute this query, include the key in the queryKey argument of this call. To programmatically create a query and get a key, see the Contensive webclient reference, GetAjaxQueryKey method.
args - A list of arguments to be passed to the server for processing with the query. They are in 'name=value&name=value' format. Each name and each value must be individually escaped before assembling the string. Depending on the QueryType setup for this key, the args can be used differently.
QueryType argument setup in the Remote Query content table:
1. SQLQuery - args are replacement name=value pairs
2. ContentInsert - args are fieldname=value pairs, but all fieldnames must be in the fieldnamelist
3. ContentUpdate - args are fieldname=value pairs, but all fieldnames must be in the fieldnamelist
cj.ajax.update
cj.ajax.update(handler,queryKey,criteria,setPairs)
Arguments
1. handler - the javascript function (event handler) to be called when the ajax call returns. The response from the ajax call is passed to the handler as it's single argument. For example, if your handler is
2. function myHandler( resultSet ) {}
3. then the handler would be 'myHandler'
queryKey - a string that uniquely identifies the query record in the Remote Query content. If you need to run a query on a client-side event, you can create the query in the Remote Query content table and add a unique key to the record. To execute this query, include the key in the queryKey argument of this call. To programmatically create a query and get a key, see the Contensive webclient reference, GetAjaxQueryKey method.
cj.ajax.setVisitProperty
cj.ajax.setVisitProperty(handler,propertyName,propertyValue)
Arguments
handler - the javascript function (event handler) to be called when the ajax call returns. The response from the ajax call is passed to the handler as it's single argument. For example, if your handler is
function myHandler( resultSet ) {}
then the handler would be 'myHandler'
cj.ajax.getVisitProperty
cj.ajax.getVisitProperty(handler,propertyName,propertyValueDefault)
Arguments
handler - the javascript function (event handler) to be called when the ajax call returns. The response from the ajax call is passed to the handler as it's single argument. For example, if your handler is
function myHandler( resultSet ) {}
then the handler would be 'myHandler'
cj.ajax.url
cj.ajax.url(localUrl,formId,destinationId,onEmptyHideId,onEmptyShowId)
Arguments
localUrl
formId
destinationId
onEmptyHideId
onEmptyShowId
cj.ajax.addon
cj.ajax.addon(addonName,queryString,formId,destinationId,onEmptyHideId,onEmptyShowID)
Arguments
addonName
queryString
formId
destinationId
onEmptyHideId
onEmptyShowId
cj.ajax.addonCallback
cj.ajax.addonCallback(addonName,queryString,callback,callbackArg)
Arguments
addonName - the remoteMethod addon to call on the server.
queryString - the querystring to pass to the server addon.
callback - When the method returns, it will call this function with two possible arguments. The frist argument is always the serverResponse. If the callbackArg is included in this call, it will be the second argument in the callback.
callbackArg - When included, this argument is passed to the callback routine as its second argument.
Return
Example
functionButtonClick() {
var varString = 'button=submit';
cj.ajax.addonCallback( 'registrationFormHandlerAddon', varString, callbackHandler, '1' );
return false;
}
function callbackHander( serverResponse, passthroughArgument ) {
alert('The call passed the argument ['+passthroughArgument+'], and server returned '+serverResponse );
}
cj.ajax.qs
cj.ajax.qs(queryString,formId,destinationId,onEmptyHideId,onEmptyShowID))
Arguments
queryString
formId
destinationId
onEmptyHideId
onEmptyShowId

5. cj.admin