Changeset 257


Ignore:
Timestamp:
Mar 11, 2010, 2:23:53 PM (13 years ago)
Author:
duh
Message:
  • added limited auto parsing for DATE template entity values that are set as String instead of Date instances
  • general improvements and bugfixes
Location:
trunk
Files:
5 edited

Legend:

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

    r252 r257  
    586586                                        def value = params.get('subject_' + subjectId + '_' + subjectField.name)
    587587
    588                                         if (value) flow.subjects[ subjectId ].setFieldValue(subjectField.name, value)
     588                                        if (value) {
     589                                                flow.subjects[ subjectId ].setFieldValue(subjectField.name, value)
     590                                        }
    589591                                }
    590592
  • trunk/grails-app/domain/dbnp/studycapturing/TemplateEntity.groovy

    r247 r257  
    9090                }
    9191                else {
    92                         TemplateField field = this.template.fields.find { it.name == fieldName} 
     92                        TemplateField field = this.template.fields.find { it.name == fieldName}
    9393                        if (field == null) {
    9494                                throw new NoSuchFieldException("Field ${fieldName} not found in class properties or template fields")
     
    9999                                        value = field.listEntries.find { it.name == value }
    100100                                }
     101
     102                                // handle string values for date fields
     103                                if (field.type == TemplateFieldType.DATE && value.class == String) {
     104                                        // a string was given, attempt to transform it into a date instance
     105                                        // and -for now- assume the dd/mm/yyyy format
     106                                        def dateMatch = value =~ /^([0-9]{1,})([^0-9]{1,})([0-9]{1,})([^0-9]{1,})([0-9]{1,})((([^0-9]{1,})([0-9]{1,2}):([0-9]{1,2})){0,})/
     107                                        if (dateMatch.matches()) {
     108                                                // create limited 'autosensing' datetime parser
     109                                                // assume dd mm yyyy  or dd mm yy
     110                                                def parser = 'd' + dateMatch[0][2] + 'M' + dateMatch[0][4] + (((dateMatch[0][5] as int) > 999) ? 'yyyy' : 'yy')
     111
     112                                                // add time as well?
     113                                                if (dateMatch[0][7] != null) {
     114                                                        parser += dateMatch[0][6] + 'HH:mm'
     115                                                }
     116
     117                                                value = new Date().parse(parser, value)
     118                                        }
     119                                }
     120
    101121                                // Caution: this assumes that all template...Field Maps are already initialized
    102122                                // Otherwise, the results are pretty much unpredictable!
  • trunk/grails-app/taglib/dbnp/studycapturing/WizardTagLib.groovy

    r250 r257  
    584584                // output columns for these subjectFields
    585585                template.fields.each() {
     586                        def fieldValue = subject.getFieldValue(it.name)
     587
    586588                        // output div
    587589                        out << '<div class="' + attrs.get('class') + '">'
    588590
     591                        // handle field types
    589592                        switch (it.type.toString()) {
    590593                                case ['STRING', 'TEXT', 'INTEGER', 'FLOAT', 'DOUBLE']:
    591594                                        out << textField(
    592595                                                name: attrs.name + '_' + it.name,
    593                                                 value: (intFields) ? intFields.get(it.name) : ''
     596                                                value: fieldValue
    594597                                        )
    595598                                        break
     
    600603                                                        name: attrs.name + '_' + it.name,
    601604                                                        from: it.listEntries,
    602                                                         value: (stringFields) ? stringFields.get(it.name) : ''
     605                                                        value: fieldValue
    603606                                                )
    604607                                        } else {
     
    606609                                        }
    607610                                        break
     611                                case 'DATE':
     612                                        // transform value?
     613                                        if (fieldValue instanceof Date) {
     614                                                if (fieldValue.getHours() == 0 && fieldValue.getMinutes() == 0) {
     615                                                        // transform date instance to formatted string (dd/mm/yyyy)
     616                                                        fieldValue = String.format('%td/%<tm/%<tY', fieldValue)
     617                                                } else {
     618                                                        // transform to date + time
     619                                                        fieldValue = String.format('%td/%<tm/%<tY %<tH:%<tM', fieldValue)
     620                                                }
     621                                        }
     622
     623                                        // output a date field (not the 'rel' which makes the
     624                                        // javascript front-end bind the jquery-ui datepicker)
     625                                        out << textField(
     626                                                name: attrs.name + '_' + it.name,
     627                                                value: fieldValue,
     628                                                rel: 'date'
     629                                        )
     630                                        break
     631                                case 'ONTOLOGYTERM':
     632                                        out << it.getClass()
     633                                        break
    608634                                default:
    609635                                        // unsupported field type
    610636                                        out << '<span class="warning">!' + it.type + '</span>'
    611                                         //out << subject.getFieldValue(it.name)
    612                                         break;
     637                                        break
    613638                        }
    614639
  • trunk/grails-app/views/wizard/index.gsp

    r247 r257  
    2222        <script type="text/javascript" src="${resource(dir: 'js', file: 'jquery.qtip-1.0.0-rc3.min.js')}"></script>
    2323        <script type="text/javascript" src="${resource(dir: 'js', file: 'swfobject.js')}"></script>
    24         <script type="text/javascript" src="${resource(dir: 'js', file: 'grouping.js')}"></script>
    2524        <script type="text/javascript" src="${resource(dir: 'js', file: 'table-editor.js')}"></script>
    2625        <script type="text/javascript" src="${resource(dir: 'js', file: 'timepicker-0.2.1.js')}"></script>
    2726        <script type="text/javascript" src="${resource(dir: 'js', file: 'wizard.js')}"></script>
     27        <script type="text/javascript" src="http://bioportal.bioontology.org/javascripts/widgets/form_complete.js"></script>
    2828</head>
    2929<body>
  • trunk/web-app/js/wizard.js

    r250 r257  
    5555        var re = /^#/gi;
    5656
     57        // bind to the anchor?
    5758        if (!element.attr('href').match(/^#/gi) && !element.attr('href').match(/\/([^\/]+)\/wizard\/pages/gi)) {
    5859            // bind a warning to the onclick event
    59             element.bind('click',function() {
    60                 return confirm('Warning: navigating away from the wizard causes loss of work and unsaved data. Are you sure you want to continue?');
    61             })
     60            element.bind('click',function() { return onDirectWarning(); });
    6261        }
    6362    })
     63}
     64
     65function onDirectWarning() {
     66    return confirm('Warning: navigating away from the wizard causes loss of work and unsaved data. Are you sure you want to continue?');
    6467}
    6568
Note: See TracChangeset for help on using the changeset viewer.