Index: trunk/grails-app/controllers/TaskDetailedController.groovy
===================================================================
--- trunk/grails-app/controllers/TaskDetailedController.groovy	(revision 395)
+++ trunk/grails-app/controllers/TaskDetailedController.groovy	(revision 418)
@@ -14,14 +14,10 @@
 
     // these actions only accept POST requests
-    static allowedMethods = [save:'POST', update:'POST', restore:'POST', trash:'POST', approve:'POST', renegeApproval:'POST', complete:'POST', reopen:'POST']
+    static allowedMethods = [save:'POST',update:'POST',restore:'POST', trash:'POST',
+                                                approve:'POST', renegeApproval:'POST', complete:'POST',
+                                                reopen:'POST', setAttentionFlag:'POST', clearAttentionFlag:'POST']
 
     @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser'])
     def index = { redirect(action: 'search', params: params) }
-
-    @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser'])
-    def list = {
-        params.max = Math.min( params.max ? params.max.toInteger() : 10,  100 )
-        [ taskInstanceList: Task.list( params ), taskInstanceTotal: Task.count() ]
-    }
 
     @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser'])
@@ -115,5 +111,5 @@
         filterParams.max = params.max
         filterParams.offset = params.offset?.toInteger() ?: 0
-        filterParams.sort = params.sort ?: "id"
+        filterParams.sort = params.sort ?: "attentionFlag"
         filterParams.order = params.order ?: "desc"
 
@@ -253,9 +249,4 @@
             params.sort = "id"
 
-            def entryWorkDoneList = Entry.withCriteria {
-                                                                eq("entryType", EntryType.get(2))
-                                                                eq("task", taskInstance)
-                                                        }
-
             def entryFaultList = Entry.withCriteria {
                                                                 eq("entryType", EntryType.get(1))
@@ -263,4 +254,14 @@
                                                         }
 
+            def entryCauseList = Entry.withCriteria {
+                                                                eq("entryType", EntryType.get(2))
+                                                                eq("task", taskInstance)
+                                                        }
+
+            def entryWorkDoneList = Entry.withCriteria {
+                                                                eq("entryType", EntryType.get(3))
+                                                                eq("task", taskInstance)
+                                                        }
+
             def subTaskInstanceList = Task.findAllByParentTaskAndTrash(taskInstance, false, params)
             def subTaskInstanceTotal = Task.countByParentTaskAndTrash(taskInstance, false)
@@ -290,6 +291,7 @@
 
             return [ taskInstance: taskInstance,
+                            entryFaultList: entryFaultList,
+                            entryCauseList: entryCauseList,
                             entryWorkDoneList: entryWorkDoneList,
-                            entryFaultList: entryFaultList,
                             taskProcedureInstance: taskProcedureInstance,
                             taskProcedureExits: taskProcedureExits,
@@ -308,35 +310,26 @@
     }
 
