webgui/www/extras/yui/docs/calendar/overview-summary-CalendarGroup.js.html
JT Smith 4f68a0933c added YUI and YUI-ext
fixed the resizable text area with IE problem
fixed the ad space with IE problem
merged the 7.2.0 and 7.1.4 change logs
2006-11-07 23:15:57 +00:00

658 lines
23 KiB
HTML

<html>
<head>
<title>API: Calendar overview-summary-CalendarGroup.js.html (YUI Library)</title>
<link href="stylesheet.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="header">
<h1>Yahoo! UI Library</h1>
<h3><a href="./index.html">Yahoo! UI Library: Calendar</a></h3>
<div class="breadcrumbs">
<a href="./index.html">Yahoo! UI Library: Calendar</a>
&gt;
<strong>CalendarGroup.js</strong>
</div>
</div>
<div id="body">
<div class="nav">
<div class="module resources">
<ul class="content">
<li><a href="overview-tree.html">Tree View</a></li>
<li><a href="index-all.html">Element Index</a></li>
</ul>
</div>
<div class="module">
<h4><a href="./allclasses-noframe.html">Classes</a></h4>
<ul class="content">
<li>
<a href="YAHOO.widget.html">
YAHOO.widget</a>
</li>
<li>
<a href="YAHOO.widget.Calendar.html">
YAHOO.widget.Calendar</a>
</li>
<li>
<a href="YAHOO.widget.Calendar2up.html">
YAHOO.widget.Calendar2up</a>
</li>
<li>
<a href="YAHOO.widget.Calendar2up_Cal.html">
YAHOO.widget.Calendar2up_Cal</a>
</li>
<li>
<a href="YAHOO.widget.Calendar_Core.html">
YAHOO.widget.Calendar_Core</a>
</li>
<li>
<a href="YAHOO.widget.CalendarGroup.html">
YAHOO.widget.CalendarGroup</a>
</li>
<li>
<a href="YAHOO.widget.DateMath.html">
YAHOO.widget.DateMath</a>
</li>
</ul>
</div>
<div class="module">
<h4><a href="./overview-summary.html">Files</a></h4>
<ul class="content">
<li>
<a href="overview-summary-Calendar.js.html">
Calendar.js</a>
</li>
<li>
<a href="overview-summary-Calendar2up.js.html">
Calendar2up.js</a>
</li>
<li>
<a href="overview-summary-Calendar_Core.js.html">
Calendar_Core.js</a>
</li>
<li>
<a href="overview-summary-CalendarGroup.js.html">
CalendarGroup.js</a>
</li>
<li>
<a href="overview-summary-DateMath.js.html">
DateMath.js</a>
</li>
</ul>
</div>
</div>
<div class="main">
<h2>CalendarGroup.js</h2>
<div class="meta">
</div>
<div class="quick-links">
<strong>Quick Links:</strong>&nbsp;
<a href="#source">Source Code</a>
</div>
<div class="section class summaries">
<div class="content">
</div>
</div>
<div class="section source">
<style>
strong.alert {color:red;}
</style>
<p><strong class="alert">Note:</strong> Code presented here has been
modified from the original source to aid in processing and
presentation. This is <strong>NOT</strong> functional code. To review this
component's literal, functional source, please refer to its
JavaScript files as provided in <a href="http://sourceforge.net/
projects/yui/">the downloadable YUI Library distribution</a>.</p>
<h3><a name="source">Source Code</a> <span class="top">[<a href="#top">top</a>]</span></h3>
<pre class="sourceview"><span class="comment">/*
Copyright (c) 2006, Yahoo! Inc. All rights reserved.
Code licensed under the BSD License:
http://developer.yahoo.net/yui/license.txt
Version 0.11.3
*/</span>
<span class="comment">/**
* &lt;p&gt;YAHOO.widget.CalendarGroup is a special container class for YAHOO.widget.Calendar_Core. This class facilitates
* the ability to have multi-page calendar views that share a single dataset and are
* dependent on each other.&lt;/p&gt;
*
* &lt;p&gt;The calendar group instance will refer to each of its elements using a 0-based index.
* For example, to construct the placeholder for a calendar group widget with id "cal1" and
* containerId of "cal1Container", the markup would be as follows:
* &lt;xmp&gt;
* &lt;div id="cal1Container_0"&gt;&lt;/div&gt;
* &lt;div id="cal1Container_1"&gt;&lt;/div&gt;
* &lt;/xmp&gt;
* The tables for the calendars ("cal1_0" and "cal1_1") will be inserted into those containers.
* &lt;/p&gt;
* <span class="attrib">@constructor</span>
* <span class="attrib">@param</span> {Integer} pageCount The number of pages that this calendar should display.
* <span class="attrib">@param</span> {String} id The id of the element that will be inserted into the DOM.
* <span class="attrib">@param</span> {String} containerId The id of the container element that the calendar will be inserted into.
* <span class="attrib">@param</span> {String} monthyear The month/year string used to set the current calendar page
* <span class="attrib">@param</span> {String} selected A string of date values formatted using the date parser. The built-in
default date format is MM/DD/YYYY. Ranges are defined using
MM/DD/YYYY-MM/DD/YYYY. Month/day combinations are defined using MM/DD.
Any combination of these can be combined by delimiting the string with
commas. Example: "12/24/2005,12/25,1/18/2006-1/21/2006"
*/</span>
YAHOO.widget.CalendarGroup = <span class="reserved">function</span>(pageCount, id, containerId, monthyear, selected) {
<span class="reserved">if</span> (arguments.length &gt; 0) {
<span class="reserved">this</span>.init(pageCount, id, containerId, monthyear, selected);
}
}
<span class="comment">/**
* Initializes the calendar group. All subclasses must call this method in order for the
* group to be initialized properly.
* <span class="attrib">@param</span> {Integer} pageCount The number of pages that this calendar should display.
* <span class="attrib">@param</span> {String} id The id of the element that will be inserted into the DOM.
* <span class="attrib">@param</span> {String} containerId The id of the container element that the calendar will be inserted into.
* <span class="attrib">@param</span> {String} monthyear The month/year string used to set the current calendar page
* <span class="attrib">@param</span> {String} selected A string of date values formatted using the date parser. The built-in
default date format is MM/DD/YYYY. Ranges are defined using
MM/DD/YYYY-MM/DD/YYYY. Month/day combinations are defined using MM/DD.
Any combination of these can be combined by delimiting the string with
commas. Example: "12/24/2005,12/25,1/18/2006-1/21/2006"
*/</span>
YAHOO.widget.CalendarGroup.<span class="reserved">prototype</span>.init = <span class="reserved">function</span>(pageCount, id, containerId, monthyear, selected) {
<span class="reserved">this</span>.id = id;
<span class="reserved">this</span>.selectedDates = new Array();
<span class="reserved">this</span>.containerId = containerId;
<span class="reserved">this</span>.pageCount = pageCount;
<span class="reserved">this</span>.pages = new Array();
<span class="reserved">for</span> (var p=0;p&lt;pageCount;++p) {
var cal = <span class="reserved">this</span>.constructChild(id + <span class="literal">"_"</span> + p, <span class="reserved">this</span>.containerId + <span class="literal">"_"</span> + p , monthyear, selected);
cal.parent = <span class="reserved">this</span>;
cal.index = p;
cal.pageDate.setMonth(cal.pageDate.getMonth()+p);
cal._pageDate = new Date(cal.pageDate.getFullYear(),cal.pageDate.getMonth(),cal.pageDate.getDate());
<span class="reserved">this</span>.pages.push(cal);
}
<span class="reserved">this</span>.sync();
<span class="reserved">this</span>.doNextMonth = <span class="reserved">function</span>(e, calGroup) {
calGroup.nextMonth();
};
<span class="reserved">this</span>.doPreviousMonth = <span class="reserved">function</span>(e, calGroup) {
calGroup.previousMonth();
};
};
<span class="comment">/**
* Adds a function to all child Calendars within this CalendarGroup.
* <span class="attrib">@param</span> {String} fnName The name of the function
* <span class="attrib">@param</span> {Function} fn The function to apply to each Calendar page object
*/</span>
YAHOO.widget.CalendarGroup.<span class="reserved">prototype</span>.setChildFunction = <span class="reserved">function</span>(fnName, fn) {
<span class="reserved">for</span> (var p=0;p&lt;<span class="reserved">this</span>.pageCount;++p) {
<span class="reserved">this</span>.pages[p][fnName] = fn;
}
}
<span class="comment">/**
* Calls a function within all child Calendars within this CalendarGroup.
* <span class="attrib">@param</span> {String} fnName The name of the function
* <span class="attrib">@param</span> {Array} args The arguments to pass to the function
*/</span>
YAHOO.widget.CalendarGroup.<span class="reserved">prototype</span>.callChildFunction = <span class="reserved">function</span>(fnName, args) {
<span class="reserved">for</span> (var p=0;p&lt;<span class="reserved">this</span>.pageCount;++p) {
var page = <span class="reserved">this</span>.pages[p];
<span class="reserved">if</span> (page[fnName]) {
var fn = page[fnName];
fn.call(page, args);
}
}
}
<span class="comment">/**
* Constructs a child calendar. This method can be overridden if a subclassed version of the default
* calendar is to be used.
* <span class="attrib">@param</span> {String} id The id of the element that will be inserted into the DOM.
* <span class="attrib">@param</span> {String} containerId The id of the container element that the calendar will be inserted into.
* <span class="attrib">@param</span> {String} monthyear The month/year string used to set the current calendar page
* <span class="attrib">@param</span> {String} selected A string of date values formatted using the date parser. The built-in
default date format is MM/DD/YYYY. Ranges are defined using
MM/DD/YYYY-MM/DD/YYYY. Month/day combinations are defined using MM/DD.
Any combination of these can be combined by delimiting the string with
commas. Example: "12/24/2005,12/25,1/18/2006-1/21/2006"
* <span class="attrib">@return</span> The YAHOO.widget.Calendar_Core instance that is constructed
* <span class="attrib">@type</span> YAHOO.widget.Calendar_Core
*/</span>
YAHOO.widget.CalendarGroup.<span class="reserved">prototype</span>.constructChild = <span class="reserved">function</span>(id,containerId,monthyear,selected) {
<span class="reserved">return</span> new YAHOO.widget.Calendar_Core(id,containerId,monthyear,selected);
};
<span class="comment">/**
* Sets the calendar group's month explicitly. This month will be set into the first
* page of the multi-page calendar, and all other months will be iterated appropriately.
* <span class="attrib">@param</span> {Integer} month The numeric month, from 1 (January) to 12 (December)
*/</span>
YAHOO.widget.CalendarGroup.<span class="reserved">prototype</span>.setMonth = <span class="reserved">function</span>(month) {
<span class="reserved">for</span> (var p=0;p&lt;<span class="reserved">this</span>.pages.length;++p)
{
var cal = <span class="reserved">this</span>.pages[p];
cal.setMonth(month+p);
}
};
<span class="comment">/**
* Sets the calendar group's year explicitly. This year will be set into the first
* page of the multi-page calendar, and all other months will be iterated appropriately.
* <span class="attrib">@param</span> {Integer} year The numeric 4-digit year
*/</span>
YAHOO.widget.CalendarGroup.<span class="reserved">prototype</span>.setYear = <span class="reserved">function</span>(year) {
<span class="reserved">for</span> (var p=0;p&lt;<span class="reserved">this</span>.pages.length;++p)
{
var cal = <span class="reserved">this</span>.pages[p];
<span class="reserved">if</span> ((cal.pageDate.getMonth()+1) == 1 &amp;&amp; p&gt;0)
{
year+=1;
}
cal.setYear(year);
}
};
<span class="comment">/**
* Calls the render function of all child calendars within the group.
*/</span>
YAHOO.widget.CalendarGroup.<span class="reserved">prototype</span>.render = <span class="reserved">function</span>() {
<span class="reserved">for</span> (var p=0;p&lt;<span class="reserved">this</span>.pages.length;++p)
{
var cal = <span class="reserved">this</span>.pages[p];
cal.render();
}
};
<span class="comment">/**
* Calls the select function of all child calendars within the group.
*/</span>
YAHOO.widget.CalendarGroup.<span class="reserved">prototype</span>.select = <span class="reserved">function</span>(date) {
var ret;
<span class="reserved">for</span> (var p=0;p&lt;<span class="reserved">this</span>.pages.length;++p)
{
var cal = <span class="reserved">this</span>.pages[p];
ret = cal.select(date);
}
<span class="reserved">return</span> ret;
};
<span class="comment">/**
* Calls the selectCell function of all child calendars within the group.
*/</span>
YAHOO.widget.CalendarGroup.<span class="reserved">prototype</span>.selectCell = <span class="reserved">function</span>(cellIndex) {
var ret;
<span class="reserved">for</span> (var p=0;p&lt;<span class="reserved">this</span>.pages.length;++p)
{
var cal = <span class="reserved">this</span>.pages[p];
ret = cal.selectCell(cellIndex);
}
<span class="reserved">return</span> ret;
};
<span class="comment">/**
* Calls the deselect function of all child calendars within the group.
*/</span>
YAHOO.widget.CalendarGroup.<span class="reserved">prototype</span>.deselect = <span class="reserved">function</span>(date) {
var ret;
<span class="reserved">for</span> (var p=0;p&lt;<span class="reserved">this</span>.pages.length;++p)
{
var cal = <span class="reserved">this</span>.pages[p];
ret = cal.deselect(date);
}
<span class="reserved">return</span> ret;
};
<span class="comment">/**
* Calls the deselectAll function of all child calendars within the group.
*/</span>
YAHOO.widget.CalendarGroup.<span class="reserved">prototype</span>.deselectAll = <span class="reserved">function</span>() {
var ret;
<span class="reserved">for</span> (var p=0;p&lt;<span class="reserved">this</span>.pages.length;++p)
{
var cal = <span class="reserved">this</span>.pages[p];
ret = cal.deselectAll();
}
<span class="reserved">return</span> ret;
};
<span class="comment">/**
* Calls the deselectAll function of all child calendars within the group.
*/</span>
YAHOO.widget.CalendarGroup.<span class="reserved">prototype</span>.deselectCell = <span class="reserved">function</span>(cellIndex) {
<span class="reserved">for</span> (var p=0;p&lt;<span class="reserved">this</span>.pages.length;++p)
{
var cal = <span class="reserved">this</span>.pages[p];
cal.deselectCell(cellIndex);
}
<span class="reserved">return</span> <span class="reserved">this</span>.getSelectedDates();
};
<span class="comment">/**
* Calls the reset function of all child calendars within the group.
*/</span>
YAHOO.widget.CalendarGroup.<span class="reserved">prototype</span>.reset = <span class="reserved">function</span>() {
<span class="reserved">for</span> (var p=0;p&lt;<span class="reserved">this</span>.pages.length;++p)
{
var cal = <span class="reserved">this</span>.pages[p];
cal.reset();
}
};
<span class="comment">/**
* Calls the clear function of all child calendars within the group.
*/</span>
YAHOO.widget.CalendarGroup.<span class="reserved">prototype</span>.clear = <span class="reserved">function</span>() {
<span class="reserved">for</span> (var p=0;p&lt;<span class="reserved">this</span>.pages.length;++p)
{
var cal = <span class="reserved">this</span>.pages[p];
cal.clear();
}
};
<span class="comment">/**
* Calls the nextMonth function of all child calendars within the group.
*/</span>
YAHOO.widget.CalendarGroup.<span class="reserved">prototype</span>.nextMonth = <span class="reserved">function</span>() {
<span class="reserved">for</span> (var p=0;p&lt;<span class="reserved">this</span>.pages.length;++p)
{
var cal = <span class="reserved">this</span>.pages[p];
cal.nextMonth();
}
};
<span class="comment">/**
* Calls the previousMonth function of all child calendars within the group.
*/</span>
YAHOO.widget.CalendarGroup.<span class="reserved">prototype</span>.previousMonth = <span class="reserved">function</span>() {
<span class="reserved">for</span> (var p=<span class="reserved">this</span>.pages.length-1;p&gt;=0;--p)
{
var cal = <span class="reserved">this</span>.pages[p];
cal.previousMonth();
}
};
<span class="comment">/**
* Calls the nextYear function of all child calendars within the group.
*/</span>
YAHOO.widget.CalendarGroup.<span class="reserved">prototype</span>.nextYear = <span class="reserved">function</span>() {
<span class="reserved">for</span> (var p=0;p&lt;<span class="reserved">this</span>.pages.length;++p)
{
var cal = <span class="reserved">this</span>.pages[p];
cal.nextYear();
}
};
<span class="comment">/**
* Calls the previousYear function of all child calendars within the group.
*/</span>
YAHOO.widget.CalendarGroup.<span class="reserved">prototype</span>.previousYear = <span class="reserved">function</span>() {
<span class="reserved">for</span> (var p=0;p&lt;<span class="reserved">this</span>.pages.length;++p)
{
var cal = <span class="reserved">this</span>.pages[p];
cal.previousYear();
}
};
<span class="comment">/**
* Synchronizes the data values for all child calendars within the group. If the sync
* method is called passing in the caller object, the values of all children will be set
* to the values of the caller. If the argument is ommitted, the values from all children
* will be combined into one distinct list and set into each child.
* <span class="attrib">@param</span> {YAHOO.widget.Calendar_Core} caller The YAHOO.widget.Calendar_Core that is initiating the call to sync().
* <span class="attrib">@return</span> Array of selected dates, in JavaScript Date object form.
* <span class="attrib">@type</span> Date[]
*/</span>
YAHOO.widget.CalendarGroup.<span class="reserved">prototype</span>.sync = <span class="reserved">function</span>(caller) {
var calendar;
<span class="reserved">if</span> (caller)
{
<span class="reserved">this</span>.selectedDates = caller.selectedDates.concat();
} <span class="reserved">else</span> {
var hash = new Object();
var combinedDates = new Array();
<span class="reserved">for</span> (var p=0;p&lt;<span class="reserved">this</span>.pages.length;++p)
{
calendar = <span class="reserved">this</span>.pages[p];
var values = calendar.selectedDates;
<span class="reserved">for</span> (var v=0;v&lt;values.length;++v)
{
var valueArray = values[v];
hash[valueArray.toString()] = valueArray;
}
}
<span class="reserved">for</span> (var val in hash)
{
combinedDates[combinedDates.length]=hash[val];
}
<span class="reserved">this</span>.selectedDates = combinedDates.concat();
}
<span class="comment">// Set all the values into the children</span>
<span class="reserved">for</span> (p=0;p&lt;<span class="reserved">this</span>.pages.length;++p)
{
calendar = <span class="reserved">this</span>.pages[p];
<span class="reserved">if</span> (! calendar.Options.MULTI_SELECT) {
calendar.clearAllBodyCellStyles(calendar.Config.Style.CSS_CELL_SELECTED);
}
calendar.selectedDates = <span class="reserved">this</span>.selectedDates.concat();
}
<span class="reserved">return</span> <span class="reserved">this</span>.getSelectedDates();
};
<span class="comment">/**
* Gets the list of currently selected dates from the calendar.
* <span class="attrib">@return</span> An array of currently selected JavaScript Date objects.
* <span class="attrib">@type</span> Date[]
*/</span>
YAHOO.widget.CalendarGroup.<span class="reserved">prototype</span>.getSelectedDates = <span class="reserved">function</span>() {
var returnDates = new Array();
<span class="reserved">for</span> (var d=0;d&lt;<span class="reserved">this</span>.selectedDates.length;++d)
{
var dateArray = <span class="reserved">this</span>.selectedDates[d];
var date = new Date(dateArray[0],dateArray[1]-1,dateArray[2]);
returnDates.push(date);
}
returnDates.sort();
<span class="reserved">return</span> returnDates;
};
<span class="comment">/**
* Calls the addRenderer function of all child calendars within the group.
*/</span>
YAHOO.widget.CalendarGroup.<span class="reserved">prototype</span>.addRenderer = <span class="reserved">function</span>(sDates, fnRender) {
<span class="reserved">for</span> (var p=0;p&lt;<span class="reserved">this</span>.pages.length;++p)
{
var cal = <span class="reserved">this</span>.pages[p];
cal.addRenderer(sDates, fnRender);
}
};
<span class="comment">/**
* Calls the addMonthRenderer function of all child calendars within the group.
*/</span>
YAHOO.widget.CalendarGroup.<span class="reserved">prototype</span>.addMonthRenderer = <span class="reserved">function</span>(month, fnRender) {
<span class="reserved">for</span> (var p=0;p&lt;<span class="reserved">this</span>.pages.length;++p)
{
var cal = <span class="reserved">this</span>.pages[p];
cal.addMonthRenderer(month, fnRender);
}
};
<span class="comment">/**
* Calls the addWeekdayRenderer function of all child calendars within the group.
*/</span>
YAHOO.widget.CalendarGroup.<span class="reserved">prototype</span>.addWeekdayRenderer = <span class="reserved">function</span>(weekday, fnRender) {
<span class="reserved">for</span> (var p=0;p&lt;<span class="reserved">this</span>.pages.length;++p)
{
var cal = <span class="reserved">this</span>.pages[p];
cal.addWeekdayRenderer(weekday, fnRender);
}
};
<span class="comment">/**
* Sets an event handler universally across all child calendars within the group. For instance,
* to set the onSelect handler for all child calendars to a function called fnSelect, the call would be:
* &lt;code&gt;
* calGroup.wireEvent("onSelect", fnSelect);
* &lt;/code&gt;
* <span class="attrib">@param</span> {String} eventName The name of the event to handler to set within all child calendars.
* <span class="attrib">@param</span> {Function} fn The function to set into the specified event handler.
*/</span>
YAHOO.widget.CalendarGroup.<span class="reserved">prototype</span>.wireEvent = <span class="reserved">function</span>(eventName, fn) {
<span class="reserved">for</span> (var p=0;p&lt;<span class="reserved">this</span>.pages.length;++p)
{
var cal = <span class="reserved">this</span>.pages[p];
cal[eventName] = fn;
}
};
<span class="comment">/**
* Returns a string representation of the object.
* <span class="attrib">@type</span> string
*/</span>
YAHOO.widget.CalendarGroup.<span class="reserved">prototype</span>.toString = <span class="reserved">function</span>() {
<span class="reserved">return</span> <span class="literal">"CalendarGroup "</span> + <span class="reserved">this</span>.id;
}
YAHOO.widget.CalGrp = YAHOO.widget.CalendarGroup;</pre>
</div>
</div>
</div>
<div id="footer">
<hr />
Copyright &copy; 2006 Yahoo! Inc. All rights reserved.
<br /><br />
Documentation generated by <a href="http://jsdoc.sourceforge.net/">
JSDoc</a>
</div>
</body>
</html>