Friday, September 17, 2004

That Damned Calendar: Errata

While preparing the database for OpenNTF.org, I ran across a couple of errors in the code and a couple of things that I could have done a bit better. I have no qualms about editing postings like those ("articles" as opposed to "opinion and observation"), so the original articles will be corrected as necessary. Those who have been following this since the beginning, though, will need to be told which bits have been changed and why. Let's do the bugs first, shall we?

First, the goToDate() funtion is missing a set of parentheses. As it stood, if there were no categories in use, you would always go to the redirect page, and then to the current month. The problem is this line:

window.location.search = 'OpenView&RestrictToCategory=' + (cat=='')?'':(cat + '~') + year + '-' + month;

If "cat" is an empty string, then year and month are ignored as well. The line should have read:

window.location.search = 'OpenView&RestrictToCategory=' + ((cat=='')?'':(cat + '~')) + year + '-' + month;

As well, the line checking the Category field is going to cause fires and explosions if there are no categories in use in your application. The Categories field does not exist, and when you try to examine its properties, the script errors out. This line:

var cat = f.Category.options[f.Category.selectedIndex].value;

needs to be changed to:

var cat = (f.Category)? f.Category.options[f.Category.selectedIndex].value: '';

Next, the formulas for the Previous and next links are missing "?OpenView&RestrictToCategory=". The formula given for the Previous link should have read:

lastMonth := @Adjust(StartDate;0;-1;0;0;0;0);
year := @Year(lastMonth);
month := @Month(lastMonth);
textMonth := @Select(month; "January"; "February"; "March"; "April"; "May"; "June"; "July"; "August"; "September"; "October"; "November"; "December");
"<a href=\"" + @ViewTitle + "?OpenView&RestrictToCategory=" + @If(SelectedCategory = "";"";@URLEncode("Domino";SelectedCategory) + "~") + @Right("000" + @Text(year);4) + "-" + @Right("0" + @Text(month);2) + "\">" + textMonth + " " + @Text(year) + "</a>"

Note, too, that I have put "@ViewTitle" in where ViewName used to be. I don't know quite what I was thinking when I typed the original posting; the application has always used @ViewTitle, even in its earliest incarnation. Sorry. And I have incorporated the enhancement discussed below.

On to the refinements, then. I had been storing a URL-encoded version of the current category in the SelectedCategory field. It occurred to me that it's easier to @URLEncode that value where it needs to be encoded than it is to try to decode it when needed for R5 use, like for the window title and page heading displays. Change the formula for the SelectedCategory field to:

@Left(Category; "~")

The formula for the category picker already has taken this change into account. Again, there may be typos remaining. The demo database is clean and works, but getting its bits and pieces up here as HTML has induced the odd problem. If you find anything, please let me know.

Addendum

A change to keep Internet Explorer happy: in the two spacer fields, insert a &nbsp;into both the "spacetop" and "spacebootom" cells. That will force the borders (if any) to display in those cells.

For Mozilla: add "height: 58px;" to the DIV.cellcontent CSS entry, or Mozilla will extend the <div> content outside of the table cell.

No comments: