TwelvestoneFlash

Calendar(dateChooser) component


Sign in

  • Waiting for Godot ( 730 k posts )
    Just conversation.
  • Thunder Dome ( 23 k posts )
    Photoshop Tennis and Collabs.
  • Photography ( 5.1 k posts )
    For all you shutterbugs, sh...
  • Flash ( 18 k posts )
    ActionScripting to tweens, ...
  • Front End ( 5.9 k posts )
    general front end design an...
  • Back End ( 9.7 k posts )
    serverside scripting, progr...
  • Projects and Theory ( 12 k posts )
    This forum is for discussio...
  • FAQ ( 269 posts )
    All those nagging questions...
  • Design ( 17 k posts )
    graphics & all aspects of g...
  • Purgatory ( 3.6 k posts )
    12stone Jail, feel free to ...
Icculus
 
2007-11-21

I haven't done any sort of coding in a couple years and my brain hurts trying to sort this out.

I'm trying to add a calendar to my photo blahg. I have a simple nested array I update that contain the photo date, name and some commentary if I'm so inclined.

What i want to do is check the date info and any date that isn't in the nested array I would like to disable using DateChooser.disabledRanges.

but for some reason I can't wrap my head around how to go about it. Any help as usual would be fantastically appreciated.

Cheers

Icculus
 
2007-11-21

I guess I should have included an example of the array i pull data from:

var p587 = ["2007/11/13", "water series", "An exploration on the movement/fluidity of water."];

and these get put into a nested array like so

var nested_photos = []; for(var i = 0; i<total_photos; i++) { nested_photos.push(eval("p" + i)); cb.addItem(nested_photos[i][1], i+1) }

Icculus
 
2007-11-23

alright so I figured how to get it rocking in the opposite way (disabled days abled, abled days disabled)

I changed the structure of my array breaking up the date property to year, month, day. instead of lumped together

var p587 = ["2007", "11", "13", "water series", "An exploration on the movement/fluidity of water."];

and using this code I can disable al the days in my array

var disabledRanges:Array = new Array();

for (var i = 0; i<total_photos; i++){ disabledRanges.push(new Date(nested_photos[i][0],nested_photos[i][1]-1,nested_photos[i][2])); }

cal.disabledRanges = disabledRanges;

but if I switch out disabledRanges for selectableRange it doesn't work

any ideas?

DontBogartMe
 
2007-11-23

I've never used the dateChooser, but reading the help on it I think I understand your problem - you want the whole calendar to be disabled except the days where there is something to view? And the dateChooser component is geared to have it all enabled, with the possibility of disabling dates or date ranges. That's a bit of a pain - and a bit of an oversight on the component author's part IMO.

'selectableRange' is not going to work for you, because that only lets you set either one date or one date range that is active in the whole calendar.

I think you'll have to start with the whole calendar enabled, then go thru it disabling ranges that fall between your active days.

So the first range to disable is between the first day in the calendar and the first date that you want active. The next range is between that first active date and the second. etc etc The final range is between the final active date and the last date in the calendar.

So you'll need to have you array of dates sorted by date, starting with the earliest. Loop thru that and work out the ranges to disable as I described above.

Icculus
 
2007-11-25

I think I understand what you are saying but I'm still lost on how to fill the diasabledRanges array with dates that there are no photos.

how could I take the dates that i already have and use them to find the any date that isn't listed?

DontBogartMe
 
2007-11-26

create a variable that stores the first date in your calendar, e.g. if your calendar goes back to 2004, then that would be Jan 1 2004, regardless of whether or not you have a photo there to link to.

