Why register?
Registration is necessary because running code can be used to attack other systems.
If this behaviour is registered for an account, the account can be suspended.
If you want start by creating a complete example:
1. Start
Scripts can contain Java or Groovy Code (also mixed), the simpliest example would be like this:
// title: Personal Notes
System.out.println("Hello User!");
Anything you write to System.out.println
will be shown in the HTML page.
Writing HTML-tags will apply formatting.
2. Input & Storage
By adding simple instructions, form fields to enter data can be defined:
// title: Personal Notes
// input line label=Title
// input text label=Note
// input type=select; label="Color" item=red item=blue item=green
System.out.println("Hello User!");
The Built-in Storage allows to persist data easily.
Storage Example:
// Store Notes To Built-in Storage
RecordDef spec = new RecordDef()
.add("title") // Defaults to data type string
.add("note")
.add("color");
Record note1 = new Record()
.set("title", "Buy Food")
.set("note", "Vegetables, Oil")
.set("color", "yello");
Record note2 = new Record()
.set("title", "Cafe Favorite")
.set("note", "Arabica Mix")
.set("color", "brown");
STORAGE.set("all_notes", Arrays.asList(note1, note2), spec);
// Read Notes From Built-in Storage
List<Record> records = STORAGE.get("all_notes");
for (Record record : records) {
// Show In Page
System.out.println("<h2>" + record.get("title") + "</h2>");
System.out.println(record.get("note"), spec);
}
Use record.get("..")
to get a String stored. There is also record.getLong(".."), record.getDouble(".."), record.getDate(".."), record.getBinary(".."), record.getString("..")
.
3. Complete Example
// title: Personal Notes
// input line label=Title
// input text label=Note
// input type=select; label="Color" item=red item=blue item=green
NotesApp.show();
class NotesApp {
static show() {
// Define Specification
RecordDef spec = new RecordDef()
.add("title")
.add("note")
.add("color");
// Read Notes From Built-in Storage
List<Record> records = STORAGE.get("all_notes", spec);
// Add New Record (only on input)
if (INPUT.get(0) != null) {
Record note = new Record()
.set("title", INPUT.get(0))
.set("note", INPUT.get(1))
.set("color", INPUT.get(2));
records.add(note);
STORAGE.set("all_notes", records, spec);
}
// Add some CSS
addCss();
// Show Content
for (Record record : records) {
addItem(record);
}
}
static addItem(Record record) {
// Show Note In Page
HTML.add("<div class='note'>");
HTML.add("<div class='note_title'>" + record.get("title") + "</div>");
if ("green".equals(record.get("color"))) {
HTML.add("<div class='color_green'></div>");
}
HTML.add("<div class='note_content'>" + record.get("note") + "</div>");
HTML.add("<a href='#' onclick='remove(\"notes\", " + record.getId() + ");' class='link_remove'>x</a>");
HTML.add("</div>");
}
static addCss() {
String css = "";
css += ".note { display: block; position: relative; margin-bottom: 4; background-color: #efefef; padding: 5 5; }";
css += ".note_title { display: inline-block; font-size: 1.5em; }";
css += ".note_content { display: block; }";
css += ".link_remove { display: block; position: absolute; right: 7px; top: 1px; color: #666 !important; text-decoration: none; }";
css += ".color_green { display: inline-block; width: 18px; height: 18px; background-color: #aaeeaa; }";
HTML.css(css);
}
}
Learn
Understand how scripts are working (Documentation):