+    @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser'])
     def restore = {
 
-        if(!Task.exists(params.id)) {
-            flash.message = "Task not found with id ${params.id}"
-            redirect(action: 'search')
-        }
-
         def result = taskService.restore(params)
 
         if(!result.error) {
                 flash.message = "Task ${params.id} has been restored."
-                redirect(action: 'show', id: result.taskInstance.id)
-        }
-        else {
-            if(result.taskInstance) {
-                render(view:'edit',model:[taskInstance:result.taskInstance])
-            }
-            else {
-                flash.message = "Task could not be updated."
-                redirect(action: 'search')
-            }
-        }
-
-    }
-
+                redirect(action: show, id: params.id)
+                return
+        }
+
+        flash.errorMessage = g.message(code: result.error.code, args: result.error.args)
+
+        if(result.taskInstance)
+            redirect(action: show, id: params.id)
+        else
+            redirect(action: 'search')
+
+    }
+
+    @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser'])
     def trash = {
-
-        if(!Task.exists(params.id)) {
-            flash.message = "Task not found with id ${params.id}."
-            redirect(action: 'search')
-        }
 
         def result = taskService.trash(params)
@@ -345,64 +338,53 @@
                 flash.message = "Task ${params.id} has been moved to trash."
                 redirect(action: 'search')
-        }
-        else {
-            if(result.taskInstance) {
-                render(view:'edit',model:[taskInstance:result.taskInstance])
-            }
-            else {
-                flash.message = "Task could not be updated."
-                redirect(action: 'search')
-            }
-        }
-
-    }
-
+                return
+        }
+
+        flash.errorMessage = g.message(code: result.error.code, args: result.error.args)
+
+        if(result.taskInstance)
+            redirect(action: show, id: params.id)
+        else
+            redirect(action: 'search')
+
+    }
+
+    @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager'])
     def approve = {
 
-        if(!Task.exists(params.id)) {
-            flash.message = "Task not found with id ${params.id}."
-            redirect(action: 'search')
-        }
-
         def result = taskService.approve(params)
 
         if(!result.error) {
                 flash.message = "Task ${params.id} has been approved."
-                redirect(action: 'show', id: result.taskInstance.id)
-        }
-        else {
-            if(result.taskInstance) {
-                render(view:'edit',model:[taskInstance:result.taskInstance])
-            }
-            else {
-                flash.message = "Task could not be updated."
-                redirect(action: 'search')
-            }
-        }
-
-    }
-
+                redirect(action: show, id: params.id)
+                return
+        }
+
+        flash.errorMessage = g.message(code: result.error.code, args: result.error.args)
+
+        if(result.taskInstance)
+            redirect(action: show, id: params.id)
+        else
+            redirect(action: 'search')
+
+    }
+
+    @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser'])
     def renegeApproval = {
 
-        if(!Task.exists(params.id)) {
-            flash.message = "Task not found with id ${params.id}."
-            redirect(action: 'search')
-        }
-
         def result = taskService.renegeApproval(params)
 
         if(!result.error) {
                 flash.message = "Task ${params.id} has had approval removed."
-                redirect(action: 'show', id: result.taskInstance.id)
-        }
-        else {
-            if(result.taskInstance) {
-                render(view:'edit',model:[taskInstance:result.taskInstance])
-            }
-            else {
-                flash.message = "Task could not be updated."
-                redirect(action: 'search')
-            }
-        }
+                redirect(action: show, id: params.id)
+                return
+        }
+
+        flash.errorMessage = g.message(code: result.error.code, args: result.error.args)
+
+        if(result.taskInstance)
+            redirect(action: show, id: params.id)
+        else
+            redirect(action: 'search')
 
     }
@@ -411,24 +393,58 @@
     def complete = {
 
-        if(!Task.exists(params.id)) {
-            flash.message = "Task not found with id ${params.id}."
-            redirect(action: 'search')
-        }
-
         def result = taskService.complete(params)
 
         if(!result.error) {
                 flash.message = "Task ${params.id} has been completed."
-                redirect(action: 'show', id: result.taskInstance.id)
-        }
-        else {
-            if(result.taskInstance) {
-                render(view:'edit',model:[taskInstance:result.taskInstance])
-            }
-            else {
-                flash.message = "Task could not be updated."
-                redirect(action: 'search')
-            }
-        }
+                redirect(action: show, id: params.id)
+                return
+        }
+
+        flash.errorMessage = g.message(code: result.error.code, args: result.error.args)
+
+        if(result.taskInstance)
+            redirect(action: show, id: params.id)
+        else
+            redirect(action: 'search')
+
+    }
+
+    @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser'])
+    def setAttentionFlag = {
+
+        def result = taskService.setAttentionFlag(params)
+
+        if(!result.error) {
+                flash.message = "Task ${params.id} has been flagged for attention."
+                redirect(action: show, id: params.id)
+                return
+        }
+
+        flash.errorMessage = g.message(code: result.error.code, args: result.error.args)
+
+        if(result.taskInstance)
+            redirect(action: show, id: params.id)
+        else
+            redirect(action: 'search')
+
+    }
+
+    @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser'])
+    def clearAttentionFlag = {
+
+        def result = taskService.clearAttentionFlag(params)
+
+        if(!result.error) {
+                flash.message = "Task ${params.id} attention flag cleared."
+                redirect(action: show, id: params.id)
+                return
+        }
+
+        flash.errorMessage = g.message(code: result.error.code, args: result.error.args)
+
+        if(result.taskInstance)
+            redirect(action: show, id: params.id)
+        else
+            redirect(action: 'search')
 
     }
