source: trunk/grails-app/controllers/InventoryMovementDetailedController.groovy @ 208

Last change on this file since 208 was 205, checked in by gav, 15 years ago

Switch InventoryMovement to the Grails provided attach() from refresh().

File size: 2.5 KB
Line 
1import org.codehaus.groovy.grails.plugins.springsecurity.Secured
2
3class InventoryMovementDetailedController extends BaseController {
4
5    def inventoryMovementService
6
7    def index = { redirect(action:list,params:params) }
8
9    // the delete, save and update actions only accept POST requests
10    static allowedMethods = [delete:'POST', save:'POST']
11
12    def list = {
13        flash.message = flash.message
14        redirect(controller:"taskDetailed", action:"search")
15    }
16
17    def show = {
18        def inventoryMovementInstance = InventoryMovement.get( params.id )
19
20        if(!inventoryMovementInstance) {
21            flash.message = "InventoryMovement not found with id ${params.id}"
22            redirect(action:list)
23        }
24        else { return [ inventoryMovementInstance : inventoryMovementInstance ] }
25    }
26
27    def delete = {
28        def result = inventoryMovementService.reverseMove(params)
29
30        if(!result.error) {
31            flash.message = "InventoryMovement ${params.id} deleted"
32            redirect(controller:"taskDetailed", action:"show", id:result.taskId)
33        }
34        else {
35            if(result.inventoryMovementInstance) {
36                render(view:'show',model:[inventoryMovementInstance:result.inventoryMovementInstance.attach()])
37            }
38            else {
39                flash.message = "Could not delete inventory movement."
40                redirect(controller:"taskDetailed", action:"search")
41            }
42        }
43    }
44
45    def create = {
46        if(!params.task?.id) {
47            flash.message = "Please select a task, then the Inventory tab."
48            redirect(controller:"taskDetailed", action:"search")
49        }
50        def inventoryMovementInstance = new InventoryMovement()
51        inventoryMovementInstance.properties = params
52        return ['inventoryMovementInstance':inventoryMovementInstance]
53    }
54
55    def save = {
56        def result = inventoryMovementService.move(params)
57
58        if(!result.error) {
59            flash.message = "Inventory Movement for ${result.inventoryMovementInstance.inventoryItem.name} created."
60            redirect(controller:"taskDetailed", action:"show", id: result.taskId)
61        }
62        else {
63            if(result.inventoryMovementInstance) {
64                render(view:'create',model:[inventoryMovementInstance:result.inventoryMovementInstance])
65            }
66            else {
67                flash.message = "Could not create inventory movement."
68                redirect(controller:"taskDetailed", action:"search", id:result.taskId)
69            }
70
71        }
72    }
73
74}
Note: See TracBrowser for help on using the repository browser.