Changeset 896


Ignore:
Timestamp:
Sep 20, 2010, 5:17:37 PM (13 years ago)
Author:
keesvb
Message:

the workaround for checking Template name uniqueness actually broke the template editor, it doesn't work for validating existing Template objects. Deleted for now, and added validate to Template editor.

Location:
trunk/grails-app
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/controllers/dbnp/studycapturing/TemplateEditorController.groovy

    r711 r896  
    503503                        template.fields.add( Integer.parseInt( params.position ), templateField )
    504504                }
    505                 template.save(flush:true);
     505
     506            if (!template.validate()) {
     507                    response.status = 500;
     508                    template.errors.each { render it}
     509            }
     510            template.save(flush:true);
    506511
    507512                def html = g.render( template: 'elements/selected', model: [templateField: templateField, template: template, ontologies: Ontology.list(), fieldTypes: TemplateFieldType.list()] );
  • trunk/grails-app/domain/dbnp/studycapturing/Template.groovy

    r883 r896  
    7373                // which can co-exist with the same name. See also TemplateField
    7474                // name(unique:['entity'])
    75                 // workaround:
    76                 name(validator: { value, obj, errors ->
    77                         // 'obj' refers to the actual Template object
    78 
    79                         // define a boolean
    80                         boolean error = false
    81 
    82                         if (value && obj.entity) {
    83 
    84                                 // gather all Cars with this particular model
    85                                 def entityTemplates = Template.findAllByEntity(obj.entity)
    86 
    87                                 // check if there is already a Template object with this name in that collection
    88                                 if (entityTemplates.findAll{it.name.equals(value)}.size() > 0) {
    89                                         errors.rejectValue(
    90                                                 'name',
    91                                                 'template.UniqueNameViolation',
    92                                                 [value, obj.entity] as Object[],
    93                                                 'There already exists a template named {0} for entity {1}'
    94                                         )
    95                                         error = true
    96                                 }
    97                         }
    98                         else {
    99                                 // if there is no name or model defined, fail immediately
    100                                 error = true
    101                         }
    102                         // got an error, or not?
    103                         if (error) return false
    104                 })
    10575
    10676        }
Note: See TracChangeset for help on using the changeset viewer.