Udskriving af markedrede elementer ?
Jeg har en Kalender hvor jeg kan markere forskellige dage, men nu vil gerne ha at man i et andet dynamisk tekstfelt kan få vist datoerne (.getselctedItems)Mit dynamiske tekstfelt hedder VisDato og her er koden til kalenderen...
FCalendarClass = function()
{
FMultiTextComponentClass.apply(this);
this.init();
}
FCalendarClass.prototype = new FUIComponentClass();
Object.registerClass("FCalendarSymbol", FCalendarClass);
FCalendarClass.prototype.init = function(){
this.controller = this;
super.setSize(this._width,this._height);
this.boundingBox_mc.unloadMovie();
this.boundingBox_mc._x +=100;
super.init();
this.setChangeHandler(this.changeHandler);
this.dayWidth = 30;
this.dayHeight = 22;
this.dayTextHeight = 20;
this.headerHeight = this.headerArea._y + this.headerArea._height;
this.leftEdge = 1;
this.controller = this;
this.setDayOfWeekNames(this.dayOfWeekNames, false);
this.setMonthNames(this.monthNames, false);
this.defaultFont = "Verdana";
this.selections = new Object();
this.anchor = undefined;
if(this.selectionType == undefined){
this.selectionType = "multiple";
}
this.selectionRequired = false;
this.enabled = true;
if(this.firstDayOfWeek == undefined) this.firstDayOfWeek = 0;
this.dateFilter = undefined;
this.displayRange = new Object();
this.displayRange.beginTime = -Number.MAX_VALUE;
this.displayRange.endTime = Number.MAX_VALUE;
this.showAsDisabled = true;
this.dragListener = new Object();
this.dragListener.component = this;
this.dragListener.onMouseMove = function(){
this.component.updateDragSelection()
}
this.dragListener.onMouseUp = function(){
this.component.endDragSelection()
}
this.theBaseDate = new Date();
this.today = new Date(this.theBaseDate.getFullYear(), this.theBaseDate.getMonth(), this.theBaseDate.getDate());
this.caret = this.today;
this.guiInitPending = true;
this.invalidate("setSize");
this.tabChildren = false;
}
// ::: PUBLIC METHODS
FCalendarClass.prototype.getSelectedItem = function(){
var latest = -Number.MAX_VALUE;
var lastDate = undefined;
for(x in this.selections){
var day = this.selections[x]
if(day.getTime() >= latest){
latest = day.getTime();
lastDate = day;
}
}
return lastDate;
}
FCalendarClass.prototype.getSelectedItems = function(){
var list = new Array();
for(x in this.selections){
list.push(this.selections[x]);
}
return list;
}
FCalendarClass.prototype.setSelectedItem = function(theDate, append, flag){
if(arguments.length < 2) append = false;
if(theDate.getFullYear() == undefined && theDate.length >= 1) theDate = theDate[0];
if(this.selectionType == 'single') append = false;
if(!append) this.selections = new Object();
if(theDate != undefined){
this.selectDate(theDate);
}
if (flag!=false) {
this.executeCallBack();
}
this.redraw();
return true;
}
FCalendarClass.prototype.setSelectedItems = function(dates, append, flag){
if(arguments.length < 2) append = false;
if(!append) this.selections = new Object();
if(dates == undefined) return true;
for(i = 0; i < dates.length; i++){
if(dates[i] != undefined) this.selectDate(dates[i]);
}
if (flag!=false) {
this.executeCallBack();
}
this.redraw();
return true;
}
FCalendarClass.prototype.getDisplayedMonth = function(){
return this.currDisplay;
}
FCalendarClass.prototype.setDisplayedMonth = function(newMonth){
this.currDisplay = newMonth;
this.redraw();
}
FCalendarClass.prototype.getDisplayRange = function(){
return this.displayRange;
}
FCalendarClass.prototype.setDisplayRange = function(dateRange){
var beginDate = dateRange.begin;
this.displayRange.beginTime = -Number.MAX_VALUE;
this.displayRange.endTime = Number.MAX_VALUE;
if(beginDate != undefined){
beginDate = new Date(beginDate.getFullYear(), beginDate.getMonth(), beginDate.getDate());
this.displayRange.beginTime = beginDate.getTime();
}
var endDate = dateRange.end;
if(endDate != undefined){
endDate = new Date(endDate.getFullYear(), endDate.getMonth(), endDate.getDate(), 23, 59, 59);
this.displayRange.endTime = endDate.getTime();
}
this.displayRange.begin = beginDate;
this.displayRange.end = endDate;
this.redraw();
return true;
}
FCalendarClass.prototype.setDateFilter = function(aDateFilter){
var old = this.dateFilter;
this.dateFilter = aDateFilter;
this.redraw();
return old;
}
FCalendarClass.prototype.getDayOfWeekNames = function(){
return this.myDayOfWeekNames;
}
FCalendarClass.prototype.setDayOfWeekNames = function(dayNames, redraw){
this.defaultDayOfWeekNames = new Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
if(this.myDayOfWeekNames == undefined){
this.myDayOfWeekNames = this.defaultDayOfWeekNames;
}
for(i = 0; i < 7 && i < dayNames.length; i++){
this.myDayOfWeekNames[i] = dayNames[i];
}
if(redraw ==undefined || redraw == true){
this.redraw();
}
}
FCalendarClass.prototype.getMonthNames = function(){
return this.myMonthNames;
}
FCalendarClass.prototype.setMonthNames = function(monthNames, redraw){
this.defaultMonthNames = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
if(this.myMonthNames == undefined){
this.myMonthNames = this.defaultMonthNames;
}
for(i = 0; i < 12 && i < monthNames.length;i++){
this.myMonthNames[i] = monthNames[i];
}
if(redraw ==undefined || redraw == true){
this.redraw();
}
}
FCalendarClass.prototype.setFirstDayOfWeek = function(dayOfWeek){
var old = this.firstDayOfWeek;
this.firstDayOfWeek = dayOfWeek;
if(old != dayOfWeek){
this.redraw();
}
return true;
}
FCalendarClass.prototype.getFirstDayOfWeek = function(){
return this.firstDayOfWeek;
}
FCalendarClass.prototype.setShowAsDisabled = function(disableFlag){
var old = this.showAsDisabled;
if(arguments.length < 1) disableFlag = true;
this.showAsDisabled = disableFlag;
if(old != disableFlag){
this.redraw();
}
}
FCalendarClass.prototype.getShowAsDisabled = function(disableFlag){
return this.showAsDisabled;
}
FCalendarClass.prototype.setSize = function(width, ht){
if(width == undefined) width = this._width;
if(ht == undefined) ht = this._height;
var newXScale = this._xscale * width / this._width;
var w = this.dayWidth * newXScale;
newXScale *= Math.floor(w) / w;
width = this._width * newXScale / this._xscale;
this._xscale = newXScale;
var newYScale = this._yscale * ht / this._height;
var h = this.dayHeight * newYScale;
newYScale *= Math.floor(h) / h;
ht = this._height * newYScale / this._yscale;
this._yscale = newYScale;
Super.setSize(width, ht);
if(this.guiInitPending) {
this.guiInitPending = undefined;
this.initGrid();
this.drawDays();
this.initMonth(this.today);
}
}
FCalendarClass.prototype.setEnabled = function(enable){
var old = this.enable;
if(enable == true || enable == undefined){
this.enable = true;
Super.setEnabled(true);
} else {
this.enable = false;
Super.setEnabled(false);
}
if(old != this.enable){
this.backMonth_btn.enabled = this.enable;
this.backYear_btn.enabled = this.enable;
this.fwdMonth_btn.enabled = this.enable;
this.fwdYear_btn.enabled = this.enable;
this.backMonth_btn.gotoAndStop(this.enable? "_up" : "disabled");
this.backYear_btn.gotoAndStop(this.enable? "_up" : "disabled");
this.fwdMonth_btn.gotoAndStop(this.enable? "_up" : "disabled");
this.fwdYear_btn.gotoAndStop(this.enable? "_up" : "disabled");
this.redraw();
}
}
FCalendarClass.prototype.getEnabled = function(){
return this.enable;
}
FCalendarClass.prototype.setSelectionType = function(selType){
if(arguments.length < 1) selType = "multiple";
var old = this.selectionType;
this.selectionType = new String(selType);
this.selectionType = this.selectionType.toLowerCase();
if(old != this.selectionType)
this.initSelectionType();
this.redraw();
}
FCalendarClass.prototype.getSelectionType = function(){
return this.selectionType;
}
FCalendarClass.prototype.getSelectionRequired = function(){
return this.selectionRequired;
}
FCalendarClass.prototype.setSelectionRequired = function(required){
this.selectionRequired = required;
if(required && this.isSelectionEmpty()){
this.setSelectedItem(this.today);
}
this.redraw();
return true;
}
// ::: PRIVATE METHODS
FCalendarClass.prototype.StepDate = function (deltaY, deltaM) {
var month = this.currDisplay.getMonth() + deltaM;
var year = this.currDisplay.getFullYear() + deltaY;
while(month < 0){
year--;
month += 12;
}
while(month > 11){
month = month - 12;
year++;
}
var theDate = this.limitDisplay(new Date(year, month, 1));
this.initMonth(theDate);
}
FCalendarClass.prototype.limitDisplay = function(theDate){
if(this.displayRange.begin != undefined && this.displayRange.begin.getTime() > theDate.getTime()){
theDate = this.displayRange.begin;
}
if(this.displayRange.end != undefined && this.displayRange.end.getTime() < theDate.getTime()){
theDate = this.displayRange.end;
}
return theDate;
}
FCalendarClass.prototype.drawDays = function(){
var y = this.headerHeight;
var x = this.leftEdge;
for(day = 0; day < 7; day++){
var day_mc;
if(this["head_day"+day] == undefined){
this.attachMovie("fcal_dayOfWeek_mc", "head_day"+day, 80+day);
day_mc = this["head_day"+day];
day_mc.attachMovie("FLabelSymbol", "dayText", 1, {controller:this, hostComponent:this});
this.registerTextElement(day_mc.dayText, "FCalendarDayText");
}
day_mc = this["head_day"+day];
var pt = {x :x, y:y};
this.localToGlobal(pt);
pt.x = Math.floor(pt.x);
pt.y = Math.round(pt.y);
this.globalToLocal(pt);
day_mc._x = pt.x;
day_mc._y = pt.y;
var dow = (day + this.firstDayOfWeek) % 7;
day_mc.dayText.labelField.multiline = false;
day_mc.dayText.labelField.wordWrap = false;
day_mc.dayText.labelField.restrict = true;
day_mc.dayText.setLabel(this.myDayOfWeekNames[dow]);
var textw = day_mc.dayText.labelfield.textWidth;
var xt = Math.floor((this.dayWidth - day_mc.dayText.labelfield.textWidth) / 2) - 2;
var yt = Math.floor((this.dayTextHeight - day_mc.dayText.labelfield.textHeight) / 2);
var label = new String(this.myDayOfWeekNames[dow]);
if(label.charAt(0) == 'W'){
label = " " + label;
day_mc.dayText.setLabel(label);
xt -= day_mc.dayText.labelfield.textWidth - textw;
}
pt = {x :xt, y:yt};
pt.x = Math.floor(pt.x);
pt.y = Math.round(pt.y);
xt = pt.x;
yt = pt.y;
var w = this.dayWidth - xt;
day_mc.dayText._x = Math.max(0, xt);
day_mc.dayText._y = yt;
day_mc.dayText.labelfield._x = 0;
day_mc.dayText.textStyle.align = "left";
day_mc.dayText.setSize(w, this.dayTextHeight - yt);
day_mc.dayText.setLabel(label);
day_mc.dayText.setEnabled(this.enable);
x += this.dayWidth;
}
}
FCalendarClass.prototype.initGrid = function(){
for(cell=1; cell<=42; cell++){
this["cell"+cell].removeMovieClip();
this.attachMovie("fcal_dayStates_mc", "cell"+cell, cell );
var day_mc = this["cell"+cell];
day_mc.attachMovie("FLabelSymbol", "dayText", 1, {controller:this, hostComponent:this});
day_mc.dayText.labelField.autoSize = "left";
day_mc.dayText.labelField.multiline = false;
day_mc.dayText.labelField.wordWrap = false;
day_mc.dayText.labelField.restrict = true;
this.registerTextElement(day_mc.dayText, "FCalendarDateText");
day_mc.dayText._visible = false;
day_mc._visible = false;
}
}
FCalendarClass.prototype.initMonth = function(dateObj){
if(dateObj==null){
dateObj = new Date();
}
this.offset = this.getOffsetOfMonth(dateObj);
this.last = this.getLastOfMonth(dateObj);
var curr_x = this.leftEdge;
var curr_y = this.dayTextHeight + this.headerHeight;
var cell = 1;
for(i=1; i <= this.offset; i++){
var day_mc = this["cell"+cell++];
day_mc["todayIndicator_mc"].removeMovieClip()
var pt = {x :curr_x, y:curr_y};
this.localToGlobal(pt);
pt.x = Math.round(pt.x);
pt.y = Math.round(pt.y);
this.globalToLocal(pt);
day_mc.gotoAndStop("notaday");
day_mc._x = pt.x;
day_mc._y = pt.y;
day_mc._width = this.dayWidth;
day_mc._height = this.dayHeight;
day_mc._visible = true;
day_mc.dayText._visible = false;
curr_x += this.dayWidth;
}
curr_x = this.offset * this.dayWidth + this.leftEdge;
var yr = dateObj.getFullYear();
var m = dateObj.getMonth();
var dt = dateObj.getDate();
var curr_date = new Date(yr, m, 1);
this.currDisplay = curr_date;
this.headerTextMonth = this.myMonthNames[m];
this.headerTextYear = yr;
this.setHeaders();
var ct = 1;
var textColor = globalStyleFormat.textColor;
if(textColor == undefined) textColor = 0x000000;
var disabledColor = globalStyleFormat.textDisabled;
if(disabledColor == undefined) disabledColor = 0xaaaaaa;
while(curr_date.getMonth() == m){
this.drawCell(curr_date, textColor, disabledColor);
++ct;
curr_date = new Date(yr, m, ct);
cell++;
}
var col = (cell - 1) % 7;
var row = Math.floor((cell - 1)/ 7);
var xoffset = this.leftEdge;
var yoffset = this.dayTextHeight + this.headerHeight;
curr_x = col * this.dayWidth + xoffset;
curr_y = row * this.dayHeight + yoffset;
while(cell <= 42){
var day_mc = this["cell"+cell];
day_mc.gotoAndStop("notaday");
day_mc["todayIndicator_mc"].removeMovieClip()
var pt = {x :curr_x, y:curr_y};
this.localToGlobal(pt);
pt.x = Math.round(pt.x);
pt.y = Math.round(pt.y);
this.globalToLocal(pt);
day_mc._x = pt.x;
day_mc._y = pt.y;
day_mc._width = this.dayWidth;
day_mc._height = this.dayHeight;
day_mc._visible = true;
day_mc.dayText._visible = false;
cell++;
if(cell % 7 == 1){
curr_x = this.leftEdge;
curr_y += this.dayHeight;
}
else{
curr_x += this.dayWidth;
}
}
}
FCalendarClass.prototype.selectiveRedraw = function(){
this.offset = this.getOffsetOfMonth(this.currDisplay);
this.last = this.getLastOfMonth(this.currDisplay);
var textColor = globalStyleFormat.textColor;
if(textColor == undefined) textColor = 0x000000;
var disabledColor = globalStyleFormat.textDisabled;
if(disabledColor == undefined) disabledColor = 0xaaaaaa;
var delta = this.getSelectionDelta();
for(x in delta){
var curr_date = delta[x]
this.drawCell(curr_date, textColor, disabledColor);
}
}
FCalendarClass.prototype.drawCell = function (curr_date, textColor, disabledColor){
var dt = curr_date.getDate();
var cell = dt + this.offset;
var col = (cell - 1) % 7;
var row = Math.floor((cell - 1)/ 7);
var xoffset = this.leftEdge;
var yoffset = this.dayTextHeight + this.headerHeight;
var pt = {x :col * this.dayWidth + xoffset, y:row * this.dayHeight + yoffset};
this.localToGlobal(pt);
pt.x = Math.round(pt.x);
pt.y = Math.round(pt.y);
this.globalToLocal(pt);
var day_mc = this["cell"+cell];
day_mc.gotoAndStop(this.isSelected(curr_date)? "selected" :"normal");
day_mc.myDate = curr_date;
day_mc._x = pt.x;
day_mc._y = pt.y;
day_mc._width = this.dayWidth;
day_mc._height = this.dayHeight;
day_mc.day = dt;
day_mc._visible = true;
day_mc.dayText._visible = true;
day_mc.dayText._x = 2;
day_mc.dayText._y = 2;
day_mc.dayText.setSize(this.dayWidth -4, this.dayTextHeight - 4);
day_mc.dayText.setLabel(dt);
day_mc.dayText.setEnabled(this.enabled);
var selectable = true;
if(!this.enable || !this.isSelectable(curr_date)){
if(this.showAsDisabled) day_mc.dayText.setEnabled(false);
selectable = false;
}
if(selectable){
day_mc.onPress = function () {
this._parent.selectHandler(this.day);
};
}
else {
delete day_mc.onPress;
}
if(curr_date.getTime() == this.today.getTime()){
day_mc.attachMovie("fcal_todayIndicator_mc", "todayIndicator_mc", 5);
} else {
day_mc["todayIndicator_mc"].removeMovieClip()
}
}
FCalendarClass.prototype.setHeaders = function (){
var title = this.headerTextMonth + " " + this.headerTextYear;
if(this.headerArea.title == undefined){
this.headerArea.attachMovie("FLabelSymbol", "title", 1, {controller:this, hostComponent:this});
this.registerTextElement(this.headerArea.title, "FCalendarHeadText");
}
this.headerArea.title.labelField.multiline = false;
this.headerArea.title.labelField.wordWrap = false;
this.headerArea.title.labelField.restrict = true;
this.headerArea.title.setLabel(title);
var xt = Math.floor((this.headerArea._width - this.headerArea.title.labelfield.textWidth) / 2);
var w = this.headerArea._width - xt;
this.headerArea.title._x = Math.max(0, xt);
this.headerArea.title._y = 0;
this.headerArea.title.setSize(w, this.headerArea._height);
this.headerArea.title.setEnabled(this.enable);
}
FCalendarClass.prototype.getFont = function (){
var theFont = globalStyleFormat.textFont;
if(theFont == undefined){
theFont = this.defaultFont;
}
return theFont;
}
FCalendarClass.prototype.getOffsetOfMonth = function(theBaseDate){
var first = new Date(theBaseDate.getFullYear(), theBaseDate.getMonth(), 1);
var offset = first.getDay() - this.firstDayOfWeek
return (offset < 0 ? offset + 7 : offset);
}
FCalendarClass.prototype.getLastOfMonth = function(theBaseDate){
var lastOfMonth = "";
var month = theBaseDate.getMonth();
var year = theBaseDate.getFullYear();
endDate="";
if(month == 1){
if(year % 4 != 0 && (year != 1200 || year != 1600 || year != 2000 || year != 2400)){
lastOfMonth = 28;
}
else{
lastOfMonth = 29;
}
}
else if(month == 3 || month == 5 || month == 8 || month == 10){
lastOfMonth = 30;
}
else{
lastOfMonth = 31;
}
return lastOfMonth;
}
FCalendarClass.prototype.startSelection = function(){
this.oldSelections = new Object();
for(x in this.selections){
var d = this.selections[x];
if(d.getFullYear() == this.currDisplay.getFullYear() && d.getMonth() == this.currDisplay.getMonth()){
this.oldSelections[x] = d;
}
}
}
FCalendarClass.prototype.getSelectionDelta = function(){
var delta = new Object();
for(x in this.selections){
if(this.oldSelections[x] == undefined){
var d = this.selections[x];
if(d.getFullYear() == this.currDisplay.getFullYear() && d.getMonth() == this.currDisplay.getMonth()){
delta[x] = d;
}
}
}
for(x in this.oldSelections){
if(this.selections[x] == undefined){
var d = this.oldSelections[x];
delta[x] = d;
}
}
return delta;
}
FCalendarClass.prototype.startDrag = function(day){
this.dragAnchor = day;
this.dragLast = day;
Mouse.addListener(this.dragListener);
}
FCalendarClass.prototype.updateDragSelection = function(){
point = new object();
point.x = _root._xmouse;
point.y = _root._ymouse;
this.globalToLocal(point);
var xoffset = this.leftEdge;
var yoffset = this.dayTextHeight + this.headerHeight;
var row = Math.floor((point.y - yoffset) / this.dayHeight);
var col = Math.floor((point.x - xoffset) / this.dayWidth);
var day;
var last = this.getLastOfMonth(this.currDisplay);
if(row < 0){
day = 1;
} else if (row > 5){
day = last;
} else {
col = Math.max(col,0);
col = Math.min(col,6);
day = row * 7 + col - this.offset + 1;
}
day = Math.max(day, 1);
day = Math.min(day, last);
if(day != this.dragLast){
this.startSelection();
var changed = false;
var year = this.currDisplay.getFullYear();
var month = this.currDisplay.getMonth();
var theDate = new Date(year, month, day);
changed = true;
if(this.selectionType == 'single'){
this.anchor = theDate;
if(this.isSelected(theDate) && !this.selectionRequired && this.getSelectionCount() == 1)
theDate = undefined;
this.selections = new Object();
this.selectDate(theDate);
} else {
var anchorDate = new Date(year, month, this.dragAnchor);
var lastDate = new Date(year, month, this.dragLast);
if((this.dragLast <= this.dragAnchor && day <= this.dragLast) ||
(this.dragLast >= this.dragAnchor && day >= this.dragLast)){
this.selectAppendRange(lastDate, theDate);
} else {
this.deselectRange(lastDate, anchorDate);
this.selectAppendRange(anchorDate, theDate);
}
}
this.dragLast = day;
this.caret = theDate;
if(changed) this.executeCallBack();
this.selectiveRedraw();
}
}
FCalendarClass.prototype.endDragSelection = function(){
Mouse.removeListener(this.dragListener);
}
FCalendarClass.prototype.selectHandler = function(day){
Selection.setFocus(this);
this.startDrag(day);
var ctl = Key.isDown(Key.CONTROL) && this.selectionType != 'range' && this.selectionType != 'single';
var shift = Key.isDown(Key.SHIFT) && this.selectionType != 'single';
year = this.currDisplay.getFullYear();
var theDate = new Date(year, this.currDisplay.getMonth(), day);
this.caret = theDate;
var key = theDate.getFullYear() + "/" +theDate.getMonth() + "/" + day;
var changed = false;
this.startSelection();
if(ctl && shift && this.anchor != undefined){
this.selectAppendRange(this.anchor, theDate);
changed = true;
} else if(ctl){
this.anchor = theDate;
if(this.isSelected(theDate) && (!this.selectionRequired || this.getSelectionCount() > 1)){
theDate = undefined;
}
this.selections[key] = theDate;
changed = true;
} else if(shift && this.anchor != undefined) {
this.selections = new Object();
this.selectAppendRange(this.anchor, theDate);
changed = true;
} else {
this.anchor = theDate;
if(this.isSelected(theDate) && !this.selectionRequired && this.getSelectionCount() == 1)
theDate = undefined;
this.selections = new Object();
this.selections[key] = theDate;
changed = true;
}
if(changed) this.executeCallBack();
this.selectiveRedraw();
}
FCalendarClass.prototype.isSelectionEmpty = function() {
for(x in this.selections){
return false;
}
return true;
}
FCalendarClass.prototype.getSelectionCount = function() {
var ct = 0;
for(x in this.selections){
ct++;
}
return ct;
}
FCalendarClass.prototype.selectDate = function(theDate) {
var key = theDate.getFullYear() + "/" + theDate.getMonth() + "/" + theDate.getDate();
this.selections[key] = theDate;
}
FCalendarClass.prototype.selectAppendRange = function(date1, date2, deselect) {
if(deselect == undefined) deselect = false;
if(date1.getTime() > date2.getTime()){
var tmp = date2;
date2 = date1;
date1 = tmp;
}
date1 = new Date(date1.getFullYear(), date1.getMonth(), date1.getDate());
date2 = new Date(date2.getFullYear(), date2.getMonth(), date2.getDate());
var theDate = date1;
var time2 = date2.getTime();
while(theDate.getTime() <= time2){
var day = theDate.getDate();
if(this.isSelectable(theDate)){
var key = theDate.getFullYear() + "/" + theDate.getMonth() + "/" + day;
this.selections[key] = deselect ? undefined : theDate;
}
theDate = new Date(theDate.getFullYear(), theDate.getMonth(), ++day);
}
}
FCalendarClass.prototype.deselectRange = function(date1, date2) {
this.selectAppendRange(date1, date2, true);
}
FCalendarClass.prototype.isSelected = function(aDate){
var key = aDate.getFullYear() + "/" +aDate.getMonth() + "/" + aDate.getDate();
if(this.selections[key] != undefined) return true;
return false;
}
FCalendarClass.prototype.onSetPress = function(){
Selection.setFocus(this);
}
FCalendarClass.prototype.myOnSetFocus = function()
{
Key.addListener(this.keyListener);
this.focused =true;
this.drawFocusRect()
}
FCalendarClass.prototype.myOnKillFocus = function()
{
Super.myOnKillFocus();
this.focusRect.removeMovieClip();
}
FCalendarClass.prototype.drawFocusRect = function()
{
var pt = {x : -2, y : -2};
this.drawRect(pt.x, pt.y,
(this._width+4) * 100 / this._xscale,
(this._height+4) * 100 / this._yscale);
}
FCalendarClass.prototype.myOnKeyDown = function( )
{
var shift = Key.isDown(Key.SHIFT) && this.selectionType != 'single';
var ctrl = Key.isDown(Key.CONTROL ) && this.selectionType != 'single';
var theDate = this.caret;
var changed = false;
if (Key.getCode() == Key.RIGHT) {
this.kbdSelect(1, shift || ctrl, false);
changed = true;
} else if(Key.getCode() == Key.LEFT) {
this.kbdSelect(-1, shift || ctrl, true);
changed = true;
} else if (Key.getCode() == Key.SPACE){
// Toggle current if legal to do so
if(this.isSelectable(theDate)){
this.startSelection();
if(!this.selectionRequired || this.getSelectionCount() > 1){
var selected = this.isSelected(theDate);
if(selected || this.selectionType == "multiple"){
this.selectAppendRange(theDate, theDate, selected);
changed = true;
this.selectiveRedraw();
}
}
}
}else if (Key.getCode() == Key.HOME){
this.kbdSelect(1 - this.caret.getDate(), false, false);
this.anchor = this.caret;
changed = true;
}else if (Key.getCode() == Key.END){
var last = this.getLastOfMonth(theDate);
if(last != this.caret.getDate()){
this.kbdSelect(last - this.caret.getDate(), false, true);
this.anchor = this.caret;
changed = true;
}
}else if (Key.getCode() == Key.PGDN){
if(Key.isDown(Key.CONTROL )) this.stepDate(1, 0);
else this.stepDate(0, 1);
}else if (Key.getCode() == Key.PGUP){
if(Key.isDown(Key.CONTROL )) this.stepDate(-1, 0);
else this.stepDate(0, -1);
}
if(changed) this.executeCallBack();
}
FCalendarClass.prototype.kbdSelect = function(deltaDays, append, before )
{
this.startSelection();
if(arguments.length < 3) before = false;
var oldMonth = this.currDisplay.getMonth();
var oldYear = this.currDisplay.getFullYear();
this.currDisplay = this.caret;
var day = this.caret.getDate() + deltaDays;
var month = this.caret.getMonth();
var year = this.caret.getFullYear();
var theDate = new Date(year, month, day);
var i = 0;
if(this.displayRange.begin != undefined && this.displayRange.begin.getTime() > theDate.getTime()){
theDate = this.displayRange.begin;
before = false;
}
if(this.displayRange.end != undefined && this.displayRange.end.getTime() < theDate.getTime()){
theDate = this.displayRange.end;
before = true;
}
while(!this.isSelectable(theDate) && i < 100000){
var delta = (before ? -1 : 1);
day = theDate.getDate() + delta;
month = theDate.getMonth();
year = theDate.getFullYear();
theDate = new Date(year, month, day);
i++;
}
var key = theDate.getFullYear() + "/" +theDate.getMonth() + "/" + theDate.getDate();
if(!append){
this.selections = new Object();
}
this.selections[key] = theDate;
this.caret = theDate;
if(oldMonth != theDate.getMonth() || oldYear != theDate.getFullYear()){
this.stepDate(theDate.getFullYear() - oldYear, theDate.getMonth() - oldMonth);
} else this.selectiveRedraw();
}
FCalendarClass.prototype.setCaret = function(day ){
this.caret.setDate(day);
}
FCalendarClass.prototype.initSelectionType = function(){
this.selections = new Object();
if(this.selectionRequired){
this.setSelectedItem(new Date());
}
}
FCalendarClass.prototype.isDisplayable = function(day){
if(day.getTime() < this.displayRange.beginTime || day.getTime() > this.displayRange.endTime)
return false;
return true;
}
FCalendarClass.prototype.isSelectable = function(day){
if(!this.isDisplayable(day)) return false;
if(this.dateFilter.isSelectable != undefined && !this.dateFilter.isSelectable(this, day)){
return false;
}
return true;
}
FCalendarClass.prototype.redraw = function(){
this.drawDays();
this.initMonth(this.currDisplay);
}
