event_search.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. jQuery(document).ready(function($)
  2. {
  3. try
  4. {
  5. function datePlusDays(submittedDate, numDays) {
  6. return new Date(submittedDate.getTime() + numDays*24*60*60*1000);
  7. }
  8. $("#first_date_string").datepicker({
  9. dateFormat: "D, M d yy",
  10. showButtonPanel: true,
  11. });
  12. // `@first_date_string` should be set in the controller and referenced
  13. // for this field's value in the view, but this is just in case
  14. if ($("#first_date_string").val() == "") {
  15. var defaultFirstDate = datePlusDays(new Date(), -1)
  16. $("#first_date_string").datepicker("setDate", defaultFirstDate);
  17. }
  18. $("#last_date_string").datepicker({
  19. dateFormat: "D, M d yy",
  20. showButtonPanel: true,
  21. });
  22. // `@last_date_string` should be set in the controller and referenced
  23. // for this field's value in the view, but this is just in case
  24. if ($("#last_date_string").val() == "") {
  25. var defaultLastDate = datePlusDays(new Date(), 2)
  26. $("#last_date_string").datepicker("setDate", defaultLastDate);
  27. }
  28. }
  29. catch (err)
  30. {
  31. alert(err);
  32. }
  33. });