Difference between revisions of "JavaScript Functions and Variables"

From AgileApps Support Wiki
imported>Aeric
imported>Aeric
(Redirected page to JavaScript Functions)
Β 
(14 intermediate revisions by the same user not shown)
Line 1: Line 1:
These Javascript functions and variables are available for use in a JSP/HTML [[Page]] in the platform. They can also be used in Javascript defined for [[Action]] buttons.
#REDIRECT [[JavaScript Functions]]
__TOC__
Β 
==Functions==
Β 
===lj_closeDialog===
Close the current dialog. Typically used in conjunction with [[#lj_refreshCurrentTab|<tt>lj_refreshCurrentTab</tt>]].
Β 
;Sample Usage:
{{:Javascript closeDialog Sample}}
Β 
;Syntax:
:<syntaxhighlight lang="javascript" enclose="div">
lj_refreshCurrentTab();
</syntaxhighlight>
Β 
===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 {{type|}}s.)
Β 
;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 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:
::; <tt>$("print_button").remove()</tt>: Remove the standard print button
::; <tt>$("#edit_button").parent().append</tt>: Finds the location of the edit button (present in every form), gets it's parent (the toolbar), and adds the new button to it.
::; <tt>class='lj-button fg-button ui-state-default ui-corner-all'</tt>: The standard CSS style elements for platform buttons.
::; <tt><nowiki><input type='button' ...</nowiki></tt>: Define the button. (The entire string is one uninterrupted line.)
::; <tt>onClick=\"javascript:lj_printRecord(...</tt>: Specify the button's action
Β 
;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.
Β 
:{| border="1" cellpadding="5" cellspacing="1"
! align="left"| Parameter !! align="left"| Description (default value in '''bold''')
|-
| default_print_layout || Specify "form" or "template" to use a [[Print Form]] or [[Print Template]]
|-
| show_print_layout || '''yes''' (allows user to specify which kind of form 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''' (The print dialog is shown. The user can then change any options that are displayed. Printing occurs when the user clicks the Print button). If "yes", printing occurs immediately and the results are displayed in a new window. (But it only works if both <tt>default_print_layout</tt> and <tt>default_print_document</tt> are specified.)
|-
| default_page_orientation || '''portrait''' or landscape
|-
| show_page_orientation || '''yes'''
|-
| default_pdf || '''yes''' (otherwise, an HTML page is generated)
|-
| show_pdf || '''yes'''
|}
Β 
===lj_refreshCurrentTab===
Refresh the current tab. Typically used in conjunction with [[#lj_closeDialog|<tt>lj_closeDialog</tt>]]
Β 
;Sample Usage:
{{:Javascript closeDialog Sample}}
Β 
;Syntax:
:<syntaxhighlight lang="javascript" enclose="div">
lj_refreshCurrentTab();
</syntaxhighlight>
Β 
===lj_refreshTab===
Refresh a specific tab. Typically used in conjunction with [[#lj_closeDialog|<tt>lj_closeDialog</tt>]]
Β 
;Sample Usage:
{{:Javascript closeDialog Sample}}
Β 
;Syntax:
:<syntaxhighlight lang="javascript" enclose="div">
{window}.lj_refreshTab();
</syntaxhighlight>
Β 
===lj_showDialog===
This function displays a JSP/HTML [[Page]] as a 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>
Β 
;Syntax:
:<syntaxhighlight lang="javascript" enclose="div">
lj_showDialog(url, height, width, "dialog style", "title");
</syntaxhighlight>
Β 
;Parameters:
Β 
:{| border="1" cellpadding="5" cellspacing="1"
! align="left"| Parameter !! align="left"| Description
|-
| url || A string that gives the URL of a JSP/HTML [[Page]] in the platform, in the form <tt>/networking/pages/SomePage.jsp</tt> with optional query parameters to pass data: <tt>?param1=abc&param2=xyz&...</tt>
|-
| 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'':<br>There is also no close icon in the corner, with this option.<br>When using it, add your own controls to close the dialog.
|-
| title || Displayed in the banner of the dialog.
|}
Β 
==Variables==
Β 
===lj_window_src===
Contains the URL of the current page. (Needs to be URL encoded when used.)
Β 
;Sample Usage:
:<syntaxhighlight lang="javascript" enclose="div">
encodeURIComponent(lj_window_src)
</syntaxhighlight>

Latest revision as of 00:40, 6 December 2014