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