source: trunk/grails-app/controllers/dbnp/studycapturing/StudyController.groovy @ 253

Last change on this file since 253 was 253, checked in by keesvb, 10 years ago

Cleaned up BootStrap? (removed accidental multiple addition of eventGroup in PPSH study), cleaned up scaffolded classes in root package, removed obsolete BaseController?, added some code to Sandbox

  • Property svn:keywords set to Author Rev Date
File size: 3.8 KB
Line 
1package dbnp.studycapturing
2
3class StudyController {
4
5    //static allowedMethods = [save: "POST", update: "POST", delete: "POST"]
6
7    def index = {
8        redirect(action: "list", params: params)
9    }
10
11    def list = {
12        params.max = Math.min(params.max ? params.int('max') : 10, 100)
13        [studyInstanceList: Study.list(params), studyInstanceTotal: Study.count()]
14    }
15
16    /*def create = {
17        def studyInstance = new Study()
18        studyInstance.properties = params
19        return [studyInstance: studyInstance]
20    }
21
22    def save = {
23        def studyInstance = new Study(params)
24        if (studyInstance.save(flush: true)) {
25            flash.message = "${message(code: 'default.created.message', args: [message(code: 'study.label', default: 'Study'), studyInstance.id])}"
26            redirect(action: "show", id: studyInstance.id)
27        }
28        else {
29            render(view: "create", model: [studyInstance: studyInstance])
30        }
31    }*/
32
33    def show = {
34        def studyInstance = Study.get(params.id)
35        if (!studyInstance) {
36            flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'study.label', default: 'Study'), params.id])}"
37            redirect(action: "list")
38        }
39        else {
40            [studyInstance: studyInstance]
41        }
42    }
43
44    /*def edit = {
45        def studyInstance = Study.get(params.id)
46        if (!studyInstance) {
47            flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'study.label', default: 'Study'), params.id])}"
48            redirect(action: "list")
49        }
50        else {
51            return [studyInstance: studyInstance]
52        }
53    }
54
55    def update = {
56        def studyInstance = Study.get(params.id)
57        if (studyInstance) {
58            if (params.version) {
59                def version = params.version.toLong()
60                if (studyInstance.version > version) {
61                   
62                    studyInstance.errors.rejectValue("version", "default.optimistic.locking.failure", [message(code: 'study.label', default: 'Study')] as Object[], "Another user has updated this Study while you were editing")
63                    render(view: "edit", model: [studyInstance: studyInstance])
64                    return
65                }
66            }
67            studyInstance.properties = params
68            if (!studyInstance.hasErrors() && studyInstance.save(flush: true)) {
69                flash.message = "${message(code: 'default.updated.message', args: [message(code: 'study.label', default: 'Study'), studyInstance.id])}"
70                redirect(action: "show", id: studyInstance.id)
71            }
72            else {
73                render(view: "edit", model: [studyInstance: studyInstance])
74            }
75        }
76        else {
77            flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'study.label', default: 'Study'), params.id])}"
78            redirect(action: "list")
79        }
80    }
81
82    def delete = {
83        def studyInstance = Study.get(params.id)
84        if (studyInstance) {
85            try {
86                studyInstance.delete(flush: true)
87                flash.message = "${message(code: 'default.deleted.message', args: [message(code: 'study.label', default: 'Study'), params.id])}"
88                redirect(action: "list")
89            }
90            catch (org.springframework.dao.DataIntegrityViolationException e) {
91                flash.message = "${message(code: 'default.not.deleted.message', args: [message(code: 'study.label', default: 'Study'), params.id])}"
92                redirect(action: "show", id: params.id)
93            }
94        }
95        else {
96            flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'study.label', default: 'Study'), params.id])}"
97            redirect(action: "list")
98        }
99    }*/
100}
Note: See TracBrowser for help on using the repository browser.