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

7/29/2010 4:10:45 AM

watch television on computer

I have read something about it on another forum but your post is also very informative.

watch television on computer us

7/29/2010 5:19:57 AM

Pregnancy Week

What about stretch marks of pregnancy (Striae gravidarum)? During pregnancy, skin changes are very common. Many of these skin changes are normal in pregnancy and should not be mistaken for a rash or skin disorder. Except for affecting the mother's appearance (cosmetic effects), these skin changes do not harm mother or baby in any way. Most of these changes disappear within a few months after the baby is born, but tend to reappear in subsequent pregnancies. http://pregnancyconception.org.

Pregnancy Week us

7/29/2010 7:11:31 AM

email blasting

Awesome, I was searching for something along the lines of this. I was thinking, do you think newsletters are still an great way of marketing online? Does anybody still use them well and actually acquire readers?

Cheers!
Eric

email blasting us

7/29/2010 8:06:12 AM

digital drum set

Thank you for the interesting read. The web is so cluttered with junk it's becoming difficult to find exactly what you're looking for these days. Have you got RSS on this site?

digital drum set us

7/29/2010 8:20:30 AM

vigrx

this site is really great.. nice layout

vigrx us

7/29/2010 8:25:45 AM

Relationship Breakup Advice

A relationship breakup is a death of sorts, the death of possibilities, a future together and plans that were spun around during your better days together. http://relationshipbreakupadvice.us.

Relationship Breakup Advice us

7/29/2010 8:30:18 AM

funeral urns

I was wondering if you needed any SEO help to move this blog up on google? I do this for a living and would help you out since I enjoy reading this. Just let me know and we can get the SEO going.

funeral urns us

7/29/2010 8:32:54 AM

Snow Cone Syrup

Valuable tips shared I am very happy to read this post..many thanks with regard to presenting us nice info.Fantastic walk-through. I appreciate this write-up.

Snow Cone Syrup us

7/29/2010 9:21:42 AM

ImHosted Review

Thank you for this article, It's fantastic to see another BlogEngine.NET user. Most users these days tend to use Wordpress, but I think BlogEngine is the better system to use.

ImHosted Review us

7/29/2010 9:52:32 AM

abercrombie and fitch

Very regularly I go to see this site. It very greatly is pleasant to me. Thanks the author

abercrombie and fitch us

7/29/2010 9:52:34 AM

abercrombie and fitch

Very frequently I visit this site. It very greatly is satisfying to me. Thanks the author

abercrombie and fitch us

7/29/2010 10:06:39 AM

seo company

It's not that I want to replicate your web page, but I really like the style. Could you tell me which design are you using? Or was it tailor made?

seo company us

7/29/2010 10:06:44 AM

google seo

Your article usually have a decent amount of really up to date info. Where do you come up with this? Just saying you are very resourceful. Thanks again

google seo us

7/29/2010 10:46:17 AM

Sugar Free Syrup

Great information. Wish I could find more information like this by other people! Thanks!

Sugar Free Syrup us

7/29/2010 11:46:40 AM

Atlantica online gold

This is one of the most incredible blogs Ive read in a very long time. The amount of information in here is stunning, like you practically wrote the book on the subject. Your blog is great for anyone who wants to understand this subject more. Great stuff; please keep it up!

Atlantica online gold us

7/29/2010 11:56:16 AM

Lose 10 Pounds in 3 Days

Clearly, one of the best article l have come across on this great subject. I quite agree with your conclusions and will eagerly look forward to your future updates.

Lose 10 Pounds in 3 Days us

7/29/2010 12:06:04 PM

lorie

totally cute!

lorie us

7/29/2010 12:13:17 PM

Dairy Equipment

What theme are you utilizing here ? I really like the style. Many thanks for this posting.

Dairy Equipment us

7/29/2010 12:51:36 PM

Emergency Vehicle Lights

I like your blog. Very helpful and very inspirational. Thanks a lot. It’ll help me a lot.

Emergency Vehicle Lights us

7/29/2010 12:58:46 PM

Issac Maez

I have read about this on newspaper a few week ago...

Issac Maez us

7/29/2010 1:01:04 PM

Wind Power Generators

That has been an incredible posting. I couldn't agree much more with your comments. Hi and thanks for the effort.

Wind Power Generators us

7/29/2010 1:12:42 PM

Bankruptcy Pros And Cons

What Is a Trustee in Bankruptcy? The trustee is an officer of the court, usually a practicing attorney, appointed by the bankruptcy court. His or her primary duty is to gather your non-exempt property, turn it into cash, and pay this money to your creditors. You are required by law to cooperate with the trustee. If you refuse to cooperate, your discharge may be denied. Any property selected by the debtor in any amount not exceeding $925 plus any unused amount of the $20200 listed about up to $10100, including income tax refunds. This is called the wildcard exemption. http://bankruptcysearch.info.

Bankruptcy Pros And Cons us

7/29/2010 2:10:20 PM

sexy lingerie

The new Zune browser is surprisingly good, but not as good as the iPod's. It works well, but isn't as fast as Safari, and has a clunkier interface. If you occasionally plan on using the web browser that's not an issue, but if you're planning to browse the web alot from your PMP then the iPod's larger screen and better browser may be important.

sexy lingerie us

7/29/2010 2:36:10 PM

refugium aquarium

great post! I totally enjoyed reading it. I will definitely come back to this website.

refugium aquarium 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