diff --git a/phpgwapi/inc/class.jscalendar.inc.php b/phpgwapi/inc/class.jscalendar.inc.php index b19febcbb5..35479ad7b4 100644 --- a/phpgwapi/inc/class.jscalendar.inc.php +++ b/phpgwapi/inc/class.jscalendar.inc.php @@ -180,6 +180,43 @@ function dateChanged(calendar) { window.location = "'.$url.'&date=" + calendar.date.print("%Y%m%d"); } }; + +function todayClicked(calendar) { + var parts = window.location.search.split("&"); + var newsearch = ""; + var hasdate = false; + + /* Assemble the new search string, if the "date" property is found, replace its value + with the current date */ + for (i = 0; i < parts.length; i++) + { + var split = parts[i].split("="); + if (split[0] && split[0] == "date") { + split[1] = "'.date('Ymd').'"; + hasdate = true; + } + + if (split[1]) + newsearch += split[0] + "=" + split[1]; + else + newsearch += split[0]; + + if (i < parts.length - 1) + newsearch += "&" + } + + /* If the date property hasn\'t been found, add it to the search string */ + if (!hasdate) { + if (parts.length == 0) + newsearch = "?"; + else + newsearch += "&"; + newsearch += "date='.date('Ymd').'"; + } + + window.location.search = newsearch; +} + '.($weekUrl ? ' function weekClicked(calendar,weekstart) { window.location = "'.$weekUrl.'&date=" + weekstart.print("%Y%m%d"); @@ -198,6 +235,7 @@ function monthClicked(calendar,monthstart) { flatWeekTTip : "'.addslashes($weekTTip).'"' : '').($monthUrl ? ', flatMonthCallback : monthClicked' : '').($monthTTip ? ', flatMonthTTip : "'.addslashes($monthTTip).'"' : '').($date ? ', + flatTodayCallback : todayClicked, date : "'.$date.'" ' : '').' } diff --git a/phpgwapi/js/jscalendar/calendar.js b/phpgwapi/js/jscalendar/calendar.js index 3f183ef937..a546a5c4f2 100644 --- a/phpgwapi/js/jscalendar/calendar.js +++ b/phpgwapi/js/jscalendar/calendar.js @@ -693,6 +693,7 @@ Calendar.cellClick = function(el, ev) { return; case 0: // TODAY will bring us here + cal.callTodayHandler(); if ((typeof cal.getDateStatus == "function") && cal.getDateStatus(date, date.getFullYear(), date.getMonth(), date.getDate())) { // remember, "date" was previously set to new // Date() if TODAY was clicked; thus, it @@ -1251,6 +1252,17 @@ Calendar.prototype.callMonthHandler = function () { } }; +/** Calls the today-clicked user handler (selectedHandler) */ +Calendar.prototype.hasTodayHandler = function () { + return this.params && this.params.flat && this.params.flatTodayCallback; +} + +Calendar.prototype.callTodayHandler = function () { + if (this.hasTodayHandler()) { + this.params.flatTodayCallback(this); + } +} + /** Calls the second user handler (closeHandler). */ Calendar.prototype.callCloseHandler = function () { if (this.onClose) {