Built-In Namespace _global_

Method Summary
Method Attributes Method Name and Description
 
_404(custom404)
 
_addIfNotPresent(obj, key, value)
 
 
 
 
 
 
 
 
 
_coll_add(id, o)
 
 
_coll_remove(id, obj)
 
 
_cronId(date, path, period, params, published)
 
 
 
_doWrite(str)
 
 
 
 
 
 
 
 
 
 
_newUniqueId(prefix)
 
 
 
 
 
_proxy(id)
 
 
 
 
 
_sameProperties(obj1, obj2)
 
 
 
_setHandler(id, raw)
 
_setstorage(key, val)
 
 
 
add(id, obj)
 
cmp(a, b)
Comparator that returns -1, +1, or 0 depending on whether a < b, or a > b, or neither, respectively.
 
comparator(id1, id2)
 
create(id)
 
dispatch(opts)
Converts the path into a function name and calls that function.
 
eachProperty(obj, func)
Iterator convenience for JavaScript Objects.
 
erase(id, key)
 
filter(id, newId, match)
 
first(id)
 
form(url, param1, param2, etc)
Helper fuction for printing a form.
 
get(id, key)
 
getById(id)
 
gethostbyaddr(ipaddr)
Converts an IP address string (such as "74.86.117.106") to a hostname (such as "appjet.com").
 
gethostbyname(hostname)
Converts a hostname string (such as "appjet.com") to an IP address, returned as a string (such as "74.86.117.106").
 
getIds(id)
 
Gets a StorableObject or StorableCollection by its id.
 
hasNext(id)
 
html(text)
Used for printing un-escaped HTML, such as your own HTML tags.
 
image(url)
Helper function for printing an image (an IMG tag).
 
iterator(id, newId)
 
keys(obj)
Creates an array of the properties of obj, not including built-in or inherited properties.
 
limit(id, newId, n)
 
link(url, optionalText)
Helper function for printing a link (A HREF tag).
 

Returns an array of objects describing all scheduled CRON tasks.

 
md5(x)
Returns a string version of the MD5 signature of x.
 
name(id)
 
next(id)
 
object(parent)
Douglas Crockford's "object" function for prototypal inheritance, taken from http://javascript.crockford.com/prototypal.html
 
patternDispatch(pattern1, pattern2, patternN, optional404)
Similar to dispatch(), but you provide your own mapping of regular expresions to functions.
 
print(thing1, thing2, etc)
HTML-aware printing.
 
printf(formatString, arg1, arg2, arg3)
Prints a string with any number of variables substituted in, as popularized by C's function of the same name.
 
