Using beforeShowDay (jquery.ui.datepicker) to display different employee schedule states.

by Admin 2. December 2008 10:06

Using the JQUERY calendar has been a great experience for us here at eSchedule so we've decided to share how we've accomplished some of our basic employee scheduling calendar features utilizing great open source projects like JQUERY. If you haven't heard of JQUERY then you should definitely check it out.

Let's assume we are displaying the jquery calendar in place with 2 months displayed:

First we need a holder element:

<div id="CalendarHolder"></div>

Then we can extend the div element with a JQUERY datepicker. The first thing to note below is that we've encapsulated our code inside $(document).ready(function(){});. We always wait until the page is ready before attaching our datepickers, safety first!

<SCRIPT LANGUAGE=javascript><!--

 

var activeDate = new Date('12/2/2008');

$(document).ready(function()

{$("#CalendarHolder").datepicker(

    {

        numberOfMonths: 2,

        showStatus:true,

        yearRange: '2000:2009',

        defaultDate: activeDate,

        firstDay: 0,

        inline: true,

        showOtherMonths: true,

        beforeShowDay: setScheduledDays

    });

 });

//--></SCRIPT>

A few things to point out here are the defaultDate and beforeShowDay properties. defaultDate is fairly self explanatory, and is how we set the selected date displayed on our calendars..

What we're really interested in is the
beforeShowDay property. Here we are instructing the datepicker to call this function setScheduledDays (below) immediately before showing each day on the calendar. This function simply returns [bool, 'CSS_CLASS']. The bool signifies whether the date is selectable, and the css class will set the css of our cell accordingly.

Below we initialize two arrays, scheduledDays and holidayDays. scheduledDays holds the date and css class for each day (only scheduled days have any sort of status), while holidayDays identifies which days of the year we can't schedule.

<SCRIPT LANGUAGE=javascript><!--

var scheduledDays = [[12, 2, 2008, 'PEND'], [12, 3, 2008, 'PEND'], [12, 4, 2008, 'PEND']]

var holidayDays = [[12, 25, 2008],[4, 12, 2009],[11, 26, 2009],[12, 25, 2009]];

function setScheduledDays(date) {

    var isScheduled = false;

    var isHoliday = false;

    var scheduleStatus = "";

    // Check for scheduled day

    for (i = 0; i < scheduledDays.length; i++) {

      if (date.getMonth() == scheduledDays[i][0] - 1 && date.getDate() == scheduledDays[i][1] && date.getFullYear() == scheduledDays[i][2])

      {

        isScheduled = true;

        scheduleStatus = scheduledDays[i][3];

      }

    }

    // Check for holidays

    if (holidayDays != null)

    {

        for (i = 0; i < holidayDays.length; i++) {

          if (date.getMonth() == holidayDays[i][0] - 1 && date.getDate() == holidayDays[i][1] && date.getFullYear() == holidayDays[i][2])

          {

            isHoliday = true;

          }

        }

    }   

    if (isHoliday)

        return [false, 'CLOSED'];

    else if (isScheduled)

        return [true, scheduleStatus];

    else

      return [true, ''];

} 

//--></SCRIPT>

Currently rated 5.0 by 9 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , , , ,

Technology

Comments

12/13/2008 11:20:23 PM

Brook

