Saturday, September 12, 2009

daterange for jqueryui

I've been using jquery a lot. I write a lot of reports, and I've not had a lot of time to add a date picker. I finally decided to do some research. I found that jqueryui (the sister to jquery) has a datepicker. What's even better is that it has a range option. Well, it did. Unfortunately that was in version 1.2 something. I really need a range. In doing some research, I found the the jqueryui team points you to a really cool plugin. Although I think it is pretty cool, I don't really think it meets my need. That being said, this was my solution, and a very simple one at that:

Required:
jquery 1.3.2
jqueryui core 1.7.2
jqueryui datepicker widget
jquery field plugin

You need to include these files, and you should probably include the jqueryui css as well, although the docs say that isn't necessary (i saw the calendar without the css, and I'd suggest using the css).

Basic input from a form:

<label for="startDate">Start Date:</label><input type="text" id="startDate" name="startDate" value="09/02/2009" autocomplete="off"><br/>
<label for="endDate">End Date:</label><input type="text" id="endDate" name="endDate" value="09/04/2009" autocomplete="off"><br/>
<div id="daysBetween"></div>

I supply a default date so that use of the fields is only required if you want to change the dates. The one peculiar thing is the empty div. This doesn't have to be included, but I want my users to know how many days are between the dates, and this is where I place that information.

The javascript:

var $endDate = $("#endDate");
var $startDate = $("#startDate");
var startDateMax = new Date($endDate.getValue());
var endDateMin = new Date($startDate.getValue());
var $daysBetween = $("#daysBetween");
var oneDay=1000*60*60*24;
$(window).load(function(){
$startDate.datepicker({changeMonth: true, changeYear: true, minDate: '-2Y', maxDate: startDateMax});
$endDate.datepicker({changeMonth: true, changeYear: true, minDate: endDateMin, maxDate: '+0D'});
calcDwell(startDateMax, endDateMin);
});
$(window).load(function(){
$startDate.change(function() {
changeDates();
});
$endDate.change(function() {
changeDates();
});
});
function changeDates(){
$(function () {
var startDateMax = new Date($endDate.getValue());
var endDateMin = new Date($startDate.getValue());
$startDate.datepicker('option', 'maxDate', startDateMax);
$endDate.datepicker('option', 'minDate', endDateMin);
calcDwell(startDateMax, endDateMin);
})
}
function calcDwell(startDateMax, endDateMin){
$daysBetween.text('Days: ' + (Math.ceil((startDateMax.getTime() - endDateMin.getTime())/(oneDay))));
}

Since I will be using the jquery selectors over, I set them to variables. I initialize the datepicker, and then wait for a change on #startDate or #endDate. If that occurs, I call changeDates, which resets the min and max dates for each field. I also recalculate the daysBetween after the change.

The getVal function comes from Dan's field plugin. I was originally just using js to get the value, but after the value changes, it no longer works. I decided to check for a better way. I came across a google thread where Dan pointed to his plugin (I'm surprised at how many times I find CFers in jquery threads). I added it, and it just worked. I plan to retrofit this into the rest of my application.

I later found a way to just use jquery, but I am happy with the way it is. I wanted to offer this post, as I did a lot of searching and found little to nothing of how to do this. Hopefully you will find this post useful.

Thursday, March 19, 2009

SQL Like Null

Wow! That is interesting...

I just ran into a situation I have never known I was in before (I know be careful where you run). I was writing some SQL (one of my favorite things to do), and had a record not show up that I knew matched the criteria. I use a like operator in the query and in the table used to compare I have a wild card (%). This works great. Except for when the main table has a null.

The reason the record didn't show up was due to the fact that the table had a null cell. Since I was working in Oracle, it was very easy to fix this.

nvl(table1.column_name, ' ') like table2.column_name


That fixed it. I really prefer MS SQL Server over Oracle, but that is a fantastic little method/function.

So I figured this wouldn't be the same in SQL Server. Sure enough like doesn't work with a null cell. I'm not taking the time now to think about how to handle this in SQL Server, but I'm sure it's much longer.

Come to think about it I suppose this would work:

(table1.column_name like table2.column_name or table1.column_name is null)


So there you have it.

Thursday, November 20, 2008

Requirements Gathering: DRY

So I'm on this project as an SME (Subject Matter Expert). I previously wrote a report for a warehousing application that provides a list of items that have a specific status of ready to go. So if the status of a package is ready to go and has not moved then it should show on the report. No problem. It works great.

Someone decided that this type of report needed to be in the warehousing application (ya think?). So my part in the project is to write the requirements (since I wrote the requirements for my own report, and actually coded it).

The warehouse application can be set into two different modes. The difference between the two is what events have to occur before the status is set to ready to go.

So the developer and the IT project lead had some questions about this particular requirement. The big question was does this need to perform differently based on the mode the application is set.

What do you think?

I simply responded that the requirement was agnostic to what mode the application was running under. I simply want the application to respond based on the status being set to ready to go. This created all kinds of issues. They refused to accept that as a requirement. They wanted to define the events that caused the status based on the mode. They didn't even understand DRY in the programming world, why would I think they would understand the concept requirements.

Again, what do you think? Would you need to know the events or simply the status? Could you not look at how the system gets the status?

Tuesday, November 4, 2008

Requirements Gathering: Shout and Scream Method

A co-worker and I just created a new and unique requirements gathering method. We are calling it the "Shout and Scream" method. It's the simplest method ever.

Step 1 - Turn off the existing application.
This is easier than it sounds, and can be completed in a few seconds no matter how complicated your application. Each application is run on some sort of server. It could be a real server class machine, or a regular pc that is set up to act as a server. Each of these servers has a button/switch on the front or back, and if not, they all have a large cable that somehow attaches to the wall for power. Depress the button, flip the switch or yank the cable (depending on the model). If you have a really large application, repeat this step for every server.

