Difference between revisions of "JavaScript built-in Lianja/VFP functions"

From Lianjapedia
Jump to: navigation, search
(Lianja Web Client built-in Lianja/VFP functions)
(Lianja JavaScript built-in LianjaScript functions)
 
(26 intermediate revisions by 2 users not shown)
Line 1: Line 1:
==Lianja Web Client built-in Lianja/VFP functions==
+
{{DISPLAYTITLE:JavaScript built-in LianjaScript functions}}
 +
==Using Global Variables in Lianja/JavaScript==
 +
Lianja.public is an object containing global/public variables and is supported on desktop and web/mobile, e.g.
 +
<pre>Lianja.public.mytext = "hello world";
 +
Lianja.public.num = 10;</pre>
  
The following Lianja/VFP functions are included in the Lianja HTML5 Client API for JavaScript.
+
==Lianja JavaScript built-in LianjaScript functions==
  
<div style="height:90px;margin-bottom:5px;padding:5px;border:0px solid orange;border-left:5px solid orange;background:#fff8dc;vertical-align:middle;position:relative;">
+
<div style="height:60px;margin-bottom:5px;padding:5px;border:0px solid orange;border-left:5px solid orange;background:#fff8dc;vertical-align:middle;position:relative;">
 
[[File:bm-noteicon.png|top|40px|link=]]<div style="position:absolute;top:3px;margin-bottom;bottom:5px;margin-left:50px;"><b> Pro Tip</b>
 
[[File:bm-noteicon.png|top|40px|link=]]<div style="position:absolute;top:3px;margin-bottom;bottom:5px;margin-left:50px;"><b> Pro Tip</b>
As of Lianja 5, you can use <b>console.log(text)</b> to help debug your code in desktop, web and mobile Apps. Previously this was not available in desktop Apps.<br>
+
As of Lianja v8.0, JavaScript delegates (desktop and web) can reference the UI element for the delegate using '''this'''.
Additionally, if you place the keyword <b>debugger</b> in your JavaScript code the JavaScript debugger will be activated.
+
 
</div>
 
</div>
 +
<span style="height:6px;"> </span>
 
</div>
 
</div>
 +
 +
<div style="height:110px;margin-bottom:5px;padding:5px;border:0px solid orange;border-left:5px solid orange;background:#fff8dc;vertical-align:middle;position:relative;">
 +
[[File:bm-noteicon.png|top|40px|link=]]<div style="position:absolute;top:3px;margin-bottom;bottom:5px;margin-left:50px;"><b> Pro Tip</b>
 +
As of Lianja 5, you can use <b>console.log(text)</b> to help debug your code in desktop, web and mobile Apps.<br>Previously this was not available in desktop Apps.<br>
 +
Additionally, if you place the keyword <b>debugger</b> or the function <b>debug()</b> in your JavaScript code the JavaScript debugger will be activated.
 +
</div>
 +
</div>
 +
 +
The following LianjaScript functions are built into Lianja JavaScript.
  
 
{| class="wikitable" width="100%"
 
{| class="wikitable" width="100%"
Line 26: Line 39:
 
|-
 
|-
 
|valign="top"|between()||valign="top"|value as expression,<br>low as expression,<br>high as expression||valign="top"|Function to check that a given value is within a given range.
 
|valign="top"|between()||valign="top"|value as expression,<br>low as expression,<br>high as expression||valign="top"|Function to check that a given value is within a given range.
 +
|-
 +
|valign="top"|browse()||valign="top"|title as string,<br>database as string,<br>table as string,<br>[filter as string,]<br>[columns as string,]<br>[onDblClick as function]||valign="top"|Browse a grid of columns of the filtered records from the specified database table.<br>The onDblClick callback function is called with one argument, an object for the active row in the grid.
 
|-
 
|-
 
|valign="top"|cdow()||valign="top"|source as date||valign="top"|Function to return the day of the week from the specified date as a string.
 
|valign="top"|cdow()||valign="top"|source as date||valign="top"|Function to return the day of the week from the specified date as a string.
 
|-
 
|-
|valign="top"|choose()||valign="top"|index as numeric,<br>value as expr<br>[, ...]<br>||valign="top"|Returns the nth argument in the argument list. The first index is 1. If index is out of bounds  returns an empty string.
+
|valign="top"|choose()||valign="top"|index as numeric,<br>value as expr<br>[, ...]<br>||valign="top"|Returns the nth argument in the argument list.<br>The first index is 1.<br>If index is out of bounds  returns an empty string.
 
|-
 
|-
 
|valign="top"|chrtran()||valign="top"|source as string,<br>find as string,<br>replacewith as string||valign="top"|Function to replace text within a string.
 
|valign="top"|chrtran()||valign="top"|source as string,<br>find as string,<br>replacewith as string||valign="top"|Function to replace text within a string.
 +
|-
 +
|valign="top"|clear_events()||valign="top"|none||valign="top"|Stops event processing started with read_events() (desktop only).
 
|-
 
|-
 
|valign="top"|cmonth()||valign="top"|source as date||valign="top"|Function to return the month from the specified date as a string.
 
|valign="top"|cmonth()||valign="top"|source as date||valign="top"|Function to return the month from the specified date as a string.
 
|-
 
|-
|valign="top"|createObject()||valign="top"|class as string||valign="top"|Create new object based on the specified UI class.
+
|valign="top"|createObject()||valign="top"|class as string||valign="top"|Create new object based on the specified UI class. See [[:Category:Framework_Classes|Working with Framework Classes]]
 
|-
 
|-
 
|valign="top"|ctod()||valign="top"|source as string||valign="top"|Function to return the specified string as a date.
 
|valign="top"|ctod()||valign="top"|source as string||valign="top"|Function to return the specified string as a date.
 
|-
 
|-
 
|valign="top"|currency()||valign="top"|value as numeric, <br>decimals as numeric||valign="top"|Function to return the specified numeric value formatted as a currency value.
 
|valign="top"|currency()||valign="top"|value as numeric, <br>decimals as numeric||valign="top"|Function to return the specified numeric value formatted as a currency value.
 +
|-
 +
|valign="top"|database()||valign="top"|none||valign="top"|Returns the name of the current database.
 
|-
 
|-
 
|valign="top"|date()||valign="top"|[year as numeric,<br>month as numeric,<br>day as numeric]||valign="top"|Function to return system or the specified date as a date.
 
|valign="top"|date()||valign="top"|[year as numeric,<br>month as numeric,<br>day as numeric]||valign="top"|Function to return system or the specified date as a date.
Line 46: Line 65:
 
|-
 
|-
 
|valign="top"|dow()||valign="top"|source as date||valign="top"|Function to return the day of the week from the specified date as a numeric.
 
|valign="top"|dow()||valign="top"|source as date||valign="top"|Function to return the day of the week from the specified date as a numeric.
 +
|-
 +
|valign="top"|dtoa()||valign="top"|source as date||valign="top"|Function to return the specified date as a string in the format YYYY-MM-DD.
 
|-
 
|-
 
|valign="top"|dtoc()||valign="top"|source as date||valign="top"|Function to return the specified date as a string.
 
|valign="top"|dtoc()||valign="top"|source as date||valign="top"|Function to return the specified date as a string.
Line 58: Line 79:
 
|-
 
|-
 
|valign="top"|explode()||valign="top"|separator as expression,<br>string as expression||valign="top"|Returns an array by splitting the given string up as specified by the given separator.
 
|valign="top"|explode()||valign="top"|separator as expression,<br>string as expression||valign="top"|Returns an array by splitting the given string up as specified by the given separator.
 +
|-
 +
|valign="top"|format()||valign="top"|source as string,<br>arg1 as expression,<br>..., argN as expression||valign="top"|Returns a string formatted with a variable list of arguments.  See [[FORMAT()]] for examples.
 
|-
 
|-
 
|valign="top"|function_exists()||valign="top"|arg as string||valign="top"|Returns true if the specified function is declared.
 
|valign="top"|function_exists()||valign="top"|arg as string||valign="top"|Returns true if the specified function is declared.
 +
|-
 +
|valign="top"|getfile()||valign="top"|[arg as function]||valign="top"|The getfile() function returns the file selected as a character string. In web/mobile this is async so you should specify a callback function e.g. <pre>getfile(function(filename) {console.log(filename);})</pre>
 +
|-
 +
|valign="top"|gmtime()||valign="top"|none||valign="top"|Returns the current datetime in the GMT/UTC timezone.
 
|-
 
|-
 
|valign="top"|guid()||valign="top"|none||valign="top"|Returns a GUID.
 
|valign="top"|guid()||valign="top"|none||valign="top"|Returns a GUID.
Line 95: Line 122:
 
|valign="top"|is_string()||valign="top"|arg as expression||valign="top"|Returns true if the given arg is a string.
 
|valign="top"|is_string()||valign="top"|arg as expression||valign="top"|Returns true if the given arg is a string.
 
|-
 
|-
|valign="top"|keyLookup()||valign="top"|database!table as string,<br>tag as string,<br>keyexpr as expr,<br>valueexpr as expr,<br>notfoundexpr as expr,<br>resultexpression as expr||valign="top"|Performs a cross table lookup.
+
|valign="top"|keyLookup()||valign="top"|database!table as string,<br>tag as string,<br>keyexpr as expr,<br>valueexpr as string,<br>notfoundexpr as string||valign="top"|Performs a cross table lookup.
 
|-
 
|-
 
|valign="top"|len()||valign="top"|source as expr<br>[, options as logical]||valign="top"|Return length of expression.
 
|valign="top"|len()||valign="top"|source as expr<br>[, options as logical]||valign="top"|Return length of expression.
Line 108: Line 135:
 
|-
 
|-
 
|valign="top"|md5()||valign="top"|source as string||valign="top"|MD5 encypts the specified string.
 
|valign="top"|md5()||valign="top"|source as string||valign="top"|MD5 encypts the specified string.
 +
|-
 +
|valign="top"|message()||valign="top"|none||valign="top"|Returns a character string describing the last error encountered.  In web/mobile, this is the last error encountered on the server.  From v9.1.3.
 
|-
 
|-
 
|valign="top"|messageBox()||valign="top"|message as string<br>[, options as numeric<br>[, title as string<br>[, okcallback as function<br>[, cancelcallback as function]]]]||valign="top"|Display a dialog box and continues execution. If the callback functions are specified they are called on clicking a button.
 
|valign="top"|messageBox()||valign="top"|message as string<br>[, options as numeric<br>[, title as string<br>[, okcallback as function<br>[, cancelcallback as function]]]]||valign="top"|Display a dialog box and continues execution. If the callback functions are specified they are called on clicking a button.
Line 118: Line 147:
 
|-
 
|-
 
|valign="top"|proper()||valign="top"|source as string||valign="top"|Convert to proper case.
 
|valign="top"|proper()||valign="top"|source as string||valign="top"|Convert to proper case.
 +
|-
 +
|valign="top"|read_events()||valign="top"|none||valign="top"|read_events() suspends execution until a clear_events() command is executed (desktop only).
 
|-
 
|-
 
|valign="top"|reccount()||valign="top"|alias as string||valign="top"|Return record count.
 
|valign="top"|reccount()||valign="top"|alias as string||valign="top"|Return record count.
Line 134: Line 165:
 
|-
 
|-
 
|valign="top"|rtrim()||valign="top"|source as string ||valign="top"|Remove trailing spaces.
 
|valign="top"|rtrim()||valign="top"|source as string ||valign="top"|Remove trailing spaces.
 +
|-
 +
|valign="top"|screenHeight()||valign="top"|none||valign="top"|Returns the screen/viewport height.
 +
|-
 +
|valign="top"|screenWidth()||valign="top"|none||valign="top"|Returns the screen/viewport width.
 
|-
 
|-
 
|valign="top"|space()||valign="top"|len as numeric||valign="top"|Returns a string of len spaces.
 
|valign="top"|space()||valign="top"|len as numeric||valign="top"|Returns a string of len spaces.
Line 170: Line 205:
 
[[Category:JavaScript Scripting]]
 
[[Category:JavaScript Scripting]]
 
[[Category:Visual FoxPro Scripting]]
 
[[Category:Visual FoxPro Scripting]]
 +
[[Category:Lianja v9.1]]

Latest revision as of 23:15, 6 March 2024

Using Global Variables in Lianja/JavaScript

Lianja.public is an object containing global/public variables and is supported on desktop and web/mobile, e.g.

Lianja.public.mytext = "hello world";
Lianja.public.num = 10;

Lianja JavaScript built-in LianjaScript functions

Bm-noteicon.png
Pro Tip

As of Lianja v8.0, JavaScript delegates (desktop and web) can reference the UI element for the delegate using this.

Bm-noteicon.png
Pro Tip

As of Lianja 5, you can use console.log(text) to help debug your code in desktop, web and mobile Apps.
Previously this was not available in desktop Apps.
Additionally, if you place the keyword debugger or the function debug() in your JavaScript code the JavaScript debugger will be activated.

The following LianjaScript functions are built into Lianja JavaScript.

Function Arguments Description
addslashes() arg as string Quote string with slashes.
alltrim() arg as string Remove leading and trailing spaces.
at() substring as string,
source as string
[, start as numeric]
Search for substring and return position.
base64_decode() text as string Function to decode a text string from MIME base64.
base64_encode() text as string Function to encode a text string to MIME base64.
between() value as expression,
low as expression,
high as expression
Function to check that a given value is within a given range.
browse() title as string,
database as string,
table as string,
[filter as string,]
[columns as string,]
[onDblClick as function]
Browse a grid of columns of the filtered records from the specified database table.
The onDblClick callback function is called with one argument, an object for the active row in the grid.
cdow() source as date Function to return the day of the week from the specified date as a string.
choose() index as numeric,
value as expr
[, ...]
Returns the nth argument in the argument list.
The first index is 1.
If index is out of bounds returns an empty string.
chrtran() source as string,
find as string,
replacewith as string
Function to replace text within a string.
clear_events() none Stops event processing started with read_events() (desktop only).
cmonth() source as date Function to return the month from the specified date as a string.
createObject() class as string Create new object based on the specified UI class. See Working with Framework Classes
ctod() source as string Function to return the specified string as a date.
currency() value as numeric,
decimals as numeric
Function to return the specified numeric value formatted as a currency value.
database() none Returns the name of the current database.
date() [year as numeric,
month as numeric,
day as numeric]
Function to return system or the specified date as a date.
day() source as date Function to return the day of the month from the specified date as a numeric.
dow() source as date Function to return the day of the week from the specified date as a numeric.
dtoa() source as date Function to return the specified date as a string in the format YYYY-MM-DD.
dtoc() source as date Function to return the specified date as a string.
dtos() source as date Function to return the specified date as a string in the format YYYYMMDD.
empty() arg as expression Returns true if the given expression is empty, i.e. an empty string, a numeric zero or a boolean false.
endsWith() source as string,
substring as string
Check if source string ends with substring.
etos() source as expr
[, length as numeric]
Evaluate expression and return it as a string, optionally specifying length.
explode() separator as expression,
string as expression
Returns an array by splitting the given string up as specified by the given separator.
format() source as string,
arg1 as expression,
..., argN as expression
Returns a string formatted with a variable list of arguments. See FORMAT() for examples.
function_exists() arg as string Returns true if the specified function is declared.
getfile() [arg as function] The getfile() function returns the file selected as a character string. In web/mobile this is async so you should specify a callback function e.g.
getfile(function(filename) {console.log(filename);})
gmtime() none Returns the current datetime in the GMT/UTC timezone.
guid() none Returns a GUID.
icase() condition as logical,
result as expr
[, ...]
[, otherwiseresult]
Execute immediate case statement. Evaluates a condition then if it is true returns the next argument in the argument list. If no conditions are true returns the otherwiseresult.
iif() condition as logical,
expression1 as exp,
expression2 as exp
Execute an immediate if. Returns expression1 if condition is true otherwise returns expression2.
implode() separator as expression,
array as expression
Returns a string of all items in the given array separated by the given separator.
in_array() value as expression,
array as expression
Returns true if the given value is in the specified array.
indexOf() source as string,
substring as string
Search for substring and return position.
inlist() source as string,
list as string
Check if source string is contained in a list of arguments.
inputBox() prompt as string
[, title as string
[, defaultvalue as string
[, okcallback as function
[, cancelcallback as function]]]]
Display a dialog inputbox and continues execution. If the callback functions are specified they are called with the value input as an argument on clicking a button.
is_array() arg as expression Returns true if the given arg is an array.
is_date() arg as expression Returns true if the given arg is a date.
is_float() arg as expression Returns true if the given arg is a number.
is_function() arg as expression Returns true if the given arg is a function.
is_int() arg as expression Returns true if the given arg is a number.
is_logical() arg as expression Returns true if the given arg is a boolean.
is_numeric() arg as expression Returns true if the given arg is a number.
is_object() arg as expression Returns true if the given arg is an object.
is_string() arg as expression Returns true if the given arg is a string.
keyLookup() database!table as string,
tag as string,
keyexpr as expr,
valueexpr as string,
notfoundexpr as string
Performs a cross table lookup.
len() source as expr
[, options as logical]
Return length of expression.
loadlibrary() fileURL.js as string Load the specified JavaScript file.
lower() arg as string Convert to lower case.
lpad() source as string,
length as numeric
[, padchar as string]
Pad string to defined length from left.
ltrim() source as string Remove leading spaces.
md5() source as string MD5 encypts the specified string.
message() none Returns a character string describing the last error encountered. In web/mobile, this is the last error encountered on the server. From v9.1.3.
messageBox() message as string
[, options as numeric
[, title as string
[, okcallback as function
[, cancelcallback as function]]]]
Display a dialog box and continues execution. If the callback functions are specified they are called on clicking a button.
month() source as date Function to return the month from the specified date as a numeric.
padl() source as string,
length as numeric
[, padchar as string]
Pad string to defined length from left.
padr() source as string,
length as numeric
[, padchar as string]
Pad string to defined length from right.
proper() source as string Convert to proper case.
read_events() none read_events() suspends execution until a clear_events() command is executed (desktop only).
reccount() alias as string Return record count.
recno() alias as string Return current record number.
replicate() arg as expression,
count as expression
Returns a string which is a replication of the given arg 'count' times.
require() jsfileURL as string Load the specified JavaScript file.
require_once() jsfileURL as string Load the specified JavaScript file (if not already loaded).
rowcount() alias as string Return row count (excludes deleted and those not matching current filter).
rpad() source as string,
length as numeric
[, padchar as string]
Pad string to defined length from right.
rtrim() source as string Remove trailing spaces.
screenHeight() none Returns the screen/viewport height.
screenWidth() none Returns the screen/viewport width.
space() len as numeric Returns a string of len spaces.
startsWith() source as string,
substring as string
Check if source string starts with substring.
str() source as numeric
[, width as numeric
[, decimals as numeric]]
Convert numeric to string.
strlen() source as expr
[, options as logical]
Return length of expression.
strtran() source as string,
find as string,
replacewith as string
Function to replace text within a string.
str_replace() substring as string,
replacestring as string,
source as string
Search for substring and replace with replacestring in source.
substr() source as string,
start as numeric
[, end as numeric]
Extract substring.
sqlLookup() database!table as string,
keyfield as expr,
keyvalue as expr,
resultexpression as expr,
notfoundexpr as expr
Performs a cross table lookup.
time() none Function to return current system time.
tostring() arg as expression Returns the given arg as a string type.
tostring() arg as expression Returns the given arg as a string type.
username() none Returns the name of the logged in user.
upper() arg as string Convert to upper case.
val() arg as string Convert string to numeric.
year() arg as date Function to return the year from the specified date as a numeric.