@@ -437,24 +453,18 @@
     def reopen = {
 
-        if(!Task.exists(params.id)) {
-            flash.message = "Task not found with id ${params.id}."
-            redirect(action: 'search')
-        }
-
         def result = taskService.reopen(params)
 
         if(!result.error) {
                 flash.message = "Task ${params.id} has been reopened."
-                redirect(action: 'show', id: result.taskInstance.id)
-        }
-        else {
-            if(result.taskInstance) {
-                render(view:'edit',model:[taskInstance:result.taskInstance])
-            }
-            else {
-                flash.message = "Task could not be updated."
-                redirect(action: 'search')
-            }
-        }
+                redirect(action: show, id: params.id)
+                return
+        }
+
+        flash.errorMessage = g.message(code: result.error.code, args: result.error.args)
+
+        if(result.taskInstance)
+            redirect(action: show, id: params.id)
+        else
+            redirect(action: 'search')
 
     }
@@ -488,18 +498,16 @@
     def update = {
 
-        if(!Task.exists(params.id)) {
-            flash.message = "Task not found with id ${params.id}"
-            redirect(action: 'search')
-        }
-
         def result = taskService.update(params)
 
         if(!result.error) {
                 flash.message = "Task ${params.id} updated"
-                redirect(action: 'show', id: result.taskInstance.id)
-        }
-        else {
-            render(view:'edit',model:[taskInstance:result.taskInstance.attach()])
-        }
+                redirect(action: show, id: params.id)
+                return
+        }
+
+        if(result.error.code == "task.modifications.failedToSave")
+            flash.errorMessage = g.message(code: result.error.code, args: result.error.args)
+
+        render(view:'edit',model:[taskInstance:result.taskInstance.attach()])
 
     }
@@ -526,15 +534,11 @@
             flash.message = "Task ${result.taskInstance.id} created."
             redirect(action: 'show', id: result.taskInstance.id)
-        }
-        else {
-            if(result.taskInstance) {
-                render(view:'create', model:[taskInstance:result.taskInstance])
-            }
-            else {
-                flash.message = "Could not create task."
-                redirect(action: 'search')
-            }
-
-        }
+            return
+        }
+
+        if(result.error.code == "task.modifications.failedToSave")
+            flash.errorMessage = g.message(code: result.error.code, args: result.error.args)
+
+        render(view:'create', model:[taskInstance:result.taskInstance])
     }
 
@@ -571,5 +575,5 @@
             else {
                 if(result.taskInstance.errors.hasFieldErrors("parentTask")) {
-                    flash.message = g.message(code:"task.operationNotPermittedOnTaskInTrash")
+                    flash.errorMessage = g.message(code:"task.operationNotPermittedOnTaskInTrash")
                     redirect(action: 'show', id:  parentTaskInstance.id)
                 }
@@ -587,18 +591,20 @@
 
     @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser'])
-    def createBreakin = {
+    def createImmediateCallout = {
         def taskInstance = new Task()
 
         def entryFaultInstance = new Entry(entryType: EntryType.get(1))  // Fault.
-        def entryWorkDoneInstance = new Entry(entryType: EntryType.get(2))  // Work Done.
+        def entryCauseInstance = new Entry(entryType: EntryType.get(2))  // Cause.
+        def entryWorkDoneInstance = new Entry(entryType: EntryType.get(3))  // Work Done.
 
         return ['taskInstance': taskInstance,
                         'entryFaultInstance': entryFaultInstance,
+                        'entryCauseInstance': entryCauseInstance,
                         'entryWorkDoneInstance': entryWorkDoneInstance]
     }
 
     @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_TaskManager', 'ROLE_TaskUser'])
-    def saveBreakin = {
-        def result = taskService.saveBreakin(params)
+    def saveImmediateCallout = {
+        def result = taskService.saveImmediateCallout(params)
 
         if(!result.error) {
@@ -611,7 +617,8 @@
             flash.errorMessage = g.message(code: result.error.code, args: result.error.args)
 
-        render(view:'createBreakin',
+        render(view:'createImmediateCallout',
                     model: ['taskInstance': result.taskInstance,
                                 'entryFaultInstance': result.entryFaultInstance,
+                                'entryCauseInstance': result.entryCauseInstance,
                                 'entryWorkDoneInstance': result.entryWorkDoneInstance])
 