Step 2 - Sit back and wait.
This is where the shouting and screaming comes in to play. You will begin getting e-mails and phone calls regarding the relevant pieces of the application. Those are your requirements. If it's important, you will find out.

FAQ's:
  • How will they know who to contact if they can't see our support page?
    • What does it matter? If it's that important, they will find a way to get in touch with you.
  • What if the shouts and screams are not descriptive enough.
    • Reply asking for clarification.
  • What if the shouts and screams never get more descriptive?
    • Explain that the requirement is out of scope, and that they will be logged in the event the scope widens to include the requirement.
  • What if the shouts and screams are rude or personal?
    • They are not real requirements? When was the last time you saw requirements that personally attacked you?
Training:
We are considering offering a training course in the future. After evaluating the market be believe our course for $1600 USD/person would be a bargain. Let us know if you would be interested in this training, and how many participants would attend. The additional expense of traveling would be covered in a speakers fee in addition to the per person cost.

Please feel free to post any further questions below.

Tuesday, October 14, 2008

ColdFire Contribution

Ok, I'm not much on blogging, but I wanted to post that I have finally contributed to open source.

Sammy Larbi has interested me in OSS contribution, but I never saw anything to contribute toward. last week, I discovered where ColdFire wasn't acting the way I wanted it to. I took a look at the cfm file, and made some changes that worked. i submitted them to Nathan Mische. Nathan responded that the cfm wasn't the problem, but would look into it.

Nathan pointed me away from the cfm, so I decided to take a look at how ColdFire works (it's mostly js). I dug around, and change about 50 things trying to make it work. In the end, Nathan accepted the patches for the cfm. I believe these directly affected 2 open tickets. I believe the report contributed to his fix on the 3rd ticket. Those changes were relased here:

http://coldfire.riaforge.org/blog/index.cfm/2008/10/13/ColdFire-129595

Unfortunately, these fixes did not change anything for my problem. I sent Nathan an e-mail about 30 minutes prior to the 1.2.95.95 release letting him know that I had the fix for my issue. I admitted that I didn't like the fix, but it does work and does not cause any harm. Nathan responded letting me know he accepted the patch for the js. I really like his response:

"I think that is a good fix. ... I agree that the fix is a bit of a hack, but it is a pretty darn good one."

I had a CFSQLType of CF_SQL_CHAR. The value passed was 20081001. It was interpretted as a number instead of a string. The hack was simple. value = value + ""... now it's a string.

In the end, this was a lot of fun. I've been slowly getting into the js world as I am implementing pieces of jquery into my apps. I may begin to contribute more now that I've got a patch under my belt.

You can go to just about any post from Sammy regarding open source.
http://www.codeodor.com/

I also found this article important in actually posting this:
http://www.mischefamily.com/nathan/index.cfm/2008/7/16/Contributing-to-OSS

Tuesday, February 19, 2008

access forms

funny thing. i have managed to avoid access for all but perhaps exporting data (which is not really using access). i mean... i have used it. written a query or two. perhaps a lame report. but i have never used access.

things changed today. i was helping a new co-worker out. telling her she didn't have to print so much paper. turns out she had printed a stack of forms that were to be manually filled out by folks in the field offices. and she was going to store them for use later.

so onto the change. i got her started by showing her a couple of things. she created a worksheet type table. she input some data. she even modified a query to pull back data.

i looked her form over during our staff meeting, and figured out how her data needed to be broken up. i got back to my desk and fired up access. i am using 2003, and it has some pretty neat features.

table.field:
input mask - i found that access has an input mask that allows you to define what is allowed as input. this was great for phone numbers, employee numbers, a FIRMS code (A123) etc.
caption - now i thought this was pretty neat. you define your field name, ramp_loc in my case, and you add a caption of Ramp Location. now when i build a form or report Ramp Location is in the header instead of ramp_loc. this is very nice if you are going to be using access as the front gui (although i am sure there is a way to get this as meta for use in any application).

using access as a database is not bad. but i have always dreaded writing an interface in access. since this is being used for 1 person, i figured i would kick the tires (this is for a new employee who has never used access before and is not a programmer). the first form i made i just ran the wizard and viola. everything was pretty neat.

and then i had to go and get all complicated. i know what i want to do and i am about 75% there. of course at this time tomorrow, i could have built the entire thing using a web language, but hey... it's another tool in the toolbox.... right?

Monday, February 18, 2008

css and xhtml

i've been interested in both css and xhtml for some time now. the majority of my work is in reporting, and it hasn't led to much work with either. my current project is refactoring an exisitng application. i decided while i am having to dig into the view of this application to improve error handling, that i would remove all styling and place it into a css file. i have enjoyed doing this. it has been pretty simple, but fun none the less.

this even lent itself asking advice from chris coyier at css-tricks.com. i wasn't really sure what to expect, but he responded to my email. it appeared that he spent more than 5 minutes in his response as well. pretty cool. i guess that just goes to show that he's a cool cat.

so with the styling taken care of, i made sure that the only thing left was xhtml compliant. well, this is true for the part of the view i was working in. since there is other code in the rest of the template, and i haven't attacked the template yet, i've still got some work. at this point though, i've got several div's, some tables, some links and some breaks. pretty compliant. everything is in lowercase.

well.. not everything. here is what i think is funny. xhtml states that all tags and attributes are to be in lowercase. since xhtml is strict and case sensitive, it is important. what i find so humourous though is the doctype declaration. one of the following three must be used:

< !DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">


< !DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


< !DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">


notice all of the capital letters? i just find it humorous.