Javascript Library

Extensibility
Extensibility covers the mechanisms by which you, as the user or developer, can extend the functionality of the Teradata Database, for example with the use of User Defined Functions, or UDFs.
Teradata Employee

Javascript Library

For general purpose DOM searching and manipulation, the jQuery library has been included with Teradata Viewpoint.

Additionally, some commonly needed javascript functions are gathered in the files and JS Classes below.

TDAjaxManager (CommonsWeb/TDPortalManager.js)

The TDAjaxManager class contains methods to handle AJAX requests to the server. Some of the more commonly used methods are:

  • post: Load a remote page using an HTTP POST request.
    code example

    TDAjaxManager.post("/QueriesPortlet/dataserver/clearPreferences",
    { portletName: 'myQueries', context: '${context}' },
    null,
    { target: ".removedefaultsbutton"}
    );



  • load: Load a remote page using an HTTP GET request.
    code example

    TDAjaxManager.load(url, params, function() {
    TDPortalManager.triggerPortletReady(context);
    }, { target: selector, context: context, eventType: TDActivityManager.LINK }
    );



  • getScript: Loads and executes a remote JavaScript file using an HTTP GET request.
    code example

    TDAjaxManager.getScript(url, null, { context: controller.context,
    eventType: TDActivityManager.REFRESH
    });



TDPortalManager (CommonsWeb/TDPortalManager.js)

The TDPortalManager class provides interfaces for managing the portlets in the portal. Some of the more commonly used methods are:

  • onPortletReady: The onPortletReady method registers a function to be called when the portlet is fully loaded into the page. This method should be used to register a callback that performs the initialization for a portlet screen.
    code example

    TDPortalManager.onPortletReady('${context}', function() {
    alert('portlet is ready');
    });



  • onPortletRemove: The onPortletRemove method registers a function to be called when the portlet is removed from the page. This method should be used to register a callback that performs the cleanup for a portlet.
    code example

    TDPortalManager.onPortletRemove('${context}', function() {
    alert('cleaning up');
    });



  • saveValue/getValue: The saveValue method saves a string value and the getValue method gets it.
    code example

    TDPortalManager.saveValue('${context}', "tdportal.queries.${context}.tabIndex",
    tabIndex, TDPortalManager.PERSIST_SESSION_COOKIE);

    var tabIndex = TDPortalManager.getValue('${context}', "tdportal.queries.${context}.tabIndex",
    TDPortalManager.PERSIST_SESSION_COOKIE);



  • registerPortlet: The registerPortlet method should be called once when the portlet is loaded. It associates a context name with an element on the page.
    code example

    TDPortalManager.registerPortlet("${context}", "${context}_portlet", null);



  • registerObject: The registerObject method is used to store "global" portlet objects so that portlets don't need to use javascript global variables. The portlet may obtain the object in the future by calling getObject.
    code example

    TDPortalManager.registerObject('${context}', 'viewModeURL', '${viewModeURL}');



TjsUtils (CommonsWeb/TjsUtils.js)

This collection of utility functions provides some commonly needed abilities:

  • get/set cookie
  • add/remove event handler functions
  • add/remove element class
  • get elements by class
  • get element position
  • get/set radio value
  • get selected element from a select list
  • format number
  • decimal/hex conversion functions

Some functions have parallels in jQuery.

TjsUtils also includes Javascript Date Object Extensions. These functions are analogous to the corresponding Javascript get/set commands except that they act with the knowledge of the user's configured timezone.

  • setLocalFullYear(y[,m,d]) - Sets the local year (and optionally month and day of the month).
  • setLocalMonth(m[,d]) - Sets the local month (0-11, and optionally day of the month).
  • setLocalDate(d) - Sets the local day of the month.
  • setLocalHours(h[,m,s,ms]) - Sets the local hour field (and optionally minutes, seconds, and milliseconds fields) --
  • setLocalMinutes(m[,s,ms]) - Sets the local minutes field (and optionally seconds and milliseconds fields) --
  • setLocalSeconds(s[,ms]) - Sets the local seconds field (and optionally the milliseconds field) --
  • setLocalMilliseconds(ms) - Sets the local millisecond field
  • getLocalFullYear() - Returns the local full year.
  • getLocalMonth() - Returns the local month (0-11)
  • getLocalDate() - Returns the local day of the month.
  • getLocalDay() - Returns the local day of the week.
  • getLocalHours() - Returns the local hour field.
  • getLocalMinutes() - Returns the local minutes field.
  • getLocalSeconds() - Returns the local seconds field.
  • getLocalMilliseconds() - Returns the local milliseconds field.

