Javascript API

From Contensive Wiki
Revision as of 14:39, 2 July 2015 by Admin (Talk | contribs)

Jump to: navigation, search

The Javascript API contains a programming interface to simplify the interaction between the server and the browser. You reference the API with the cj object in javascript.

A simple example is a text box that saves it's data as it is typed. Create a new add-on, and add a text box. Add javascript to onChange or onKeyUp of the text box to call the cj.ajax.data() method to save the content of the text box into a field in a record of a table.

Drop this add-on on any page, and when it is rendered, the data will automatically save.

Alternately, you can write a remote method add-on that accepts data from the query string and saves it how you wish. Your client-side code could then call the cj.ajax.addon() method which executes your server-side code and performs the function.

cj Methods

  • cj.setSpinner()
  • cj.encodeHTML()
  • cj.invisible()
  • cj.visible()
  • cj.hide()
  • cj.show()
  • cj.setFrameHeight()
  • cj.encodeTextAreaKey()
  • cj.addHeadScriptLink()
  • cj.addHeadStyle()
  • cj.addHeadStyleLink()
  • cj.addHeadScriptCode()
  • cj.addLoadEvent()
  • cj.addListener()

cj Objects

1. cj.frame (requires admin framework)

The remote method uses ajax to execute server add-on methods.
cj.frame.submitForm( remoteMethodName, frameHtmlId, formHtmlId)
Example
cj.frame.submitForm('myAccountFrameHandler','myAccountFrame','FormToSubmitId');
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
cj.frame.update( remoteMethodName, frameHtmlId, queryString)
Example
cj.frame.update('myAccountFrameHandler','myAccountFrame','formId=10');
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


2. cj.remote

The remote method uses ajax to execute server add-on methods.
cj.remote(arguments)
Example
cj.remote({
'method':'myRemoteMethodAddon'
,'callback':myCallback
});
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


   cj.xml
   cj.ajax
   cj.admin