JS DESK

From FreeDESK
Jump to: navigation, search

Contents

Overview

The FreeDESK Javascript object will always be available on any page instantiated as DESK.

This provides most common functionality within the FreeDESK client-side interface.

Common Functions and Examples

Logging In

Calling DESK.show_login() will show the login pop-over DIV and allow the user to login.

Logging Out

Calling DESK.logout_click() will simulate the user clicking on the logout button, clear the session and return to the main index.

Checking for Response Errors

XML data received from the API can be checked to see if it is a FreeDESK error using DESK.isError(xml) which will return a boolean value (true for an error false if not an error).

A descriptive string stating the error code and a textual description can be got from an error with DESK.getError(xml). Just the error code can be returned with DESK.getErrorCode(xml).

Loading a Subpage

To load a subpage (that is a page of text/html provided from the page.php script server-side) the function DESK.loadSubpage(pageid, options) can be called. Options are in URI format and are passed onto the page URL.

Opening a Window

A window can be opened (of default size) using DESK.openWindow(windowname, url).

Form to Query

A function is provided to turn a form into a suitable URI string for query (get) or post data. All the fields of the form are parsed into one string and returned.

For example a form of ID 'testform' containing a text input called 'A' with an inputted value of 'hello' and another text input of 'B' with a value of 'there' as follows:

<form id="testform">
<input type="text" name="A" value="hello" />
<input type="text" name="B" value="there" />
</form>

With the following Javascript:

var data = DESK.formToQuery('testform');

The data var should contain: A=hello&B=there

Note: as required data will be escaped into URI format.

Form API

Using DESK.formAPI can automatically submit a form to the API as a POST request with all the data encoded.

The API mode and any other control information should be passed as hidden inputs.

On return if an error has been found it will be displayed to the user or failing that the set next course of action will take place.

DESK.formAPI(formid, closeOnComplete, reloadOnComplete, callbackOnComplete) - where formid is the ID of the form to POST to the API, closeOnComplete is a flag indicating the window should be closed on success, reloadOnComplete that the window should reload on success or callbackOnComplete a function for the response XML to be passed to on completion.

For example:

<form id="myform" onsubmit="return false;">
<input type="hidden" name="mode" value="apimode" />
<input type="text" name="someinput" value="something" />
<input type="submit" value="Submit to API" onclick="DESK.formAPI('myform',false,false,someFunction);" />
</form>

Would submit the form to the API (with the mode of 'apimode' and a second data field of 'someinput' equal to 'something'. On return, assuming no error has been encountered, the method someFunction will be called and passed the resulting XML.

Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox