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