printp(thing1, thing2, etc)
Like print(.
 
put(id, key, tv)
 
raw(text)

The raw() function is deprecated.

 
remove(id, obj)
 
reverse(id, newId)
 
schedule(date, path, params, published, mailOnError)

Schedules a CRON request to execute once at an exact date in the future.

 
scheduleRepeating(date, period, path, params, published, mailOnError)

Schedules a CRON request to execute every period minutes, starting at date.

 
sendEmail(toAddress, subject, body, headers)
Simple way to send an email to a single recipient.
 
size(id)
 
skip(id, newId, n)
 
sort(id, newId, f)
 
sortBy(id, newId, propertyNames)
 
sprintf(formatString, arg1, arg2, arg3)
Just like printf, but returns the string instead of printing it.
 
supplant(data, str)
Replaces keys of data found in string with their corresponding values.
 
toHTML(x)
This function is used by print(.
 
trim(str)
Removes leading and trailing whitespace from a string.
 
unschedule(name)
Unschedules the CRON task identified by name.
 
Unschedules all CRON tasks.
 
wget(url, params, options)
Fetches the text of a URL and returns it as a string.
 
wpost(url, params, options)
Simple way to POST data to a URL and get back the response.
Method Detail
_404(custom404)

Defined in: dispatching.js.
Parameters:
custom404

_addIfNotPresent(obj, key, value)

Defined in: request.js.
Parameters:
obj
key
value

_arrayToHTML(a)

Defined in: printing.js.
Parameters:
a

_arrayToStringOrArray(value)

Defined in: request.js.
Parameters:
value

_checkSetup()

Defined in: facebook.js.

_clearfloats()

Defined in: quickforms.js.

_coerceObjectToHTML(obj)

Defined in: printing.js.
Parameters:
obj

_coerceToHolder(obj)

Defined in: storage.js.
Parameters:
obj

_coerceToStorableHolder(obj)

Defined in: storage.js.
Parameters:
obj

_coerceToStorableObject(obj)

Defined in: storage.js.
Parameters:
obj

_coll_add(id, o)

Defined in: storage.js.
Parameters:
id
o

_coll_iterator(id)

Defined in: storage.js.
Parameters:
id

_coll_remove(id, obj)

Defined in: storage.js.
Parameters:
id
obj

_Collections()

Defined in: storage.js.

_cronId(date, path, period, params, published)

Defined in: cron.js.
Parameters:
date
path
period
params
published

_default404()

Defined in: dispatching.js.

_deleteHandler(id)

Defined in: storage.js.
Parameters:
id

_doWrite(str)

Defined in: printing.js.
Parameters:
str

_getHandler(id)

Defined in: storage.js.
Parameters:
id

_getIdsHandler(id)

Defined in: storage.js.
Parameters:
id

_getObjectForId(id)

Defined in: storage.js.
Parameters:
id

_getstorage(key)

Defined in: facebook.js.
Parameters:
key

_headerCapitalize(str)

Defined in: request.js.
Parameters:
str

_Iterable(id)

Defined in: storage.js.
Parameters:
id

_iteratingToString(obj)

Defined in: storage.js.
Parameters:
obj

_Iterators()

Defined in: storage.js.

_longToString(n)

Defined in: storage.js.
Parameters:
n

_newUniqueId(prefix)

Defined in: storage.js.
Parameters:
prefix

_objectHash(obj)

Defined in: facebook.js.
Parameters:
obj

_objectToArray(obj)

Defined in: storage.js.
Parameters:
obj

_objectToOL(obj)

Defined in: printing.js.
Parameters:
obj

_paramObjectToParamArray(params, enc)

Defined in: cron.js.
Parameters:
params
enc

_proxy(id)

Defined in: storage.js.
Parameters:
id

_renderFacebook()

Defined in: page.js.

_renderFooter()

Defined in: page.js.

_renderHtml()

Defined in: page.js.

_renderPlain()

Defined in: page.js.

_sameProperties(obj1, obj2)

Defined in: printing.js.
Parameters:
obj1
obj2

_setAggressiveNoCacheHeaders()

Defined in: page.js.

_setAggressiveYesCacheHeaders()

Defined in: page.js.

_setHandler(id, raw)

Defined in: storage.js.
Parameters:
id
raw

_setstorage(key, val)

Defined in: facebook.js.
Parameters:
key
val

_Storage()

Defined in: storage.js.

_stringToHTML(str)

Defined in: printing.js.
Parameters:
str

add(id, obj)

Defined in: storage.js.
Parameters:
id
obj

{number} cmp(a, b)
Comparator that returns -1, +1, or 0 depending on whether a < b, or a > b, or neither, respectively.
Defined in: utilities.js.
Parameters:
{object} a
{object} b
Returns:
{number} -1, 0, or +1

comparator(id1, id2)

Defined in: storage.js.
Parameters:
id1
id2

create(id)

Defined in: storage.js.
Parameters:
id

dispatch(opts)
Converts the path into a function name and calls that function. The function name is by replacing '/' characters in the path with underscores, and prepending the request method (get or post). For requests that end in '/', you can optionally suffix your function name with 'main'.
Defined in: dispatching.js.
function get_main() {
  // called with user visits http://appname.appjet.net/
  print("hello");
}
function get_page() {
  // called with user visits http://appname.appjet.net/page
}
function post_foo() {
  // called when user POSTs to http://appname.appjet.net/foo
}
dispatch(); // examines request and calls one of the above functions.
Parameters:
{object} opts Optional
(optional) if opts.custom404 is a function, then this function will be called if there is no function corresponding to the request path. If opts is is not specified, a default 404 handler displays "404 not found".

eachProperty(obj, func)
Iterator convenience for JavaScript Objects. Note that if func returns false, the iteration will be immediately terminated. (Returning undefined, or not specifying a return type, does not terminate the iteration).
Defined in: utilities.js.
var pastels = {
  red: "#fcc",
  green: "#cfc",
  blue: "#ccf"
};
eachProperty(pastels, function(key, value) {
  print(DIV({style: 'background: '+value+';'}, key));
});
Parameters:
{object} obj
The object over which to iterate.
{function} func
The function to run on each [key,value] pair.

erase(id, key)

Defined in: storage.js.
Parameters:
id
key

filter(id, newId, match)

Defined in: storage.js.
Parameters:
id
newId
match

first(id)

Defined in: storage.js.
Parameters:
id

form(url, param1, param2, etc)
Helper fuction for printing a form.
Defined in: printing.js.
if (request.path == "/bar") {
  printp("Your name is: ", request.param("name"));
  printp(link("/", "back"));
} else {
  printp("Enter your name:");
  print(form("/bar", "name"));
}
Parameters:
{string} url
an absolute or relative URL to post the form data to
{string} param1
the first form parameter name
{string} param2
the second form parameter name
{string} etc
...

get(id, key)

Defined in: storage.js.
Parameters:
id
key

getById(id)

Defined in: storage.js.
Parameters:
id

{string} gethostbyaddr(ipaddr)
Converts an IP address string (such as "74.86.117.106") to a hostname (such as "appjet.com"). This function is the inverse of gethostbyname().
Defined in: dns.js.
Parameters:
{string} ipaddr
The IP address to resolve (example: "74.86.117.106").
Returns:
{string} the hostname corresponding to the given ip address, or undefined.

{string} gethostbyname(hostname)
Converts a hostname string (such as "appjet.com") to an IP address, returned as a string (such as "74.86.117.106"). This function is the inverse of gethostbyaddr().
Defined in: dns.js.
Parameters:
{string} hostname
The DNS name to resolve (example: "www.appjet.com").
Returns:
{string} the IP address corresponding to the given hostname, or undefined.

getIds(id)

Defined in: storage.js.
Parameters:
id

{StorableObject} getStorable(id)
Gets a StorableObject or StorableCollection by its id.

Each StorableObject or StorableCollection has an id that never changes, and this id can be used to refer to the object in a URL or form parameter.
Defined in: storage.js.

import("quickforms");
import("storage");

if (! storage.things) {
    storage.things = new StorableCollection();
    storage.things.add({message: "Hello world!"});
}

if (! request.param("idToDisplay")) {
    var firstId = storage.things.first().id;
    // show a button that creates a request with idToDisplay = firstId
    printp(new QuickButton("Show first thing.", {}, {idToDisplay: firstId}));
}
else {
    // display the "foo" property of whatever object has an id of idToDisplay
    printp(getStorable(request.param("idToDisplay")).message);
}
Parameters:
{string} id
The id of the object to be gotten.
Returns:
{StorableObject} The StorableObject whose id is id, or undefined if no such object exists.

hasNext(id)

Defined in: storage.js.
Parameters:
id

{object} html(text)
Used for printing un-escaped HTML, such as your own HTML tags.

Normally, printing a string will cause it to be translated so that it appears the same on the screen as it did in your code. If you're writing your own HTML, you don't want it to be processed this way. Wrapping a string in html(...) by-passes normal printing behavior, so that print(html(" -- html goes here ---")) will write the HTML directly to the page.

If you want to mix your own HTML code with HTML code generated from a tag object, you can get the HTML for the tag by calling its toHTML(...) method.

Multiple arguments to html(...) will be concatenated into one string.
Defined in: printing.js.

print(html("""
<br />
<br />
<div><p>Here is some text inside a P inside a DIV.</p>
</div>
<br />
"""));
Parameters:
{string} text
the raw text
Returns:
{object} an object which, when printed, prints the raw html text

image(url)
Helper function for printing an image (an IMG tag).
Defined in: printing.js.
print(image("http://i29.tinypic.com/vfwc60.gif"));
Parameters:
{string} url
an absolute or relative URL to an image.

iterator(id, newId)

Defined in: storage.js.
Parameters:
id
newId

keys(obj)
Creates an array of the properties of obj, not including built-in or inherited properties. If no argument is given, applies to the global object.
Defined in: utilities.js.
// Prints "abc"
keys({a: 1, b: 2, c: 3}).forEach(function(k) {
  print(k);
}
// Prints all the functions and object members of the global "appjet" object,
// one per line.
print(keys(appjet).join('\n'));
Parameters:
{object} obj

limit(id, newId, n)

Defined in: storage.js.
Parameters:
id
newId
n

link(url, optionalText)
Helper function for printing a link (A HREF tag).
Defined in: printing.js.
print(link("http://appjet.com"));
Parameters:
{string} url
an absolute or relative URL to link to
{string} optionalText Optional
the text of the link, defaults to the url if absent

{Array} listAll()

Returns an array of objects describing all scheduled CRON tasks. Modifications to these objects are not reflected in the scheduled tasks.

The returned objects have property names that are the same as the arguments to schedule() and scheduleRepeating(), namely:

  • name: the task's identifier
  • date: date the task is (or was) first scheduled to run
  • period: delay between repeated requests, in minutes
  • path: path to request
  • params: query string containing the parameters on the request
  • published: whether to send the request to the published or preview version of the code
  • mailOnError: whether to send mail if there's an error

Defined in: cron.js.
Returns:
{Array} An array of objects describing all scheduled CRON tasks.

{String} md5(x)
Returns a string version of the MD5 signature of x.
Defined in: utilities.js.
print(md5("appjet")); // prints "9b458805f67473b49761c13e48c5de35"
Parameters:
{String} x
a string
Returns:
{String} the md5 hash of x

name(id)

Defined in: storage.js.
Parameters:
id

next(id)

Defined in: storage.js.
Parameters:
id

{object} object(parent)
Douglas Crockford's "object" function for prototypal inheritance, taken from http://javascript.crockford.com/prototypal.html
Defined in: utilities.js.
Parameters:
{object} parent
The parent object.
Returns:
{object} A new object whose prototype is parent.

patternDispatch(pattern1, pattern2, patternN, optional404)
Similar to dispatch(), but you provide your own mapping of regular expresions to functions.
Defined in: dispatching.js.
function handleIndex() {
  print("this is the main landing page");
}
function handleFoo() {
  print("this is the foo page");
}
function unknown() {
  response.setStatusCode(404);
  print("path not found: ", request.path);
}
patternDispatch(
  [/^\/$/, handleIndex],
  [/^\/foo$/, handleFoo],
  unknown
);
Parameters:
{array} pattern1
array of [regexp, method]
{array} pattern2
array of [regexp, method]
{array} patternN
...
{function} optional404 Optional
called if none of the previous patterns match

print(thing1, thing2, etc)
HTML-aware printing. This function prints its arguments to the body of the page. Printing a string will cause it to show up as-is on the screen (even if it contains HTML tags or angle-brackets). Printing an HTML tag object will cause it to be rendered on the screen. Printing a normal Javascript object or array will cause it to be rendered in an easily-readable HTML format.
Defined in: printing.js.
Parameters:
{*} thing1
any javascript type
{*} thing2
any javascript type
{*} etc
...

printf(formatString, arg1, arg2, arg3)
Prints a string with any number of variables substituted in, as popularized by C's function of the same name. Some common substitutions:
  • %d - an integer
  • %f - a floating-point number
  • %b - a boolean
  • %s - a string

Each time one of these "slot" appears in your format string, the next argument is displayed according to the type of slot you specified.

AppJet supports Java's specification of printf, which has a ton of features, including selecting arguments out of order, formatting dates and times, and specifying how many characters wide each slot should be.
Defined in: printing.js.

var x = 5;
printf("an integer: %d", x);
printf("Two strings: [%s] and [%s].", "string one", "string two");
Parameters:
{string} formatString
{*} arg1
{*} arg2
{*} arg3
...

printp(thing1, thing2, etc)
Like print(...), but prints its arguments inside an HTML p (paragraph) tag.
Defined in: printing.js.
Parameters:
{*} thing1
any javascript type
{*} thing2
any javascript type
{*} etc
...

put(id, key, tv)

Defined in: storage.js.
Parameters:
id
key
tv

raw(text)

The raw() function is deprecated. Now use the html() function instead. (It does the same thing).


Defined in: printing.js.
Parameters:
text

remove(id, obj)

Defined in: storage.js.
Parameters:
id
obj

reverse(id, newId)

Defined in: storage.js.
Parameters:
id
newId

{string} schedule(date, path, params, published, mailOnError)

Schedules a CRON request to execute once at an exact date in the future.

The generated request appears as any other request, but uses HTTP method CRON to distinguish itself from external HTTP requests. It is not possible to generate a CRON request in any way other than by scheduling one.

To prevent abuse, only about 2000 CRON requests can be executed by an app in any given minute. (This limit is lower for requests that are very expensive, such as those that call wget() and perform other high-cost operations.) Requsts beyond this limit are rescheduled for the next minute but ultimately canceled if the reschedule queue grows too large.


Defined in: cron.js.
result = schedule(new Date("Jan 12, 2008"), "/dosomething");
function cron_dosomething() {
  sendEmail("you@example.com", "A scheduled message.", "Greetings!");
}
Parameters:
{Date} date
The date the request should trigger.
{string} path
The path to be specified by the HTTP CRON request. Maximum length of 100 characters.
{object} params Optional
Optional parameters to be given with the HTTP CRON request. Maximum of 256 bytes of data; use storage if you need more.
{boolean} published Optional
Whether the request should be sent to the published version of the app, or the most recent preview version. By default only requests scheduled in published mode go to the published version of the app.
{boolean} mailOnError Optional
Whether to email this app's owner if the cron request fails or is canceled; defaults to false.
Returns:
{string} A unique identifier for this cron task.

{string} scheduleRepeating(date, period, path, params, published, mailOnError)

Schedules a CRON request to execute every period minutes, starting at date.

The generated request appears as any other request, but uses HTTP method CRON to distinguish itself from other external HTTP requests. It is not possible to generate a CRON request in any way other than by scheduling one.

A CRON request cannot schedule a repeating CRON request.


Defined in: cron.js.
result = schedule(new Date("Jan 12, 2008"), "/dosomething");
Parameters:
{Date} date
The exact date the cron requests should start.
{number} period
The delay between subsequent requests in minutes. Minimum of 1 minute.
{string} path
The path specified by the HTTP CRON requests. Maximum length of 100 characters.
{object} params Optional
Optional parameters to be given with the HTTP CRON requests. Maximum of 256 bytes of data.
{boolean} published Optional
Whether the CRON requests should be sent to the published version of the app, or the most recent preview version. By default only requests scheduled in published mode go to the published version of the app.
{boolean} mailOnError Optional
Whether to email this app's owner if the cron request fails or is canceled; defaults to false.
Returns:
{string} A unique identifier for this cron task.

sendEmail(toAddress, subject, body, headers)
Simple way to send an email to a single recipient. Emails will have a "from" address of noreply@{appjet.appName}.{appjet.mainDomain}. Sending is limited to 100 emails per developer account per day. However, emails sent to the address on file for the app's owner are not counted toward this limit.
Defined in: utilities.js.
result = sendEmail("noone@example.com", "Test Subject",
                   "Greetings!", {"Reply-To": "sender@example.com"});
Parameters:
{string} toAddress
The one email address to send a message to.
{string} subject
The message subject.
{string} body
The message body.
{object} headers Optional
Optional headers to include in the message, as a dictionary of {name: value} entries.

size(id)

Defined in: storage.js.
Parameters:
id

skip(id, newId, n)

Defined in: storage.js.
Parameters:
id
newId
n

sort(id, newId, f)

Defined in: storage.js.
Parameters:
id
newId
f

sortBy(id, newId, propertyNames)

Defined in: storage.js.
Parameters:
id
newId
propertyNames

sprintf(formatString, arg1, arg2, arg3)
Just like printf, but returns the string instead of printing it.
Defined in: printing.js.
var result = sprintf("%f", Math.sqrt(2));
print("The square root of two, as a string, is: ", result);
Parameters:
{string} formatString
{*} arg1
{*} arg2
{*} arg3
...

{string} supplant(data, str)
Replaces keys of data found in string with their corresponding values.

(Inspired by http://javascript.crockford.com/remedial.html)
Defined in: printing.js.

var data = {name: "Aaron", age: 25, today: new Date()};
print(supplant(data, """

{name}'s age is {age} years, as of {today}.

"""));
Parameters:
{object} data
dictionary of values
{string} str
Returns:
{string} str with keys of data replaced by their values

{string} toHTML(x)
This function is used by print(...) to convert a string or object into nice-looking printable HTML. It may be useful in conjunction with raw(...) if you wish to work directly with HTML.

You can control how toHTML(...) (and therefore print(...)) behave on an object by giving that object a .toHTML() function.
Defined in: printing.js.

Parameters:
{*} x
any javascript variable
Returns:
{string} html-formatted string

{string} trim(str)
Removes leading and trailing whitespace from a string.
Defined in: utilities.js.
Parameters:
{string} str
Returns:
{string} The trimmed string.

unschedule(name)
Unschedules the CRON task identified by name.

If the CRON task is non-repeating and has already been executed, this function has no effect.


Defined in: cron.js.
result = schedule(new Date("Jan 12, 2008"), "/dosomething");
unschedule(result);
Parameters:
{string} name
The identifier of the CRON task to cancel.

unscheduleAll()
Unschedules all CRON tasks.
Defined in: cron.js.

{string, HttpResponse} wget(url, params, options)
Fetches the text of a URL and returns it as a string.
Defined in: utilities.js.
g = wget("google.com");
page.setMode("plain");
print(raw(g));
Parameters:
{string} url
The name of the url to retreive. If the transport is not specified, HTTP is assumed.
{object} params Optional
Optional parameters to include with the GET, as a dictionary of {name: value} entries.
{object} options Optional
Optional object with three optional properties:
  • headers: HTTP request headers to send with the GET, as a dictionary of {name: value} entries.
  • followRedirects: A boolean indicating whether to follow redirect headers returned by the server. Defaults to true.
  • complete: If true, wget returns an object containing all information about the response, not just its contents. Otherwise, wget throws a HttpRequestError if it encounters an error GETing.
Returns:
{string} The full text of the url's content.
{HttpResponse} The "complete" response, returned if the "complete" parameter is true.

{string, HttpResponse} wpost(url, params, options)
Simple way to POST data to a URL and get back the response. Values of params will automatically be escaped.
Defined in: utilities.js.
result = wpost("example.com", {id: 25, value: "here is the post value"});
Parameters:
{string} url
The url to POST to.
{object} params Optional
Optional parameters to include with the POST, as a dictionary of {name: value} entries.
{object} options Optional
Optional object with three optional properties:
  • headers: HTTP request headers to send with the POST, as a dictionary of {name: value} entries.
  • followRedirects: A boolean indicating whether to follow redirect headers returned by the server.
  • complete: If true, wpost returns an object containing all information about the response, not just its contents. Otherwise, wpost throws a HttpRequestError if it encounters an error POSTing.
Returns:
{string} The full text returned from the server POSTed to.
{HttpResponse} The complete response, returned if the "complete" parameter is true.

©2011 by JGate on AppJet
Documentation generated by JsDoc Toolkit 2.1.0 on Thu Jan 06 2011 10:36:33 GMT+0100 (MEZ)