AgileApps Support Wiki Pre Release

Difference between revisions of "JavaScript Functions"

From AgileApps Support Wiki
imported>Aeric
imported>Aeric
Line 1: Line 1:
These functions are available anywhere that [[JavaScript]] is running on the platform.
These functions are available anywhere that [[JavaScript]] is running on the platform.
{{Note|Examples on this page may have newlines added for readability.}}


====showTab====
====showTab====
Line 17: Line 19:
''Learn more:''
''Learn more:''
:* [[Get an Object ID]]
:* [[Get an Object ID]]
:* [[Get a Form ID]]
:* [[Get a View ID]]


;Sample Usage:
;Sample Usage:
Here is the basic usage pattern, with newlines added for readability:
Here is the basic usage pattern:
:<syntaxhighlight lang="javascript" enclose="div">
:<syntaxhighlight lang="javascript" enclose="div">
<a href="javascript:top.showTab('{objectId}','{Tab title}',
<a href="javascript:top.showTab('{objectId}','{Tab title}',
Line 48: Line 50:


;Parameters:
;Parameters:
:* key - Unique key which will be used to paint the tab. It is recommeded to use {objectId}-1 as the key
:* '''key -''' Unique key that identifies the tab. <tt>{objectId}-1</tt> is recommended.
:* tabTitle - Title for the tab that will be opened
 
:* url - URL to add the record
:* '''tabTitle -''' The tab label.
:* preserveTabTitle – Boolean.  
:: '''Note:'''<br>When displaying a record, the label is overwritten. Standard practice is to use it as a temporary label. For example: <tt>'Loading...'</tt>
::* If true, the specified title is used for the tab label
 
::* If false, the Object name is used for the tab label
:* '''url -''' The URL used to display the record [[Form]]: <tt>Service?t=498&object_id={id}</tt>
::* Add <tt>&a=view</tt> to add a new record
::* Add <tt>&a=view&policyaction=view</tt> to display an existing record
::* Optionally, add <tt>&show_layout={FormId}</tt> to specify a particular Form.
 
:* '''displayTitle -''' Boolean value that determines whether or not the specified title is used.
::* If true, the specified title is used for the tab label. (Must be true for a temporary label to be displayed, as well.)
::* If false, the Object name is used, instead.
 
''Learn more:''
:* [[Get an Object ID]]
:* [[Get a Record ID]]
:* [[Get a Form ID]]


;Sample Usage:
;Sample Usage:
:<syntaxhighlight lang="javascript" enclose="div">
Here is the basic usage pattern:
showTabInIFrame();
:''Learn more:'' For a complete example in context, see [[Create a JSP Record List from a SQL Query]]
 
:<syntaxhighlight lang="javascript" enclose="div">
:<syntaxhighlight lang="javascript" enclose="div">
<a href="javascript:top.showTabInIframe('{objectId}-1','{Tab title}',
<a href="javascript:top.showTabInIframe('{objectId}-1','{Tab title}',
'Service?t=498&id=-1&a=add&object_id={objectId}', true);">{Link Title}</a>
'Service?t=498&id=-1&a={action}&object_id={objectId}', true);">{Link Title}</a>
</syntaxhighlight>
</syntaxhighlight>


This example opens a tab to add a record to the Orders Object (ID=<tt>bd5b766236dd487c8cce3648bd5ffe64</tt>):
:<syntaxhighlight lang="javascript" enclose="div">
:<syntaxhighlight lang="javascript" enclose="div">
<a href="javascript:top.showTabInIframe('bd5b766236dd487c8cce3648bd5ffe64-1',
<a href="javascript:top.showTabInIframe('bd5b766236dd487c8cce3648bd5ffe64-1',
Line 70: Line 82:
Add Order</a>
Add Order</a>
</syntaxhighlight>
</syntaxhighlight>
This example opens a tab to display a record, where:
:* objectID = bd5b766236dd487c8cce3648bd5ffe64
:* recordID = ...
:* link text = "Details"
:<syntaxhighlight lang="javascript" enclose="div">   
<a href="javascript:top.showTabInIframe('bd5b766236dd487c8cce3648bd5ffe64-1', 'Loading...',
'Service?t=498&id={recordID}&object_id=bd5b766236dd487c8cce3648bd5ffe64&a=view&policyaction=view',true);">Details</a>
</syntaxhighlight>
:''Learn more:'' For a complete example in context, see [[Create a JSP Record List from a SQL Query]]


