PageRenderTime 57ms CodeModel.GetById 29ms RepoModel.GetById 1ms app.codeStats 0ms

/Server/AjaxControlToolkit/Calendar/CalendarExtender.cs

http://ajaxcontroltoolkit.codeplex.com
C# | 279 lines | 181 code | 29 blank | 69 comment | 6 complexity | 6e7592b0df96b8ea074d67b85243be5d MD5 | raw file
Possible License(s): BSD-3-Clause
  1. using System;
  2. using System.Web.UI.WebControls;
  3. using System.Web.UI;
  4. using System.ComponentModel;
  5. using System.ComponentModel.Design;
  6. using AjaxControlToolkit;
  7. #region [ Resources ]
  8. [assembly: System.Web.UI.WebResource("Calendar.CalendarBehavior.js", "text/javascript")]
  9. [assembly: System.Web.UI.WebResource("Calendar.CalendarBehavior.debug.js", "text/javascript")]
  10. [assembly: System.Web.UI.WebResource("Calendar.Calendar_resource.css", "text/css", PerformSubstitution = true)]
  11. [assembly: System.Web.UI.WebResource("Calendar.arrow-left.gif", "image/gif")]
  12. [assembly: System.Web.UI.WebResource("Calendar.arrow-right.gif", "image/gif")]
  13. #endregion
  14. namespace AjaxControlToolkit {
  15. /// <summary>
  16. /// The Calendar control extender can be attached to any ASP.NET TextBox control. It provides client-side
  17. /// date-picking functionality with customizable date format and UI in a popup control. You can interact
  18. /// with the calendar by clicking on a day to set the date, or the "Today" link to set the current date.
  19. ///
  20. /// In addition, the left and right arrows can be used to move forward or back a month.
  21. /// By clicking on the title of the calendar you can change the view from Days in the current month,
  22. /// to Months in the current year. Another click will switch to Years in the current Decade.
  23. /// This action allows you to easily jump to dates in the past or the future from within
  24. /// the calendar control.
  25. /// </summary>
  26. [Designer("AjaxControlToolkit.CalendarDesigner, AjaxControlToolkit")]
  27. [RequiredScript(typeof(CommonToolkitScripts), 0)]
  28. [RequiredScript(typeof(DateTimeScripts), 1)]
  29. [RequiredScript(typeof(PopupExtender), 2)]
  30. [RequiredScript(typeof(AnimationScripts), 3)]
  31. [RequiredScript(typeof(ThreadingScripts), 4)]
  32. [TargetControlType(typeof(TextBox))]
  33. [ClientCssResource("Calendar.Calendar_resource.css")]
  34. [ClientScriptResource("Sys.Extended.UI.CalendarBehavior", "Calendar.CalendarBehavior.js")]
  35. [System.Drawing.ToolboxBitmap(typeof(CalendarExtender), "Calendar.Calendar.ico")]
  36. public class CalendarExtender : ExtenderControlBase {
  37. /// <summary>
  38. /// Name of the Cascading Style Sheet class used to style the calendar
  39. /// </summary>
  40. [DefaultValue("")]
  41. [ExtenderControlProperty]
  42. [ClientPropertyName("cssClass")]
  43. public virtual string CssClass {
  44. get { return GetPropertyValue("CssClass", string.Empty); }
  45. set { SetPropertyValue("CssClass", value); }
  46. }
  47. /// <summary>
  48. /// Format string used to display the selected date. The default value is "d"
  49. /// </summary>
  50. [DefaultValue("d")]
  51. [ExtenderControlProperty]
  52. [ClientPropertyName("format")]
  53. public virtual string Format {
  54. get { return GetPropertyValue("Format", "d"); }
  55. set { SetPropertyValue("Format", value); }
  56. }
  57. /// <summary>
  58. /// Format string used to display today's date. The default value is "MMMM d, yyyy"
  59. /// </summary>
  60. [DefaultValue("MMMM d, yyyy")]
  61. [ExtenderControlProperty]
  62. [ClientPropertyName("todaysDateFormat")]
  63. public virtual string TodaysDateFormat {
  64. get { return GetPropertyValue("TodaysDateFormat", "MMMM d, yyyy"); }
  65. set { SetPropertyValue("TodaysDateFormat", value); }
  66. }
  67. /// <summary>
  68. /// Format string used to display Days Mode Title. The default value is "MMMM, yyyy"
  69. /// </summary>
  70. [DefaultValue("MMMM, yyyy")]
  71. [ExtenderControlProperty]
  72. [ClientPropertyName("daysModeTitleFormat")]
  73. public virtual string DaysModeTitleFormat {
  74. get { return GetPropertyValue("DaysModeTitleFormat", "MMMM, yyyy"); }
  75. set { SetPropertyValue("DaysModeTitleFormat", value); }
  76. }
  77. /// <summary>
  78. /// Whether time should be cleared in edited date/time
  79. /// </summary>
  80. [DefaultValue(false)]
  81. [ExtenderControlProperty]
  82. [ClientPropertyName("clearTime")]
  83. public virtual bool ClearTime {
  84. get { return GetPropertyValue("ClearTime", false); }
  85. set { SetPropertyValue("ClearTime", value); }
  86. }
  87. /// <summary>
  88. /// Whether this behavior is available for the current element
  89. /// </summary>
  90. [DefaultValue(true)]
  91. [ExtenderControlProperty]
  92. [ClientPropertyName("enabled")]
  93. public virtual bool EnabledOnClient {
  94. get { return GetPropertyValue("EnabledOnClient", true); }
  95. set { SetPropertyValue("EnabledOnClient", value); }
  96. }
  97. /// <summary>
  98. /// Whether changing modes is animated
  99. /// </summary>
  100. [DefaultValue(true)]
  101. [ExtenderControlProperty]
  102. [ClientPropertyName("animated")]
  103. public virtual bool Animated {
  104. get { return GetPropertyValue("Animated", true); }
  105. set { SetPropertyValue("Animated", value); }
  106. }
  107. /// <summary>
  108. /// Gets or sets the first day of week
  109. /// </summary>
  110. [DefaultValue(FirstDayOfWeek.Default)]
  111. [ExtenderControlProperty]
  112. [ClientPropertyName("firstDayOfWeek")]
  113. public virtual FirstDayOfWeek FirstDayOfWeek {
  114. get { return GetPropertyValue("FirstDayOfWeek", FirstDayOfWeek.Default); }
  115. set { SetPropertyValue("FirstDayOfWeek", value); }
  116. }
  117. /// <summary>
  118. /// The ID of a control to show the calendar popup when clicked. If this value is not set, the calendar will pop up when the textbox receives focus
  119. /// </summary>
  120. [DefaultValue("")]
  121. [ExtenderControlProperty]
  122. [ClientPropertyName("button")]
  123. [ElementReference]
  124. [IDReferenceProperty]
  125. [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1706:ShortAcronymsShouldBeUppercase", Justification = "Following ASP.NET AJAX pattern")]
  126. public virtual string PopupButtonID {
  127. get { return GetPropertyValue("PopupButtonID", string.Empty); }
  128. set { SetPropertyValue("PopupButtonID", value); }
  129. }
  130. /// <summary>
  131. /// Gets or sets the popup position of the calendar. The default value is BottomLeft
  132. /// </summary>
  133. [ExtenderControlProperty]
  134. [ClientPropertyName("popupPosition")]
  135. [DefaultValue(CalendarPosition.BottomLeft)]
  136. [Description("Indicates where you want the calendar displayed, bottom or top of the textbox.")]
  137. public virtual CalendarPosition PopupPosition {
  138. get { return GetPropertyValue("PopupPosition", CalendarPosition.BottomLeft); }
  139. set { SetPropertyValue("PopupPosition", value); }
  140. }
  141. /// <summary>
  142. /// Gets or sets the date that the calendar is initialized with
  143. /// </summary>
  144. [DefaultValue(null)]
  145. [ExtenderControlProperty]
  146. [ClientPropertyName("selectedDate")]
  147. public DateTime? SelectedDate {
  148. get {
  149. DateTime? selectedDate = GetPropertyValue<DateTime?>("SelectedDate", null);
  150. return selectedDate != null ? (DateTime?)DateTime.SpecifyKind(selectedDate.Value, DateTimeKind.Utc) : null;
  151. }
  152. set {
  153. var utcValue = value != null ? (DateTime?)DateTime.SpecifyKind(value.Value, DateTimeKind.Utc) : null;
  154. SetPropertyValue<DateTime?>("SelectedDate", utcValue);
  155. }
  156. }
  157. /// <summary>
  158. /// Gets or sets the default view of the calender. The default value is Days.
  159. /// </summary>
  160. [DefaultValue(CalendarDefaultView.Days)]
  161. [ExtenderControlProperty]
  162. [ClientPropertyName("defaultView")]
  163. [Description("Default view of the calendar when it first pops up.")]
  164. public virtual CalendarDefaultView DefaultView {
  165. get { return GetPropertyValue("DefaultView", CalendarDefaultView.Days); }
  166. set { SetPropertyValue("DefaultView", value); }
  167. }
  168. /// <summary>
  169. /// Gets or sets the client script that executes immediately before the calendar is displayed
  170. /// </summary>
  171. [DefaultValue("")]
  172. [ExtenderControlEvent]
  173. [ClientPropertyName("showing")]
  174. public virtual string OnClientShowing {
  175. get { return GetPropertyValue("OnClientShowing", string.Empty); }
  176. set { SetPropertyValue("OnClientShowing", value); }
  177. }
  178. /// <summary>
  179. /// Gets or sets the client script that executes immediately after the calendar is displayed
  180. /// </summary>
  181. [DefaultValue("")]
  182. [ExtenderControlEvent]
  183. [ClientPropertyName("shown")]
  184. public virtual string OnClientShown {
  185. get { return GetPropertyValue("OnClientShown", string.Empty); }
  186. set { SetPropertyValue("OnClientShown", value); }
  187. }
  188. /// <summary>
  189. /// Gets or sets the client script that executes immediately before the calendar is hidden
  190. /// </summary>
  191. [DefaultValue("")]
  192. [ExtenderControlEvent]
  193. [ClientPropertyName("hiding")]
  194. public virtual string OnClientHiding {
  195. get { return GetPropertyValue("OnClientHiding", string.Empty); }
  196. set { SetPropertyValue("OnClientHiding", value); }
  197. }
  198. /// <summary>
  199. /// Gets or sets the client script that executes immediately after the calendar is hidden
  200. /// </summary>
  201. [DefaultValue("")]
  202. [ExtenderControlEvent]
  203. [ClientPropertyName("hidden")]
  204. public virtual string OnClientHidden {
  205. get { return GetPropertyValue("OnClientHidden", string.Empty); }
  206. set { SetPropertyValue("OnClientHidden", value); }
  207. }
  208. /// <summary>
  209. /// Gets or sets the script that executes when a new date is selected
  210. /// </summary>
  211. [DefaultValue("")]
  212. [ExtenderControlEvent]
  213. [ClientPropertyName("dateSelectionChanged")]
  214. public virtual string OnClientDateSelectionChanged {
  215. get { return GetPropertyValue("OnClientDateSelectionChanged", string.Empty); }
  216. set { SetPropertyValue("OnClientDateSelectionChanged", value); }
  217. }
  218. //Issue#8109
  219. /// <summary>
  220. /// Gets or sets the property of the start date for range
  221. /// </summary>
  222. [DefaultValue(null)]
  223. [ExtenderControlProperty]
  224. [ClientPropertyName("startDate")]
  225. public DateTime? StartDate {
  226. get {
  227. DateTime? startDate = GetPropertyValue<DateTime?>("StartDate", null);
  228. return startDate != null ? (DateTime?)DateTime.SpecifyKind(startDate.Value, DateTimeKind.Utc) : null;
  229. }
  230. set {
  231. SetPropertyValue<DateTime?>("StartDate", value != null ? (DateTime?)DateTime.SpecifyKind(value.Value, DateTimeKind.Utc) : null);
  232. }
  233. }
  234. /// <summary>
  235. /// Gets or sets the property of the end date for range
  236. /// </summary>
  237. [DefaultValue(null)]
  238. [ExtenderControlProperty]
  239. [ClientPropertyName("endDate")]
  240. public DateTime? EndDate {
  241. get {
  242. DateTime? endDate = GetPropertyValue<DateTime?>("EndDate", null);
  243. return endDate != null ? (DateTime?)DateTime.SpecifyKind(endDate.Value, DateTimeKind.Utc) : null;
  244. }
  245. set {
  246. SetPropertyValue<DateTime?>("EndDate", value != null ? (DateTime?)DateTime.SpecifyKind(value.Value, DateTimeKind.Utc) : null);
  247. }
  248. }
  249. }
  250. }