zpm.js Documentation

General purpose library for the ZPM.Net framework.

General void .AjaxCallbackTimer(methodUrl, waitSeconds)

Parameter methodUrl is the server method being called. This is only used to display a message if timeout occurs (server doesn't respond)
Parameter waitSeconds (optional, default is 30) is how many seconds to wait for an ajax call to the server to respond.

This function will will inhibit user input, display a busy spinner and calls .AjaxCallbackCheck() every 100 milliseconds until all ajax calls have completed. See Internal below.

General void .AppendDialog()

Used by zpm.ErrorDialog(). Adds a div to the current page for use by jQuery .dialog().

General string .BlankIfNull(str)

returns empty string (blank) if parameter str is null.

General string .FormatDate(dt)

Returns a string, in the format MM/DD/YYYY if the date is valid, otherwise "". Parameter dt can be ""(blank), null, a javascript date, a json date

General string .FormatNumber(num, decimals(optional)) - returns a string formatted with floating or fixed decimal places

Returns string representation of a number.
If num is zero or null, returns "".
If decimals is not specified, returns num.toString() (floating decimal point).
If decimals is specified, returns num.toFixed() where the string has a fixed number of decimal positions.

General int .GetInteger(i) - converts string to integer

If parameter i is '' or null, returns 0.
if parameter i is an invalid number, returns null.

General number .GetNumeric(n, decimals) - converts string to numeric, rounding to a fixed number of decimals (optional)

If parameter i is '' or null, returns 0.
if parameter i is an invalid number, returns null.
If parameter decimals is specified, the number returned is rounded to the number of decimals specified.

General bool .IsNumeric(n)

Parameter n is a string.
Returns true if n can be converted to a number.

General void .ScrollIntoView($element, $container) - Scroll table so a row of that table is in view.

Parameter $element is a jQuery selector of a table row.
Parameter $container is a jQuery selector of a table.
ScrollIntoView() will scroll the table so the row is visible.

General int[ ] .StringArrayToInt(strArray) - converts string array to integer array

Returns an integer array build from the string arrry strArray.
Parameter strArray is a string array. All values in strArray are assumed to be valid numbers (no checking is performed).

General string .ValidFileName(name) - reject names with invalid characters for a filename.

Parameter name is a file name (string).
Returns empty string if parameter name doesn't contain invalid characters.
If invalid characters are found it returns an error message.

Date Picker struct .DatePickerOptions - defaults used for the jQuery Datepicker widget

dateFormat: "mm/dd/yy"
onSelect: this.DatePickerOnSelect - call this zpm method when a date is selected
showOtherMonths: true
selectOtherMonths: true
beforeShow: this.DatePickerBeforeShow - call this zpm method before showing the Datepicker pop-up.

Date Picker void.DatePickerBeforeShow(textbox, instance)

Used internally by DatePicker.

Date Picker void .DatePickerOnSelect(dateText, inst)

Used internally by DatePicker.

Fixed Heading void .FixedHeading($tbl) - Converts the first row of a html table to a fixed heading.

Parameter $tbl is a jQuery selector of a table with a heading row.
The first row of the table must be a heading row with th elements that are modified such that the heading row is fixed and will not move vertically when the table is scrolled.

Any styling must be applied to an inclosed div and not to the th element. For example, <th style="color:blue">Title</th> must be changed to <th><div style="color:blue">Title</div></th>

If table data is changed after calling FixedHeading(), call FixedHeadingAlign() to realign headings with data.

Fixed Heading void .FixedHeadingAlign($tbl) - Call this whenever the content of a fixed heafing table changes.

Parameter $tbl is a jQuery selector of a table with a heading row.
Call this function after rows or cells for a table have changed to realign the heading with data rows.
FixedHeading() must have already been called on this table.

Fixed Heading void .FixedHeadingScroll(e) - called whenever a fixed heading table scrolls.

Used internally by FixedHeading. FixedHeadingScroll() is called whenever the table is scrolled horzontally.

Fixed Heading bool .MoveCss(style, newFromValue, $from, $to) - move css style from one element to another.

Used internally by FixedHeading.

Fixed Heading bool CopyCss(style, $from, $to) - copy css style from one element to another.

Used internally by FixedHeading.

Html Table Sort void .TableSort(th, fnSort)

Sorts a table by the heading column clicked on. If the table is already sorted on that column, it toggles assending/desending order.

Parameter th - th element user clicked on.
Parameter fnSort - optional, function to use for sorting column th. The default function is RowTextCompare().

Heading cell should look like: <th onclick="zpm.TableSort(this);">Customer Name</th>.
Use zpm.TableSort(this, myFunction) to customize sorting (see RowTextCompare()).

Html Table Sort void .TableSortDefaults($table, columnIndex, assending)

TableSort assumes rows are presorted by the first column, in assending order. Call this function to alter that assumption.
Parameter $table - jQuery selector to the table.
Parameter columnIndex - index (first one is 0) of the column the table is sorted by when initially loaded by the application.
Parameter assending - true if initially sorted assending, or false for desending.

Html Table Sort void .TableReSort($table)

Call this function to resort the table after a change to the rows or columns. It will resort the table according to the default or last sort.
Parameter $table - jQuery selector to the table.

Html Table Sort int .RowTextCompare(a, b, columnIndex, assending)

Used by TableSort() to sort text data.
Use this as a template to sort numbers, dates or for custom sorting.
Returns -1 if a<b, 0 if a=b, 1 if a>b.

Number Extension string Number.prototype.numberWithCommas(decimals)

Extends the javascript Number class.
Parameter decimals - number of decimal positions in formatted output.
Converts number to string with commas and fixed number of decimals. Usage: var n = 123.99; var text = n.numberWithCommas(2);

String Extension string String.prototype.replaceAll(search, replacement)

Extends the javascript String class.
This is the same as string.replace, except it replaces all occurances, not just the first one.

String Extension string String.prototype.padLeft(len, c)

Extends the javascript String class.
Parameter len - length of the returned string.
Parameter c - (optional) character to pad the string with. Default is a space
Returns a string padded on the left to length len with character c.

String Extension string String.prototype.padRight(len, c)

Extends the javascript String class.
Parameter len - length of the returned string.
Parameter c - (optional) character to pad the string with. Default is a space
Returns a string padded on the right to length len with character c.

Internal void .AjaxCallbackCheck(startTime)

This is used by .AjaxCallbackTimer(), and should not be called directly. It checks to see if all ajax calls have completed and updates the seconds counter. If all ajax calls have completed, it closes the busy spinner and restores user input.