[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 | |
---|
[360] | 6 | def siteService |
---|
| 7 | |
---|
[116] | 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']) |
---|
[116] | 15 | def list = { |
---|
| 16 | params.max = Math.min( params.max ? params.max.toInteger() : 10, 100) |
---|
| 17 | [ siteInstanceList: Site.list( params ), siteInstanceTotal: Site.count() ] |
---|
| 18 | } |
---|
| 19 | |
---|
[298] | 20 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_AssetManager', 'ROLE_AssetUser']) |
---|
[116] | 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 | |
---|
[116] | 27 | def siteInstance = Site.get( params.id ) |
---|
| 28 | |
---|
| 29 | if(!siteInstance) { |
---|
| 30 | flash.message = "Site not found with id ${params.id}" |
---|
| 31 | redirect(action:list) |
---|
| 32 | } |
---|
| 33 | else { return [ siteInstance : siteInstance ] } |
---|
| 34 | } |
---|
| 35 | |
---|
[289] | 36 | @Secured(['ROLE_AppAdmin']) |
---|
[116] | 37 | def delete = { |
---|
[360] | 38 | def result = siteService.delete(params) |
---|
| 39 | |
---|
| 40 | if(!result.error) { |
---|
| 41 | flash.message = g.message(code: "default.delete.success", args: ["Site", params.id]) |
---|
| 42 | redirect(action:list) |
---|
| 43 | return |
---|
[116] | 44 | } |
---|
[360] | 45 | |
---|
| 46 | flash.errorMessage = g.message(code: result.error.code, args: result.error.args) |
---|
| 47 | |
---|
| 48 | if(result.error.code == "default.not.found") { |
---|
[116] | 49 | redirect(action:list) |
---|
[360] | 50 | return |
---|
[116] | 51 | } |
---|
[360] | 52 | |
---|
| 53 | redirect(action:show, id: params.id) |
---|
[116] | 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 | |
---|
[116] | 62 | def siteInstance = Site.get( params.id ) |
---|
| 63 | |
---|
| 64 | if(!siteInstance) { |
---|
| 65 | flash.message = "Site not found with id ${params.id}" |
---|
| 66 | redirect(action:list) |
---|
| 67 | } |
---|
| 68 | else { |
---|
| 69 | return [ siteInstance : siteInstance ] |
---|
| 70 | } |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | def update = { |
---|
| 74 | def siteInstance = Site.get( params.id ) |
---|
| 75 | if(siteInstance) { |
---|
| 76 | if(params.version) { |
---|
| 77 | def version = params.version.toLong() |
---|
| 78 | if(siteInstance.version > version) { |
---|
| 79 | |
---|
[403] | 80 | siteInstance.errors.rejectValue("version", "default.optimistic.locking.failure") |
---|
[116] | 81 | render(view:'edit',model:[siteInstance:siteInstance]) |
---|
| 82 | return |
---|
| 83 | } |
---|
| 84 | } |
---|
| 85 | siteInstance.properties = params |
---|
[178] | 86 | if(!siteInstance.hasErrors() && siteInstance.save(flush: true)) { |
---|
[116] | 87 | flash.message = "Site ${params.id} updated" |
---|
| 88 | redirect(action:show,id:siteInstance.id) |
---|
| 89 | } |
---|
| 90 | else { |
---|
| 91 | render(view:'edit',model:[siteInstance:siteInstance]) |
---|
| 92 | } |
---|
| 93 | } |
---|
| 94 | else { |
---|
| 95 | flash.message = "Site not found with id ${params.id}" |
---|
[163] | 96 | redirect(action:list) |
---|
[116] | 97 | } |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | def create = { |
---|
| 101 | def siteInstance = new Site() |
---|
| 102 | siteInstance.properties = params |
---|
| 103 | return ['siteInstance':siteInstance] |
---|
| 104 | } |
---|
| 105 | |
---|
| 106 | def save = { |
---|
| 107 | def siteInstance = new Site(params) |
---|
[178] | 108 | if(!siteInstance.hasErrors() && siteInstance.save(flush: true)) { |
---|
[116] | 109 | flash.message = "Site ${siteInstance.id} created" |
---|
| 110 | redirect(action:show,id:siteInstance.id) |
---|
| 111 | } |
---|
| 112 | else { |
---|
| 113 | render(view:'create',model:[siteInstance:siteInstance]) |
---|
| 114 | } |
---|
| 115 | } |
---|
| 116 | } |
---|