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.

« XPages question... Editable Area within a Repeat? | Home Page| Weird SSJS Time/Date stuff... »

SnTT: XPages Calendar Control (Part 3), making it reusable

02/09/2010 1:24 PM By Keith Strickland

In our previous posts we've created a blank calendar and then added some data to it. While this is all well and good, it's not very reusable in it's current state. It's quite dependent on a view being formatted a particular way. What if you already have a view with the data you want to put on the calendar and don't want to change that view? Well, this is what we're going to address today. With these changes the calendar really takes on the form of something useful and not something that only works on your machine.

In this SnTT I will show you how to make your calendar more reusable and we'll also add the framework for some navigation to each cell to open up a day view, week view and month view (the month view may be redundant and I haven't yet decided on if we need to keep it). Also being addressed here is if you want text other than what is in the calendar to show up in the dojo tool tip. As a bonus, we'll also do the blank view with an editable area so you can use your own custom control to display data.

So, with the requirements defined for this session, we're now ready to begin. Looking at the code for the dayCells computed field on the ccCalendar custom control, you'll notice our view name is hard coded along with the column values. This is where the problem lies, we want this to be configurable. We can use "Property Definitions" to address this issue. Property Definitions allow us to define our own properties for a custom control. These get stored in the "compositeData" object(?) and are available for you to use anywhere within that custom control.
Calendar-PropertyDefinition.jpg

Here we need to define some properties for the following:

  • The View Name - lookupViewName - String
  • The Data Column - lookupViewDataCol - Integer
  • The Column that contains the UNID - lookupViewUNIDCol - Integer
  • The Column that contains the Tool Tip text - lookupViewToolTipCol - Integer
  • The text that will used in the lookupViewToolTipCol if no Tool Tip text is available - NoTooltipText - String
You should end up with something like this:
Calendar-PropertiesDone.jpg

Now, open the default XPage, highlight the ccCalendar custom control (it'll be under facets) and fill in the properties we defined. Except here you can use values for your own view instead of the one included in this DB:
Calendar-PropertiesValues.jpg

Once you save and close and view the calendar in the browser, it should look exactly like it did when we left off from Part 2 of the SnTT. The only difference is that the tool tips will now be populated with whatever is in the column defined for the tool tips.

With these changes, the calendar takes on a more useful role, we can now use views we've already designed and just change the properties to match each view. But what if you want to design your own custom control to display data the way you want it displayed? In this case, we can use an Editable Area instead of putting all the data computation within a computed field on the calendar itself. This will allow us to put a custom control onto the editable area on the XPage instead of within the ccCalendar custom control. So, to support this, in the sample database (located in the downloads section) I've added another custom control called ccCalendarEditable. I've modified the dayCells computed field to only spit out the html to begin the column and include the number for the day and start the div which contains all the data for that particular day. We also changed the name of this computed field to beginTD. You'll notice also, that now the day is included within a span instead of a div and also that there is a function call that is within another span. I will get to this shortly.

I added another computed field named endTD which contains the code closing the column and data div.

Now, in between these 2 computed fields I've added an Editable Area and gave it a Name of calData and a Facet Name of calData:
EditableAreaOutline.jpg

When we drag this custom control (ccCalendarEditable) onto a new XPage I think I did find a bug which I discussed in my previous blog entry about being able to drop a custom control onto an editable area which is contained within a repeat. Since this is the case we'll have to hand code the embedding of the custom control I created to contain the data onto the facet within the XPage. This is a simple process and shouldn't cause too much headache. But, I created a new custom control called ccCalData. This control basically contains the code we removed from the dayCells computed field and put into a computed field on the ccCalData custom control. I did it this way to really just show the ability of being able to split up the data and design a little bit more. Also, please forgive my lack of a useful naming convention, since I'm just now really getting started with XPages I haven't really come up with a naming convention I use all the time. But to hand code the embedding of the ccCalData custom control onto the XPage this is the format. Notice the "xp:key" item defines the name of the Editable Area (calData in our case):

So, we now have 2 different ways to make our calendar more reusable. You can use @DbLookups to a view that you've already designed and just change the properties to return the data you want on the calendar or you can design your own custom control to drop onto the calendar. Also, in the case of this sample db the calendar should look at react exactly the same as it did when we left off with part 2. Either way makes this much more useful. Now, in preparation for having a "day view" and "week view" I've added a small drop down menu to allow you to switch views. Read on...

This part is really just a preparation for providing the ability to switch your calendar to a day view or a week view. The only thing this does is open up a couple of XPages (day and week) I created to hold the controls for these 2 views in the future. To include this I changed the beginTD computed field to have the following:

  • Starting html for the TD
  • A div holding the day number and a menu within 2 separate spans
  • The opening code for the div containing the data for that particular day

Within the span for the menu, we make a call to the buildMenu function. This function is located in the XPCalendar server side javascript library. It requires a few parameters:

  • day view XPage
  • week view XPage
  • month view XPage

You can pass either pagename.xsp or just pagename. The function will then build an html list for the menu which is then formatted with CSS (dropdown.css). The CSS was generated by a tool I talked about a while back called CSS Menu Generator. I just had to tweak it a little bit to take out the fluff and make it display how I wanted it to. But this will produce a menu like the following:
calendar-viewNav.jpg

To make this so we don't have to hard code our day/week XPage names in code somewhere we also use another property definition for the 3 pages that the function requires to be passed. This makes it much easier to make this configurable.

And that's it. You should now have a calendar that is reusable, contains data and a navigation structure for navigating to different views. In the next installment we'll delve into making the controls for the day and week views.

calendar-part3results.jpg

Comments

ID: 1
Date: 02/09/2010 04:06:22 PM
Name: Bob Balfe
Website: http://blog.balfes.net

You should consider going a step further and making your xpage into a component. This way your calendar can be used to publish the currently selected date and then be used in a composite application.

ID: 2
Date: 02/09/2010 05:01:59 PM
Name: Keith Strickland
Website: http://www.keithstric.com

Thanks Bob, however I'm not really sure how to go about that. I've only done 1 composite app and it was when composite apps first made a showing in the blogsphere. I know a lot has changed since then.

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.