Changeset 1260
- Timestamp:
- Dec 10, 2010, 3:12:28 PM (13 years ago)
- Location:
- trunk/grails-app
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/controllers/dbnp/studycapturing/WizardController.groovy
r1227 r1260 8 8 import dbnp.authentication.AuthenticationService 9 9 import dbnp.authentication.SecUser 10 import org.codehaus.groovy.grails.plugins.web.taglib.ValidationTagLib 10 11 11 12 … … 30 31 class WizardController { 31 32 def authenticationService 33 def validationTagLib = new ValidationTagLib() 32 34 33 35 /** … … 145 147 } 146 148 } else if (flow.jump && flow.jump.action == 'create') { 149 if (!flow.study) flow.study = new Study() 147 150 toStudyPage() 148 151 } else { … … 167 170 // clean the flow scope 168 171 flow.remove('study') 172 173 // create a new study instance 174 if (!flow.study) flow.study = new Study() 169 175 170 176 // set 'quicksave' variable to false … … 469 475 // remove eventGroup 470 476 def eventGroupToRemove = flow.study.eventGroups.find { it.getIdentifier() == (params.get('do') as int) } 471 if (eventGroupToRemove) {472 println flow.study.deleteEventGroup( eventGroupToRemove )473 }474 477 }.to "events" 475 478 on("previous") { … … 664 667 flow.assay.setFieldValue( 665 668 'externalAssayID', 666 this.ucwords(flow.study.code).replaceAll("([ ]{1,})", "") + '_' + this.ucwords(template.name).replaceAll("([ ]{1,})", "")669 ucwords(flow.study.code).replaceAll("([ ]{1,})", "") + '_' + ucwords(template.name).replaceAll("([ ]{1,})", "") 667 670 ) 668 671 } … … 673 676 flow.assay.setFieldValue( 674 677 'externalAssayID', 675 this.ucwords(flow.study.code).replaceAll("([ ]{1,})", "") + '_' + this.ucwords(template.name).replaceAll("([ ]{1,})", "")678 ucwords(flow.study.code).replaceAll("([ ]{1,})", "") + '_' + ucwords(template.name).replaceAll("([ ]{1,})", "") 676 679 ) 677 680 } … … 708 711 }.to "assays" 709 712 on("deleteAssay") { 710 println params711 712 713 // handle form data 713 714 assayPage(flow, flash, params) … … 908 909 */ 909 910 def loadStudy(flow, flash, params, user) { 910 flash.wizardErrors = new LinkedHashMap()911 flash.wizardErrors = [:] 911 912 912 913 // load study … … 960 961 */ 961 962 def studyPage(flow, flash, params) { 962 // remember the params in the flash scope963 flash. values = params963 flash.values = params 964 flash.wizardErrors = [:] 964 965 965 966 // instantiate study of it is not yet present … … 968 969 // did the study template change? 969 970 if (params.get('template').size() && flow.study.template?.name != params.get('template')) { 970 println ".change study template!"971 972 // yes, was the template already set?973 if (flow.study.template instanceof Template) {974 // yes, first make sure all values are unset?975 println "!!! check the database fields if data of a previous template remains in the database or is deleted by GORM!"976 }977 978 971 // set the template 979 972 flow.study.template = Template.findByName(params.remove('template')) … … 1004 997 } 1005 998 1006 // validate the study 1007 if (flow.study.validate()) { 1008 // instance is okay 1009 return true 999 // have we got a template? 1000 if (flow.study.template && flow.study.template instanceof Template) { 1001 // validate the study 1002 if (flow.study.validate()) { 1003 // instance is okay 1004 return true 1005 } else { 1006 // validation failed 1007 this.appendErrors(flow.study, flash.wizardErrors) 1008 return false 1009 } 1010 1010 } else { 1011 // validation failed 1012 flash.wizardErrors = [:] 1013 this.appendErrors(flow.study, flash.wizardErrors) 1011 // no, return an error that the template is not set 1012 this.appendErrorMap(['template': g.message(code: 'select.not.selected.or.add', args: ['template'])], flash.wizardErrors) 1014 1013 return false 1015 1014 } … … 1024 1023 */ 1025 1024 def handlePublications(flow, flash, params) { 1025 flash.wizardErrors = [:] 1026 1026 1027 if (!flow.study.publications) flow.study.publications = [] 1027 1028 … … 1065 1066 */ 1066 1067 def handleContacts(flow, flash, params) { 1068 flash.wizardErrors = [:] 1069 1067 1070 if (!flow.study.persons) flow.study.persons = [] 1068 1071 … … 1126 1129 */ 1127 1130 def handleUsers(flow, flash, params, type) { 1131 flash.wizardErrors = [:] 1132 1128 1133 def users = [] 1129 1134 … … 1140 1145 1141 1146 // Users are saved as user_id 1142 def userIDs = params.get( 1147 def userIDs = params.get(type + '_ids') 1143 1148 if (userIDs) { 1144 1149 // Find the individual IDs and make integers … … 1153 1158 def user = SecUser.get(id) 1154 1159 if (user) { 1155 1160 users.add(user) 1156 1161 } else { 1157 1162 log.info('.user with ID ' + id + ' not found in database.') … … 1167 1172 if (type == "readers") { 1168 1173 if (flow.study.readers) 1169 flow.study.readers.clear()1174 flow.study.readers.clear() 1170 1175 users.each { flow.study.addToReaders(it) } 1171 1176 } else if (type == "writers") { 1172 1177 if (flow.study.writers) 1173 flow.study.writers.clear()1178 flow.study.writers.clear() 1174 1179 1175 1180 users.each { flow.study.addToWriters(it) } 1176 1181 } 1177 1182 } 1178 1183 1179 1184 /** … … 1286 1291 errors = true 1287 1292 if (number < 1) this.appendErrorMap(['addNumber': 'Enter a positive number of subjects to add'], flash.wizardErrors) 1288 if (!species) this.appendErrorMap(['species': 'You need to select a species, or add one if it is not yet present'], flash.wizardErrors)1289 if (!template) this.appendErrorMap(['template': 'You need to select a template, or add one if it is not yet present'], flash.wizardErrors)1293 if (!species) this.appendErrorMap(['species': g.message(code: 'select.not.selected.or.add', args: ['species'])], flash.wizardErrors) 1294 if (!template) this.appendErrorMap(['template': g.message(code: 'select.not.selected.or.add', args: ['template'])], flash.wizardErrors) 1290 1295 } 1291 1296 … … 1353 1358 eventGroup.subjects.each() { subject -> 1354 1359 // instantiate a sample for this subject / event 1355 def samplingEventName = this.ucwords(event.template.name)1356 def eventGroupName = this.ucwords(eventGroup.name).replaceAll("([ ]{1,})", "")1357 def sampleName = ( this.ucwords(subject.name) + '_' + samplingEventName + '_' + eventGroupName + '_' + new RelTime(event.startTime).toString()).replaceAll("([ ]{1,})", "")1360 def samplingEventName = ucwords(event.template.name) 1361 def eventGroupName = ucwords(eventGroup.name).replaceAll("([ ]{1,})", "") 1362 def sampleName = (ucwords(subject.name) + '_' + samplingEventName + '_' + eventGroupName + '_' + new RelTime(event.startTime).toString()).replaceAll("([ ]{1,})", "") 1358 1363 def tempSampleIterator = 0 1359 1364 def tempSampleName = sampleName … … 1450 1455 // iterate through samplingEvents 1451 1456 eventGroup.samplingEvents.each() { samplingEvent -> 1452 def samplingEventName = this.ucwords(samplingEvent.template.name)1453 def eventGroupName = this.ucwords(eventGroup.name)1454 def sampleName = ( this.ucwords(subject.name) + '_' + samplingEventName + '_' + eventGroupName + '_' + new RelTime(samplingEvent.startTime).toString()).replaceAll("([ ]{1,})", "")1457 def samplingEventName = ucwords(samplingEvent.template.name) 1458 def eventGroupName = ucwords(eventGroup.name) 1459 def sampleName = (ucwords(subject.name) + '_' + samplingEventName + '_' + eventGroupName + '_' + new RelTime(samplingEvent.startTime).toString()).replaceAll("([ ]{1,})", "") 1455 1460 def tempSampleIterator = 0 1456 1461 def tempSampleName = sampleName … … 1609 1614 flow.study.assays.each() { assay -> 1610 1615 if (params.get( 'sample_' + sample.getIdentifier() + '_assay_' + assay.getIdentifier() )) { 1611 println "add sample "+sample.getIdentifier()+" to assay "+assay.getIdentifier()1612 1616 // add sample to assay 1613 1617 assay.addToSamples( sample ) … … 1616 1620 assay.removeFromSamples( sample ) 1617 1621 } 1618 println assay.samples1619 1622 } 1620 1623 } … … 1631 1634 * @return String 1632 1635 */ 1633 defucwords(String text) {1636 public static ucwords(String text) { 1634 1637 def newText = '' 1635 1638 … … 1670 1673 def getHumanReadableErrors(object) { 1671 1674 def errors = [:] 1672 object.errors.getAllErrors().each() { 1673 def message = it.toString() 1674 1675 //errors[it.getArguments()[0]] = it.getDefaultMessage() 1676 errors[it.getArguments()[0]] = message.substring(0, message.indexOf(';')) 1675 object.errors.getAllErrors().each() { error -> 1676 // error.codes.each() { code -> println code } 1677 1678 // generally speaking g.message(...) should work, 1679 // however it fails in some steps of the wizard 1680 // (add event, add assay, etc) so g is not always 1681 // availably. Using our own instance of the 1682 // validationTagLib instead so it is always 1683 // available to us 1684 errors[ error.getArguments()[0] ] = validationTagLib.message(error: error) 1677 1685 } 1678 1686 … … 1687 1695 */ 1688 1696 def appendErrors(object, map) { 1689 this.appendErrorMap( this.getHumanReadableErrors(object), map)1697 this.appendErrorMap(getHumanReadableErrors(object), map) 1690 1698 } 1691 1699 1692 1700 def appendErrors(object, map, prepend) { 1693 this.appendErrorMap( this.getHumanReadableErrors(object), map, prepend)1701 this.appendErrorMap(getHumanReadableErrors(object), map, prepend) 1694 1702 } 1695 1703 -
trunk/grails-app/i18n/messages.properties
r1167 r1260 55 55 typeMismatch.java.math.BigInteger=Property {0} must be a valid number 56 56 57 // TemplateEntity errors 58 templateEntity.typeMismatch.integer=Property {0} must be of type Integer and is currently of type {1} 59 templateEntity.typeMismatch.string=Property {0} must be of type String and is currently of type {1} 60 templateEntity.tooLong.string=Property {0} may contain at most 255 characters. 57 # Generic error messages 58 nullable={0} is required and may not be left blank 59 select.not.selected=You need to select a {0} 60 select.not.selected.or.add=You need to select a {0}, or add one if it is not yet present 61 62 # TemplateEntity errors 63 templateEntity.typeMismatch.long={0} has to be an absolute number (without comma's) 64 templateEntity.typeMismatch.double={0} must be a number 65 templateEntity.typeMismatch.integer={0} must be a number 66 templateEntity.typeMismatch.string={0} must be a text (maximum 255 characters) 67 templateEntity.tooLong.string={0} may contain at most 255 characters 61 68 templateEntity.typeMismatch.templateFieldListItem=Property {0} must be of type TemplateFieldListItem and is currently of type {1} 62 templateEntity.typeMismatch.float=Property {0} must be of type Float and is currently of type {1} 63 templateEntity.typeMismatch.double=Property {0} must be of type Double and is currently of type {1} 64 templateEntity.typeMismatch.date=Property {0} must be of type Date and is currently of type {1} 65 templateEntity.typeMismatch.term=Property {0} must be of type Term and is currently of type {1} 66 69 templateEntity.typeMismatch.date={0} must be a date 70 templateEntity.typeMismatch.term={0} must be an ontology term 67 71 event.endTime.greaterThanStartTime=End time should be greater than or equal to the Start Time -
trunk/grails-app/i18n/messages_nl.properties
r1181 r1260 54 54 typeMismatch.java.math.BigDecimal=Attribuut {0} is geen geldig nummer 55 55 typeMismatch.java.math.BigInteger=Attribuut {0} is geen geldig nummer 56 57 # Generic error messages 58 nullable={0} is verplicht en mag niet leeg zijn 59 select.not.selected=Je moet een {0} kiezen 60 select.not.selected.or.add=Je moet een {0} kiezen, of er een toevoegen als hij nog niet bestaat 61 62 63 # Template entity meesages 64 templateEntity.typeMismatch.long={0} moet een absoluut getal zijn (zonder komma's) 65 templateEntity.typeMismatch.double={0} moet een getal zijn 66 templateEntity.typeMismatch.integer={0} moet een getal zijn 67 templateEntity.typeMismatch.string={0} moest een tekst zijn (maximum 255 karakters) 68 templateEntity.tooLong.string={0} maar maar 255 karakters bevatten 69 templateEntity.typeMismatch.templateFieldListItem={0} moet van het type TemplateFieldListItem zijn en momenteel is het een {1} instantie 70 templateEntity.typeMismatch.date={0} moet een datum zijn 71 templateEntity.typeMismatch.term={0} must ontology term zijn 72 event.endTime.greaterThanStartTime=de eindtijd moet groter of gelijk zijn aan de begin tijd -
trunk/grails-app/views/wizard/common/_error.gsp
r1149 r1260 27 27 // mark error fields 28 28 <g:each in="${wizardErrors}" var="error"> 29 var element = $("input:[name='${error.key}'], input:[name='${error.key.toLowerCase().replaceAll("([^a-z0-9])","_")}'], select:[name='${error.key}'], select:[name='${error.key.toLowerCase().replaceAll("([^a-z0-9])","_")}'] ");29 var element = $("input:[name='${error.key}'], input:[name='${error.key.toLowerCase().replaceAll("([^a-z0-9])","_")}'], select:[name='${error.key}'], select:[name='${error.key.toLowerCase().replaceAll("([^a-z0-9])","_")}'], textarea:[name='${error.key}'], textarea:[name='${error.key.toLowerCase().replaceAll("([^a-z0-9])","_")}']"); 30 30 <g:if test="${error.value['dynamic']}"> 31 31 element.addClass('error');
Note: See TracChangeset
for help on using the changeset viewer.