source: trunk/grails-app/controllers/AssignedGroupDetailedController.groovy @ 247

Last change on this file since 247 was 247, checked in by gav, 15 years ago

Refactor AssignedGroup to use a serviced controller.

File size: 3.9 KB
RevLine 
[242]1import org.codehaus.groovy.grails.plugins.springsecurity.Secured
2
3class AssignedGroupDetailedController extends BaseController {
4
[247]5    def assignedGroupService
[242]6
[247]7    def index = {
8        flash.message = g.message(code: "assignedGroup.task.not.found")
9        redirect(controller:"taskDetailed", action:"search")
10    }
11
[242]12    // the delete, save and update actions only accept POST requests
13    static allowedMethods = [delete:'POST', save:'POST', update:'POST']
14
15    def list = {
[247]16            def result = assignedGroupService.list(params)
17            if(!result.error) {
18                return [ assignedGroupInstanceList: result.assignedGroupInstanceList,
19                                assignedGroupInstanceTotal: result.assignedGroupInstanceTotal ]
20            }
21
22            flash.message = g.message(code: result.error.code, args: result.error.args)
23            redirect( url: resource(dir:'') )
[242]24    }
25
26    def show = {
[247]27        def result = assignedGroupService.show(params)
[242]28
[247]29        if(!result.error)
30            return [ assignedGroupInstance: result.assignedGroupInstance ]
31
32        flash.message = g.message(code: result.error.code, args: result.error.args)
33
34        if(params.task?.id)
35            redirect(controller:"taskDetailed", action:"show", id: params.task.id)
36
37        redirect(controller:"taskDetailed", action:"search")
[242]38    }
39
40    def delete = {
[247]41        def result = assignedGroupService.delete(params)
42
43        if(!result.error) {
44            flash.message = g.message(code: "default.delete.success", args: ["AssignedGroup", params.id])
45            redirect(controller:"taskDetailed", action:"show", id: params.task?.id)
46            return
[242]47        }
[247]48
49        flash.message = g.message(code: result.error.code, args: result.error.args)
50
51        if(result.error.code == "default.not.found") {
52            redirect(controller:"taskDetailed", action:"show", id: params.task?.id)
53            return
[242]54        }
[247]55
56        redirect(action:show, id: params.id)
[242]57    }
58
59    def edit = {
[247]60        def result = assignedGroupService.edit(params)
[242]61
[247]62        if(!result.error)
63            return [ assignedGroupInstance : result.assignedGroupInstance ]
64
65        flash.message = g.message(code: result.error.code, args: result.error.args)
66
67        redirect(controller:"taskDetailed", action:"show", id: params.task?.id)
68
[242]69    }
70
71    def update = {
[247]72        def result = assignedGroupService.update(params)
[242]73
[247]74        if(!result.error) {
75            flash.message = g.message(code: "default.update.success", args: ["AssignedGroup", params.id])
76            redirect(action:show, id: params.id)
77            return
[242]78        }
[247]79
80        if(result.error.code == "default.not.found") {
81            flash.message = g.message(code: result.error.code, args: result.error.args)
82            redirect(controller:"taskDetailed", action:"show", id: params.task?.id)
83            return
[242]84        }
[247]85
86        render(view:'edit', model:[assignedGroupInstance: result.assignedGroupInstance.attach()])
[242]87    }
88
89    def create = {
[247]90        def result = assignedGroupService.create(params)
91
92        if(!result.error)
93            return [assignedGroupInstance: result.assignedGroupInstance]
94
95        if(result.error.code == "assignedGroup.task.not.found") {
96            flash.message = g.message(code: result.error.code, args: result.error.args)
[242]97            redirect(controller: "taskDetailed", action: "search")
[247]98            return
[242]99        }
[247]100
101        flash.message = g.message(code: result.error.code, args: result.error.args)
102        redirect(controller:"taskDetailed", action:"show", id: params.task?.id)
[242]103    }
104
105    def save = {
[247]106        def result = assignedGroupService.save(params)
[242]107
[247]108        if(!result.error) {
109            flash.message = g.message(code: "default.create.success", args: ["AssignedGroup", result.assignedGroupInstance.id])
110            redirect(controller:"taskDetailed", action:"show", id: result.assignedGroupInstance.task.id)
111            return
[242]112        }
[247]113
114        render(view:'edit', model:[assignedGroupInstance: result.assignedGroupInstance])
[242]115    }
[247]116
[242]117}
Note: See TracBrowser for help on using the repository browser.