====lj_closeDialog====
====lj_closeDialog====

Revision as of 01:18, 29 December 2011

These functions are available anywhere that JavaScript is running on the platform.

Notepad.png

Note: Examples on this page may have newlines added for readability.

showTab

Display an object list view (list of object records) as a tab in the GUI.

Syntax
<syntaxhighlight lang="javascript" enclose="div">

showTab(key, tabTitle, url); </syntaxhighlight>

Parameters
  • key - Unique key that identifies the tab. Object ID is recommended.
  • tabTitle - The tab label.
  • url - The URL used to render the view, in the form: Service?t=499&object_id={id}
Optionally, add &show_layout={viewId} to specify a particular view.

Learn more:

Sample Usage

Here is the basic usage pattern:

<syntaxhighlight lang="javascript" enclose="div">

<a href="javascript:top.showTab('{objectId}','{Tab title}', 'Service?t=499&object_id={objectId}');">{Link title}</a> </syntaxhighlight>

Show the default view of the Orders Object (ID=bd5b766236dd487c8cce3648bd5ffe64)

<syntaxhighlight lang="javascript" enclose="div">

<a href="javascript:top.showTab('bd5b766236dd487c8cce3648bd5ffe64','Orders', 'Service?t=499&object_id=bd5b766236dd487c8cce3648bd5ffe64');">View Orders</a> </syntaxhighlight>

Show a specific view with ID de5dnnn8798, instead of the default view:

<syntaxhighlight lang="javascript" enclose="div">

<a href="javascript:top.showTab('bd5b766236dd487c8cce3648bd5ffe64','Orders', 'Service?t=499&object_id=bd5b766236dd487c8cce3648bd5ffe6464 &show_layout=de5dnnn8798');">Orders</a> </syntaxhighlight>

showTabInIFrame

Display a record form as a tab in the GUI, using the form either to add a record to an object or to display record details.

Syntax
<syntaxhighlight lang="javascript" enclose="div">

showTabInIframe(key, tabTitle, url, preserveTabTitle); </syntaxhighlight>

Parameters
  • key - Unique key that identifies the tab. {objectId}-1 is recommended.
  • tabTitle - The tab label.
Note:
When displaying a record, the label is overwritten. Standard practice is to use it as a temporary label. For example: 'Loading...'
  • url - The URL used to display the record Form: Service?t=498&object_id={id}
  • Add &a=view to add a new record
  • Add &a=view&policyaction=view to display an existing record
  • Optionally, add &show_layout={FormId} to specify a particular Form.
  • displayTitle - Boolean value that determines whether or not the specified title is used.
  • If true, the specified title is used for the tab label. (Must be true for a temporary label to be displayed, as well.)
  • If false, the Object name is used, instead.

Learn more:

Sample Usage

Here is the basic usage pattern:

<syntaxhighlight lang="javascript" enclose="div">

<a href="javascript:top.showTabInIframe('{objectId}-1','{Tab title}', 'Service?t=498&id=-1&a={action}&object_id={objectId}', true);">{Link Title}</a> </syntaxhighlight>

This example opens a tab to add a record to the Orders Object (ID=bd5b766236dd487c8cce3648bd5ffe64):

<syntaxhighlight lang="javascript" enclose="div">

<a href="javascript:top.showTabInIframe('bd5b766236dd487c8cce3648bd5ffe64-1', 'New Order','Service?t=498&id=-1&a=add&object_id=bd5b766236dd487c8cce3648bd5ffe64');"> Add Order</a> </syntaxhighlight>

This example opens a tab to display a record, where:

  • objectID = bd5b766236dd487c8cce3648bd5ffe64
  • recordID = ...
  • link text = "Details"
<syntaxhighlight lang="javascript" enclose="div">

<a href="javascript:top.showTabInIframe('bd5b766236dd487c8cce3648bd5ffe64-1', 'Loading...', 'Service?t=498&id={recordID}&object_id=bd5b766236dd487c8cce3648bd5ffe64&a=view&policyaction=view',true);">Details</a> </syntaxhighlight>

Learn more: For a complete example in context, see Create a JSP Record List from a SQL Query

lj_closeDialog

Close the current dialog. Typically used in conjunction with lj_refreshCurrentTab.

Syntax
<syntaxhighlight lang="javascript" enclose="div">

