Alexander Hawkey <[EMAIL PROTECTED]> wrote:
> I need to make adapt the calendar in the library palette so that I can have
> a rollover & click on the numbers, not just month and year.
> I want to be able to select a range of dates and then feed them into a
> spreadsheet.



Hi Alexander,

Here's something to get you started.  You could replace the existing
beginSprite(), prepareFrame() and hyperlinkClicked() handlers with the
following:


property pClickedDates

on beginSprite me
  Initialize me
  
  pClickedDates = value(getPref("Absences"))
  if not listP(pClickedDates) then
    pClickedDates = []
  end if
  
  pClickedDates.sort()
  me.hiliteDates()
end beginSprite



on prepareFrame me
  if myBrowseMode <> #no then CheckLinkRollover me
end prepareFrame



on hyperlinkClicked me, linkData, range
  TreatLinkClick me, linkData, range
  me.hiliteDates()
end hyperlinkClicked



on mouseUp(me)
  tWord = mySprite.pointToWord(the mouseLoc)
  tDate = value(myMember.text.word[tWord])
  
  if tDate and tDate < 32 then
    -- Work out which date was clicked
    tDateObject = the systemDate
    tDateObject.year  = myDateList.year
    tDateObject.month = myDateList.month
    tDateObject.day   = tDate
    
    if myMember.word[tWord].color = rgb(255, 0, 0) then
      -- This date has already been clicked
      myMember.word[tWord].color = myStandardColor
      pClickedDates.deleteOne(tDateObject)
      
    else
      -- Change the color and remember the date
      myMember.word[tWord].color = rgb(255, 0, 0)
      pClickedDates.add(tDateObject)
    end if

    setPref("Absences", string(pClickedDates))
  end if
end mouseUp



on hiliteDates(me)
  tDateWord = 11 -- Number of words before the "1"
  i = pClickedDates.count
  isInMonth = FALSE
  repeat while i
    tDate = pClickedDates[i]
    if tDate.year = myDateList.year then
      if tDate.month = myDateList.month then
        -- This date is in the current month
        isInMonth = TRUE
        myMember.word[tDateWord + tDate.day].color = rgb(255, 0, 0)
      else if isInMonth then
        -- We've treated all the dates in this month
        exit
      end if
    end if
    i = i - 1
  end repeat
end hiliteDates



on getClickedDates(me)
  return pClickedDates
end getClickedDates



This will color red any dates that you click on, and save them in a sorted
list.  You can use...

  put sendAllSprites(#getClickedDates)
  -- [date( 2001, 10, 2 ), date( 2001, 10, 25 ), date( 2001, 12, 1 )]

... to return a list of dates the user clicked on.  The mouseUp handler
saves the list of dates automatically to a preferences file named
"Absences".


You'll need to adapt this in three ways:

1. Staff records
I imagine that you would want to modify this so that there is a different
file for each staff member.  This would mean adding a popup menu of staff
member names beside the calendar, and loading the appropriate prefs file on
beginSprite or whenever the selection in the popup menu changes.

2. Export to a database
The database won't be able to handle Director date objects as such, so you
should convert the data you save to some value the database can understand.

3. You'll probably want to save the data to a file elsewhere than in the
Prefs file alongside your application.  You can use the FileIO xtra to do
this.


Cheers,

James


[To remove yourself from this list, or to change to digest mode, go to
http://www.penworks.com/lingo-l.cgi  To post messages to the list,
email [EMAIL PROTECTED]  (Problems, email [EMAIL PROTECTED])
Lingo-L is for learning and helping with programming Lingo.  Thanks!]

Reply via email to