[40] | 1 | class ModificationController extends BaseController { |
---|
| 2 | |
---|
| 3 | def beforeInterceptor = [action:this.&auth] |
---|
| 4 | |
---|
[21] | 5 | def index = { redirect(action:list,params:params) } |
---|
[16] | 6 | |
---|
[21] | 7 | // the delete, save and update actions only accept POST requests |
---|
| 8 | def allowedMethods = [delete:'POST', save:'POST', update:'POST'] |
---|
| 9 | |
---|
| 10 | def list = { |
---|
| 11 | if(!params.max) params.max = 10 |
---|
| 12 | [ modificationInstanceList: Modification.list( params ) ] |
---|
| 13 | } |
---|
| 14 | |
---|
| 15 | def show = { |
---|
| 16 | def modificationInstance = Modification.get( params.id ) |
---|
| 17 | |
---|
| 18 | if(!modificationInstance) { |
---|
| 19 | flash.message = "Modification not found with id ${params.id}" |
---|
| 20 | redirect(action:list) |
---|
| 21 | } |
---|
| 22 | else { return [ modificationInstance : modificationInstance ] } |
---|
| 23 | } |
---|
| 24 | |
---|
| 25 | def delete = { |
---|
| 26 | def modificationInstance = Modification.get( params.id ) |
---|
| 27 | if(modificationInstance) { |
---|
| 28 | modificationInstance.delete() |
---|
| 29 | flash.message = "Modification ${params.id} deleted" |
---|
| 30 | redirect(action:list) |
---|
| 31 | } |
---|
| 32 | else { |
---|
| 33 | flash.message = "Modification not found with id ${params.id}" |
---|
| 34 | redirect(action:list) |
---|
| 35 | } |
---|
| 36 | } |
---|
| 37 | |
---|
| 38 | def edit = { |
---|
| 39 | def modificationInstance = Modification.get( params.id ) |
---|
| 40 | |
---|
| 41 | if(!modificationInstance) { |
---|
| 42 | flash.message = "Modification not found with id ${params.id}" |
---|
| 43 | redirect(action:list) |
---|
| 44 | } |
---|
| 45 | else { |
---|
| 46 | return [ modificationInstance : modificationInstance ] |
---|
| 47 | } |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | def update = { |
---|
| 51 | def modificationInstance = Modification.get( params.id ) |
---|
| 52 | if(modificationInstance) { |
---|
| 53 | modificationInstance.properties = params |
---|
| 54 | if(!modificationInstance.hasErrors() && modificationInstance.save()) { |
---|
| 55 | flash.message = "Modification ${params.id} updated" |
---|
| 56 | redirect(action:show,id:modificationInstance.id) |
---|
| 57 | } |
---|
| 58 | else { |
---|
| 59 | render(view:'edit',model:[modificationInstance:modificationInstance]) |
---|
| 60 | } |
---|
| 61 | } |
---|
| 62 | else { |
---|
| 63 | flash.message = "Modification not found with id ${params.id}" |
---|
| 64 | redirect(action:edit,id:params.id) |
---|
| 65 | } |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | def create = { |
---|
| 69 | def modificationInstance = new Modification() |
---|
| 70 | modificationInstance.properties = params |
---|
| 71 | return ['modificationInstance':modificationInstance] |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | def save = { |
---|
| 75 | def modificationInstance = new Modification(params) |
---|
| 76 | if(!modificationInstance.hasErrors() && modificationInstance.save()) { |
---|
| 77 | flash.message = "Modification ${modificationInstance.id} created" |
---|
| 78 | redirect(action:show,id:modificationInstance.id) |
---|
| 79 | } |
---|
| 80 | else { |
---|
| 81 | render(view:'create',model:[modificationInstance:modificationInstance]) |
---|
| 82 | } |
---|
| 83 | } |
---|
[16] | 84 | } |
---|