Changeset 502 for trunk


Ignore:
Timestamp:
May 31, 2010, 1:53:03 PM (13 years ago)
Author:
roberth
Message:

RELTIME fields in the wizard now show the parsed text in blue when leaving the input field.

Location:
trunk
Files:
4 edited

Legend:

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

    r470 r502  
    22
    33import dbnp.data.*
     4
     5// Grails convertors is imported in order to create JSON objects
     6import grails.converters.*
     7
    48
    59/**
     
    769773                }
    770774        }
     775
     776        /**
     777         * Parses a RelTime string and returns a nice human readable string
     778         *
     779         * @returns Human Readable string or a HTTP response code 400 on error
     780         */
     781        def ajaxParseRelTime = {
     782            if( params.reltime == null ) {
     783                response.status = 400;
     784                render( 'reltime parameter is expected' );
     785            }
     786
     787            try {
     788                def reltime = RelTime.parseRelTime( params.reltime );
     789                render reltime.toPrettyString();
     790            } catch( IllegalArgumentException e ) {
     791                response.status = 400;
     792                render( e.getMessage() );
     793            }
     794        }
    771795}
  • trunk/grails-app/taglib/dbnp/studycapturing/WizardTagLib.groovy

    r497 r502  
    920920                                                        description: ucName,
    921921                                                        name: prependName + it.escapedName(),
    922                                                         value: new RelTime( fieldValue ).toString()
     922                                                        value: new RelTime( fieldValue ).toString(),
     923                                                        addExampleElement: true,
     924                                                        onBlur: 'showExampleReltime(this)'
    923925                                                ){helpText}
    924926                                                break
  • trunk/test/unit/dbnp/studycapturing/WizardControllerTests.groovy

    r496 r502  
    1212    }
    1313
    14     void testSomething() {
     14    void testAjaxParseRelTimeNonExistent() {
     15        // Without parameters, the method should give an error
     16        controller.ajaxParseRelTime();
     17        assert controller.response.status == 400;
     18    }
    1519
     20    void testAjaxParseRelTimeEmpty() {
     21        // With empty parameter, the method should work
     22        controller.params.reltime = '';
     23        controller.ajaxParseRelTime();
     24        assert controller.response.status == 200
     25        assert controller.response.contentAsString == ""
    1626    }
     27
     28    void testAjaxParseRelTimeCorrect() {
     29        // With simple parameter, the method should work
     30        controller.params.reltime = '3d';
     31        controller.ajaxParseRelTime();
     32        assert controller.response.status == 200
     33        assert controller.response.contentAsString == "3 days"
     34    }
     35
     36    void testAjaxParseRelTimeIllegal() {
     37        // With illegal parameter, the method should give status code 400
     38        controller.params.reltime = 'no valid reltime';
     39        controller.ajaxParseRelTime();
     40        assert controller.response.status == 400;
     41    }
     42
    1743}
  • trunk/web-app/js/wizard.js

    r481 r502  
    286286    });
    287287}
     288
     289// Show example of parsed data next to RelTime fields
     290function showExampleReltime(inputfield) {
     291    var fieldName = inputfield.name;
     292
     293    var successFunc = function(data, textStatus, request) {
     294        if( request.status == 200 ) {
     295            document.getElementById( fieldName + "Example" ).value = data;
     296        }
     297    };
     298
     299    var errorFunc = function( request, textStatus, errorThrown ) {
     300        // On error, clear the example field
     301        document.getElementById( fieldName + "Example" ).value = "";
     302    };
     303       
     304    $.ajax({
     305        url     : baseUrl + '/wizard/ajaxParseRelTime?reltime=' + inputfield.value,
     306        success : successFunc,
     307        error   : errorFunc
     308    });
     309}
Note: See TracChangeset for help on using the changeset viewer.