LnkWcb Framework

LnkWcb  2.5.0

LnkWcb Framework > LnkWcb > LnkWcb.Calendar
Search:
 
Filters

Class LnkWcb.Calendar

Known Subclasses:
LnkWcb.CalendarJquery LnkWcb.CalendarExtJS

Base Calendar. When using a calendar (or any subclass), you can chose one of three available flows.

Basic Flow

The basic flow (available by default) implements 2 states:

  • destroy state: the initial state
  • show state: the calendar is displayed to the websurfer, and allows to select a date/time
To perform transitions from one basic state to another:

The basic flow relies on the default value of showOnInit config which is true.

Alternate Basic Flow

The alternate basic flow (also available by default) uses 3 states:

  • destroy state: the initial state
  • show state: the calendar is displayed to the websurfer, and allows to select a date/time
  • hide state: the calendar is hidden from the websurfer
To perform transitions from one basic state to another:

The alternate basic flow relies on the default value of showOnInit config which is true.

Full Flow

When the showOnInit config is set to false, the calendar instance then implement 4 successive states:

  • destroy state: the initial state. No internal data is initialized (or all data is destroyed).
  • init state: the calendar is initialized with fresh open hours and closed days, received from the server.
  • show state: the calendar is displayed to the websurfer, and allows to select a date/time.
  • hide state: the calendar is hidden from the websurfer. All internal data is kept alive.

At creation time (after new LnkWcb.Calendar() is executed), the created instance is in the destroy state.

Transitions in the full flow are:

Constructor

LnkWcb.Calendar ( cfg )
Parameters:
cfg <Object> the initial configuration settings

Properties

cfg - Object

The current applicable configuration settings.

Methods

computeDisabledDaysOfWeek

private Array<Number> computeDisabledDaysOfWeek ( dowTimeIntervals )
Computes the days of week with no applicable open hours.
Parameters:
dowTimeIntervals <Object<Array<Array<Number>>>> the parsed open hours, as computed by the parsePlagesHoraires method
Returns: Array<Number>
the list of days of week with no open hours

computeDowHoursMinutes

private Object<Array<Array<Array<Number>>>> computeDowHoursMinutes ( dowTimeIntervals , that )
Dispatch the open time periods by day of week, hours of day, and minutes of hour. Example : dowHoursMinutes[dow][hour][minutes] is an array of the matching time periods for this instant. For hours and minutes arrays, sparse arrays are used.
Parameters:
dowTimeIntervals <Object<Array<Array<Number>>>> the parsed open hours, as computed by the parsePlagesHoraires method
that <LnkWcb.Calendar> the LnkWcb.Calendar instance
Returns: Object<Array<Array<Array<Number>>>>
the time periods, dipatched by day of week, hours and minutes

computeHoursMinutes

protected Array<Array<Array<Number>>> computeHoursMinutes ( date , now )
Computes actual open hours in a sparse Array, with values being sparse Arrays of open minutes.

When requesting the open hours of the current day, this method removes passed open hours. Those that are before now.

Parameters:
date <Date> a date instance (never null) that specifies the selected day (today or a future day, never a passed day) of which open hours will be computed
now <Date> an optional date that specifies the value for the current instant

destroy

void destroy ( )
Destroy the calendar.

Perform the transition from hide state to destroy state.

If the calendar is not yet hidden, then the hide method is called.


findFirstAvailableDate

protected Date findFirstAvailableDate ( )

getDateTime

private Object getDateTime ( )
Abstract method. Not documented. Reserved for future use.
Returns: Object
the selected date, hours and minutes

getDefaultSettings

protected Object getDefaultSettings ( )
Get the default LnkWcb.Calendar configuration settings.
Returns: Object
a clone of the default settings

getWcbDate

String getWcbDate ( )
Abstract method that should return the selected date and time.

The returned value should be formated according to the LnkWcb convention, as implemented in the LnkWcb.util.formatDateTime method.

Returns: String
the default implementation always returns undefined

hasWorkedInterval

protected Boolean hasWorkedInterval ( refIntervals , date )
Tells if a Date instance is worked or not, taking all information into account (open hours and closed days).
Parameters:
refIntervals <Array<Array<Array<Number>>>> the dispatched time periods (see the computeDowHoursMinutes) of the day of week of the date argument
date <Date> the date to test
Returns: Boolean
true if the date is worked, false otherwise

hasWorkedInterval_Internal

private Boolean hasWorkedInterval_Internal ( refIntervals , date , joursFeries )
Tells if a Date instance is worked or not, taking all information into account (open hours and closed days).
Parameters:
refIntervals <Array<Array<Array<Number>>>> the dispatched time periods (see the computeDowHoursMinutes) of the day of week of the date argument
date <Date> the date to test
joursFeries <Array<Object<String>>> the closed days (as received by the onOpenHours event)
Returns: Boolean
true if the date is worked, false otherwise

hide

