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