Grails make one g:datePicker depend on other g:datePicker - grails

imagine that you have an index.gsp with two dates: Starting day and Ending Day.
When the user picks the starting day, how can I calculate + 2 months in the ending day?
I know in the controller I could have something like:
use (TimeCategory) {
c = new Date() + 2.month
}
But how is the best way to change the Ending Day in the gsp? With remoteFunction?
EDIT:
Yes it worked, thank you very much lukelazarovic.
Like you said the only thing needed to change was the last line, I changed to: $("#myid_month").val(month+3);
function dateWasChanged(){
....
$("#myid_month").val(month+3);
}
EDIT2:
I also needed to increment year, for some reason they are strings so remember to do:
myInteger = parseInt(myString);

I assume you want to do it on the client - without reloading page +2 months date is set into the end date datePicker.
That means you have to do it using Javascript or Javascript-based framework (JQuery).
You can go along with the solution suggested in this SO question: Get Date value from Grails DatePicker
Only change would be to set the value of end datePicker on the last line of function dateWasChanged like this:
$("#endDatePickerId").datpicker("setDate", date);

Related

rails fullCalendar, How can I show end time of a event but omit the title of the event?

I have checked a lot of related questions, but no one actually solve my problem.
I am now writing a rails app and use fullCalendar.
I am able to show events on my calendar, but with start time and the title of the event.
Actually these is end time for the even under the month view, and events longer than 30 mins under the week and day view. But no end time for the events of duration less than 30 minutes under view of week and day.
Besides, I hope not to show the title of the event. I find other answers says it will need to change the source file of fullcanlendar, I am wondering if there is any way to do it without changing the souce code of full calendar.
You may be looking for the eventRender callback:
http://fullcalendar.io/docs/event_rendering/eventRender/
With this, you can alter the event's html element however you need to.

Grails Timepicker

I need to save Date Time in the (oracle) database in one column, which is sqlType of timestamp (looks like 01-JAN-14 12.00.00.000000 AM). While learning grails I've been using the Joda lib with it's "time picker".
The Joda timepicker has worked well, but now that I'm looking to go primetime I'm looking for something a little more user friendly. Frankly, text boxes might be more user friendly than the drops downs joda gives you.
Anyway, I'd like to remove joda and use something like this:
http://trentrichardson.com/examples/timepicker/
but I can't figure out how to implement it in grails. In my view, if I put:
<input type="text" name="endDate" id="endDate" value="${exampleInstance?.endDate}" />
in place of the g:datePicker, it works fine (the picker that is), except nothing gets saved to the database, and no errors are generated. I hit Save and the Show view comes up with an empty endDate field. Do I need more input tags?
Is there some easy way to implement a modern looking date+time picker that I've missed?
Furthermore, I see there is a plugin for this picker here
http://grails.org/plugin/jquery-ui-timepicker
But being that there isn't any documentation, I'm not sure how to use that either (?)
ANSWER
in controller save/update put something like:
def endDate = params.date('endDate', 'yy-MM-dd h:mm')
//println "Date from Picker was "+endDate
params.endDate = endDate
No further casting was necessary being that it ended up I could format the datepicker control to a very close format as what's in the database, but had I needed to cast from one odd format, or a string, to another, I toyed with this code, which is more psuedo than anything as I was thinking through the process (I'm sure there's a totally Groovy way to do this same thing):
SimpleDateFormat inputFormat = new SimpleDateFormat("yy-MM-dd HH:mm:ss.S");
SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yy h.mm.ss.S a");
def v = params.endDate
Date date = inputFormat.parse(v);
String temp = sdf.format(date)
Date dateOut = sdf.parse(temp)
println dateOut
The datepicker, is your UI component therefore, you can have any library that you wish for UI and anything else for back-end. Mostly they are easy to implement, if they provide a little bit of documentation!!.
The timepicker for jQuery ui plugin, that you provided the link, is exposing a resource called jqueryUiTimePicker which depends on jQuery and jQuery-ui. So simply by including this resource into you resources configuration you should be able to utilize it. Its no different than defining your own resource and use it.
About saving issue that you have, on your save pass parameter failOnError:true so you can see the errors if any.
I have created a sample project that utilizes this plugin hope it helps
In your controller, you will need to parse the parameter value to a Date value. Something like,
def endDate = params.date('endDate', 'dd-MM-yyyy')
dd-MM-yyyy is whatever format the jquery plugin submits the date value. (println params for this or look up the plugin documentation)
If you want a date format binding to happen automatically, check the Date Formats For Data Binding in the doc http://grails.org/doc/latest/guide/single.html#dataBinding for a way to globally specify the format

