! Copyright (c) 2008 Slava Pestov ! See http://factorcode.org/license.txt for BSD license. USING: accessors kernel locals sequences namespaces db db.types db.tuples http.server.sessions http.server.components http.server.components.farkup http.server.forms http.server.templating.chloe http.server.boilerplate http.server.crud http.server.auth http.server.actions http.server.db http.server.auth.login http.server ; IN: webapps.todo TUPLE: todo uid id priority summary description ; todo "TODO" { { "uid" "UID" { VARCHAR 256 } +not-null+ } { "id" "ID" +db-assigned-id+ } { "priority" "PRIORITY" INTEGER +not-null+ } { "summary" "SUMMARY" { VARCHAR 256 } +not-null+ } { "description" "DESCRIPTION" { VARCHAR 256 } } } define-persistent : init-todo-table todo ensure-table ; : ( id -- todo ) todo new swap >>id uid >>uid ; : todo-template ( name -- template ) "resource:extra/webapps/todo/" swap ".xml" 3append ; : ( -- form ) "todo"
"view-todo" todo-template >>view-template "edit-todo" todo-template >>edit-template "todo-summary" todo-template >>summary-template "id" hidden >>renderer add-field "summary" t >>required add-field "priority" t >>required 0 >>default 0 >>min-value 10 >>max-value add-field "description" add-field ; : ( -- form ) "todo-list" "todo-list" todo-template >>view-template "list" +plain+ add-field ; TUPLE: todo-list < dispatcher ; :: ( -- responder ) [let | todo-form [ ] list-form [ ] ctor [ [ ] ] | todo-list new-dispatcher list-form ctor "list" add-main-responder todo-form ctor "view" add-responder todo-form ctor "$todo-list/view" "edit" add-responder ctor "$todo-list/list" "delete" add-responder "todo" todo-template >>template f ] ;