NinjaCal

Under The Hood

The Theory Behind Integrating NinjaCal

Since NinjaCal uses global variables to store its results, we do not have to worry about defining fields or records. The NinjaCal script can be access from any context. As long as you have access to the the NinjaCalDisp field from your desired context, NinjaCal should 'just work'.

The Calendar Widget

The logic that drives the calendar widget (the grid thingy) is contained in a single field, "NinjaCal_basic" (or "NinjaCal_tripple" if you're using the 3-month widget). This is a repeating calculation field. Each calendar widget is made up of 42 of these NinjaCal_basic repetitions (cells).

Date/Month in focus

The NinjaCal_basic field will automatically determine the month in focus by looking at the date values stored in the file global $$__NinjaCalBaseDate. NinjaCal_basic defaults to the current date (today) if $$__NinjaCalBaseDate is empty or not valid.

Calendar Highlights

The calendar widget will highlight any dates found in $$__NinjaCalSelectedList. Anytime a date is selected, that selected date or list of dates are stored in $$__NinjaCalSelectedList.

Tip: You can create your own calculation fields that derive values from $$__NinjaCalSelectedList.

The "NinjaCal ( action ; params )" Script

This script controls all selection and de-selection behaviors: it sets the $$__NinjaCalBaseDate and $$__NinjaCalSelectedList global variables.

IMPORTANT: Copy this script into your solution BEFORE pasting in any calendar widgets.

Other uses of the NinjaCal controller script

Basic syntax is to call the "NinjaCal ( action ; params )" script, and pass it a valid action and the parameters for the action. Parameters separated by carriage returns (these things in FileMaker's calcs: "¶"), so multi-value parameters need to be passed as quoted list. See examples below:

The following script actions are available in NinjaCal...

{ } are for optional parameters

selectDate Parameters: datelist, {refocus}

This returns the selected date in $$__NinjaCalSelectedList. If the refocus attribute is set it also snaps the widget to the selected date. You can also send a list of ¶ separated dates to select them all. See highlighting dates for more info.
Example: Perform Script [ “NinjaCal ( action ; params )”; Parameter: "selectDate¶" & Get(CurrentDate) ]
Example (refocussing): Perform Script [ “NinjaCal ( action ; params )”; Parameter: "selectDate¶" & Get(CurrentDate) & "¶-f" ]

selectRange Parameters: daterange; {refocus}

Same as "selectDate" but takes a range as its contents. Note that the range can be sent as either a quoted pair of ¶ separated dates or a single string with "..." separating start and end dates. If you're sending ¶ separated dates, they must be in order with the earliest date followed by the last date.
Example: Perform Script [ “NinjaCal ( action ; params )”; Parameter:"selectRange" & "¶" & Quote ( List ( RelationshipToEvents::EventDate ) ) & "¶" & "-f" ]
Example: Perform Script [ “NinjaCal ( action ; params )”; Parameter: "selectRange¶" & Table::FromDateField & "..." & Table::ToDateField & "¶-f" ]

stepMonth Parameters: the number of months, usually 1 or -1.

Moves the focus of the widget forward and back through the months.
Example: Perform Script [ “NinjaCal ( action ; params )”; Parameter: "stepMonth¶1" ]

goToDate Parameters: a date

Moves the focus of the widget to the date passed as a parameter-- but does not select the date.
Example: Perform Script [ “NinjaCal ( action ; params )”; Parameter: "goToDate¶" & "2/10/2009" ]

clearDates Parameters: none

Clears the selected dates, snapping the focus of the calendar to the current month.
Example: Perform Script [ “NinjaCal ( action ; params )”; Parameter: "clearDates" ]
(855) SEEDCODE
[email protected]
Follow us: