source: branches/features/taskProcedureRework/grails-app/controllers/MaintenanceActionDetailedController.groovy @ 779

Last change on this file since 779 was 763, checked in by gav, 14 years ago

Re-enable createDemoMaintenanceActions() and add list action to MaintenanceActionController?.

File size: 4.0 KB
RevLine 
[132]1import org.codehaus.groovy.grails.plugins.springsecurity.Secured
2
[298]3@Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_AssetManager'])
[133]4class MaintenanceActionDetailedController extends BaseController {
[132]5
6    // the delete, save and update actions only accept POST requests
7    static allowedMethods = [delete:'POST', save:'POST', update:'POST']
8
[763]9    def list = {
10        render "MaintenanceActions: ${MaintenanceAction.list()}"
11    }
12
[298]13    @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_AssetManager', 'ROLE_AssetUser'])
[132]14    def show = {
15        def maintenanceActionInstance = MaintenanceAction.get( params.id )
16
17        if(!maintenanceActionInstance) {
18            flash.message = "MaintenanceAction not found with id ${params.id}"
[573]19            redirect(controller: "appCore", action:"start")
[132]20        }
21        else { return [ maintenanceActionInstance : maintenanceActionInstance ] }
22    }
23
24    def delete = {
25        def maintenanceActionInstance = MaintenanceAction.get( params.id )
26        if(maintenanceActionInstance) {
27            try {
[573]28                def taskProcedure = maintenanceActionInstance.taskProcedure
[269]29                maintenanceActionInstance.delete(flush:true)
[132]30                flash.message = "MaintenanceAction ${params.id} deleted"
[573]31                redirect(controller: "taskProcedureDetailed", action:"show", id:taskProcedure.id)
[132]32            }
33            catch(org.springframework.dao.DataIntegrityViolationException e) {
34                flash.message = "MaintenanceAction ${params.id} could not be deleted"
35                redirect(action:show,id:params.id)
36            }
37        }
38        else {
39            flash.message = "MaintenanceAction not found with id ${params.id}"
[573]40            redirect(controller: "appCore", action:"start")
[132]41        }
42    }
43
44    def edit = {
45        def maintenanceActionInstance = MaintenanceAction.get( params.id )
46
47        if(!maintenanceActionInstance) {
48            flash.message = "MaintenanceAction not found with id ${params.id}"
[573]49            redirect(controller: "appCore", action:"start")
[132]50        }
51        else {
52            return [ maintenanceActionInstance : maintenanceActionInstance ]
53        }
54    }
55
56    def update = {
57        def maintenanceActionInstance = MaintenanceAction.get( params.id )
58        if(maintenanceActionInstance) {
59            if(params.version) {
60                def version = params.version.toLong()
61                if(maintenanceActionInstance.version > version) {
62                   
[403]63                    maintenanceActionInstance.errors.rejectValue("version", "default.optimistic.locking.failure")
[132]64                    render(view:'edit',model:[maintenanceActionInstance:maintenanceActionInstance])
65                    return
66                }
67            }
68            maintenanceActionInstance.properties = params
[178]69            if(!maintenanceActionInstance.hasErrors() && maintenanceActionInstance.save(flush: true)) {
[132]70                flash.message = "MaintenanceAction ${params.id} updated"
71                redirect(action:show,id:maintenanceActionInstance.id)
72            }
73            else {
74                render(view:'edit',model:[maintenanceActionInstance:maintenanceActionInstance])
75            }
76        }
77        else {
78            flash.message = "MaintenanceAction not found with id ${params.id}"
[573]79            redirect(controller: "appCore", action:"start")
[132]80        }
81    }
82
83    def create = {
84        def maintenanceActionInstance = new MaintenanceAction()
85        maintenanceActionInstance.properties = params
86        return ['maintenanceActionInstance':maintenanceActionInstance]
87    }
88
89    def save = {
90        def maintenanceActionInstance = new MaintenanceAction(params)
[178]91        if(!maintenanceActionInstance.hasErrors() && maintenanceActionInstance.save(flush: true)) {
[132]92            flash.message = "MaintenanceAction ${maintenanceActionInstance.id} created"
93            redirect(action:show,id:maintenanceActionInstance.id)
94        }
95        else {
96            render(view:'create',model:[maintenanceActionInstance:maintenanceActionInstance])
97        }
98    }
99}
Note: See TracBrowser for help on using the repository browser.