! Copyright (c) 2008 Slava Pestov ! See http://factorcode.org/license.txt for BSD license. USING: accessors kernel sequences namespaces db db.types db.tuples validators hashtables urls html.components html.templates.chloe furnace.sessions furnace.boilerplate furnace.auth furnace.actions furnace.db furnace.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 ; : ( -- action ) [ validate-integer-id "id" value select-tuple from-object ] >>init "$todo-list/view-todo" >>template ; : validate-todo ( -- ) { { "summary" [ v-one-line ] } { "priority" [ v-integer 0 v-min-value 10 v-max-value ] } { "description" [ v-required ] } } validate-params ; : ( -- action ) [ 0 "priority" set-value ] >>init "$todo-list/new-todo" >>template [ validate-todo ] >>validate [ f dup { "summary" "priority" "description" } deposit-slots [ insert-tuple ] [ "$todo-list/view" >>path swap id>> "id" set-query-param ] bi ] >>submit ; : ( -- action ) [ validate-integer-id "id" value select-tuple from-object ] >>init "$todo-list/edit-todo" >>template [ validate-integer-id validate-todo ] >>validate [ f dup { "id" "summary" "priority" "description" } deposit-slots [ update-tuple ] [ "$todo-list/view" >>path swap id>> "id" set-query-param ] bi ] >>submit ; : ( -- action ) [ validate-integer-id ] >>validate [ "id" get delete-tuples URL" $todo-list/list" ] >>submit ; : ( -- action ) [ f select-tuples "items" set-value ] >>init "$todo-list/todo-list" >>template ; TUPLE: todo-list < dispatcher ; : ( -- responder ) todo-list new-dispatcher "list" add-main-responder "view" add-responder "new" add-responder "edit" add-responder "delete" add-responder "$todo-list/todo" >>template f ;