[133] | 1 | import org.codehaus.groovy.grails.plugins.springsecurity.Secured |
---|
| 2 | |
---|
| 3 | class TaskProcedureDetailedController extends BaseController { |
---|
| 4 | |
---|
| 5 | def index = { redirect(action:list,params:params) } |
---|
| 6 | |
---|
| 7 | // the delete, save and update actions only accept POST requests |
---|
| 8 | static allowedMethods = [delete:'POST', save:'POST', update:'POST'] |
---|
| 9 | |
---|
| 10 | def list = { |
---|
| 11 | params.max = Math.min( params.max ? params.max.toInteger() : 10, 100) |
---|
| 12 | [ taskProcedureInstanceList: TaskProcedure.list( params ), taskProcedureInstanceTotal: TaskProcedure.count() ] |
---|
| 13 | } |
---|
[134] | 14 | |
---|
| 15 | def search = { |
---|
| 16 | redirect(action:list) |
---|
| 17 | } |
---|
[133] | 18 | |
---|
| 19 | def show = { |
---|
| 20 | def taskProcedureInstance = TaskProcedure.get( params.id ) |
---|
| 21 | |
---|
| 22 | if(!taskProcedureInstance) { |
---|
| 23 | flash.message = "TaskProcedure not found with id ${params.id}" |
---|
| 24 | redirect(action:list) |
---|
| 25 | } |
---|
| 26 | else { return [ taskProcedureInstance : taskProcedureInstance ] } |
---|
| 27 | } |
---|
| 28 | |
---|
| 29 | def delete = { |
---|
| 30 | def taskProcedureInstance = TaskProcedure.get( params.id ) |
---|
| 31 | if(taskProcedureInstance) { |
---|
| 32 | try { |
---|
| 33 | taskProcedureInstance.delete() |
---|
| 34 | flash.message = "TaskProcedure ${params.id} deleted" |
---|
| 35 | redirect(action:list) |
---|
| 36 | } |
---|
| 37 | catch(org.springframework.dao.DataIntegrityViolationException e) { |
---|
| 38 | flash.message = "TaskProcedure ${params.id} could not be deleted" |
---|
| 39 | redirect(action:show,id:params.id) |
---|
| 40 | } |
---|
| 41 | } |
---|
| 42 | else { |
---|
| 43 | flash.message = "TaskProcedure not found with id ${params.id}" |
---|
| 44 | redirect(action:list) |
---|
| 45 | } |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | def edit = { |
---|
| 49 | def taskProcedureInstance = TaskProcedure.get( params.id ) |
---|
| 50 | |
---|
| 51 | if(!taskProcedureInstance) { |
---|
| 52 | flash.message = "TaskProcedure not found with id ${params.id}" |
---|
| 53 | redirect(action:list) |
---|
| 54 | } |
---|
| 55 | else { |
---|
| 56 | return [ taskProcedureInstance : taskProcedureInstance ] |
---|
| 57 | } |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | def update = { |
---|
| 61 | def taskProcedureInstance = TaskProcedure.get( params.id ) |
---|
| 62 | if(taskProcedureInstance) { |
---|
| 63 | if(params.version) { |
---|
| 64 | def version = params.version.toLong() |
---|
| 65 | if(taskProcedureInstance.version > version) { |
---|
| 66 | |
---|
| 67 | taskProcedureInstance.errors.rejectValue("version", "taskProcedure.optimistic.locking.failure", "Another user has updated this TaskProcedure while you were editing.") |
---|
| 68 | render(view:'edit',model:[taskProcedureInstance:taskProcedureInstance]) |
---|
| 69 | return |
---|
| 70 | } |
---|
| 71 | } |
---|
| 72 | taskProcedureInstance.properties = params |
---|
| 73 | if(!taskProcedureInstance.hasErrors() && taskProcedureInstance.save()) { |
---|
| 74 | flash.message = "TaskProcedure ${params.id} updated" |
---|
| 75 | redirect(action:show,id:taskProcedureInstance.id) |
---|
| 76 | } |
---|
| 77 | else { |
---|
| 78 | render(view:'edit',model:[taskProcedureInstance:taskProcedureInstance]) |
---|
| 79 | } |
---|
| 80 | } |
---|
| 81 | else { |
---|
| 82 | flash.message = "TaskProcedure not found with id ${params.id}" |
---|
| 83 | redirect(action:edit,id:params.id) |
---|
| 84 | } |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | def create = { |
---|
[134] | 88 | def taskInstance = Task.get(params.taskInstance?.id) |
---|
| 89 | |
---|
[133] | 90 | def taskProcedureInstance = new TaskProcedure() |
---|
| 91 | taskProcedureInstance.properties = params |
---|
[134] | 92 | return ['taskProcedureInstance':taskProcedureInstance, |
---|
| 93 | taskInstance: taskInstance] |
---|
[133] | 94 | } |
---|
| 95 | |
---|
| 96 | def save = { |
---|
| 97 | def taskProcedureInstance = new TaskProcedure(params) |
---|
[134] | 98 | def taskInstance = Task.get(params.taskInstance.id) |
---|
| 99 | |
---|
[133] | 100 | if(!taskProcedureInstance.hasErrors() && taskProcedureInstance.save()) { |
---|
[134] | 101 | taskProcedureInstance.addToTasks(taskInstance) |
---|
[133] | 102 | flash.message = "TaskProcedure ${taskProcedureInstance.id} created" |
---|
| 103 | redirect(action:show,id:taskProcedureInstance.id) |
---|
| 104 | } |
---|
| 105 | else { |
---|
| 106 | render(view:'create',model:[taskProcedureInstance:taskProcedureInstance]) |
---|
| 107 | } |
---|
| 108 | } |
---|
| 109 | } |
---|