Changeset 180 for trunk/grails-app/controllers
- Timestamp:
- Feb 9, 2010, 3:22:46 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/controllers/dbnp/studycapturing/WizardController.groovy
r178 r180 94 94 // validation failed, feedback errors 95 95 flash.errors = new LinkedHashMap() 96 this.appendErrors(flow.study, flash.errors)96 this.appendErrors(flow.study, flash.errors) 97 97 error() 98 98 } … … 110 110 } 111 111 } 112 on 112 on("add") { 113 113 // fetch species by name (as posted by the form) 114 114 def speciesTerm = Term.findByName(params.addSpecies) 115 115 116 116 // add x subject of species y 117 117 (params.addNumber as int).times { 118 118 def increment = flow.subjects.size() 119 flow.subjects[ increment ] = new Subject( 120 name: 'Subject ' + (increment+1), 121 species: speciesTerm 119 flow.subjects[increment] = new Subject( 120 name: 'Subject ' + (increment + 1), 121 species: speciesTerm, 122 template: flow.study.template 122 123 ) 123 124 } 124 125 }.to "subjects" 125 126 on("next") { 127 def errors = false 128 flash.errors = new LinkedHashMap() 129 126 130 // got one or more subjects? 127 131 if (flow.subjects.size() < 1) { 132 errors = true; 133 } else { 134 // handle form data 135 def id = 0; 136 flow.subjects.each() { 137 // store subject properties 138 it.name = params.get('subject_' + id + '_name') 139 it.species = Term.findByName(params.get('subject_' + id + '_species')) 140 141 // clear lists 142 def stringList = new LinkedHashMap(); 143 def intList = new LinkedHashMap(); 144 145 // get all template fields 146 flow.study.template.subjectFields.each() { 147 // get value 148 def value = params.get('subject_' + id + '_' + it.name); 149 if (value) { 150 // add to template parameters 151 switch (it.type) { 152 case 'STRINGLIST': 153 stringList[it.name] = value 154 break; 155 case 'INTEGER': 156 intList[ it.name ] = value 157 break; 158 default: 159 // unsupported type? 160 println "ERROR: unsupported type: "+it.type 161 break; 162 } 163 } 164 } 165 166 // set field data 167 it.templateStringFields = stringList 168 it.templateIntegerFields = intList 169 170 // validate subject 171 if (!it.validate()) { 172 errors = true 173 //println id + ' :: ' + it.errors.getAllErrors() 174 this.appendErrors(it, flash.errors) 175 } 176 177 id++; 178 } 179 } 180 181 // got errors? 182 if (errors) { 183 println flash.errors 128 184 error() 129 } 130 println params 185 } else { 186 success() 187 } 131 188 }.to "groups" 132 189 on("previous") { … … 146 203 on("add") { 147 204 def increment = flow.groups.size() 148 flow.groups[ increment] = new SubjectGroup(params)205 flow.groups[increment] = new SubjectGroup(params) 149 206 150 207 println flow.groups
Note: See TracChangeset
for help on using the changeset viewer.