[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 = { |
---|
[268] | 22 | def sectionInstance = Section.get( params.id ) |
---|
[118] | 23 | |
---|
[268] | 24 | if(!sectionInstance) { |
---|
| 25 | flash.message = "Section not found with id ${params.id}" |
---|
[118] | 26 | redirect(action:list) |
---|
| 27 | } |
---|
[268] | 28 | else { return [ sectionInstance : sectionInstance ] } |
---|
[118] | 29 | } |
---|
| 30 | |
---|
[289] | 31 | @Secured(['ROLE_AppAdmin']) |
---|
[118] | 32 | def delete = { |
---|
[358] | 33 | def result = sectionService.delete(params) |
---|
| 34 | |
---|
| 35 | if(!result.error) { |
---|
| 36 | flash.message = g.message(code: "default.delete.success", args: ["Section", params.id]) |
---|
| 37 | redirect(action:list) |
---|
| 38 | return |
---|
[118] | 39 | } |
---|
[358] | 40 | |
---|
| 41 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
| 42 | |
---|
| 43 | if(result.error.code == "default.not.found") { |
---|
[118] | 44 | redirect(action:list) |
---|
[358] | 45 | return |
---|
[118] | 46 | } |
---|
[358] | 47 | |
---|
| 48 | redirect(action:show, id: params.id) |
---|
[118] | 49 | } |
---|
| 50 | |
---|
| 51 | def edit = { |
---|
[268] | 52 | def sectionInstance = Section.get( params.id ) |
---|
[118] | 53 | |
---|
[268] | 54 | if(!sectionInstance) { |
---|
| 55 | flash.message = "Section not found with id ${params.id}" |
---|
[118] | 56 | redirect(action:list) |
---|
| 57 | } |
---|
| 58 | else { |
---|
[268] | 59 | return [ sectionInstance : sectionInstance ] |
---|
[118] | 60 | } |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | def update = { |
---|
[268] | 64 | def sectionInstance = Section.get( params.id ) |
---|
| 65 | if(sectionInstance) { |
---|
[118] | 66 | if(params.version) { |
---|
| 67 | def version = params.version.toLong() |
---|
[268] | 68 | if(sectionInstance.version > version) { |
---|
[118] | 69 | |
---|
[268] | 70 | sectionInstance.errors.rejectValue("version", "section.optimistic.locking.failure", "Another user has updated this Section while you were editing.") |
---|
| 71 | render(view:'edit',model:[sectionInstance:sectionInstance]) |
---|
[118] | 72 | return |
---|
| 73 | } |
---|
| 74 | } |
---|
[268] | 75 | sectionInstance.properties = params |
---|
| 76 | if(!sectionInstance.hasErrors() && sectionInstance.save(flush: true)) { |
---|
| 77 | flash.message = "Section ${params.id} updated" |
---|
| 78 | redirect(action:show,id:sectionInstance.id) |
---|
[118] | 79 | } |
---|
| 80 | else { |
---|
[268] | 81 | render(view:'edit',model:[sectionInstance:sectionInstance]) |
---|
[118] | 82 | } |
---|
| 83 | } |
---|
| 84 | else { |
---|
[268] | 85 | flash.message = "Section not found with id ${params.id}" |
---|
[162] | 86 | redirect(action:list) |
---|
[118] | 87 | } |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | def create = { |
---|
[268] | 91 | def sectionInstance = new Section() |
---|
| 92 | sectionInstance.properties = params |
---|
| 93 | return ['sectionInstance':sectionInstance] |
---|
[118] | 94 | } |
---|
| 95 | |
---|
| 96 | def save = { |
---|
[268] | 97 | def sectionInstance = new Section(params) |
---|
| 98 | if(!sectionInstance.hasErrors() && sectionInstance.save(flush: true)) { |
---|
| 99 | flash.message = "Section ${sectionInstance.id} created" |
---|
| 100 | redirect(action:show,id:sectionInstance.id) |
---|
[118] | 101 | } |
---|
| 102 | else { |
---|
[268] | 103 | render(view:'create',model:[sectionInstance:sectionInstance]) |
---|
[118] | 104 | } |
---|
| 105 | } |
---|
| 106 | } |
---|