lj_refreshCurrentTab(); </syntaxhighlight>

Sample Usage

JavaScript closeDialog Sample

lj_printRecord

This function displays a customized print dialog for a record. Use it to set defaults, to limit the available choices, and to choose the Print Template which is used. (It is only available for Custom Objects.)

Syntax
<syntaxhighlight lang="javascript" enclose="div">

lj_printRecord('{option1}={value}&{option2}={value}&...'); </syntaxhighlight>

Parameters

Each option has two parameters: One to specify a default value, the other to determine whether it should be displayed so it can be overridden by the user.

By default, an option is always shown, unless explicitly hidden.

Parameter Description
default_print_layout form (default) - use a Print Form
template - use a Print Template
show_print_layout yes (default) - allows user to specify which kind of layout to use
default_print_document The name of the form or template to pre-select in the list of possible choices.
show_print_document yes - allows user to change the default choice
print_immediately no (default) - The print dialog is shown. The user can then change any options that are displayed. Printing occurs when the user clicks the Print button).
yes - printing occurs immediately and the results are displayed in a new window. (It only works if both default_print_layout and default_print_document are specified.)
default_page_orientation portrait (default) or landscape
show_page_orientation yes - allows user to change page orientation
default_pdf yes - otherwise, an HTML page is generated
show_pdf yes - allows user to choose HTML or PDF
Sample Usage

This code adds a [Custom Print] button to a Form, when placed in an On Load Form Script. In this case, the goal is to restrict a user who has access to that form to a specific template. (The standard Print operation makes all templates available. A standard Action button, meanwhile, is present in every form. This code puts the button in a specific form, to restrict template access for users whose role causes it to be displayed.)

<syntaxhighlight lang="javascript" enclose="div">

$("#print_button").remove(); $("#edit_button").parent().append( "<input type='button' id='customPrint' value='Custom Print' class='lj-button fg-button ui-state-default ui-corner-all' onClick=\"javascript:lj_printRecord('default_print_layout=template&show_print_layout=no&default_print_document=jsp&default_page_orientation=landscape&default_pdf=yes&show_pdf=no&print_immediately=yes');\">" ); </syntaxhighlight>

How it Works
$("#print_button").remove()
Remove the standard print button
$("#edit_button").parent().append
Finds the location of the edit button (present in every form), gets it's parent (the toolbar), and adds the new button to it.
class='lj-button fg-button ui-state-default ui-corner-all'
The standard CSS style elements for platform buttons.
<input type='button' ...
Define the button. (The entire string is one uninterrupted line.)
onClick=\"javascript:lj_printRecord(...
Specify the button's action

lj_refreshCurrentTab

Refresh the current tab. Typically used in conjunction with lj_closeDialog

Syntax
<syntaxhighlight lang="javascript" enclose="div">

lj_refreshCurrentTab(); </syntaxhighlight>

Sample Usage

JavaScript closeDialog Sample

lj_refreshTab

Refresh a specific tab. Typically used in conjunction with lj_closeDialog

Syntax
<syntaxhighlight lang="javascript" enclose="div">

{window}.lj_refreshTab(); </syntaxhighlight>

Sample Usage

JavaScript closeDialog Sample

lj_showDialog

This function displays a JSP/HTML Page as a dialog.

Syntax
<syntaxhighlight lang="javascript" enclose="div">

lj_showDialog(url, height, width, "dialog style", "title"); </syntaxhighlight>

Parameters
Parameter Description
url A string that gives the URL of a JSP/HTML Page in the platform, in the form /networking/pages/SomePage.jsp with optional query parameters to pass data: ?param1=abc&param2=xyz&...
height The height of the dialog window, in pixels.
width The width of the dialog window, in pixels.
dialog style A string that specifies the display style.
  • popupdialogWithCloser - Displays the dialog with a close button.
  • popupdialog - Displays the dialog without a close button.
Note:
There is also no close icon in the corner, with this option.
When using it, add your own controls to close the dialog.
title Displayed in the banner of the dialog.
Sample Usage

This sample displays a page at the specified URL in a popup dialog that has a close button.

<syntaxhighlight lang="javascript" enclose="div">

var url = "/networking/pages/MyPage.jsp?recordId="+someValue

       + "&returnUrl="+encodeURIComponent(lj_window_src);

top.lj_showDialog(url,300,350,"popupdialogWithCloser","My Page Title"); </syntaxhighlight>