[118] | 1 | import org.codehaus.groovy.grails.plugins.springsecurity.Secured |
---|
| 2 | |
---|
[298] | 3 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_AssetManager']) |
---|
[268] | 4 | class SectionDetailedController extends BaseController { |
---|
[118] | 5 | |
---|
[358] | 6 | def sectionService |
---|
| 7 | |
---|
[118] | 8 | // the delete, save and update actions only accept POST requests |
---|
| 9 | static allowedMethods = [delete:'POST', save:'POST', update:'POST'] |
---|
| 10 | |
---|
[298] | 11 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_AssetManager', 'ROLE_AssetUser']) |
---|
[289] | 12 | def index = { redirect(action:list,params:params) } |
---|
| 13 | |
---|
[298] | 14 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_AssetManager', 'ROLE_AssetUser']) |
---|
[118] | 15 | def list = { |
---|
| 16 | params.max = Math.min( params.max ? params.max.toInteger() : 10, 100) |
---|
[268] | 17 | [ sectionInstanceList: Section.list( params ), sectionInstanceTotal: Section.count() ] |
---|
[118] | 18 | } |
---|
| 19 | |
---|
[298] | 20 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_AssetManager', 'ROLE_AssetUser']) |
---|
[118] | 21 | def show = { |
---|
[385] | 22 | |
---|
| 23 | // In the case of an actionSubmit button, rewrite action name from 'index'. |
---|
| 24 | if(params._action_Show) |
---|
| 25 | params.action='show' |
---|
| 26 | |
---|
[268] | 27 | def sectionInstance = Section.get( params.id ) |
---|
[118] | 28 | |
---|
[268] | 29 | if(!sectionInstance) { |
---|
| 30 | flash.message = "Section not found with id ${params.id}" |
---|
[118] | 31 | redirect(action:list) |
---|
| 32 | } |
---|
[268] | 33 | else { return [ sectionInstance : sectionInstance ] } |
---|
[118] | 34 | } |
---|
| 35 | |
---|
[289] | 36 | @Secured(['ROLE_AppAdmin']) |
---|
[118] | 37 | def delete = { |
---|
[358] | 38 | def result = sectionService.delete(params) |
---|
| 39 | |
---|
| 40 | if(!result.error) { |
---|
| 41 | flash.message = g.message(code: "default.delete.success", args: ["Section", params.id]) |
---|
| 42 | redirect(action:list) |
---|
| 43 | return |
---|
[118] | 44 | } |
---|
[358] | 45 | |
---|
| 46 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
| 47 | |
---|
| 48 | if(result.error.code == "default.not.found") { |
---|
[118] | 49 | redirect(action:list) |
---|
[358] | 50 | return |
---|
[118] | 51 | } |
---|
[358] | 52 | |
---|
| 53 | redirect(action:show, id: params.id) |
---|
[118] | 54 | } |
---|
| 55 | |
---|
| 56 | def edit = { |
---|
[385] | 57 | |
---|
| 58 | // In the case of an actionSubmit button, rewrite action name from 'index'. |
---|
| 59 | if(params._action_Edit) |
---|
| 60 | params.action='edit' |
---|
| 61 | |
---|
[268] | 62 | def sectionInstance = Section.get( params.id ) |
---|
[118] | 63 | |
---|
[268] | 64 | if(!sectionInstance) { |
---|
| 65 | flash.message = "Section not found with id ${params.id}" |
---|
[118] | 66 | redirect(action:list) |
---|
| 67 | } |
---|
| 68 | else { |
---|
[268] | 69 | return [ sectionInstance : sectionInstance ] |
---|
[118] | 70 | } |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | def update = { |
---|
[268] | 74 | def sectionInstance = Section.get( params.id ) |
---|
| 75 | if(sectionInstance) { |
---|
[118] | 76 | if(params.version) { |
---|
| 77 | def version = params.version.toLong() |
---|
[268] | 78 | if(sectionInstance.version > version) { |
---|
[118] | 79 | |
---|
[403] | 80 | sectionInstance.errors.rejectValue("version", "default.optimistic.locking.failure") |
---|
[268] | 81 | render(view:'edit',model:[sectionInstance:sectionInstance]) |
---|
[118] | 82 | return |
---|
| 83 | } |
---|
| 84 | } |
---|
[268] | 85 | sectionInstance.properties = params |
---|
| 86 | if(!sectionInstance.hasErrors() && sectionInstance.save(flush: true)) { |
---|
| 87 | flash.message = "Section ${params.id} updated" |
---|
| 88 | redirect(action:show,id:sectionInstance.id) |
---|
[118] | 89 | } |
---|
| 90 | else { |
---|
[268] | 91 | render(view:'edit',model:[sectionInstance:sectionInstance]) |
---|
[118] | 92 | } |
---|
| 93 | } |
---|
| 94 | else { |
---|
[268] | 95 | flash.message = "Section not found with id ${params.id}" |
---|
[162] | 96 | redirect(action:list) |
---|
[118] | 97 | } |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | def create = { |
---|
[268] | 101 | def sectionInstance = new Section() |
---|
| 102 | sectionInstance.properties = params |
---|
| 103 | return ['sectionInstance':sectionInstance] |
---|
[118] | 104 | } |
---|
| 105 | |
---|
| 106 | def save = { |
---|
[268] | 107 | def sectionInstance = new Section(params) |
---|
| 108 | if(!sectionInstance.hasErrors() && sectionInstance.save(flush: true)) { |
---|
| 109 | flash.message = "Section ${sectionInstance.id} created" |
---|
| 110 | redirect(action:show,id:sectionInstance.id) |
---|
[118] | 111 | } |
---|
| 112 | else { |
---|
[268] | 113 | render(view:'create',model:[sectionInstance:sectionInstance]) |
---|
[118] | 114 | } |
---|
| 115 | } |
---|
| 116 | } |
---|