(This is all pseudo code. hopefully you'll be able to follow it and turn it into actionscript)

rangeStartDate = Jan 1 2004

Now begin a loop to run thru your array of dates.

for each photoDate in ArrayOfPhotoDates

if photoDate > rangeStartDate then

    // Disable a range of dates beginning rangeStartDate up to the day before photoDate
    rangeEndDate = photoDate - (1 day)

    disableRange(rangeStartDate, rangeEndDate)

end if

// The next range to check starts the day after the current photo date.
rangeStartDate = photoDate + (1 day)

next

// Now we've looped thru all the dates that have photos - check to see if there is a range of dates to disable at the end of the calendar. if rangeStartDate < calendarEndDate then

disableRange(rangeStartDate, calendarEndDate)

end if

Let's test that by running some dates thru it: calendarStartDate = Jan 1 2004 calendarEndDate = Dec 31 2007

You have 4 photos in your array at Sept 7 2004, May 20 2005, May 21 2005 and Jan 3 2007.

Here's the first iteration of the for-next loop with the dates filled in:

for each photoDate in ArrayOfPhotoDates

if photoDate _(Sept 7 2004)_ > rangeStartDate _(Jan 1 2004)_ then

    rangeEndDate = photoDate - (1 day)
    _(rangeEndDate = Sept 6 2004)_

    disableRange(rangeStartDate, rangeEndDate)
    _disableRange(Jan 1 2004, Sept 6 2004)_

end if

// The next range to check starts the day after the current photo date.
rangeStartDate = photoDate + (1 day)
_rangeStartDate = Sept 8 2004_

next

.... now the next iteration ....

for each photoDate in ArrayOfPhotoDates

if photoDate _(May 20 2005)_ > rangeStartDate _(Sept 8 2004)_ then

    rangeEndDate = photoDate - (1 day)
    _(rangeEndDate = May 19 2005)_

    disableRange(rangeStartDate, rangeEndDate)
    _disableRange(Sept 8 2004, May 19 2005)_

end if

// The next range to check starts the day after the current photo date.
rangeStartDate = photoDate + (1 day)
_rangeStartDate = May 21 2005_

next

.. the next iteration is different because there is no range to disable, because you have photos on two consecutive days:

for each photoDate in ArrayOfPhotoDates

if photoDate _(May 21 2005)_ > rangeStartDate _(May 21 2005)_ then

    // THE DATES ARE THE SAME - so don't disable the range, move on to the next.

end if

// The next range to check starts the day after the current photo date.
rangeStartDate = photoDate + (1 day)
_rangeStartDate = May 22 2005_

next

.... now the 4th and final iteration ....

for each photoDate in ArrayOfPhotoDates

if photoDate _(Jan 3 2007)_ > rangeStartDate _(May 22 2005)_ then

    rangeEndDate = photoDate - (1 day)
    _(rangeEndDate = Jan 2 2007)_

    disableRange(rangeStartDate, rangeEndDate)
    _disableRange(May 22 2005, Jan 2 2007)_

end if

// The next range to check starts the day after the current photo date.
rangeStartDate = photoDate + (1 day)
_rangeStartDate = Jan 4 2007_

next

... now we break out of the loop and hit the final IF statement to disable the final range of dates to take us the end of the calendar:

// Now we've looped thru all the dates that have photos - check to see if there is a range of dates to disable at the end of the calendar. if rangeStartDate (Jan 4 2007) < calendarEndDate (Dec 31 2007) then

disableRange(rangeStartDate, calendarEndDate)
_disableRange(Jan 4 2007, Dec 31 2007)_

end if

I reckon that'll work. I hope you can follow the logic there and turn it into actionscript?

Icculus
 
2007-11-27

although I hit a few minor hitches (like the dates not being in some instances in sequence) I got it to work thanks to your explanation above DBM

Thank you very very much k

the code for those interested

//array to store photo dates var photoDates:Array = new Array();

//pulling date data from photo info array for (var i = 0; i<total_photos; i++){ photoDates.push(new Date(nested_photos[i][0],nested_photos[i][1]-1,nested_photos[i][2])); }

var firstPhoto = photoDates[photoDates.length-1]; cal.selectedDate = firstPhoto;

//sorts dates so photos don't have to be added sequentially photoDates.sort(NumCmp);

//set selectable dates var rangeStart = photoDates[0];

var rangeEnd = photoDates[photoDates.length-1];

cal.selectableRange = {rangeStart: rangeStart, rangeEnd: rangeEnd};

var disabledRanges:Array = new Array();

for (var j = 0; j<photoDates.length-1; j++){

if(photoDates[j] > rangeStart){

    rangeEnd = new Date(photoDates[j].getFullYear(),photoDates[j].getMonth(),photoDates[j].getDate()-1);
    disabledRanges.push({rangeStart: rangeStart,  rangeEnd: rangeEnd})
}
    rangeStart = new Date(photoDates[j].getFullYear(),photoDates[j].getMonth(),photoDates[j].getDate()+1)

}

cal.disabledRanges = disabledRanges;

DontBogartMe
 
2007-11-27

hey nice one - glad you could turn my pseudo code into something that works.

Sorry, you must be a member to post to a conversation. Either log in or sign up to get involved.
TwelvestoneFlash

Calendar(dateChooser) component