void hide ( )
Hide the calendar.

Perform the transition from show state to hide state.


init

protected void init ( horaires )
Initialize the calendar with fresh open hours and closed days.

This method is called by default when the onOpenHours event of the associated bouton fires. Thus you should never need to call it directly.

Perform the transition from destroy state to init state.

If showOnInit is true (the default), then the calendar is shown right after it is initialized.

Parameters:
horaires <Object> the open hours (as received by the onOpenHours event)

isWorkedDate

private Boolean isWorkedDate ( d , joursFeries )
Tells whether a Date instance is a worked date or not.
Parameters:
d <Date> the date to test
joursFeries <Array<Object<String>>> the closed days (as received by the onOpenHours event)
Returns: Boolean
true if the date is not a closed day, false otherwise

parseJoursFeries

private Array<Date> parseJoursFeries ( joursFeries , dowTimeIntervals , now )
Parse closed days (as received by the onOpenHours event) and return a list of non worked local dates, in the websurfer time zone.
Parameters:
joursFeries <Array<Object<String>>> the closed days (as received by the onOpenHours event)
dowTimeIntervals <Object<Array<Array<Number>>>> the parsed open hours, as computed by the parsePlagesHoraires method
now <Date> the date to use as the current instant
Returns: Array<Date>
a list of non worked local dates, in the websurfer time zone

parsePlagesHoraires

private Object<Array<Array<Number>>> parsePlagesHoraires ( plagesHoraires )
Parse the open hours (as received by the onOpenHours event) and split them into week days time period.

Time period are arrays containing these 3 numbers.

  1. Start of the time period in the day (number of minutes from midnight, between 0 and 1440)
  2. End of the time period in the day (number of minutes from midnight, greater than the start of period)
  3. Day shift (usually 0) to know which closed day (if any) in the channel time zone applies to this time period.

The result is, for every day of week with open hours, an array of such time periods.

Parameters:
plagesHoraires <Array<Object<String>>> the open hours
Returns: Object<Array<Array<Number>>>
the parsed open hours

refresh

void refresh ( )
This is the all-in-one method that refreshes the calendar. It asks the bouton for fresh open hours and closed days.

Get through the following states: hide (if needed), destroy (won't do no harm is instance is not yet initialized), init (after the fresh open hours have been received from the onOpenHours event), show (if showOnInit is true, which is the default).


setBouton

LnkWcb.Bouton setBouton ( )
Set the LnkWcb.Bouton instance on which this calendar depends.
Returns: LnkWcb.Bouton
an bouton instance

show

void show ( )
Display the calendar to the websurfer.

Perform the transition from init state to show state.

If the calendar is not yet initilazed, then it will be shown right after it is initialized. Even if the showOnInit config is false.

Would you create a calendar with showOnInit being false, this feature would allow you to initialize the calendar with LnkWcb.Bouton.horaires() and then call show() right after horaires() has returned, which is before the fresh open hours are received from the server, and thus before the calendar is actually initialized.


toLocalDate

private Array<Date> toLocalDate ( joursFeries , now )
Parse closed days (as received by the onOpenHours event) and convert them to Date objects with the custom yearlyRepeatable member, which is a boolean indicating whether the year is applicable (yearlyRepeatable===false) or not (yearlyRepeatable===true).
Parameters:
joursFeries <Array<Object<String>>> the closed days
now <Date> the date to use as the current instant
Returns: Array<Date>
the array of (possibly yearly repeatable) dates

Events

onCreate

protected static onCreate ( bouton )
Class event. Fires when an LnkWcb.Calendar instance is just created.
Parameters:
bouton <Object> the new instance

onDestroy

protected onDestroy ( )
Fires when the calendar is to be destroyed.

Subclasses should attach listeners to this event in order to destroy data that might have been initialized at the init step.


onHide

protected onHide ( )
Fires when the calendar is to be hidden.

Subclasses should attach listeners to this event in order to actually hide the calendar.


onInit

protected onInit ( horaires )
Fires right after the calendar is initialized.

When the showOnInit config is true, it is fired just before the calendar is showed.

Parameters:
horaires <Object> the open hours (as received by the onOpenHours event)

onShow

protected onShow ( )
Fires when the calendar is to be shown.

Subclasses should attach listeners to this event in order to actually display the calendar.


Configuration Attributes

bouton - LnkWcb.Bouton

The LnkWcb.Bouton instance on which this calendar depends.

You should not modify this setting after the calendar is created. Use the setBouton method instead.

Default Value: null

maxDays - Number

The maximum days that can be selected ahead of now.
Default Value: 8

minutesStep - Number

The step used when displaying available minutes.
Default Value: 5

showOnInit - protected Boolean

Controls the feature that allows the calendar to be displayed as soon as possible.

This helps in simplifying the calendar 4 states. Which might then be reduced to init and destroy only.

Default Value: true


Copyright © 2010 Linkeo.com All rights reserved.