From dc16669058061601f09b05fbdbed2e2846bbf41b Mon Sep 17 00:00:00 2001 From: mdb Date: Thu, 23 Jan 2003 21:22:56 +0000 Subject: [PATCH] Added ability to delete a task; modified scripts to share standard error messages. git-svn-id: https://samskivert.googlecode.com/svn/trunk@1034 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- runtime/twodue/etc/messages.properties | 6 ++-- .../twodue/data/TaskRepository.java | 29 ++++++++++++++++++- .../com/samskivert/twodue/logic/detail.java | 4 +-- .../com/samskivert/twodue/logic/edit.java | 17 +++++++---- runtime/twodue/web/edit.wm | 23 +++++++++++---- 5 files changed, 63 insertions(+), 16 deletions(-) diff --git a/runtime/twodue/etc/messages.properties b/runtime/twodue/etc/messages.properties index ae65a476..6c2c2360 100644 --- a/runtime/twodue/etc/messages.properties +++ b/runtime/twodue/etc/messages.properties @@ -1,6 +1,6 @@ # -*- mode: makefile -*- # -# $Id: messages.properties,v 1.3 2002/11/09 01:40:01 mdb Exp $ +# $Id: messages.properties,v 1.4 2003/01/23 21:22:56 mdb Exp $ # # Translation messages for Two Due application @@ -9,6 +9,8 @@ app_name=Two Due +error.no_such_task = No task exists with that task id. + # # header.wm @@ -30,7 +32,6 @@ task.error.missing_complexity = No complexity selection for task. task.error.invalid_priority = No priority selection for task. task.error.invalid_creator = Creator not specified. task.error.missing_taskid = Internal error. No task id provided. -task.error.no_such_task = No task exists with that task id. # # index.wm @@ -52,6 +53,7 @@ edit.title = Edit Task edit.message.task_updated = Task updated. edit.message.note_added = Note added. edit.message.notes_updated = Notes updated. +edit.message.task_deleted = Task deleted. edit.error.missing_note = Can\'t add blank note. diff --git a/runtime/twodue/src/java/com/samskivert/twodue/data/TaskRepository.java b/runtime/twodue/src/java/com/samskivert/twodue/data/TaskRepository.java index 826cc8a6..3e0d493b 100644 --- a/runtime/twodue/src/java/com/samskivert/twodue/data/TaskRepository.java +++ b/runtime/twodue/src/java/com/samskivert/twodue/data/TaskRepository.java @@ -1,5 +1,5 @@ // -// $Id: TaskRepository.java,v 1.4 2002/11/12 22:32:02 mdb Exp $ +// $Id: TaskRepository.java,v 1.5 2003/01/23 21:22:56 mdb Exp $ package com.samskivert.twodue.data; @@ -249,6 +249,33 @@ public class TaskRepository extends JORARepository }); } + /** + * Deletes the specified task. + */ + public void deleteTask (final int taskId) + throws PersistenceException + { + execute(new Operation () { + public Object invoke (Connection conn, DatabaseLiaison liaison) + throws PersistenceException, SQLException + { + String query = "delete from TASKS where TASK_ID = ?"; + PreparedStatement stmt = null; + + try { + stmt = conn.prepareStatement(query); + stmt.setInt(1, taskId); + JDBCUtil.checkedUpdate(stmt, 1); + + } finally { + JDBCUtil.close(stmt); + } + + return null; + } + }); + } + /** * Updates a task that was previously loaded from the repository. */ diff --git a/runtime/twodue/src/java/com/samskivert/twodue/logic/detail.java b/runtime/twodue/src/java/com/samskivert/twodue/logic/detail.java index 1c44b5f8..4284018a 100644 --- a/runtime/twodue/src/java/com/samskivert/twodue/logic/detail.java +++ b/runtime/twodue/src/java/com/samskivert/twodue/logic/detail.java @@ -1,5 +1,5 @@ // -// $Id: detail.java,v 1.1 2002/11/08 21:49:17 mdb Exp $ +// $Id: detail.java,v 1.2 2003/01/23 21:22:56 mdb Exp $ package com.samskivert.twodue.logic; @@ -35,7 +35,7 @@ public class detail extends UserLogic // load up the task in question Task task = app.getRepository().loadTask(taskId); if (task == null) { - ctx.put("error", "task.error.no_such_task"); + ctx.put("error", "error.no_such_task"); } else { // format the notes and stuff those in the context ctx.put("notes", formatNotes(task.notes)); diff --git a/runtime/twodue/src/java/com/samskivert/twodue/logic/edit.java b/runtime/twodue/src/java/com/samskivert/twodue/logic/edit.java index 90cb771c..950b8e1e 100644 --- a/runtime/twodue/src/java/com/samskivert/twodue/logic/edit.java +++ b/runtime/twodue/src/java/com/samskivert/twodue/logic/edit.java @@ -1,5 +1,5 @@ // -// $Id: edit.java,v 1.1 2002/11/08 21:49:17 mdb Exp $ +// $Id: edit.java,v 1.2 2003/01/23 21:22:56 mdb Exp $ package com.samskivert.twodue.logic; @@ -36,12 +36,13 @@ public class edit extends UserLogic // load up the task in question Task task = app.getRepository().loadTask(taskId); if (task == null) { - ctx.put("error", "edit.error.no_such_task"); - } else { - // stick the task in the context - ctx.put("task", task); + ctx.put("error", "error.no_such_task"); + return; } + // stick the task in the context + ctx.put("task", task); + // if they've submitted the form, we update the task database if (ParameterUtil.parameterEquals( ctx.getRequest(), "action", "update")) { @@ -72,6 +73,12 @@ public class edit extends UserLogic app.getRepository().updateTask(task); ctx.put("error", "edit.message.task_updated"); + } else if (ParameterUtil.parameterEquals( + ctx.getRequest(), "action", "delete")) { + app.getRepository().deleteTask(taskId); + ctx.put("error", "edit.message.task_deleted"); + ctx.remove("task"); // clear out the task + } else if (ParameterUtil.parameterEquals( ctx.getRequest(), "action", "reopen")) { // clear out the completor and completion dates diff --git a/runtime/twodue/web/edit.wm b/runtime/twodue/web/edit.wm index 29bcd38c..3eb1fa65 100644 --- a/runtime/twodue/web/edit.wm +++ b/runtime/twodue/web/edit.wm @@ -1,14 +1,15 @@ #set ($title = $i18n.xlate("edit.title")) #import ("/header.wm") -

+#if ($task) +

@@ -113,4 +122,6 @@ $form.submit("submit", "Update")
-#if ($task && $task.completor) +#if ($task.completor) $form.fixedHidden("action", "reopen") @@ -27,9 +28,7 @@ $form.fixedHidden("action", "update") @@ -73,6 +72,18 @@ $form.text("owner", "size='10'", "") + + + +
Summary:
$form.submit("submit", "Update")
 
Other actions:
+ +
+$form.fixedHidden("action", "delete") + +$form.submit("submit", "Delete") +
+ +
@@ -98,9 +109,7 @@ $form.fixedHidden("action", "editnotes")
Notes:
+#end + #import ("/footer.wm")