format(type) - The Date.format extension provides a standardized way to display a large number of date formats. You specify which fields you wish to display and format() will display them in the appropriate order and with the correct separators, as per the user's profile.  For example, for FR (France), dates are printed as dd/MM/yyyy while for US, dates are printed as MM/dd/yyyy.

"Ymdhms" full year, month, day, hours, minutes, seconds

"Ymdhm" full year, month, day, hours, minutes

"Ymdh" full year, month, day, hours

"Ymd" full year, month, day

"ymdhms" year, month, day, hours, minutes, seconds

"ymdhm" year, month, day, hours, minutes

"ymdh" year, month, day, hours

"ymd" year, month, day

"mdhms" month, day, hours, minutes, seconds

"mdhm" month, day, hours, minutes

"mdh" month, day, hours

"md" month, day

"hms" hours, minutes, seconds

"hm" hours, minutes

"h" hours, am/pm

"Month" long month, eg. March

"month" short month, eg. Mar

"Day" long day of the week, eg. Sunday

"day" short day of the week, eg. Sun

"Date" full year, month, day

"date" year, month, day

"time" hours, minutes, seconds

format() supports custom formatters as per datejs. For example, "MMMM d tt" could return "March 9 PM"

TjsValidator (CommonsWeb/TjsValidator.js)

This utility is used for validation, mostly client-side, of form input fields. The available client-side validation rules are listed here:

  • alpha - Return true if the value contains only alpha characters (a-z).
  • alphaFirst - Return true if the value begins with an alpha character followed by alpha-numerics.
  • alphaNumericSpace - Return true if the value contains only alpha-numeric characters, including underscore and spaces.
  • alphanumeric - Return true if the value contains only alpha-numeric characters, including underscore.
  • checkMetrics - Return true if there is at least one div element in the specified container.
    • Used for drag-n-drop elements where at least one metric must be included.
  • dependsOn - Return true if the field is not empty or if the specified element is empty. If the specified element is not empty, then this field is required, otherwise this field is optional.
  • greaterThan - Return true if the value is greater than the value in the specified element.
  • hostname - Return true if the value contains a valid hostname consisting of alpha-numerics and periods with optional port number at the end.
  • lessThan - Return true if the value is less than the value in the specified element.
  • minMetrics - Return true if the number of metrics is greater than or equal to the specified minimum.
    • Used for metrics checkboxes where a minimum number of metrics must be checked.
  • minSystems - Return true if the number of systems is greater than or equal to the specified minimum.
    • Used for systems checkboxes where a minimum number of systems must be checked.
  • minUsers - Return true if the number of users is greater than or equal to the specified minimum.
    • Used for user checkboxes where a minimum number of users must be checked IF the specified system checkbox is checked.
  • noSingleQuote - Return true if the value does not contain any single quotes.

In addition, the jQuery validate library (CommonsWeb/jquery.validate.js) contains several common validation rules as well:

  • accept - Returns true if the value ends with one of the specified file extensions. If nothing is specified, only images are allowed (default-param: "png|jpe?g|gif")
  • creditcard - Return true if the value is a valid credit card number.
  • date - Return true, if the value is a valid date. Uses JavaScripts built-in Date to test if the date is valid, and is therefore very limited.
  • dateDE - Return true, if the value is a valid date. Supports German dates (29.04.1994 or 1.1.2006). Doesn't make any sanity checks.
  • dateISO - Return true, if the value is a valid date, according to ISO date standard.
  • digits - Returns true if the value contains only digits.
  • email - Return true, if the value is a valid email address.
  • equalTo - Returns true if the value has the same value as the element specified by the first parameter.
  • max - Return true, if the value is less than or equal to the specified maximum.
  • maxlength - Return false, if the element is:
    • some kind of text input and its value is too big
    • a set of checkboxes and has too many boxes checked
    • a select and has too many options selected
  • min - Return true, if the value is greater than or equal to the specified minimum.
  • minlength - Return false, if the element is:
    • some kind of text input and its value is too short
    • a set of checkboxes and has not enough boxes checked
    • a select and has not enough options selected
  • number - Return true, if the value is a valid number. Checks for international number format, eg. 100,000.59
  • numberDE - Return true, if the value is a valid number. Checks for European style numbers (100.000,59)
  • range - Return true, if the value is in the specified range.
  • rangelength - Return false, if the element is:
    • some kind of text input and its value is too short or too long
    • a set of checkboxes and has not enough or too many boxes checked
    • a select and has not enough or too many options selected
  • required - Return false if the element is empty.
  • url - Return true, if the value is a valid url.
Tags (2)