Instantly share code, notes, and snippets.

Embed
What would you like to do?
// Define in some kind of registry a prototype for all the Employee objects
//
defineEntity('Employee')
.attribute("firstName")
.attribute("lastName")
.attribute({name: "emailAddress", type: "Email"})
.attribute({
name: "birthDate",
type: "Date",
constraints: [{
validator: function (v) {
return (v.timestamp() < this.clock.now().timestamp());
},
errorMessage: "Birth date must be in the past"
}]
})
.attribute({name: "notes", type: "MultilineText", rendering: "AllowSafeHtml"})
.link({name: "employer", entity: "Company"})
.link({name: "photo", entity: "Image"});
// Then, to show a new object edit form
//
entity('Employee').renderHtmlForm('full_featured.tmpl');
// Which is validated on submission
//
var submitted = entity('Employee').readForm(httpPost);
if (submitted) {
storage('Employee').save(submitted);
} else {
// Render with error messages for invalid fields
//
entity('Employee').renderHtmlForm('full_featured.tmpl', httpPost);
}
// Then, to edit an existing object
//
storage('Employee').get("ID1234567890").renderHtmlForm('popup.tmpl');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment