Example #1
0
        private static void RenderLabel(Label label, BocDateTimeValueRenderingContext renderingContext)
        {
            label.Height = Unit.Empty;
            label.Width  = Unit.Empty;
            label.ApplyStyle(renderingContext.Control.CommonStyle);
            label.ApplyStyle(renderingContext.Control.LabelStyle);

            bool isControlHeightEmpty = renderingContext.Control.Height.IsEmpty && string.IsNullOrEmpty(renderingContext.Control.Style["height"]);
            bool isLabelHeightEmpty   = label.Height.IsEmpty && string.IsNullOrEmpty(label.Style["height"]);

            if (!isControlHeightEmpty && isLabelHeightEmpty)
            {
                renderingContext.Writer.AddStyleAttribute(HtmlTextWriterStyle.Height, "100%");
            }

            bool isControlWidthEmpty = renderingContext.Control.Width.IsEmpty && string.IsNullOrEmpty(renderingContext.Control.Style["width"]);
            bool isLabelWidthEmpty   = label.Width.IsEmpty && string.IsNullOrEmpty(label.Style["width"]);

            if (!isControlWidthEmpty && isLabelWidthEmpty)
            {
                if (!renderingContext.Control.Width.IsEmpty)
                {
                    renderingContext.Writer.AddStyleAttribute(HtmlTextWriterStyle.Width, renderingContext.Control.Width.ToString());
                }
                else
                {
                    renderingContext.Writer.AddStyleAttribute(HtmlTextWriterStyle.Width, renderingContext.Control.Style["width"]);
                }
            }

            label.RenderControl(renderingContext.Writer);
        }
Example #2
0
        public string GetPositioningCssClass(BocDateTimeValueRenderingContext renderingContext, DateTimeValuePart part)
        {
            var hasTimeFieldWithSeconds = renderingContext.Control.ShowSeconds && renderingContext.Control.ActualValueType != BocDateTimeValueType.Date;
            var formatter = renderingContext.Control.DateTimeFormatter;

            return(string.Format(
                       "boc{0}{1}Hours{2}",
                       part,
                       formatter.Is12HourTimeFormat() ? 12 : 24,
                       hasTimeFieldWithSeconds ? "WithSeconds" : string.Empty));
        }
Example #3
0
        private void Initialize(BocDateTimeValueRenderingContext renderingContext, TextBox textBox, SingleRowTextBoxStyle textBoxStyle, int maxLength)
        {
            textBox.Enabled  = renderingContext.Control.Enabled;
            textBox.ReadOnly = !renderingContext.Control.Enabled;
            textBox.Width    = Unit.Empty;
            textBox.Height   = Unit.Empty;
            textBox.ApplyStyle(renderingContext.Control.CommonStyle);
            renderingContext.Control.DateTimeTextBoxStyle.ApplyStyle(textBox);
            textBoxStyle.ApplyStyle(textBox);

            if (renderingContext.Control.ProvideMaxLength)
            {
                textBox.MaxLength = maxLength;
            }
        }
Example #4
0
        public void Render(BocDateTimeValueRenderingContext renderingContext)
        {
            ArgumentUtility.CheckNotNull("renderingContext", renderingContext);

            AddAttributesToRender(renderingContext);
            renderingContext.Writer.RenderBeginTag(HtmlTextWriterTag.Span);

            if (renderingContext.Control.IsReadOnly)
            {
                RenderReadOnlyValue(renderingContext);
            }
            else
            {
                RenderEditModeControls(renderingContext);
            }

            renderingContext.Writer.RenderEndTag();
        }
Example #5
0
        private void RenderReadOnlyValue(BocDateTimeValueRenderingContext renderingContext)
        {
            ArgumentUtility.CheckNotNull("renderingContext", renderingContext);

            var dateLabel = new Label();
            var timeLabel = new Label();

            if (renderingContext.Control.IsDesignMode && !renderingContext.Control.Value.HasValue)
            {
                dateLabel.Text = c_designModeEmptyLabelContents;
                //  Too long, can't resize in designer to less than the content's width
                //  Control.label.Text = "[ " + this.GetType().Name + " \"" + this.ID + "\" ]";
            }
            else
            {
                if (renderingContext.Control.Value.HasValue)
                {
                    var formatter = renderingContext.Control.DateTimeFormatter;

                    var dateTime = renderingContext.Control.Value.Value;

                    dateLabel.Text = formatter.FormatDateValue(dateTime);
                    dateLabel.Attributes.Add("data-value", dateTime.ToString("yyyy-MM-dd"));

                    if (renderingContext.Control.ActualValueType == BocDateTimeValueType.DateTime)
                    {
                        timeLabel.Text = formatter.FormatTimeValue(dateTime, renderingContext.Control.ShowSeconds);
                        timeLabel.Attributes.Add("data-value", dateTime.ToString("HH:mm:ss"));
                    }
                }
            }

            RenderLabel(dateLabel, renderingContext);
            if (renderingContext.Control.ActualValueType == BocDateTimeValueType.DateTime)
            {
                renderingContext.Writer.Write(' ');
                RenderLabel(timeLabel, renderingContext);
            }
        }
