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

Last change on this file since 376 was 359, checked in by duh, 13 years ago
  • set keyword expansion
  • Property svn:keywords set to Date Author Rev
File size: 4.0 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 list_extended = {
17        params.max = Math.min(params.max ? params.int('max') : 10, 100)
18        [studyList: Study.list(params), studyInstanceTotal: Study.count()]
19    }
20
21    /*def create = {
22        def studyInstance = new Study()
23        studyInstance.properties = params
24        return [studyInstance: studyInstance]
25    }
26
27    def save = {
28        def studyInstance = new Study(params)
29        if (studyInstance.save(flush: true)) {
30            flash.message = "${message(code: 'default.created.message', args: [message(code: 'study.label', default: 'Study'), studyInstance.id])}"
31            redirect(action: "show", id: studyInstance.id)
32        }
33        else {
34            render(view: "create", model: [studyInstance: studyInstance])
35        }
36    }*/
37
38    def show = {
39        def studyInstance = Study.get(params.id)
40        if (!studyInstance) {
41            flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'study.label', default: 'Study'), params.id])}"
42            redirect(action: "list")
43        }
44        else {
45            [studyInstance: studyInstance]
46        }
47    }
48
49
50    /*def edit = {
51        def studyInstance = Study.get(params.id)
52        if (!studyInstance) {
53            flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'study.label', default: 'Study'), params.id])}"
54            redirect(action: "list")
55        }
56        else {
57            return [studyInstance: studyInstance]
58        }
59    }
60
61    def update = {
62        def studyInstance = Study.get(params.id)
63        if (studyInstance) {
64            if (params.version) {
65                def version = params.version.toLong()
66                if (studyInstance.version > version) {
67                   
68                    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")
69                    render(view: "edit", model: [studyInstance: studyInstance])
70                    return
71                }
72            }
73            studyInstance.properties = params
74            if (!studyInstance.hasErrors() && studyInstance.save(flush: true)) {
75                flash.message = "${message(code: 'default.updated.message', args: [message(code: 'study.label', default: 'Study'), studyInstance.id])}"
76                redirect(action: "show", id: studyInstance.id)
77            }
78            else {
79                render(view: "edit", model: [studyInstance: studyInstance])
80            }
81        }
82        else {
83            flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'study.label', default: 'Study'), params.id])}"
84            redirect(action: "list")
85        }
86    }
87
88    def delete = {
89        def studyInstance = Study.get(params.id)
90        if (studyInstance) {
91            try {
92                studyInstance.delete(flush: true)
93                flash.message = "${message(code: 'default.deleted.message', args: [message(code: 'study.label', default: 'Study'), params.id])}"
94                redirect(action: "list")
95            }
96            catch (org.springframework.dao.DataIntegrityViolationException e) {
97                flash.message = "${message(code: 'default.not.deleted.message', args: [message(code: 'study.label', default: 'Study'), params.id])}"
98                redirect(action: "show", id: params.id)
99            }
100        }
101        else {
102            flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'study.label', default: 'Study'), params.id])}"
103            redirect(action: "list")
104        }
105    }*/
106}
Note: See TracBrowser for help on using the repository browser.