JSmart functions

JSmart integrates with JQuery v1.11.2 and Bootstrap v3.3.5 JavaScript and besides that we provide useful JavaScript functions to help working with some complex components on client side. In case you want to work with other basic components interaction we advice you to use JQuery or Bootstrap capabilities directly.

To use JSmart functions you can call it via reserved object referenced as JSmart on your script. For JQuery capabilities please have a look at JQuery page or for Bootstrap JavaScript look at Bootstrap page.

Please have a look on the following available functions.

/*!
 * In case you implemented WebSecurity you can retrieve the CSRF token name generated to
 * current page, please use the following function.
 */
JSmart.getCsrfName();

/*!
 * In case you implemented WebSecurity you can retrieve the CSRF token value generated
 * to current page, please use the following function.
 */
JSmart.getCsrfToken();

/*!
 * In case you want to set the CSRF token name and value in your Ajax request as headers
 * please use the following function.
 */
JSmart.setCsrfHeader(xhr);

/*!
 * Validate function is useful for validating components such as form, input, textarea, select,
 * upload, checkbox, checkgroup or radiogroup. This function also returns true if the component
 * specified is validated or false otherwise.
 *
 * To be able to use this function the component tag must contain the validate tag as inner tag.
 * Please refer to Components page for more details.
 */
JSmart.validate('component-id');

/*!
 * Abort request function is available for stopping Ajax request initiated by some component such
 * as button, link or any component containing the ajax tag as inner tag.
 */
JSmart.abortRequest('component-id');

/*!
 * Create row function is meant to be used along with table or list components which must contain
 * internal row tag for lists or internal column tags for tables.
 * For list components each row declaration is considered as a template id starting by zero, for
 * tables there is only the template 0 (zero).
 *
 * In case the rowMode of table or list is append this function appends a row at the
 * end of component and returns it as result JQuery object.
 *
 * In case rowMode of table or list is section this function appends a row at the end
 * of the section indicated by template-index argument and return the created row as JQuery object.
 *
 * Note that for the returned row you must include an attribute name and value for you to keep
 * track of it when calling "getRow" function.
 */
JSmart.createRow('list-or-table-id', template-index);

/*!
 * As createRow function, this function was created to work along with table or list components
 * which must contain internal row tag for lists or internal column tags for tables.
 *
 * This function returns a row object based on attribute name and value you have included on
 * row object while creating it. Any changes made on returned object via JQuery will reflect on
 * the list or table in which the row was appended.
 */
JSmart.getRow('list-or-table-id', 'my-attr="my-key"');

/*!
 * Also this function was created to work along with table or list components which must contain
 * internal row tag for lists or internal column tags for tables.
 *
 * This function returns all created rows for specified template in array object so you can iterate
 * over all rows.
 */
JSmart.getAllRows('list-or-table-id', template-index);

/*!
 * The removeRow function is very similar as the function getRow so it was created to work along
 * with table or list components which must contain internal row tag for lists or internal column
 * tag for tables.
 *
 * This function removes a row object based on attribute name and value you have included on
 * row object while creating it.
 */
JSmart.removeRow('list-or-table-id', 'my-attr="my-key"');

/*!
 * Clear function was created to work on table or list components in case you need to clear its
 * content and preserve the templates, empty content and loading behavior.
 */
JSmart.clear('list-or-table-id');

/*!
 * The refresh function was created to work on table components in case you need to resize it
 * due to layout changes or window resize.
 */
JSmart.refreshTable('table-id');

/*!
 * Show empty function also is meant to be applied on table or list components to present empty
 * content message inside it. Note that to use this function your list or table component must
 * declare inner tag empty as inner tag. Please refer to Components page for more details.
 */
JSmart.showEmpty('list-or-table-id');

/*!
 * Hide empty function is meant to be applied on table or list components to hide empty
 * content message inside it. Note that to use this function your list or table component must
 * declare inner tag empty as inner tag. Please refer to Components page for more details.
 */
JSmart.hideEmpty('list-or-table-id')

/*!
 * This function is also mean to be used along with table or list components to check if its
 * content is empty besides the present of loading, empty or template components.
 */
JSmart.isEmpty('list-or-table-id');

/*!
 * This function is useful in case you want to present the load component you have placed in
 * your page. This load component can be placed inside button, link, table, list or any other
 * supported component even outside them. Please refer to Components page for more details.
 */
JSmart.showLoad('load-id');

/*!
 * This function is useful in case you want to hide the load component you have placed in
 * your page. This load component can be placed inside button, link, table, list or any other
 * supported component even outside them. Please refer to Components page for more details.
 */
JSmart.hideLoad('load-id');

/*!
 * Get date is useful to return a Date selected as string from date component that is integrated
 * with Bootstrap.
 */
JSmart.getDate('date-id');

/*!
 * Set date is useful to set a Date selection on date component that is integrated with Bootstrap.
 */
JSmart.setDate('date-id', time-string-or-number);

/*!
 * Get checkgroup is useful to return an Array of selected values from checkgroup component that
 * is integrated with Bootstrap.
 */
JSmart.getCheckGroup('checkgroup-id');

/*!
 * Set checkgroup is useful to set an Array as selected values on checkgroup component that is
 * integrated with Bootstrap.
 */
JSmart.setCheckGroup('checkgroup-id', [array-of-values]);

/*!
 * Get radiogroup is useful to return the selected value from radiogroup component that is
 * integrated with Bootstrap.
 */
JSmart.getRadioGroup('radiogroup-id');

/*!
 * Set radiogroup is useful to set value selection on radiogroup component that is integrated
 * with Bootstrap.
 */
JSmart.setRadioGroup('radiogroup-id', value);

/*!
 * Set progressbar was created to set the progress level on progressbar component by starting
 * its animation which is integrated with Bootstrap.
 */
JSmart.setProgressBar('progress-bar-or-group-id', value);

/*!
 * Useful function to show modal from Bootstrap by its id with additional callback functions
 * declaration to be called when modal is show and when it was shown. In case you need more
 * capabilities please refer to integrated Bootstrap JavaScript functions.
 */
JSmart.showModal('modal-id', onShow, onShown);

/*!
 * Useful function to hide modal from Bootstrap by its id with additional callback functions
 * declaration to be called when modal is hide and when it was hidden. In case you need more
 * capabilities please refer to integrated Bootstrap JavaScript functions.
 */
JSmart.hideModal('modal-id', onHide, onHidden);

/*!
 * Useful function to present alert from Bootstrap by its id. So you can update and show alerts
 * via JavaScript by specifying alert id, message and type of alert as minimum requirements.
 * It is also possible to specify header title and css icons such as glyphicons.
 */
JSmart.showAlert('alert-id', 'alert-msg', 'error|info|success|warning', 'head-title', 'head-icon');

/*!
 * Useful function to hide alert from Bootstrap by its id. Note that by hiding the alert all
 * alert content such as message, type, header and icon will be cleared.
 */
JSmart.hideAlert('alert-id');

/*!
 * Function to get exposed attribute value from annotated WebBean class to the current page
 * where the bean is present, so you can access the value directly via JavaScript.
 * To expose your attribute value just annotate it with @ExposeVar, for more details refer to
 * Documentation page.
 */
JSmart.getExposeVar('attribute_name');