Calendar Plugin

Support input/output value as a single string

Details

  • Type: Improvement Improvement
  • Status: Open Open
  • Priority: Minor Minor
  • Resolution: Unresolved
  • Affects Version/s: Grails-Calendar 1.1.1
  • Fix Version/s: Grails-Calendar 1.2.0
  • Component/s: None
  • Labels:
    None

Description

Seems to me the _year, _month, _day etc fields from calendar's datePicker are rather awkward to work with. Am I missing something?

I'd rather work with a single string in ISO format. Not only is it a bit easier in my controller, it seems it's much easier when creating GET URLs in my list view.

I added a _valuestr field, and the option to specify the tag's value attribute as a String, to make things easier.

In CalendarTagLib.groovy:

{{
def formatter = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
def valueStr = ''

if(value) {

// JH 2009-03-20
if(value instanceof String) { calendar = new GregorianCalendar() calendar.setTime(formatter.parse(value)) }
else if(value instanceof Calendar) { calendar = value } else { calendar = new GregorianCalendar(); calendar.setTime(value) }
...
}}

and:

{{
<input type="hidden" name="${name}_valuestr" id="${name}_valuestr" value="$valueStr"/>
}}

and:

{{
if(calendar.showsTime) {
document.getElementById('${name}_hour').value= calendar.date.getHours();
document.getElementById('${name}_minute').value= calendar.date.getMinutes();
document.getElementById('${name}_valuestr').value= calendar.date.print('%Y-%m-%d %H:%M:%S');
}else {
document.getElementById('${name}_hour').value = 0;
document.getElementById('${name}_minute').value = 0;
document.getElementById('${name}_valuestr').value = calendar.date.print('%Y-%m-%d 00:00:00');
}
}}

and in the _delete() function:
{{
document.getElementById('${name}_valuestr').value = '';
}}

I'm pretty new to Grails, and not strong at all on JavaScript, so this might be total crap. But it seemed to make my life easier. Now I can do this in my list.gsp:
{{
...
<g:form action="list">
Start:
<calendar:datePicker name="searchStartDate" value="${searchStartDate}"/>
End:
<calendar:datePicker name="searchEndDate" value="${searchEndDate}"/>
...
<g:sortableColumn property="actualDate" title="Date" params="[searchStartDate_valuestr: searchStartDate, searchEndDate_valuestr: searchEndDate]"/>
...
<g:paginate total="${expenseInstanceTotal}" params="[searchStartDate_valuestr: searchStartDate, searchEndDate_valuestr: searchEndDate]"/>
}}

With this in my controller:
{{
def formatter = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
def searchStartDate = params.searchStartDate_valuestr ?
formatter.parse(params.searchStartDate_valuestr) : null
def searchEndDate = params.searchEndDate_valuestr ?
formatter.parse(params.searchEndDate_valuestr) : null
...
return [
expenseInstanceList: result,
expenseInstanceTotal: expenseInstanceTotal,
searchStartDate: searchStartDate ? formatter.format(searchStartDate) : null,
searchEndDate: searchEndDate ? formatter.format(searchEndDate) : null
]

Does this make any sense?

John Hurst

Activity

Hide
John Hurst added a comment -

Argh, so much for using {{ and }} to format my code!

Sorry about that. What's the best way to submit readable code on this thing?

JH

Show
John Hurst added a comment - Argh, so much for using {{ and }} to format my code! Sorry about that. What's the best way to submit readable code on this thing? JH
Hide
John Hurst added a comment -

OK, I didn't do enough homework before submitting this. (I wanted to submit it before I forgot

The _year, _month _day etc fields should be picked up by a StructuredDateEditor and automatically be converted into a Date. I need to figure out what I need on my form to make this happen. Then, I will be interested to see how it works for GET URLs such as pagination controls.

Sorry for the beginner confusion.

John Hurst

Show
John Hurst added a comment - OK, I didn't do enough homework before submitting this. (I wanted to submit it before I forgot The _year, _month _day etc fields should be picked up by a StructuredDateEditor and automatically be converted into a Date. I need to figure out what I need on my form to make this happen. Then, I will be interested to see how it works for GET URLs such as pagination controls. Sorry for the beginner confusion. John Hurst

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated: