source: trunk/grails-app/controllers/PlannedMaintenanceDetailedController.groovy @ 124

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

Detail controller and views for Asset, AssetExtendedAttribute?, PlannedMaintenance?, MaintenanceAction?, RecurringSchedule?, SystemSection?.
Some minor work on Task controller and views.
Change PlannedMaintenance? relationship, adjust ERD, Bootstrap and Domain classes to suite.

File size: 4.2 KB
Line 
1import org.codehaus.groovy.grails.plugins.springsecurity.Secured
2
3class PlannedMaintenanceDetailedController 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        [ plannedMaintenanceInstanceList: PlannedMaintenance.list( params ), plannedMaintenanceInstanceTotal: PlannedMaintenance.count() ]
13    }
14
15    def show = {
16// Use this to return a list of the maintenanceActions
17//     def list = {
18//         params.max = Math.min( params.max ? params.max.toInteger() : 10,  100)
19//         [ maintenanceActionInstanceList: MaintenanceAction.list( params ), maintenanceActionInstanceTotal: MaintenanceAction.count() ]
20//     }
21        def plannedMaintenanceInstance = PlannedMaintenance.get( params.id )
22
23        if(!plannedMaintenanceInstance) {
24            flash.message = "PlannedMaintenance not found with id ${params.id}"
25            redirect(action:list)
26        }
27        else { return [ plannedMaintenanceInstance : plannedMaintenanceInstance ] }
28    }
29
30    def delete = {
31        def plannedMaintenanceInstance = PlannedMaintenance.get( params.id )
32        if(plannedMaintenanceInstance) {
33            try {
34                plannedMaintenanceInstance.delete()
35                flash.message = "PlannedMaintenance ${params.id} deleted"
36                redirect(action:list)
37            }
38            catch(org.springframework.dao.DataIntegrityViolationException e) {
39                flash.message = "PlannedMaintenance ${params.id} could not be deleted"
40                redirect(action:show,id:params.id)
41            }
42        }
43        else {
44            flash.message = "PlannedMaintenance not found with id ${params.id}"
45            redirect(action:list)
46        }
47    }
48
49    def edit = {
50        def plannedMaintenanceInstance = PlannedMaintenance.get( params.id )
51
52        if(!plannedMaintenanceInstance) {
53            flash.message = "PlannedMaintenance not found with id ${params.id}"
54            redirect(action:list)
55        }
56        else {
57            return [ plannedMaintenanceInstance : plannedMaintenanceInstance ]
58        }
59    }
60
61    def update = {
62        def plannedMaintenanceInstance = PlannedMaintenance.get( params.id )
63        if(plannedMaintenanceInstance) {
64            if(params.version) {
65                def version = params.version.toLong()
66                if(plannedMaintenanceInstance.version > version) {
67                   
68                    plannedMaintenanceInstance.errors.rejectValue("version", "plannedMaintenance.optimistic.locking.failure", "Another user has updated this PlannedMaintenance while you were editing.")
69                    render(view:'edit',model:[plannedMaintenanceInstance:plannedMaintenanceInstance])
70                    return
71                }
72            }
73            plannedMaintenanceInstance.properties = params
74            if(!plannedMaintenanceInstance.hasErrors() && plannedMaintenanceInstance.save()) {
75                flash.message = "PlannedMaintenance ${params.id} updated"
76                redirect(action:show,id:plannedMaintenanceInstance.id)
77            }
78            else {
79                render(view:'edit',model:[plannedMaintenanceInstance:plannedMaintenanceInstance])
80            }
81        }
82        else {
83            flash.message = "PlannedMaintenance not found with id ${params.id}"
84            redirect(action:edit,id:params.id)
85        }
86    }
87
88    def create = {
89        def plannedMaintenanceInstance = new PlannedMaintenance()
90        plannedMaintenanceInstance.properties = params
91        return ['plannedMaintenanceInstance':plannedMaintenanceInstance]
92    }
93
94    def save = {
95        def plannedMaintenanceInstance = new PlannedMaintenance(params)
96        if(!plannedMaintenanceInstance.hasErrors() && plannedMaintenanceInstance.save()) {
97            flash.message = "PlannedMaintenance ${plannedMaintenanceInstance.id} created"
98            redirect(action:show,id:plannedMaintenanceInstance.id)
99        }
100        else {
101            render(view:'create',model:[plannedMaintenanceInstance:plannedMaintenanceInstance])
102        }
103    }
104}
Note: See TracBrowser for help on using the repository browser.