Hosted By

Contact Me

Misc Links

OpenNTF BlogSphere LotusGeek CoComment Custom Button

Ads by Google

Welcome to keithstric.com!

I hope you find this site useful in some way or another. I strive to bring you all sorts of geeky information and solutions to your most frustrating of issues with the occasional rant on whatever topic, technical reviews and weblog. You'll also find many products that I've developed and make available for you to use however you like. So, grab a cup of coffee, sit down and visit for a while.

« Weird SSJS Time/Date stuff... | Home Page| Dojo, XPages and Graphics, oh My.... »

SnTT: XPages Calendar Control (Part 4), adding day and week views

03/01/2010 5:05 PM By Keith Strickland

In our last sessions we created a blank monthly calendar, then put some data on the calendar and last we made it reusable so we can use it in any application. While this is all well and good, we need to be able to see the breakdown of times on a daily and weekly basis. So in this SnTT we will be adding blank day and week views. I'm doing blank views because I can't quite figure out how to place entries so that they span the correct amount of time. If anyone has any ideas about this please speak up as I'm stumped as to where to go next. I was thinking that maybe Dojo could help out here but I haven't had the time to sit down and actually try anything yet. As of this release there is also an OpenNTF project for this of which I'm looking for people to contribute and be a part of the development of this project. Like I said before, I'm going to need people smarter than myself.

OK, so I started with making a couple of new XPages (day and week) and dragging the required XPages Framework elements onto the page, save and close. I then created a new custom control and called it ccCalDay. This control will have the following features/requirements

  • Navigate forward/back a day
  • Be able to configure the hours display (12 or 24)
  • At a later date, be able to add data to the view
  • Clicking the Month View sidebar link should take us to the selected month view
  • Clicking the Week View sidebar link should take us to the selected week view

We've now got our requirements so lets start putting this all together. I added a panel and called it "container". This panel holds the entire day view calendar. I added 2 other panels within the container panel and called those dayNavContainer and dayHoursContainer. Now that we've got our layout we can proceed. In order to display the proper day, we'll need some variables from the Month View calendar. I changed all the viewScope variables in the previous SnTTs to now be sessionScope variables instead of viewScope. This allows us to pass the date back and forth between different views. It also allows us to just manipulate one date at a time to change everything on a page. So, in the ccCalDay custom control, BeforePageLoad event we've got this:


If you recall, in our menu for each day on the monthly calendar we have a function which builds a list and we pass the day in a URL parameter. This is what allows us to define a specific day, we then just use the month and year from the "dispDate" sessionScope variable and then recompute all the other variables even though they aren't needed for the day view. I do this so if you go back to the month view we still have these values to build the monthly calendar, no matter how many days you navigate through on the day view. Also, I've built an array based on a property definition of all the times we want to display.

Now for the navigation, we want to be able to navigate forward or back by 1 day. This should be a fairly simple process but it did give me quite a bit of grief. Per Jeremy Hodge I tried setting the dispDate sessionScope varible like:
sessionScope.put("dispDate", sessionScope.get("dispDate").setDate(3));
but never could get this to work, along with several other methods I tried with using the set???? method of a Javascript Date, so that is one of the reasons why I had such a hard time with the navigation. I was also having some issues with the onClick event of the navigation links, the onClick code was firing at page load and incrementing/decrementing the sessionScope variables. I addressed that in this post. Just as an FYI, don't use the All Properties tab to edit event code, it screws things up. OK, now for the navigation we have a link that goes back 1 day, a computed field which displays the current date we're looking at and then another link to go forward 1 day. The back 1 day link has this onClick event code:


All this does is check the current day date, if it's 1, then we check if the month is 0 (Jan), if it is then we decrement the year by 1 and set the date to 12/31. If the month isn't 0 then we just decrement the month by 1. If the day isn't 1 we just decrement the day by 1. Once all of that is done, we set all the sessionScope variables.

For the date display, it's really simple:

For the day forward link, it's pretty much the same as the back link with the exception that we check if the day is the last day of the month and if it's the last month of the year.

The only thing left here is to build the table which contains all the different times. I defined a property definition for the timeHourFormat to be either 12 or 24. If you set it to 12, the times go from 12:00 AM to 11:59 PM. If you define 24 you get hours from 0 to 24. I also build a 4 row table within each data column which don't really contain anything right now. I'm hoping that by assigning these rows an id that we can place a div and have it span the proper amount of time. But this will probably change as I learn more about placing divs in specific spots on a page. So, at the top of the day view I display the date, week day, month and year, just like on the Notes Mail calendar day view. I use 3 separate computed fields so that we can place them where we want them and control their font sizes independently. The code for these are really straight foward and I'm not going to go into detail about these:

Big Date Number:


Big Week Day:


Big Month Year:


Then the remaining rows which are contained within a computed field which is contained within a repeat object:


All this does is loop through and build each row of the table based on the timeVar. timeVar is defined as the "collectionName" in the repeat control which is set to repeat 24 times. Then in each data column, build a 4 row table (for 0 min, 15 min, 30 min, 45 min).

And that's it for the day view of the calendar. You should end up with something looking like this:
dayView.jpg
Continue Reading for the week view....

The week view is almost identical to the day view. The biggest exception is that the dates span a course of 7 days, Sunday through Saturday. We need a list of hours (rows) and a list of days (columns). Our navigation structure will navigate forward a week and back a week and we need to list which day each column is.

I built the week view exactly the same as the day view, I will list the exceptions here, but for the most part the logic is exactly the same. We needed to set some variables in the beforePageLoad event of the ccCalWeek custom control. These allow us to keep track of the date we're looking at.


If you notice it's almost exactly the same as the day view beforePageLoad event with the exception that we set the start date. We do this by taking whatever day was clicked on and subtracting that from the date to get the date for Sunday. We then add 6 days to that for the end date and set those as viewScope variables

Next is our navigation, we want to navigate forward and back by a week. This is easy enough to figure out. So, we have our week back link with the following onclick event code:


Here we set a temporary date holder to the same as our start date viewScope variable. We then take 7 away from the date and that gives us the previous sunday's date. Add 6 to this and we've also got the end date. The code for going forward a week is almost identical except we go forward instead of back.

Now, in between these 2 links is a computed field which contains the date display. We display the start date and end date for the week here. It's pretty straight forward:


And that's it for the Navigation container.

Next up is the title of each column. This should contain the day, month and date (i.e. Sunday, Feb 28) at the top of each column. I'm using 7 computed fields with basically the same code except for sunday we just use the weekStartDate instead of setting a tempDate:

The rest of the table is done within a repeat that contains a computed field, just like for the ccCalDay control, except we add extra columns for all the different days:


Now I'm sure there's a better way to do the above, especially seeing as how it's all basically the same code. I guess I just got lazy, I apologize. But here again, we put another table within each hour for each day which contains 4 rows. Hopefully I can figure out how to use Dojo to place divs in the right place and the right size depending on the duration of the entry.

That's it, you should now have a blank week view that should look something like this:
weekView.jpg

In our next installment (if I can figure it out) we'll be adding some data to these views in a reusable sort of way. But you can find all of this in the downloads section and on OpenNTF.


Post A Comment

:-D:-o:-p:-(:-):-\:-|:angry::cool::cry::dontknow::emb::hairout::laugh::rolleyes::whew:;-)

Subscribe to keithstric.com

OpenNTF

Disclaimer

The opinions and ideas posted on keithstric.com are not necessarily the opinions and ideas of my employer. The solutions, techniques and code provided here are not guaranteed or warranted in any way and are free for you to use at your own risk.