/// <summary>
 /// Initializes a new instance of the <see cref="DayOfWeekFieldAttribute"/> class.
 /// </summary>
 /// <param name="name">The name.</param>
 /// <param name="description">The description.</param>
 /// <param name="required">if set to <c>true</c> [required].</param>
 /// <param name="defaultValue">The default value.</param>
 /// <param name="category">The category.</param>
 /// <param name="order">The order.</param>
 /// <param name="key">The key.</param>
 public DayOfWeekFieldAttribute(string name = "Day of Week", string description = "", bool required = true, DayOfWeek defaultValue = DayOfWeek.Sunday, string category = "", int order = 0, string key = null)
     : base(name, description, required, defaultValue.ConvertToInt().ToString(), category, order, key, typeof(Rock.Field.Types.DayOfWeekFieldType).FullName)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="DayOfWeekFieldAttribute"/> class.
 /// </summary>
 /// <param name="name">The name.</param>
 /// <param name="description">The description.</param>
 /// <param name="required">if set to <c>true</c> [required].</param>
 /// <param name="defaultValue">The default value.</param>
 /// <param name="category">The category.</param>
 /// <param name="order">The order.</param>
 /// <param name="key">The key.</param>
 public DayOfWeekFieldAttribute( string name = "Day of Week", string description = "", bool required = true, DayOfWeek defaultValue = DayOfWeek.Sunday, string category = "", int order = 0, string key = null )
     : base( name, description, required, defaultValue.ConvertToInt().ToString(), category, order, key, typeof( Rock.Field.Types.DayOfWeekFieldType ).FullName )
 {
 }
        /// <summary>
        /// Loads the drop downs.
        /// </summary>
        private bool SetFilterControls()
        {
            // Get and verify the view mode
            ViewMode = this.GetUserPreference("ViewMode");
            if (string.IsNullOrWhiteSpace(ViewMode))
            {
                ViewMode = GetAttributeValue("DefaultViewOption");
            }

            if (!GetAttributeValue(string.Format("Show{0}View", ViewMode)).AsBoolean())
            {
                ShowError("Configuration Error", string.Format("The Default View Option setting has been set to '{0}', but the Show {0} View setting has not been enabled.", ViewMode));
                return(false);
            }

            // Show/Hide calendar control
            pnlCalendar.Visible = GetAttributeValue("ShowSmallCalendar").AsBoolean();

            // Get the first/last dates based on today's date and the viewmode setting
            var today = RockDateTime.Today;

            // Use the CalendarVisibleDate if it's in session.
            if (Session["CalendarVisibleDate"] != null)
            {
                today = (DateTime)Session["CalendarVisibleDate"];
                calReservationCalendar.VisibleDate = today;
            }

            FilterStartDate = today;
            FilterEndDate   = today;
            if (ViewMode == "Week")
            {
                FilterStartDate = today.StartOfWeek(_firstDayOfWeek);
                FilterEndDate   = today.EndOfWeek(_firstDayOfWeek);
            }
            else if (ViewMode == "Month")
            {
                FilterStartDate = new DateTime(today.Year, today.Month, 1);
                FilterEndDate   = FilterStartDate.Value.AddMonths(1).AddDays(-1);
            }

            // Setup small calendar Filter
            calReservationCalendar.FirstDayOfWeek = _firstDayOfWeek.ConvertToInt().ToString().ConvertToEnum <FirstDayOfWeek>();
            calReservationCalendar.SelectedDates.Clear();
            calReservationCalendar.SelectedDates.SelectRange(FilterStartDate.Value, FilterEndDate.Value);

            // Setup Campus Filter
            rcwCampus.Visible    = GetAttributeValue("CampusFilterDisplayMode").AsInteger() > 1;
            cblCampus.DataSource = CampusCache.All();
            cblCampus.DataBind();
            if (!string.IsNullOrWhiteSpace(this.GetUserPreference("Campuses")))
            {
                cblCampus.SetValues(this.GetUserPreference("Campuses").SplitDelimitedValues());
            }
            else
            {
                if (GetAttributeValue("EnableCampusContext").AsBoolean())
                {
                    var contextCampus = RockPage.GetCurrentContext(EntityTypeCache.Read("Rock.Model.Campus")) as Campus;
                    if (contextCampus != null)
                    {
                        cblCampus.SetValue(contextCampus.Id);
                    }
                }
            }

            // Setup Ministry Filter
            rcwMinistry.Visible    = GetAttributeValue("MinistryFilterDisplayMode").AsInteger() > 1;
            cblMinistry.DataSource = ReservationMinistryCache.All();
            cblMinistry.DataBind();

            if (!string.IsNullOrWhiteSpace(this.GetUserPreference("Ministries")))
            {
                cblMinistry.SetValues(this.GetUserPreference("Ministries").SplitDelimitedValues());
            }

            // Setup Approval Filter
            rcwApproval.Visible = GetAttributeValue("ApprovalFilterDisplayMode").AsInteger() > 1;
            cblApproval.BindToEnum <ReservationApprovalState>();

            if (!string.IsNullOrWhiteSpace(this.GetUserPreference("Approval State")))
            {
                cblApproval.SetValues(this.GetUserPreference("Approval State").SplitDelimitedValues());
            }

            // Date Range Filter
            drpDateRange.Visible       = GetAttributeValue("ShowDateRangeFilter").AsBoolean();
            lbDateRangeRefresh.Visible = drpDateRange.Visible;
            drpDateRange.LowerValue    = FilterStartDate;
            drpDateRange.UpperValue    = FilterEndDate;

            // Get the View Modes, and only show them if more than one is visible
            var viewsVisible = new List <bool> {
                GetAttributeValue("ShowDayView").AsBoolean(),
                GetAttributeValue("ShowWeekView").AsBoolean(),
                GetAttributeValue("ShowMonthView").AsBoolean()
            };

            var howManyVisible = viewsVisible.Where(v => v).Count();

            btnDay.Visible   = howManyVisible > 1 && viewsVisible[0];
            btnWeek.Visible  = howManyVisible > 1 && viewsVisible[1];
            btnMonth.Visible = howManyVisible > 1 && viewsVisible[2];

            // Set filter visibility
            bool showFilter = (pnlCalendar.Visible || rcwCampus.Visible || rcwMinistry.Visible || rcwApproval.Visible || drpDateRange.Visible);

            pnlFilters.Visible = showFilter;
            pnlList.CssClass   = showFilter ? "col-md-9" : "col-md-12";

            return(true);
        }