Document toolboxDocument toolbox

Javascript helper functions

Screen block

blockScreen(message, callback, speed)

Blocks the screen with a progress indicator, and displays the given message. If no message is provided “Please wait” is displayed. This should be used when initializing long procedures, to prevent users from clicking several times in the interface. An optional callback can be provided, which will be called when the block animation completes.

blockScreenProgress(percentage)

The progress indicator can display a progress bar.

blockScreenPercentage(percentage)

Like blockScreenProgress() but also displays the numerical value.

unblockScreen

Unblocks the screen as a response to a previously called blockScreen. The screen is automatically unblocked when loading a new page, so this function is only useful when blockScreen has been used during an in-page operation

Misc

number = unformatnumber(formattednumber)

1024 = unformatnumber('1.024');
0 = unformatnumber('invalid');

formattednumber = formatnumber(number)

'1.024' = formatnumber(1024)

distance = calc_distance(latitude1, longitude1, latitude2, longitude2)

Calculate the distance in meters between two lat/lon coordinates.

list2checkbox(list, checkboxes)

Check all checkboxes which values are on the list provided, and unchecking everything else.

1 list2checkbox('1,2', $('input[type=”checkbox”]'));

This will check every checkbox where value is either 1 or 2.

list = checkbox2list(checkboxes)

Gather the values from all checked checkboxes and arrange them in a comma-separated list.

array = list2array(list)

Converts a list of comma-seperated values to an array with the same values

list = array2list(array)

Arranges the values of an array in a comma-separated list.

inarray(element, array)

Returns true if element is in array, otherwise false.

text = htmlentities(html)

Escapes < > and “ with html entities

text = html_decode_entities(text)

Decodes &xxx; encoded characters.

printContent(jqueryselector, stylesheet)

Spawns a popup window, and a print dialog, printing the content of the first matched element of the provided jQuery selector. If a stylesheet is required for proper printing, it can be provided also.

UI
progressbar(width,height,data,options)

Similar to the bar() in PHP.

Forms

iframe_submit(form, script, opts)

Submits the form to the specified script; the result is sent to an iframe. This allows posting results from forms which include <file>. See script/iframesubmit.js for details.

form_set_select(selector, val)

Set the value of a FSelect element or of a FDoubleSelect element.

Dates

All sorts of date and time handling is found in /script/dates.js.

Formatting

dates_time2minutes(clock)
dates_minutes2duration(time)
dates_validate_duration(str, allownegative)
dates_validate_time(str)
dates_validate_date(str)
dates_formattime(val, type, secs)
dates_formatdate(d)
dates_unformatdate(d)

Date picker

dates_init_datepickers(part)

dates_hide_datepicker()
dates_open_datepicker(date, x, y, cb)

Workdays

dates_set_default_workdays(wds)
dates_is_workday(date, validdates)
dates_diff_workdays(firstdate, lastdate, validdates)
dates_next_workday(date, validdates)
dates_add_workdays(date, days, validdates)

Names

dates_get_monthname(mn)
dates_get_short_monthname(mn)
dates_get_dayname(d)
dates_get_short_dayname(d)

Time

dates_seconds_since_midnight()
dates_timestamp()
dates_ms()

dates_now()

Misc

dates_add(date, days, months, years)
dates_timestamp2date(ts)

dates_use_iso8601()
dates_diff_days(firstdate, lastdate, validdates)
dates_normalize(dt)
dates_validate(dt)
dates_today()
dates_date2timestamp(date)
dates_split(date, extendedinfo)
dates_get_weekday(date)

validdates

Some of the functions support a parameter named validdates, which can list which dates should be included in calculation of differences between dates. This parameter can have the following values:

value

meaning
"default"Use the value set by the previous call to dates_set_default_workdays()
"mon-fri"Use only Monday to Friday in the calculations, eg. there is only 5 days from a Tuesday and until the next Tuesday
object

This is an object hashed by years, eg. 2020, 2021, 2022 etc. The value specifies the valid dates for each year; this may either be a list of dates (e.g. ['2020-01-01','2020-01-02','2020-01-04',...] ), or the string "mon-fri".

Sorting

The class SorterDialog() displays a dialog for sorting elements. See details in the javascript source.