JQuery UI / Datepicker : How to initialize datepicker with an empty year?

My problem is the following :
On my website, I use the Jquery-ui datepicker to allow my visitor to enter a date.
I have configured the datepicker such users can modify the month and the year.
However, I have noticed that they never enter the year : they leave in the default value.
In my mind, they don't see that they can edit the year value...
So, I would like to intialize the default year value to empty/blank and show an error alert if the user has not modified it.
I try to do that, but in vain....
So how can I do that ?
Maybe, there is an other way to force my users to select a correct year value. Have you got any suggestions ?
In advance, thanks for your answer.
I thought a little bit and I think what I would do is not possible...
How could the datpicker calculate the days of the month if the year is not specified?
So, Have you got any suggestions to force my users to change the year default value ?
You could identify what the default value is and then, in your onSelect callback you could see if the current year value is different than what the original was and execute whatever code seems appropriate.

Modx - Getresource filter by TV date

I am trying to use getResources to filter based on a date-type TV.
I ant to create a filter that allows me to either show Future events and Past events.
TVname = voucherdate
What I have done is:
Create a current date snippet with the following:
<?php
return date('Y-m-d H:i:s');
Then I created the following getResource:
Current events
[[!getResources?
...
&tvFilters=`voucherdate>=[[curDate]]`
]]
Past events
[[!getResources?
...
&tvFilters=`voucherdate<<[[curDate]]`
]]
But it does not seem to be working. I have tested to se where the sniper works by calling only [[curDate]] in a template and that shows the current date.
Could anyone offer some advice.
thanks
all your template variables are store as strings, so you are going to have to do some string comparison..... which is probably not going to work in the getresources call...
best thing to do is to pass the date string value to a snippet and do your date comparison there, something like:
[[!getResources? ...
&tvFilters=`[[!DateCompare? &date=`[[*voucherdate]]` &range=`future|past` ]] == 'true']]
]]
convert your dates to epoch or something in the DateCompare snippett and return true or false... then getResources ~should~ return the correct resources ... I think, not tested... I con't think of an easier way off the top of my head. UNLESS you want to store your dates as an epoch value initially... [that would be better anyway] then your string comparison you were trying would 'just work'

Sharepoint 2007 - Displaying current date in a custom list

I have been reading blog after blog about displaying the current date in a sharepoint list and nothing seems to work. I do not have administrative rights to my sharepoint server but I was able to combine some java scripts and was able to display the current date (that change each day) in a custom list. My problem is that my success is only half full and I need someone's help to figure out the rest. Here it goes:
1. I created a column in my list called "DateField", I use the calculation field with ="<B></B>
as the calculation
2. I created a Content Edit WebPart and use the source below:
<script type="text/javascript">
var currentTime = new Date()
var month = currentTime.getMonth()+1
var day = currentTime.getDate()
var year = currentTime.getFullYear()
var CurrentDate = month + "/"+ day + "/" + year
$(document).ready(function(){
$(".ms-vb2:contains('<B')").each(function(){
var tempB = document.createElement ("B");
tempB.style.cursor = "pointer";
tempB.innerHTML = $(this).text();
$(this).text(CurrentDate);
$(this).append(tempB);
});
});
</script>
The script works and the date changes each day but I cannot use the date for anything. For some reason it only sees the HTML tags in the field but it displays the current date in the column on the list. Can someone help me figure out how I can store the actual date in the column?
Thanks
Ramon
If you want to store the current date field on the column to be reused
that means that you will have to modify all the items every day with today's date.
Is that what do you really need ? it could be achieved with some ajax call to the web services (if you have update permissions for those items).
However I don't really understand your scenario.
Could you elaborate ?
My solution was to create a custom field type for the column, which would always return the current date (and time if needed). This produced the desired effect - the current date (and time) would be displayed on the front end, but still available for use in other fields in the back end.
A quick Google for examples (my code is two jobs behind me, and I haven't touched MOSS in 6 months) gives me http://vspug.com/nicksevens/2007/08/31/create-custom-field-types-for-sharepoint/
Good luck!
Regards
Moo

Resources