Example #6
0
        private void RenderEditModeControls(BocDateTimeValueRenderingContext renderingContext)
        {
            var formatter = renderingContext.Control.DateTimeFormatter;

            var dateTextBox = _dateTextBox;

            dateTextBox.ID       = renderingContext.Control.GetDateValueName();
            dateTextBox.CssClass = CssClassDate;
            Initialize(
                renderingContext,
                dateTextBox,
                renderingContext.Control.DateTextBoxStyle,
                formatter.GetDateMaxLength());
            dateTextBox.Text = renderingContext.Control.DateString;
            dateTextBox.Page = renderingContext.Control.Page.WrappedInstance;

            var timeTextBox = _timeTextBox;

            timeTextBox.ID       = renderingContext.Control.GetTimeValueName();
            timeTextBox.CssClass = CssClassTime;
            Initialize(
                renderingContext,
                timeTextBox,
                renderingContext.Control.TimeTextBoxStyle,
                formatter.GetTimeMaxLength(renderingContext.Control.ShowSeconds));
            timeTextBox.Text = renderingContext.Control.TimeString;
            timeTextBox.Page = renderingContext.Control.Page.WrappedInstance;

            var datePickerButton = renderingContext.Control.DatePickerButton;

            datePickerButton.AlternateText = renderingContext.Control.GetDatePickerText();
            datePickerButton.IsDesignMode  = renderingContext.Control.IsDesignMode;

            if (IsDiagnosticMetadataRenderingEnabled)
            {
                dateTextBox.Attributes[DiagnosticMetadataAttributesForObjectBinding.BocDateTimeValueDateField] = "true";
                dateTextBox.Attributes[DiagnosticMetadataAttributes.TriggersPostBack] = dateTextBox.AutoPostBack.ToString().ToLower();

                timeTextBox.Attributes[DiagnosticMetadataAttributesForObjectBinding.BocDateTimeValueTimeField] = "true";
                var showSeconds = renderingContext.Control.ShowSeconds;
                timeTextBox.Attributes[DiagnosticMetadataAttributesForObjectBinding.BocDateTimeValueTimeFieldHasSeconds] = showSeconds.ToString().ToLower();
                timeTextBox.Attributes[DiagnosticMetadataAttributes.TriggersPostBack] = timeTextBox.AutoPostBack.ToString().ToLower();
            }

            bool hasDateField = false;
            bool hasTimeField = false;

            switch (renderingContext.Control.ActualValueType)
            {
            case BocDateTimeValueType.Date:
                hasDateField = true;
                break;

            case BocDateTimeValueType.DateTime:
            case BocDateTimeValueType.Undefined:
                hasDateField = true;
                hasTimeField = true;
                break;
            }

            if (hasDateField)
            {
                renderingContext.Writer.AddAttribute(
                    HtmlTextWriterAttribute.Class, CssClassDateInputWrapper + " " + GetPositioningCssClass(renderingContext, DateTimeValuePart.Date));
                renderingContext.Writer.RenderBeginTag(HtmlTextWriterTag.Span);
                dateTextBox.RenderControl(renderingContext.Writer);
                renderingContext.Writer.RenderEndTag();

                datePickerButton.CssClass = GetPositioningCssClass(renderingContext, DateTimeValuePart.Picker);
                datePickerButton.RenderControl(renderingContext.Writer);
            }

            if (hasTimeField)
            {
                renderingContext.Writer.AddAttribute(
                    HtmlTextWriterAttribute.Class, CssClassTimeInputWrapper + " " + GetPositioningCssClass(renderingContext, DateTimeValuePart.Time));
                renderingContext.Writer.RenderBeginTag(HtmlTextWriterTag.Span);
                timeTextBox.RenderControl(renderingContext.Writer);
                renderingContext.Writer.RenderEndTag();
            }
        }