Hi Michal,
Well it's pretty complicated. We're actually using widgets, one of them is indeed the calendar control. We're also using jquery load to load widgets from other pages (to make a sort of "mega-menu" whihc displays different widgets depending on where you hover your mouse).
Here's the full code for the calendar web part/widget.
ASPX:
<%@ Control Language="C#" AutoEventWireup="true" Inherits="CMSWebParts_CarDealer_CalendarWithEvents"
CodeFile="~/CMSWebParts/CarDealer/CalendarWithEvents.ascx.cs" %>
<div class="WidgetCalendarWithEvents">
<div class="Calendar">
<cms:CMSCalendar ID="calItems" runat="server" EnableViewState="false" TodayDayStyle-CssClass="TodayCalendar"
DayHeaderStyle-CssClass="DayHeaderCalendar" TitleStyle-CssClass="TitleCalendar"
NextPrevStyle-CssClass="NextPrevCalendar" ShowGridLines="false" OnDayRender="calItems_DayRender" CellPadding="0" BorderStyle="None" >
</cms:CMSCalendar>
<cms:CMSRepeater ID="repEvent" runat="server" EnableViewState="false" StopProcessing="true">
</cms:CMSRepeater>
</div>
<div class="BottomCalendar"></div>
</div>
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using CMS.FileManager;
using CMS.GlobalHelper;
using CMS.CMSHelper;
using CMS.PortalControls;
using CMS.WorkflowEngine;
using CMS.PortalEngine;
using CMS.Controls;
using CMS.SiteProvider;
using System.Diagnostics;
using System.Data;
using TreeNode = CMS.TreeEngine.TreeNode;
using System.IO;
using System.ComponentModel;
public partial class CMSWebParts_CarDealer_CalendarWithEvents : CMSAbstractWebPart
{
private ITemplate mFooterTemplate = null;
private ITemplate mHeaderTemplate = null;
private ITemplate mSeparatorTemplate = null;
#region "Public properties"
/// <summary>
/// Gets or sets the value that indicates whether permissions are checked.
/// </summary>
public bool CheckPermissions
{
get
{
return ValidationHelper.GetBoolean(GetValue("CheckPermissions"), calItems.CheckPermissions);
}
set
{
SetValue("CheckPermissions", value);
calItems.CheckPermissions = value;
repEvent.CheckPermissions = value;
}
}
/// <summary>
/// Gets or sets the class names.
/// </summary>
public string ClassNames
{
get
{
return DataHelper.GetNotEmpty(ValidationHelper.GetString(GetValue("ClassNames"), calItems.ClassNames), calItems.ClassNames);
}
set
{
SetValue("ClassNames", value);
calItems.ClassNames = value;
repEvent.ClassNames = value;
}
}
/// <summary>
/// Gets or sets the value that indicates whether data are combined with default control.
/// </summary>
public bool CombineWithDefaultCulture
{
get
{
return ValidationHelper.GetBoolean(GetValue("CombineWithDefaultCulture"), calItems.CombineWithDefaultCulture);
}
set
{
SetValue("CombineWithDefaultCulture", value);
calItems.CombineWithDefaultCulture = value;
repEvent.CombineWithDefaultCulture = value;
}
}
/// <summary>
/// Gets or sets the culture code.
/// </summary>
public string CultureCode
{
get
{
return DataHelper.GetNotEmpty(ValidationHelper.GetString(GetValue("CultureCode"), calItems.CultureCode), calItems.CultureCode);
}
set
{
SetValue("CultureCode", value);
calItems.CultureCode = value;
repEvent.CultureCode = value;
}
}
/// <summary>
/// Gets or sets the max. relative level.
/// </summary>
public int MaxRelativeLevel
{
get
{
return ValidationHelper.GetInteger(GetValue("MaxRelativeLevel"), calItems.MaxRelativeLevel);
}
set
{
SetValue("MaxRelativeLevel", value);
calItems.MaxRelativeLevel = value;
}
}
/// <summary>
/// Gets or sets the order by value.
/// </summary>
public string OrderBy
{
get
{
return DataHelper.GetNotEmpty(ValidationHelper.GetString(GetValue("OrderBy"), calItems.OrderBy), calItems.OrderBy);
}
set
{
SetValue("OrderBy", value);
calItems.OrderBy = value;
}
}
/// <summary>
/// Gets or sets the path.
/// </summary>
public string Path
{
get
{
return DataHelper.GetNotEmpty(ValidationHelper.GetString(GetValue("Path"), calItems.Path), calItems.Path);
}
set
{
SetValue("Path", value);
calItems.Path = value;
}
}
/// <summary>
/// Gets or sets the value that indicates whether related node is on the lef side.
/// </summary>
public bool RelatedNodeIsOnTheLeftSide
{
get
{
return ValidationHelper.GetBoolean(GetValue("RelatedNodeIsOnTheLeftSide"), calItems.RelatedNodeIsOnTheLeftSide);
}
set
{
SetValue("RelatedNodeIsOnTheLeftSide", value);
calItems.RelatedNodeIsOnTheLeftSide = value;
}
}
/// <summary>
/// Gets or sets the relationship name.
/// </summary>
public string RelationshipName
{
get
{
return DataHelper.GetNotEmpty(ValidationHelper.GetString(GetValue("RelationshipName"), calItems.RelationshipName), calItems.RelationshipName);
}
set
{
SetValue("RelationshipName", value);
calItems.RelationshipName = value;
}
}
/// <summary>
/// Gets or sets the relationShip with node guid.
/// </summary>
public Guid RelationshipWithNodeGuid
{
get
{
return ValidationHelper.GetGuid(GetValue("RelationshipWithNodeGuid"), calItems.RelationshipWithNodeGuid);
}
set
{
SetValue("RelationshipWithNodeGuid", value);
calItems.RelationshipWithNodeGuid = value;
}
}
/// <summary>
/// Gets or sets the value that indicates whether selected documents must be only published.
/// </summary>
public bool SelectOnlyPublished
{
get
{
return ValidationHelper.GetBoolean(GetValue("SelectOnlyPublished"), calItems.SelectOnlyPublished);
}
set
{
SetValue("SelectOnlyPublished", value);
calItems.SelectOnlyPublished = value;
repEvent.SelectOnlyPublished = value;
}
}
/// <summary>
/// Gets or sets the site name.
/// </summary>
public string SiteName
{
get
{
return DataHelper.GetNotEmpty(ValidationHelper.GetString(GetValue("SiteName"), calItems.SiteName), calItems.SiteName);
}
set
{
SetValue("SiteName", value);
calItems.SiteName = value;
repEvent.SiteName = value;
}
}
/// <summary>
/// Gets or sets the name of the transforamtion which is used for displaying the results.
/// </summary>
public string TransformationName
{
get
{
return DataHelper.GetNotEmpty(ValidationHelper.GetString(GetValue("TransformationName"), "cms.event.CalendarItem"), "cms.event.CalendarItem");
}
set
{
SetValue("TransformationName", value);
calItems.TransformationName = value;
}
}
[PersistenceMode(PersistenceMode.InnerProperty), DefaultValue((string)null), Browsable(false)]
public virtual ITemplate HeaderTemplate
{
get
{
return mHeaderTemplate;
}
set
{
mFooterTemplate = value;
}
}
/// <summary>
/// Sets or gets footer template.
/// </summary>
[PersistenceMode(PersistenceMode.InnerProperty), DefaultValue((string)null), Browsable(false)]
public virtual ITemplate FooterTemplate
{
get
{
return mFooterTemplate;
}
set
{
mFooterTemplate = value;
}
}
/// <summary>
/// Sets or gets separator template.
/// </summary>
[PersistenceMode(PersistenceMode.InnerProperty), DefaultValue((string)null), Browsable(false)]
public virtual ITemplate SeparatorTemplate
{
get
{
return mSeparatorTemplate;
}
set
{
mSeparatorTemplate = value;
}
}
/// <summary>
/// Gets or sets the where condition.
/// </summary>
//public string HeaderTemplate
//{
// get
// {
// return DataHelper.GetNotEmpty(ValidationHelper.GetString(GetValue("HeaderTemplate"), calItems.HeaderTemplate), calItems.HeaderTemplate);
// }
// set
// {
// SetValue("HeaderTemplate", value);
// repEvent.HeaderTemplate = value;
// }
//}
/// <summary>
/// Gets or sets the field of event start date.
/// </summary>
public string DayField
{
get
{
return DataHelper.GetNotEmpty(ValidationHelper.GetString(GetValue("DayField"), "EventDate"), "EventDate");
}
set
{
SetValue("DayField", value);
calItems.DayField = value;
}
}
/// <summary>
/// Gets or sets the field of event end date.
/// </summary>
public string EventEndField
{
get
{
return ValidationHelper.GetString(GetValue("EventEndField"), calItems.EventEndField);
}
set
{
SetValue("EventEndField", value);
calItems.EventEndField = value;
}
}
/// <summary>
/// Gets or sets the no event transformation name.
/// </summary>
public string NoEventTransformationName
{
get
{
return DataHelper.GetNotEmpty(GetValue("NoEventTransformationName"), "cms.event.calendarnoevent");
}
set
{
SetValue("NoEventTransformationName", value);
calItems.NoEventTransformationName = value;
}
}
//public string EventTransformationNameOnMouseOver
//{
// get
// {
// return DataHelper.GetNotEmpty(GetValue("EventTransformationNameOnMouseOver"), "cms.event.calendareventdetails");
// }
// set
// {
// SetValue("EventTransformationNameOnMouseOver", value);
// calItems.EventTransformationNameOnMouseOver = value;
// }
//}
/// <summary>
/// Indicates whether the day number is displayed or cell is full filled by the transformation.
/// Current day is saved in the "__day" column.
/// </summary>
public bool HideDefaultDayNumber
{
get
{
return ValidationHelper.GetBoolean(GetValue("HideDefaultDayNumber"), calItems.HideDefaultDayNumber);
}
set
{
SetValue("HideDefaultDayNumber", value);
calItems.HideDefaultDayNumber = value;
}
}
/// <summary>
/// Gets or sets the columns to retrieve.
/// </summary>
//public ITemplate FooterTemplate
//{
// get
// {
// return DataHelper.GetNotEmpty(ValidationHelper.GetString(GetValue("FooterTemplate"), calItems.FooterTemplate), calItems.FooterTemplate);
// }
// set
// {
// SetValue("FooterTemplate", value);
// repEvent.FooterTemplate = value;
// }
//}
/// <summary>
/// Gets or sets the SkinID which should be used.
/// </summary>
public override string SkinID
{
get
{
return base.SkinID;
}
set
{
base.SkinID = value;
if ((calItems != null) && (PageCycle < PageCycleEnum.Initialized))
{
calItems.SkinID = SkinID;
}
}
}
/// <summary>
/// Calendar control.
/// </summary>
public CMSCalendar CalendarControl
{
get
{
return calItems;
}
}
/// <summary>
/// Filter name.
/// </summary>
public string FilterName
{
get
{
return ValidationHelper.GetString(GetValue("FilterName"), calItems.FilterName);
}
set
{
SetValue("FilterName", value);
calItems.FilterName = value;
}
}
/// <summary>
/// Gets or sets the cache minutes.
/// </summary>
public override int CacheMinutes
{
get
{
return base.CacheMinutes;
}
set
{
base.CacheMinutes = value;
calItems.CacheMinutes = value;
repEvent.CacheMinutes = value;
}
}
/// <summary>
/// Gets or sets the cache item dependencies.
/// </summary>
public override string CacheDependencies
{
get
{
return base.CacheDependencies;
}
set
{
base.CacheDependencies = value;
calItems.CacheDependencies = value;
repEvent.CacheDependencies = value;
}
}
/// <summary>
/// Gets or sets the name of the cache item. If not explicitly specified, the name is automatically
/// created based on the control unique ID
/// </summary>
public override string CacheItemName
{
get
{
return base.CacheItemName;
}
set
{
base.CacheItemName = value;
calItems.CacheItemName = value;
if (!String.IsNullOrEmpty(value))
{
repEvent.CacheItemName = value + "detail";
}
else
{
repEvent.CacheItemName = string.Empty;
}
}
}
#endregion
#region "Repeater properties"
/// <summary>
/// Event detail transformation.
/// </summary>
public string EventDetailTransformation
{
get
{
return DataHelper.GetNotEmpty(GetValue("EventDetailTransformation"), "cms.event.Default");
}
set
{
SetValue("EventDetailTransformation", value);
repEvent.SelectedItemTransformationName = value;
}
}
#endregion
/// <summary>
/// Content loaded event handler.
/// </summary>
public override void OnContentLoaded()
{
base.OnContentLoaded();
SetupControl();
}
/// <summary>
/// Reloads control data.
/// </summary>
public override void ReloadData()
{
base.ReloadData();
SetupControl();
calItems.ReloadData(true);
repEvent.ReloadData(true);
}
/// <summary>
/// Initializes the control properties.
/// </summary>
protected void SetupControl()
{
if (StopProcessing)
{
calItems.StopProcessing = true;
}
else
{
calItems.ControlContext = repEvent.ControlContext = ControlContext;
// Calendar properties
calItems.CacheItemName = CacheItemName;
calItems.CacheDependencies = CacheDependencies;
calItems.CacheMinutes = CacheMinutes;
calItems.CheckPermissions = CheckPermissions;
calItems.ClassNames = ClassNames;
calItems.CombineWithDefaultCulture = CombineWithDefaultCulture;
calItems.CultureCode = CultureCode;
calItems.MaxRelativeLevel = MaxRelativeLevel;
calItems.OrderBy = OrderBy;
//calItems.WhereCondition = WhereCondition;
//calItems.Columns = Columns;
calItems.Path = Path;
calItems.SelectOnlyPublished = SelectOnlyPublished;
calItems.SiteName = SiteName;
calItems.FilterName = FilterName;
calItems.RelationshipName = RelationshipName;
calItems.RelationshipWithNodeGuid = RelationshipWithNodeGuid;
calItems.RelatedNodeIsOnTheLeftSide = RelatedNodeIsOnTheLeftSide;
calItems.TransformationName = TransformationName;
calItems.NoEventTransformationName = NoEventTransformationName;
// calItems.EventTransformationNameOnMouseOver = EventTransformationNameOnMouseOver;
calItems.DayField = DayField;
calItems.EventEndField = EventEndField;
calItems.HideDefaultDayNumber = HideDefaultDayNumber;
calItems.TodaysDate = CMSContext.ConvertDateTime(DateTime.Now, this);
TableItemStyle style = new TableItemStyle();
TableItemStyle tooltip = new TableItemStyle();
style.CssClass = "DayWithEventsCalendar";
calItems.DayWithEventsStyle = style;
bool detail = false;
// If calendar event path is defined event is loaded in accordance to the selected path
string eventPath = QueryHelper.GetString("CalendarEventPath", null);
if (!String.IsNullOrEmpty(eventPath))
{
detail = true;
repEvent.Path = eventPath;
// Set selected date to specific document
TreeNode node = TreeHelper.GetDocument(SiteName, eventPath, CultureCode, CombineWithDefaultCulture, ClassNames, SelectOnlyPublished, CheckPermissions, CMSContext.CurrentUser);
if (node != null)
{
object value = node.GetValue(DayField);
if (ValidationHelper.GetDateTime(value, DataHelper.DATETIME_NOT_SELECTED) != DataHelper.DATETIME_NOT_SELECTED)
{
calItems.TodaysDate = CMSContext.ConvertDateTime((DateTime)value, this);
}
}
}
// By default select current event from current document value
PageInfo currentPage = CMSContext.CurrentPageInfo;
if ((currentPage != null) && (ClassNames.ToLower().Contains(currentPage.ClassName.ToLower())))
{
detail = true;
repEvent.Path = currentPage.NodeAliasPath;
// Set selected date to current document
object value = CMSContext.CurrentDocument.GetValue(DayField);
if (ValidationHelper.GetDateTime(value, DataHelper.DATETIME_NOT_SELECTED) != DataHelper.DATETIME_NOT_SELECTED)
{
calItems.TodaysDate = CMSContext.ConvertDateTime((DateTime)value, this);
// Get name of coupled class ID column
string idColumn = CMSContext.CurrentDocument.CoupledClassIDColumn;
if (!string.IsNullOrEmpty(idColumn))
{
// Set selected item ID and the ID column name so it is possible to highlight specific event in the calendar
calItems.SelectedItemIDColumn = idColumn;
calItems.SelectedItemID = ValidationHelper.GetInteger(CMSContext.CurrentDocument.GetValue(idColumn), 0);
}
}
}
if (detail)
{
// Setup the detail repeater
repEvent.Visible = true;
repEvent.StopProcessing = false;
repEvent.SelectedItemTransformationName = EventDetailTransformation;
repEvent.ClassNames = ClassNames;
repEvent.HeaderTemplate = this.HeaderTemplate;
repEvent.FooterTemplate = this.FooterTemplate;
repEvent.ItemTemplate = this.HeaderTemplate;
// repEvent.Columns = Columns;
if (!String.IsNullOrEmpty(CacheItemName))
{
repEvent.CacheItemName = CacheItemName + "|detail";
}
// repEvent.CacheDependencies = CacheDependencies;
// repEvent.CacheMinutes = CacheMinutes;
// repEvent.CheckPermissions = CheckPermissions;
// repEvent.CombineWithDefaultCulture = CombineWithDefaultCulture;
// repEvent.CultureCode = CultureCode;
// repEvent.SelectOnlyPublished = SelectOnlyPublished;
repEvent.SiteName = SiteName;
//repEvent.WhereCondition = WhereCondition;
}
}
}
protected void calItems_DayRender(object sender, DayRenderEventArgs e)
{
if (this.calItems.VisibleDate != DateTimeHelper.ZERO_TIME)
{
if (e.Day.Date.Month != this.calItems.VisibleDate.Month)
{
e.Cell.Text = "";
}
}
else
{
if (e.Day.Date.Month != this.calItems.TodaysDate.Month)
{
e.Cell.Text = "";
}
}
if (e.Day.IsOtherMonth)
{
e.Cell.BorderStyle = BorderStyle.None;
}
if ((e.Day.IsToday) && (!e.Day.IsOtherMonth))
{
e.Cell.BorderStyle = BorderStyle.Solid;
}
}
/// <summary>
/// Applies given stylesheet skin.
/// </summary>
public override void ApplyStyleSheetSkin(Page page)
{
calItems.SkinID = SkinID;
base.ApplyStyleSheetSkin(page);
}
/// <summary>
/// Clear cache.
/// </summary>
public override void ClearCache()
{
calItems.ClearCache();
repEvent.ClearCache();
}
}