ultimatepp/examples/AddressBookWeb/Pages.icpp
cxl f766ccc947 .examples: AddressBookWeb improved
git-svn-id: svn://ultimatepp.org/upp/trunk@5195 f0d560ea-af0d-0410-9eb7-867de7ffcac7
2012-07-15 15:17:17 +00:00

53 lines
1.1 KiB
Text

#include "AddressBook.h"
SKYLARK(HomePage, "")
{
SqlBool where;
String s = http["search"];
if(!IsNull(s)) {
s << '%';
where = Like(FIRSTNAME, s) || Like(LASTNAME, s) || Like(EMAIL, s);
}
http("PERSON", Select(ID, FIRSTNAME, LASTNAME, EMAIL).From(PERSON)
.Where(where).OrderBy(LASTNAME, FIRSTNAME))
.RenderResult("AddressBookWeb/Index");
}
SKYLARK(CatchAll, "**")
{
http.Redirect(HomePage);
}
SKYLARK(SubmitNew, "submit/create:POST")
{
SQL * http.Insert(PERSON);
http.Redirect(HomePage);
}
SKYLARK(New, "person/create")
{
http("ACTION", SubmitNew)
.RenderResult("AddressBookWeb/Dialog");
}
SKYLARK(SubmitEdit, "submit/edit/*:POST")
{
SQL * http.Update(PERSON).Where(ID == http.Int(0));
http.Redirect(HomePage);
}
SKYLARK(Edit, "person/edit/*")
{
int id = http.Int(0);
http
(Select(FIRSTNAME, LASTNAME, EMAIL).From(PERSON).Where(ID == id))
("ID", id)
("ACTION", SubmitEdit, id)
.RenderResult("AddressBookWeb/Dialog");
}
SKYLARK(Delete, "person/delete/*")
{
SQL * Delete(PERSON).Where(ID == atoi(http[0]));
http.Redirect(HomePage);
}