Jrapid-runtime.js

From JRapid

Jump to: navigation, search

Contents

Introduction

Contains functions used to open and include listings and forms.

Including the Libraries

This library is included in every generated JRapid HTML file by default, but if you create your own custom front-end files you should remember to include them if you are planning to include JRapid forms or listings in it.

You do this by using the <script> HTML tag. You can point its src attribute to the jrapid-runtime.js included in your project using a relative URL, or to a copy of the library publicly available at JRapid's CDN.

Note that this file may change according to the version of your JRapid project. When you update your project's version the new file is automatically copied to the '/WebContent/jrapid-runtime' folder. The request parameter v, in the location relative to the project's root is used to force browsers to update the file when the version is changed. The CDN includes the version in its own URL.

When using the jrapid-runtime.js you need to include the jrapid-tags.js library too, a it is a dependency.

Project's location:

<script type="text/javascript" src="../jrapid-runtime/jrapid-runtime.js?v=1.0nb80">/**/</script>
<script type="text/javascript" src="../jrapid-runtime/jrapid-tags.js?v=1.0nb80">/**/</script>

CDN:

//REPLACE {VERSION} with your project's JRapid version. eg.:1.0nb80
<script type="text/javascript" src="http://js.jrapid.net/{VERSION}/jrapid.min.js">/**/</script>

The CDN version is actually a minified version of the jrapid-runtime.js and jrapid-tags.js files merged in a single file.

The 'jrapid.form()' and 'jrapid.listing()' functions described below fetch the corresponding HTML file contents and insert them on the page. These files are the generated form or listing that already include the necessary <script> and <link> HTML tags to import other external JavaScript libraries and stylesheets. As they are inserted into the page, these other libraries and stylesheets are loaded by the browser too. This makes the imported form or list have the same look and feel as it would if opened or included through the standard generated application workflow. Keep this in mind if you wish to modify the style of an element as you will need to override the one defined in this imported stylesheet.

jrapid.form()

Forms can be included in any HTML file (or JSP, PHP, etc.) by using the jrapid.form() function of the jrapid-runtime JavaScript library.

For example, to open an Employee's form you can use the following.

jrapid.form( {
    entity: 'Employee', 
    canvas: 'canvas',
    target: 'replace',
    handler: function() { $('input,select')[0].focus(); }
});


This function can take the following parameters:

  • url: if the function is used from within a page located in a custom folder, this parameter must be used to specify the relative path to the '/WebContent' folder. In other words, the function assumes it is being called from within a first level folder inside the '/WebContent', such as '/WebContent/Main'.
  • module: module to which the entity belongs. Value 'Main', the default, is correct, unless your project is composed of more than one module.
  • entity: the entity's form to be opened.
  • obj: DOM element that triggers the action. This is used as a reference to find a related listing that must be refreshed after submitting the form.
  • target: specifies whether the new form should replace existing one or be appended. Possible values: 'window', 'append', 'replace', 'insert', 'href'.
  • defaultset: name of the defaultset to be used when opening the form.
  • defaultsetparams: parameteres for the specified defaultset. For multiple params, use a JavaScript Array.
  • canvas: specifies the place holder for the form.
  • repeat: if this parameter is present, the form is cleared and kept open after submit.
  • handler: function called when form is opened and the form elements are already added to the DOM document

The window value of the target parameter opens the new form as a floating draggable window. This is the default value for this parameter. Every other value opens the form including it as plain HTML form inside the canvas element, or in the place where the jrapid.form() function is called.

jrapid.listing()

Listings can be included in any HTML file (or JSP, PHP, etc.) by using the jrapid.listing() function of the jrapid-runtime JavaScript library.

For example, to open an Employee's default listing you can use the following.

jrapid.listing( {
    entity: 'Employee',
    canvas: 'list_placeholder',
    module: 'Main',
    target: 'replace'
});

This function can take the following parameters:

  • module: module to which the entity belongs. Value 'Main' is correct, unless your project is composed of more than one module.
  • entity: the entity's listing to be opened.
  • defaultset: name of the defaultset to be used when opening the form.
  • defaultsetparams: parameteres for the specified defaultset.
  • canvas: specifies the place holder for the form.
  • listing: name of a listing other than the default to be opened.
  • subset: name of the subset used by the listing, followed by '/' and a subsetparam value if required.
  • defaultset: name of the defaultset used by the listing.
  • defaultsetparams: parameters for the defaultset if required.

The target parameter behaves in the same way it does for the jrapid.form() function.

Listing other than default with subset

If you have the following Employee entity and wish to include the other listing with using the corresponding 'nestedProperties' subset, this is how you should use the jrapid.listing() function.

<entity label="Employee" menu="Menu" name="Employee">
        <subset displayproperties="firstName,lastName,company.name,company.country.countryName"
             name="nestedProperties"/>
        <defaultset name="myDefaultset">
            <param name="myParam"/>
            <default name="firstName" value="myParam"/>
        </defaultset>
        <listing displayproperties="firstName,lastName,company.name,company.country.countryName"
             name="other" subset="nestedProperties" view="table"/>

        <property display="primary" label="First Name" name="firstName"/>
        <property display="primary" label="Last Name" name="lastName"/>
        <property display="secondary" entity="Company" label="Company" name="company"/>
        <property display="secondary" label="Email" name="email"/>
</entity>

<entity label="Company" menu="Menu" name="Company">
        <property display="primary" label="Name" name="name"/>
        <property display="secondary" entity="Country" label="Country" name="country"/>
</entity>

<entity label="Country" menu="Menu" name="Country">
        <property display="primary" label="Name" name="countryName"/>
</entity>
jrapid.listing( {
    entity: 'Employee',
    module: 'Main',
    target: 'replace',
    listing: 'other',
    subset: 'nestedProperties'
});


jrapid.filter()

Filter functionality can be applied through the use of this function.

jrapid.filter(property, value, me, op);

Parameters:

  • property: name of the property on which to apply the filter
  • value: value to use when applying the filter.
  • me
  • op

jrapid.order()

Apply ordering on lists using this function.

jrapid.order(obj, label, ev);

Parameters:

  • obj
  • label
  • ev


See also

Personal tools