- Timestamp:
- May 31, 2010, 1:53:03 PM (13 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/controllers/dbnp/studycapturing/WizardController.groovy
r470 r502 2 2 3 3 import dbnp.data.* 4 5 // Grails convertors is imported in order to create JSON objects 6 import grails.converters.* 7 4 8 5 9 /** … … 769 773 } 770 774 } 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 } 771 795 } -
trunk/grails-app/taglib/dbnp/studycapturing/WizardTagLib.groovy
r497 r502 920 920 description: ucName, 921 921 name: prependName + it.escapedName(), 922 value: new RelTime( fieldValue ).toString() 922 value: new RelTime( fieldValue ).toString(), 923 addExampleElement: true, 924 onBlur: 'showExampleReltime(this)' 923 925 ){helpText} 924 926 break -
trunk/test/unit/dbnp/studycapturing/WizardControllerTests.groovy
r496 r502 12 12 } 13 13 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 } 15 19 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 == "" 16 26 } 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 17 43 } -
trunk/web-app/js/wizard.js
r481 r502 286 286 }); 287 287 } 288 289 // Show example of parsed data next to RelTime fields 290 function 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.