imported>Aeric |
imported>Aeric |
Line 42: |
Line 42: |
| ====Add a Help Button to an Arbitrary Form==== | | ====Add a Help Button to an Arbitrary Form==== |
| This code works for forms in all objects, including Cases, Tasks, and custom objects. And it works when adding a new record, as well as when viewing an existing record. | | This code works for forms in all objects, including Cases, Tasks, and custom objects. And it works when adding a new record, as well as when viewing an existing record. |
| | | For information about adding a help button to a form, see the tech community article [http://techcommunity.softwareag.com/pwiki/-/wiki/Main/Adding%20a%20Custom%20Button%20to%20an%20Arbitrary%20Form%20using%20Form%20Script Adding a Custom Button to an Arbitrary Form using Form Script.] |
| In general, it puts a '''[Help]''' button in the upper right corner of a form:
| |
| :[[File:HelpButtonScriptExample.png]]
| |
| | |
| Note that when viewing a record, there are two options, depending on which code you enable:
| |
| :* Put the button in the details area. (The button is only visible when details are shown, but the short block of code works for all objects.)
| |
| :* Put the button above the details area.
| |
| :: This option requires special-case code for the Cases object. Note that the placement isn't perfect (the case-description is pushed down). But the button is always visible, whether or not the details area is open:
| |
| :::[[File:HelpButtonCaseRecord.png]]
| |
| | |
| In either case, the code below opens the target page in a separate window.<br>(To open the page in the Help tab, see [[HowTo:Create Application-Specific Help]].)
| |
| :<syntaxhighlight lang="javascript" enclose="div">
| |
| var targetURL = "http://google.com";
| |
| var action = _sdForm.get(0).a.value; // Is this an add-record or view-record form?
| |
| var button =
| |
| '<div style="float:right;padding-right:20px"> \
| |
| <input type="button" value=" Help " onclick="window.open(\''+targetURL+'\')"> \
| |
| </div>';
| |
| | |
| if (action == "add") {
| |
| // POPUP DIALOG. PUT HELP BUTTON IN THE NEW-RECORD FORM.
| |
| _sdForm.parent('div').parent('div').parent('div')
| |
| .find('.assigned_title .row-fluid').append(button);
| |
| } else {
| |
| // RECORD VIEW. PUT HELP BUTTON IN DETAILS AREA.
| |
| // The simplest code. Works for all objects: custom objects, cases, and tasks.
| |
| // The button shows only when the details section is open
| |
| // Ideal when Company Info > Application Settings > Expand Details" is TRUE
| |
| _sdForm.parent('div').parent('div').prepend(button);
| |
| | |
| // OR (choose the else-clause above, or the one below)
| |
| | |
| // PUT THE HELP BUTTON ABOVE THE DETAILS AREA, so it is always visible
| |
| // This code pushes the case summary down by the height of the button.
| |
| // Help button appears even when record details are hidden.
| |
| var banner = _sdForm.parent('div').parent('div').parent('div')
| |
| .find('.case-priority-status-header');
| |
| if (banner.length == 0) {
| |
| // NORMAL RECORD VIEW (custom objects and tasks)--PUT BUTTON IN TITLE AREA.
| |
| _sdForm.parent('div').parent('div').parent('div').find('h5').append(button);
| |
| } else {
| |
| // The special case-record banner that shows priority and status is present.
| |
| // CASE-RECORD VIEW. PUT THE BUTTON UNDER THE BANNER.
| |
| banner.after(button);
| |
| }
| |
| }
| |
| </syntaxhighlight>
| |
| | |
| =====Help Page Target Options=====
| |
| As for the help page to point to, you have many options:
| |
| | |
| :* '''An externally-hosted web page'''
| |
| ::<syntaxhighlight lang="javascript" enclose="div">
| |
| var button =
| |
| '<div style="float:right;padding-right:20px"> \
| |
| <input type="button" value=" Help " \
| |
| onclick="window.open(\'http://path/to/REMOTEPAGE.html\')"> \
| |
| </div>';
| |
| </syntaxhighlight>
| |
| {{Tip|The external page could be hosted on one of the free Wiki services, like WebDot, WebHub, or WebSpaces. (Those are some of the most widely used services at the time of this writing. They are very different from each other, so do an in-depth comparison to choose the one that will work best for you.}}
| |
| | |
| :* '''A JSP [[Page]] hosted in the application platform'''
| |
| :: This is arguably the most useful option, since displays a page that is already in the platform.
| |
| :: It also opens the page in a new window, which lets the user see the help and the application side by side.
| |
| :: (The remaining options change user-focus to a different part of the platform, so the user loses context.)
| |
| ::<syntaxhighlight lang="javascript" enclose="div">
| |
| var button =
| |
| '<div style="float:right;padding-right:20px"> \
| |
| <input type="button" value=" Help " \
| |
| onclick="window.open(\'/networking/page/PAGENAME.jsp\')"> \
| |
| </div>';
| |
| </syntaxhighlight>
| |
| | |
| {{Note|<br>In the button JavaScript, the path to a JSP page begins with a forward slash.<br>
| |
| But a relative link to the same page coded ''inside'' a JSP page would not have one.<br>
| |
| So the link would look like this:
| |
| :<tt><nowiki><a href="networking/page/PAGENAME.jsp>...link-text to click...</a></nowiki></tt>}}
| |
| | |
| :* '''A [[Knowledge Base]] article''' (if the [[Service Portal]] is configured)
| |
| :: Use the link-target pattern:
| |
| ::: <tt>https://{{domain}}/networking/servicedesk/index.jsp#_portal/articles/{articleID}</tt>
| |
| ::: ''Learn more:'' [[URL Addresses#KnowledgeBase Article]]
| |
| | |
| :* '''An [[Application Help Tab]]'''
| |
| :: For that option, the JavaScript code needs to find the Help tab element, and "click" on it.
| |
| :: ''Learn more:'' [[HowTo:Create Application-Specific Help]]
| |
| | |
| :* '''A JSP Page hosted in a platform [[Site]]'''
| |
| | |
| =====Add a Help Button Using a Static Resource Script=====
| |
| A useful piece of code tends to be useful in multiple forms, in multiple objects. To make the code available to every form in your system:
| |
| # Turn it into a function and store it in a <tt>.js</tt> file:
| |
| #:<syntaxhighlight lang="javascript" enclose="div">
| |
| /** | |
| * Usage: addHelpButton("target-page-URL");
| |
| */
| |
| function addHelpButton(targetURL) {
| |
| ...code goes here...
| |
| }
| |
| </syntaxhighlight>
| |
| #:
| |
| # Load the file as a [[Static Resource]].
| |
| # Use the REST static resource API to get the resource ID
| |
| # Put the following code into the form to read the file, use the JavaScript <tt>eval</tt> function to make the function available, and invoke it:
| |
| #:<syntaxhighlight lang="javascript" enclose="div">
| |
| $.get("https://{YOURDOMAIN}/networking/rest/staticResource/{RESOURCEID}?getFile=true",
| |
| function( data ) {
| |
| eval(data);
| |
| addHelpButton("YOUR HELP PAGE URL");
| |
| });
| |
| </syntaxhighlight>
| |
| | |
| :''Learn more:'' [[Static Resources#Accessing a JavaScript Resource from an Object Form]]
| |
| | |
| ====Add a Button Next to a Field in an Object Form====
| |
| This example adds a button to a standard object [[Form]], as shown here:
| |
| :[[File:FormLookupButtonAdded.png]]
| |
| | |
| The standard form is shown on the left. ON LOAD JavaScript added to it injects the button, producing the form on the right.
| |
| | |
| :<syntaxhighlight lang="javascript" enclose="div">
| |
| // Get a pointer to the current form
| |
| var form = _sdForm
| |
| | |
| try {
| |
| /*
| |
| * Find the order number field, modify it's CSS properties,
| |
| * and add a search button to the element it's contained in.
| |
| * (Each label and field is contained in it's own <div>. The
| |
| * .parent() function accesses it, and the button is added at the end.)
| |
| */
| |
| form.find("#orderNum").css( {'width': '50%',"margin-bottom":"0px"});
| |
| form.find("#orderNum").removeClass("text_box_case");
| |
| form.find("#orderNum").parent().append(
| |
| "<input type='button' id='lookup_order' name='lookup_order' value='Lookup Order'"
| |
| + "style='background: none repeat scroll 0 0 #EBEBEB;box-shadow: 0 0 0 0 #888888 inset;"
| |
| + " height: 26px;margin-top:-0px; padding: 0 8px 0 6px;"
| |
| + " margin-right:5px;margin-left:5px;' >"
| |
| ) ;
| |
| | |
| /*
| |
| * Add an anonymous function to the button to invoke the WebServiceProxy method.
| |
| */
| |
| form.find("#orderNum").parent().find("#lookup_order").click(
| |
| function()
| |
| {
| |
| // Perform some operation
| |
| alert("jQuery/Javascript placed here gets executed");
| |
| | |
| // Don't submit the input form when this particular button is clicked.
| |
| return false;
| |
| }
| |
| );
| |
| } catch (e) {
| |
| // Report JavaScript errors
| |
| alert(e);
| |
| };
| |
| </syntaxhighlight>
| |
| | |
| ;How it works:
| |
| # <tt>_sdform</tt> - A pointer to the current form
| |
| # <tt>form.find("#orderNum")</tt> - Find the order number field, using it's ID.
| |
| # <tt>.css</tt> - Define new [[CSS Styling]] for the field.
| |
| # <tt>.removeclass</tt> - Remove the reference to the CSS class currently used by the field. In this case, the field is a text field, so the class associated with that kind of field is removed. (For other field types, inspect the page to see what class is used.)
| |
| # <tt>.parent.append</tt> - Go to the div that contains the field and it's label. Append a new button to the end of it. Specify CSS styling for the button that fits into the form.
| |
| # <tt>Lookup Order</tt> - The label displayed on the button.
| |
| # <tt>find("#orderNum").parent</tt> - Find the button again, and go to the div that contains it.
| |
| # <tt>#lookup_order</tt> - Find the button we added.
| |
| # <tt>.click</tt> - jQuery function to define an "on click" event handler.
| |
| # <tt>function()</tt> - Define an unnamed ("anonymous") function that contains the combination of JavaScript and jQuery functions to execute when the click event occurs on the button.
| |
| # <tt>return false</tt> - Prevent the input button from causing the form to be submitted.
| |
| # <tt>catch (e)</tt> - Report JavaScript errors. (They occur in the browser, so they don't appear in the platform's Debug Log.)
| |
| | |
| ''Learn more:''
| |
| : For a fully worked-out example that uses this technique to access an external web service, see [[Java Code Samples#Invoke Web Services Programmatically|Invoke Web Services Programmatically]]. (The first part of that section defines a class to access the service. The last part adds a button to a form to access it.)
| |
| | |
| ====Add a Button to a Case Form====
| |
| This example adds a button to a Case details form. In this case, the button appears on the same line as the Save and [Cancel] buttons, but it is floated over to the left, as shown here:
| |
| :[[File:CaseFormButtonAdded.png]]
| |
| | |
| :<syntaxhighlight lang="javascript" enclose="div">
| |
| var html = "<div style='float:left'>"
| |
| + "<input type='button' id='customButton' value='Button Label'"
| |
| + " class='lj-button fg-button ui-state-default ui-corner-all'"
| |
| + "/></div>";
| |
| | |
| try {
| |
| $(".case_details_forms").find(".case_submit_button").parent().parent().prepend(html);
| |
| $("#customButton").click( function()
| |
| {
| |
| alert("jQuery/JavaScript code placed here executes when the button is clicked");
| |
| });
| |
| | |
| } catch (e) {
| |
| alert(e);
| |
| };
| |
| </syntaxhighlight>
| |
| | |
| ;How it works:
| |
| # <tt>html</tt> - Define a string that contains the HTML code to insert.
| |
| # <tt>div...float:left<tt> - Create a div that floats to the left, to contain the button.
| |
| # <tt>class</tt> - These CSS classes make the button appear the same as other platform buttons.
| |
| # <tt>.case_details_forms</tt> - Find the details form by it's CSS class. (Only item uses that class.)
| |
| # <tt>.case_submit_button</tt> - Find the [Save] button at the bottom of that form using it's CSS class. (Only one item uses that class.)
| |
| # <tt>.parent().parent()</tt> - Find the div that contains the button, then find the div that contains ''that'', so we can add our div to it.
| |
| # <tt>prepend</tt> - Insert our float-left div before the one that contains the buttons
| |
| # <tt>#custom_button</tt> - Find the button we just added, using it's ID.
| |
| # <tt>.click</tt> - jQuery function to define an "on click" event handler.
| |
| # <tt>function()</tt> - Define an unnamed ("anonymous") function that contains the combination of JavaScript and jQuery functions to execute when the click event occurs on the button.
| |
| # <tt>catch (e)</tt> - Report JavaScript errors. (They occur in the browser, so they don't appear in the platform's Debug Log.)
| |
|
| |
|
| ====Convert a Date==== | | ====Convert a Date==== |