SnTT: XPages Calendar Control (Part 5), adding data to the day view...
If you recall we left off from Part 4 with a blank day and week view. Well, through much gritting and knashing of teeth I've finally got some data on the day view. Now before I go any farther, I would like to thank a few people whom without I'm sure I would still be sitting here scratching my head trying to figure out how to do this:
- Nathan Freeman for pointing me to an Article by Jeremy Hodge on embedding data within an XPage in order to make it accessible via client side JavaScript
- Jeremy Hodge for this article and also cluing me in on using the dojo.addOnLoad function
- Steve Castledine for showing me that @DbLookup, sessionScope.get("whatever") works with client side javascript that is on an XPage
- Julian Buss for this wiki article
In order to set some guidelines of what we're trying to accomplish:
- Build a day view calendar with the times down the left side of the page and entry data for a specific day on the right
- Entries should show duration like the Notes Mail Calendar using a rectangle
- Entry rectangles should be as wide as the calendar unless there is more than 1 entry for an hour, then they should be side by side but still take up the entire width of the calendar
So, let's get started. First we need to define a few dojo resources. So, in the properties for the custom control navigate to the All Properties tab and add 4 resources:
- dojox.gfx
- dojox.gfx.move
- dojox.gfx.shape
- dojo.Colors
We just need to get some data now and then we can start working on the function that will build all our entries. Go take a look at a post by Jeremy Hodge and then scroll down the comments where he replies to me and explains how to build a heirachial XML type data structure from the entries. Well, this is the precise method I used. I added a repeat control and then added my "tags" within this repeat with their values. I added a view to the data sources of the ccCalDay control and also defined a "keys" and set "exact match" to true so that the view would only contain the entries for this day:
Here's the source for the repeat which builds all of our data:
I guess instead of defining a view as the data source, I should probably do this via a Property Definition, but I just needed to get this thing working as I've been getting frustrated with trying to figure out pixel counts and such.
So, that gives us our data for all the entries. Now it's just a matter of getting this data when the day.xsp XPage loads and doing something with it. In the source of the ccCalDay custom control at the bottom I've added the following javascript to run a javascript function after the page loads.
The addOnLoadFunc is a function in the XPCalendarClient javascript library which is added as a source to the ccCalDay custom control. This function is the work horse of the day view and is what builds all the minute divs, sets the styles and adds the rectangles to the page.
So, I'm just going to briefly explain each of the loops inside this function. I'm sure there is a better way than how I've done this but at the moment this is the best I've come up with. So to start with we've got to get all the data we produced in the repeat above. The data above is contained within a div with an id of "contextual", we get all the nodes within the contextual div.
Next up we just get a couple more variables and get into our first loop. With this loop we get everything we need, start date/time, end date/time, duration, subject, tool tip, start hour, end hour, starting minutes, the hours the entry spans, the div id for this entry and lastly the number of divs that should be in the dayTimeMinutesContainer div. Now I know there is a problem here, because of something in this loop one of the limitations of this is that it only supports up to 2 different entries in any hour. I'm sure it's because of how I'm handling it so I just need to fix it. But here is the loop:
Next up we loop through all the entries we gathered above and build all the divs.
Ok, we now set the style of all the dayTimeMinutes-hour divs for each hour that only has one entry. I do this for single entry hours only, because it's easier to figure out where the dayTimeMinutes div will be placed on the page and how wide it will be if we only have to deal with containers which contain more than one dayTimeMinutes div. But in setting the style for the dayTimeMinutes divs we get the dayTimeMinutesContainer coordinates so we can determine exactly where on the page the dayTimeMinutes div will be placed. We have to determine it's location because it has a position of "absolute" and the dayTimeMinutesContainer has a position of relative. This allows us to place the dayTimeMinutes div anywhere on the page we want. But, we see how wide the dayTimeMinutesContainer is and also get it's X coordinates and pass that on to the style for the dayTimeMinutes div. While we're looping through all the entries we determine if a container has more than 1 div and if so, we just record that in another array.
Now we loop through the multiDivs array and set the style and determine the width of the dayTimeMinutes divs.
OK, the last loop will determine the Y coordinates of the div and then place a dojox.gfx surface on the page within the appropriate dayTimeMinutes div. This surface is what will hold the rectangle that represents the entry and duration. We also set a dojo color which in our case will be a gradient.
And that's it really. You should end up with something like this:

UPDATE: I've added the demo application to the downloads section. Also, I forgot to mention, this works with all browsers except IE. I believe this may be a limitation with dojo.gfx, but more research will need to be done to determine this exactly.











Comments
Date: 03/19/2010 01:21:13 AM
Name: Elijah Lapson
Website: http://
I have to say it is almost a religious experience following your blog. I think there are so many developers out there who were waiting for IBM to release a reusable calendar control and here you are developing one.
The beauty of the whole thing is of course following your foray into Xpages and gaining the knowledge as your project progresses. I can not say enough how helpful it is posting the code. I as I am sure many can relate to your struggles into an area which you are unfamiliar. I feel the triumph/relief you express when you tackle each piece of the puzzle.
It is really cool when someone creates something and shares it with the community. It is really, really cool when someone takes the time to write it up in a way that the general developer population can understand.
You are following in the footsteps of many of the great Lotus developer sharers before you Declan, and the great Jake Howlett.
Keep em coming, I actually get pumped to read your posts.
One of countless geeky lotus notes developer lurkers out there,
Elijah Lapson
Date: 03/19/2010 08:58:37 AM
Name: Keith Strickland
Website: http://www.keithstric.com
Thank you for the kind words Elijah.
You are correct in that this project has been a struggle. While I dabble with Javascript, Java, PHP, Perl and others I'm really a LotusScript developer. If not for the other Lotus Bloggers and contributors I would never have been able to tackle this project.