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