Built-In Namespace _global_
| Method Attributes | Method Name and Description |
|---|---|
|
_404(custom404)
|
|
|
_addIfNotPresent(obj, key, value)
|
|
|
_arrayToHTML(a)
|
|
|
_arrayToStringOrArray(value)
|
|
|
_coerceObjectToHTML(obj)
|
|
|
_coerceToHolder(obj)
|
|
|
_coll_add(id, o)
|
|
|
_coll_iterator(id)
|
|
|
_coll_remove(id, obj)
|
|
|
_cronId(date, path, period, params, published)
|
|
|
_deleteHandler(id)
|
|
|
_doWrite(str)
|
|
|
_getHandler(id)
|
|
|
_getIdsHandler(id)
|
|
|
_getObjectForId(id)
|
|
|
_getstorage(key)
|
|
|
_headerCapitalize(str)
|
|
|
_Iterable(id)
|
|
|
_iteratingToString(obj)
|
|
|
_newUniqueId(prefix)
|
|
|
_objectHash(obj)
|
|
|
_objectToArray(obj)
|
|
|
_objectToOL(obj)
|
|
|
_paramObjectToParamArray(params, enc)
|
|
|
_proxy(id)
|
|
|
_sameProperties(obj1, obj2)
|
|
|
_setHandler(id, raw)
|
|
|
_setstorage(key, val)
|
|
|
_Storage()
|
|
|
_stringToHTML(str)
|
|
|
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)
|
|
|
getStorable(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).
|
|
|
importTags(scopeObj, tagArray)
Imports a specified list of tags.
|
|
|
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).
|
|
|
listAll()
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 |
|
|
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.
|
Defined in: <global\dispatching.js>.
- Parameters:
- custom404
Defined in: <global\request.js>.
- Parameters:
- obj
- key
- value
Defined in: <global\printing.js>.
- Parameters:
- a
Defined in: <global\request.js>.
- Parameters:
- value
Defined in: <lib\facebook.js>.
Defined in: <lib\quickforms.js>.
Defined in: <global\printing.js>.
- Parameters:
- obj
Defined in: <lib\storage.js>.
- Parameters:
- obj
Defined in: <lib\storage.js>.
- Parameters:
- obj
Defined in: <lib\storage.js>.
- Parameters:
- obj
Defined in: <lib\storage.js>.
- Parameters:
- id
- o
Defined in: <lib\storage.js>.
- Parameters:
- id
Defined in: <lib\storage.js>.
- Parameters:
- id
- obj
Defined in: <lib\storage.js>.
Defined in: <lib\cron.js>.
- Parameters:
- date
- path
- period
- params
- published
Defined in: <global\dispatching.js>.
Defined in: <lib\storage.js>.
- Parameters:
- id
Defined in: <global\printing.js>.
- Parameters:
- str
Defined in: <lib\storage.js>.
- Parameters:
- id
Defined in: <lib\storage.js>.
- Parameters:
- id
Defined in: <lib\storage.js>.
- Parameters:
- id
Defined in: <lib\facebook.js>.
- Parameters:
- key
Defined in: <global\request.js>.
- Parameters:
- str
Defined in: <lib\storage.js>.
- Parameters:
- id
Defined in: <lib\storage.js>.
- Parameters:
- obj
Defined in: <lib\storage.js>.
Defined in: <lib\storage.js>.
- Parameters:
- n
Defined in: <lib\storage.js>.
- Parameters:
- prefix
Defined in: <lib\facebook.js>.
- Parameters:
- obj
Defined in: <lib\storage.js>.
- Parameters:
- obj
Defined in: <global\printing.js>.
- Parameters:
- obj
Defined in: <lib\cron.js>.
- Parameters:
- params
- enc
Defined in: <lib\storage.js>.
- Parameters:
- id
Defined in: <global\page.js>.
Defined in: <global\page.js>.
Defined in: <global\page.js>.
Defined in: <global\page.js>.
Defined in: <global\printing.js>.
- Parameters:
- obj1
- obj2
Defined in: <global\page.js>.
Defined in: <global\page.js>.
Defined in: <lib\storage.js>.
- Parameters:
- id
- raw
Defined in: <lib\facebook.js>.
- Parameters:
- key
- val
Defined in: <lib\storage.js>.
Defined in: <global\printing.js>.
- Parameters:
- str
Defined in: <lib\storage.js>.
- Parameters:
- id
- obj
Defined in: <global\utilities.js>.
- Returns:
- {number} -1, 0, or +1
Defined in: <lib\storage.js>.
- Parameters:
- id1
- id2
Defined in: <lib\storage.js>.
- Parameters:
- id
Defined in: <global\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".
Defined in: <global\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.
Defined in: <lib\storage.js>.
- Parameters:
- id
- key
Defined in: <lib\storage.js>.
- Parameters:
- id
- newId
- match
Defined in: <lib\storage.js>.
- Parameters:
- id
Defined in: <global\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
- ...
Defined in: <lib\storage.js>.
- Parameters:
- id
- key
Defined in: <lib\storage.js>.
- Parameters:
- id
Defined in: <lib\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.
Defined in: <lib\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.
Defined in: <lib\storage.js>.
- Parameters:
- 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: <lib\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, orundefinedif no such object exists.
Defined in: <lib\storage.js>.
- Parameters:
- id
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: <global\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
Defined in: <global\printing.js>.
print(image("http://i29.tinypic.com/vfwc60.gif"));
- Parameters:
- {string} url
- an absolute or relative URL to an image.
Defined in: <global\tags.js>.
importTags(this, ["MEDIA:TITLE"]);
print(MEDIA_TITLE({type:"html"}, "funny pictures"));
// prints <media:title type="html">funny pictures</media:title>
- Parameters:
- {object} scopeObj
- where to define the tags; to define in the global scope, pass
thisfrom the top level (not from inside a function) - {array} tagArray
- an array of strings, the tags to import
Defined in: <lib\storage.js>.
- Parameters:
- id
- newId
obj,
not including built-in or inherited properties. If no
argument is given, applies to the global object.
Defined in: <global\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
Defined in: <lib\storage.js>.
- Parameters:
- id
- newId
- n
Defined in: <global\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
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: <lib\cron.js>.
- Returns:
- {Array} An array of objects describing all scheduled CRON tasks.
Defined in: <global\utilities.js>.
print(md5("appjet")); // prints "9b458805f67473b49761c13e48c5de35"
- Parameters:
- {String} x
- a string
- Returns:
- {String} the md5 hash of x
Defined in: <lib\storage.js>.
- Parameters:
- id
Defined in: <lib\storage.js>.
- Parameters:
- id
Defined in: <global\utilities.js>.
- Parameters:
- {object} parent
- The parent object.
- Returns:
- {object} A new object whose prototype is parent.
Defined in: <global\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
Defined in: <global\printing.js>.
- Parameters:
- {*} thing1
- any javascript type
- {*} thing2
- any javascript type
- {*} etc
- ...
- %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: <global\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
- ...
Defined in: <global\printing.js>.
- Parameters:
- {*} thing1
- any javascript type
- {*} thing2
- any javascript type
- {*} etc
- ...
Defined in: <lib\storage.js>.
- Parameters:
- id
- key
- tv
The raw() function is deprecated. Now use the html() function instead. (It does the same thing).
Defined in: <global\printing.js>.
- Parameters:
- text
Defined in: <lib\storage.js>.
- Parameters:
- id
- obj
Defined in: <lib\storage.js>.
- Parameters:
- id
- newId
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: <lib\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.
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: <lib\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.
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: <global\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.
Defined in: <lib\storage.js>.
- Parameters:
- id
Defined in: <lib\storage.js>.
- Parameters:
- id
- newId
- n
Defined in: <lib\storage.js>.
- Parameters:
- id
- newId
- f
Defined in: <lib\storage.js>.
- Parameters:
- id
- newId
- propertyNames
Defined in: <global\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
- ...
(Inspired by http://javascript.crockford.com/remedial.html)
Defined in: <global\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
You can control how toHTML(...) (and therefore print(...)) behave on an object
by giving that object a .toHTML() function.
Defined in: <global\printing.js>.
- Parameters:
- {*} x
- any javascript variable
- Returns:
- {string} html-formatted string
Defined in: <global\utilities.js>.
- Parameters:
- {string} str
- Returns:
- {string} The trimmed string.
name.
If the CRON task is non-repeating and has already been executed, this function has no effect.
Defined in: <lib\cron.js>.
result = schedule(new Date("Jan 12, 2008"), "/dosomething");
unschedule(result);
- Parameters:
- {string} name
- The identifier of the CRON task to cancel.
Defined in: <lib\cron.js>.
Defined in: <global\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.
Defined in: <global\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.