] each
] ;
+: styled-row ( class list -- )
+ #! Output an html TR row with each element of the list
+ #! being called to produce the output for each TD.
+
[
+ [
[ call ]
] each
+ ]
;
+
: simple-input ( name -- )
#! Output a simple HTML input field which will have the
#! specified name.
;
+: simple-input-with-value ( name value -- )
+ #! Output a simple HTML input field which will have the
+ #! specified name and value.
+ ;
+
: textarea-input ( name -- )
#! Output a simple HTML textarea field which will have the
#! specified name.
- ;
-! ;
+ ;
+
+: textarea-input-with-value ( name value -- )
+ #! Output a simple HTML textarea field which will have the
+ #! specified name and value.
+ ;
: password-input ( name -- )
#! Output an HTML password input field which will have the
@@ -186,19 +274,60 @@ USE: todo
#! todo item details.
[
"Add" button
] form ;
+
+: write-edit-todo-item-form ( item url -- )
+ #! Display the HTML for a form allowing editing of a
+ #! todo item details.
+ swap [
+ [
+
[
+
[
[ "Priority" write ]
+
[ "priority" dup get simple-input-with-value ]
]
+
[
[ "Description" write ]
+
[ "description" dup get textarea-input-with-value ]
]
+ ]
+ "Save" button
+ ] form
+ ] bind ;
+: todo-details-valid? ( priority description -- bool )
+ #! Return true if a valid priority and description were entered.
+ str-length 0 > swap "[0-9]" re-matches and ;
+
: get-new-todo-item ( -- )
#! Enter a new item to the current todo list.
[
- "Enter New Todo Item" [ write-new-todo-item-form ] simple-page
+ "Enter New Todo Item" [ include-todo-stylesheet ] [ write-new-todo-item-form ] styled-page
] show [
- "priority" get "description" get
- ] bind ;
+ "priority" get "description" get
+ ] bind 2dup todo-details-valid? [
+
+ ] [
+ 2drop
+ "Please ensure you enter a Priority from 0-9 and a description." show-message-page
+ get-new-todo-item
+ ] ifte ;
+
+: edit-item-details ( item -- )
+ #! Allow editing of an existing items details.
+ [
+ "Edit Item" [ include-todo-stylesheet ] [ write-edit-todo-item-form ] styled-page
+ ] show [
+ "priority" get "description" get
+ ] bind 2dup todo-details-valid? [
+ rot [ "description" set "priority" set ] bind
+ ] [
+ drop drop
+ "Please ensure you enter a Priority from 0-9 and a description." show-message-page
+ edit-item-details
+ ] ifte ;
: save-current-todo ( -- )
#! Save the current todo list
@@ -216,22 +345,35 @@ USE: todo
dup item-complete? [
"Delete" swap [ "todo" get swap delete-item save-current-todo ] lcurry1 quot-href
] [
- "Mark Completed" swap [ set-item-completed save-current-todo ] lcurry1 quot-href
+ "Complete" swap [ set-item-completed save-current-todo ] lcurry1 quot-href
] ifte ;
+: write-edit-action ( item -- )
+ #! Write out html to allow editing an item.
+ "Edit" swap [ edit-item-details save-current-todo ] lcurry1 quot-href ;
+
+: item-class ( -- string )
+ #! Return the class to use for displaying the row for the
+ #! item.
+ item-complete? [ "complete" ] [ "item" ] ifte ;
+
: write-item-row ( -- )
#! Write the todo list item as an HTML row.
- dup dup dup
- [ [ item-priority write ]
+ dup dup dup dup
+ dup item-class [
+ [ item-priority write ]
[ item-complete? [ "Yes" ] [ "No" ] ifte write ]
[ item-description write ]
- [ write-mark-complete-action ]
- ] row ;
+ [ write-mark-complete-action ]
+ [ write-edit-action ]
+ ] styled-row ;
: write-item-table ( -- )
#! Write the table of items for the todo list.
;
@@ -243,11 +385,12 @@ USE: todo
#! Show the current todo list.
[
<% "todo" get todo-username % "'s To Do list" % %>
+ [ include-todo-stylesheet ]
[
drop
"todo" get write-item-table
"Add Item" [ do-add-new-item ] quot-href
- ] simple-page
+ ] styled-page
] show drop ;
: todo-example ( path -- )