What is PEND and CLOSED? Are those styles for css as you mentioned? If so how do I set those in CSS? Maybe like .PEND {color: #FF0000; } If you can send me an email and let me know how you changed the colore for the scheduled days. Thanks.

Brook us

12/15/2008 3:13:59 PM

Admin

Hi Brook,

Yes PEND and CLOSED are some possible CSS name values. Your example of .PEND {color: #FF0000; } would be valid. Note in the scheduleDays declaration below:

var scheduledDays = [[12, 2, 2008, 'APPR'], [12, 3, 2008, 'APPR'], [12, 4, 2008, 'PEND']];

December 2nd and 3rd would have class name 'APPR', while December 4th would have the class name 'PEND'.

Hope this helps Smile

Admin ca

1/10/2009 4:32:40 AM

Busby SEO Test

nice post, thank you for sharing :)

Busby SEO Test us

1/18/2009 4:25:14 PM

Kai

works like a charm! thanks for sharing! greetings from germany!

Kai de

4/4/2009 11:17:32 AM

jammer

great post
love it

jammer am

4/4/2009 11:18:02 AM

movers

move it on baby
move it right now
we love it

movers sv

4/27/2009 12:31:10 PM

kampanye damai pemilu indonesia 2009

great blog, i really like it.

kampanye damai pemilu indonesia 2009 us

4/27/2009 4:44:09 PM

Denver Movers

lovely thing to do
made my day

Denver Movers by

4/27/2009 4:45:11 PM

Dallas Movers

made my day
love yours sir
so funny
so happy

Dallas Movers ge

5/4/2009 4:59:00 PM

sulumits retsambew

what a great code, this is what i am looking for, thanks.

sulumits retsambew us

9/8/2010 4:24:05 AM

st petersburg computer supportst petersburg computer repair

How you been, I utterly agree with your blog post. Mine and my husband's computer start so much easier with it done. It's unbelievable how much such a small task can make such a big differance. When I first read about it I was uneasy about trying it out, but thanks to you my worries was put to bed. gracias

st petersburg computer supportst petersburg computer repair us

9/8/2010 4:24:16 AM

st petersburg computer repair

Watsup, I utterly agree with your blog post. My PC open so much faster with it on. It's hard to believe how much such a small task can make such a monumental differance. In the begining I was uneasy about trying it out, but thanks to your post my worries was put to bed. gracias

st petersburg computer repair us

9/8/2010 5:11:32 AM

annunci gratuiti

Your site is getting more traffic thanks to sites like Myspace and other social media. Thanks again for the awesome article I'll be back for updates.

annunci gratuiti it

9/8/2010 5:56:47 AM

jobs melbourne

Intimately, the post is in reality the sweetest on this worthy topic. I concur with your conclusions and will thirstily look forward to your incoming updates. Just saying thanks will not just be adequate, for the wonderful clarity in your writing. I will directly grab your rss feed to stay informed of any updates. Fabulous work and much success in your business dealings!

jobs melbourne us

9/8/2010 6:18:08 AM

Gravura Bucuresti

Hi,Its very greatful for choice BlogEngine.Net as platform your blog. I'm using blogengine too and for me thats easy to manage althought I'm newbie.happy writing Regards,andrei

Gravura Bucuresti ro

9/8/2010 6:45:14 AM

http://estateagentsinromford.co.uk/

Cool post.

http://estateagentsinromford.co.uk/ us

9/8/2010 7:32:29 AM

how do you get pregnant

She is just great! All she touches converts to gold, so despite some chitchats or lies about her, she remains on the top. So go girl, you're the best

how do you get pregnant us

9/8/2010 8:53:48 AM

Weldon Coulston

i thought this was a really great post to read. i'll check back for new posts by you!

Weldon Coulston us

9/8/2010 9:13:06 AM

Darcie Gorum

Well, this is my first visit to your blog! We are a group of volunteers and starting a new initiative in a community in the same niche. Your blog provided us valuable information to work on. You have done a marvellous job!

Darcie Gorum us

9/8/2010 9:45:08 AM

Article Submitter

Drive insane traffic to your website using the magic power of article submission. Who else wants to get thousands of real human page visitors and hundreds of valuable one-way links pointing to your site, boosting your website's pagerank like never before. Explode your website revenue and leads with this profit producint technology. <a href="http://tracking.chexbox.com/tracking202/redirect/lp.php?lpip=746" rel="nofollow">ARTICLE SUBMITTER</a>

Article Submitter us

9/8/2010 9:46:50 AM

Home Tooth Whitening

After a careful read I thought it was very informative. I appreciate you taking the time and effort to put this article together. I once again find myself spending way to much time both reading and commenting. But what ever, it was still worth it!

Home Tooth Whitening us

9/8/2010 10:45:51 AM

Consignment

I dont know who you think you are, but youre just blowing smoke out your ears. Nothing youre saying makes sense and its all a bunch of immature ranting. If you want people to get behind your blog, you should at the very least learn a little something about what youre talking about!

Consignment us

9/8/2010 11:20:29 AM

annunci

I'm excited to be finally posting online after all these years. There really is no mystique (sp) about it, is there? I just dropped by your blog and had to write something. I'm a recent college grad, journalism major if you must know, and I love the art of photography. I've got my site up but it's nothing to brag about yet. None of my stuff's been posted. Soon as I figure out how to do that, I'll spend the day posting my best shots. anyways just thought I'd drop a line. I hope to return with more substantial stuff, stuff you can actually use. SPG

annunci it

9/8/2010 11:22:41 AM

idol white review

Here is the 2nd time I have encountered your web site within the last couple weeks. Seems like I ought to bookmark it.

idol white review us

9/8/2010 12:22:53 PM

link building

This was a realy good post i appriciate the share i will be sure to add you to my favorites for sure.

link building us

9/8/2010 1:19:21 PM

Music Rocks!!!

Heyyy, Must say, a great post! Please keep it up!!!!

Music Rocks!!! us

9/8/2010 1:21:27 PM

Deloise Delmont

great post! i'm bookmarking this!

Deloise Delmont us

9/8/2010 2:21:22 PM

Decretas

I really like your writing style . You bring forth some very key policies to light and make it very simple for the reader . Thanks! <a href="http://www.squidoo.com/mortgage-notes-for-sale-note-buyers-guide-to-buying-non-performing-notes">Mortgage Notes/a>

Decretas us

9/8/2010 2:55:58 PM

Inger Hillock

Should you be looking to start your special home business by leveraging the actual possibility that the World-wide-web has to offer then it is just a action in the perfect way. However, the most important concern just isn't to transfer each of the advertising pursuits of your organization to others. When getting very good potential customers and prospects who are leads, it is important to analysis and pay attention to the perfect strategies in direction of promoting your business enterprise via the internet. If you achieve the required expertise then it'll make sense in outsourcing the advertising work related to your organization to others.

Inger Hillock us

9/8/2010 3:16:11 PM

Stairway to Heaven Sheet Music

This is a great blog entry, though sometimes I think I have to disagree with your takes and ideas on certain posts. Likewise, I just can't stop reading the things you write because it is written so flawless and elegantly. It's good to know that other people actually take the energy to think about the things they are posting about. I have a piano related site and if you are into learning piano it would be great if you could have a look. I am just starting out and I could use a couple instructions or pointers. Maybe one day my site can be as good as yours and I will have people that actually stick around. Anyway apologies for the lengthy response and I hope you continue to post on your blog unlike other people who just randomly stop. Thanks and I'll be checking back again!

Stairway to Heaven Sheet Music us

9/8/2010 3:41:46 PM

venapro

That's news to me; I didn’t know the many ramifications and depth to the story until I surfed here through Yahoo! Good job.

venapro us

9/8/2010 3:42:57 PM

online bingo

Great resource. I really enjoyed your site!

online bingo us

9/8/2010 4:12:15 PM

Custom Jewelry

I think some people's freedom of speech pass needs to be revoked. Just saying. Wow.

Custom Jewelry us

9/8/2010 6:26:19 PM

Brett - Day Trader

Hey, I was just browsing through the web seeking some facts and came across your site. I really like the data that you have on this post. Bookmarked this web site. Brett

Brett - Day Trader us

Add comment


(Will show your Gravatar icon)  

  Country flag

biuquote
  • Comment
  • Preview
Loading



Powered by BlogEngine.NET 1.4.0.0
Theme by Mads Kristensen