Posted December 7, 2006 at
3:18 PM
Tags:
ColdFusion,
Javascript / DHTML
I created a rather small calendar utility for use during project management meetings. We usually brain storm a project and use the Windows date/time calendar (in the icon tray) to think out our time estimates. The problem is that calendar sucks and only has one month at a time (and moving from month to month is a pain). My small calendar utility, written in ColdFusion with some Javascript, displays a year's worth of calendars and allows the user to click and highlight a single time span.
Feel free to use it if you like:
http://www.bennadel.com/util/calendar
If anyone is interested in the code that goes behind this, it's fairly small.
Action Script
Launch code in new window » Download code as text file »
- <cfscript>
-
- // Get the current month.
- REQUEST.ThisMonth = CreateDate(
- Year( REQUEST.Environment.DateTime.Now ),
- Month( REQUEST.Environment.DateTime.Now ),
- 1
- );
-
-
- // Create an array of months.
- REQUEST.Months = ArrayNew( 1 );
-
- // Add a date for each month to the array. Right now, we are going
- // to be using one month previous to this one, plus 11 months going
- // forward. This should give us just over a year going forward.
- for (intI = -1 ; intI LTE 12 ; intI = (intI + 1)){
-
- ArrayAppend(
- REQUEST.Months,
- DateAdd( "m", intI, REQUEST.ThisMonth )
- );
-
- }
-
-
- </cfscript>
Java Script Code
Launch code in new window » Download code as text file »
Calendar Display Code
Launch code in new window » Download code as text file »
- <div id="calendars">
-
- <!--- Loop over the months in the array. --->
- <cfloop
- index="intI"
- from="1"
- to="#ArrayLen( REQUEST.Months )#"
- step="1">
-
- <cfsilent>
-
- <!--- Get the pointer to the current date. --->
- <cfset dtThisMonth = REQUEST.Months[ intI ] />
-
- <!--- Get the starting day. --->
- <cfset dtStartDay = DateAdd(
- "d",
- -(DayOfWeek( dtThisMonth ) - 1),
- dtThisMonth
- ) />
-
- <!--- Get the ending day. --->
- <cfset dtEndDay = (DateAdd( "m", 1, dtThisMonth ) - 1) />
-
- <!--- Stretch it to the end of the week. --->
- <cfset dtEndDay = DateAdd(
- "d",
- (7 - DayOfWeek( dtEndDay )),
- dtEndDay
- ) />
-
-
- <!--- Get today's date. --->
- <cfset dtToday = Fix( REQUEST.Environment.DateTime.Now ) />
-
- </cfsilent>
-
- <table width="100%" border="0" cellspacing="2" cellpadding="0" class="calendarmonth">
- <thead>
- <tr>
- <td colspan="7">
- #MonthAsString( Month( dtThisMonth ) )# #Year( dtThisMonth )#
- </td>
- </tr>
- </thead>
- <tbody>
- <cfsilent>
- <cfsavecontent variable="strMonthCode">
-
- <tr>
-
- <!--- Loop over the days of the month. --->
- <cfloop index="dtDay" from="#dtStartDay#" to="#dtEndDay#" step="1">
-
- <td class="<cfif (dtDay EQ dtToday)>today<cfelseif (Month( dtDay ) EQ Month( dtThisMonth ))>thismonth<cfelse>othermonth</cfif>">
- #Day( dtDay )#
- </td>
-
- <cfif (
- (DayOfWeek( dtDay ) EQ 7) AND
- (dtDay NEQ dtEndDay)
- )>
- </tr>
- <tr>
- </cfif>
-
- </cfloop>
-
- </tr>
-
- </cfsavecontent>
- </cfsilent>
-
- <!--- Output code with as little white space as possible. --->
- #strMonthCode.ReplaceAll( ">\s+", ">" ).ReplaceAll( "\s+<", "<" )#
- </tbody>
- </table>
-
- <!--- Flush for user feedback. --->
- <cfflush />
-
- </cfloop>
-
- </div>
-
- <!--- Initialize the Calendar javascript. --->
- <script type="text/javascript">
- InitCalendars();
- </script>
CSS Code
Launch code in new window » Download code as text file »
- table.calendarmonth {
- margin-bottom: 20px ;
- }
-
- table.calendarmonth td {
- border: 1px solid #999999 ;
- cursor: default ;
- padding: 5px 10px 5px 10px ;
- }
-
- table.calendarmonth thead td {
- background-color: #F0F0F0 ;
- border-bottom-width: 2px ;
- font-size: 12px ;
- font-weight: bold ;
- text-align: center ;
- }
-
- table.calendarmonth td.today {
- background-color: #FEEAB7 ;
- border-color: #333333 ; /* #E4A705 ; */
- font-weight: bold ;
- }
-
- table.calendarmonth td.thismonth {}
-
- table.calendarmonth td.othermonth {
- background-color: #EAEAEA ;
- border-color: #999999 ;
- color: #AAAAAA ;
- }
-
- table.calendarmonth td.selected {
- background-color: #FFE8E1 ;
- border-color: #FF3333 ;
- /* color: #FA3E0A ; */
- }
-
- table.calendarmonth td.todayselected {
- background-color: #FFB8A4 ;
- border-color: #FF3333 ;
- font-weight: bold ;
- }
Download Code Snippet ZIP File
Comments (2) |
Post Comment |
Ask Ben |
Permalink |
Other Searches |
Print Page
What Other People Are Searching For
[ local search ]
creating a calendar coldfusion
[ local search ]
looping over calendar coldfusion
[ local search ]
looping days coldfusion
[ local search ]
coldfusion calendar
[ local search ]
calendar utility
It's delicious!
http://del.icio.us/psenn
Posted by Phillip Senn
on Dec 13, 2006
at 6:13 PM
Awesome :) Glad you like it. Please feel free to suggest any changes you want to it. Someone already suggested dragging for creating time span.
Posted by Ben Nadel
on Dec 13, 2006
at 6:55 PM
Post Comment |
Ask Ben