private void RenderTableBeginTag(BocDateTimeValueRenderingContext renderingContext, TextBox dateTextBox, TextBox timeTextBox) { if (!IsControlHeightEmpty(renderingContext.Control) && IsControlHeightEmpty(dateTextBox) && IsControlHeightEmpty(timeTextBox)) { renderingContext.Writer.AddStyleAttribute(HtmlTextWriterStyle.Height, "100%"); } if (IsControlWidthEmpty(dateTextBox) && IsControlWidthEmpty(timeTextBox)) { if (IsControlWidthEmpty(renderingContext.Control)) { renderingContext.Writer.AddStyleAttribute(HtmlTextWriterStyle.Width, c_defaultControlWidth); } else { if (!renderingContext.Control.Width.IsEmpty) { renderingContext.Writer.AddStyleAttribute(HtmlTextWriterStyle.Width, renderingContext.Control.Width.ToString()); } else { renderingContext.Writer.AddStyleAttribute(HtmlTextWriterStyle.Width, renderingContext.Control.Style["width"]); } } } renderingContext.Writer.AddAttribute(HtmlTextWriterAttribute.Cellspacing, "0"); renderingContext.Writer.AddAttribute(HtmlTextWriterAttribute.Cellpadding, "0"); renderingContext.Writer.AddAttribute(HtmlTextWriterAttribute.Border, "0"); renderingContext.Writer.AddStyleAttribute("display", "inline"); renderingContext.Writer.RenderBeginTag(HtmlTextWriterTag.Table); // Begin table }
private void RenderTimeCell(BocDateTimeValueRenderingContext renderingContext, bool hasDateField, bool hasTimeField, TextBox timeTextBox, string timeTextBoxSize) { if (!hasTimeField) { return; } renderingContext.Writer.AddStyleAttribute(HtmlTextWriterStyle.Width, timeTextBoxSize); if (hasDateField) { renderingContext.Writer.AddStyleAttribute("padding-left", "0.3em"); } renderingContext.Writer.RenderBeginTag(HtmlTextWriterTag.Td); // Begin td if (!IsControlHeightEmpty(renderingContext.Control) && IsControlHeightEmpty(timeTextBox)) { renderingContext.Writer.AddStyleAttribute(HtmlTextWriterStyle.Height, "100%"); } renderingContext.Writer.AddStyleAttribute(HtmlTextWriterStyle.Width, "100%"); timeTextBox.RenderControl(renderingContext.Writer); renderingContext.Writer.RenderEndTag(); // End td }
private bool DetermineClientScriptLevel(IDatePickerButton datePickerButton, BocDateTimeValueRenderingContext renderingContext) { if (!datePickerButton.EnableClientScript) { return(false); } return(_clientScriptBehavior.IsBrowserCapableOfScripting(renderingContext.HttpContext, renderingContext.Control)); }
private void InsertDummyCellForOpera(BocDateTimeValueRenderingContext renderingContext, bool hasDatePicker) { if (hasDatePicker || renderingContext.HttpContext.Request.Browser.Browser != "Opera") { return; } renderingContext.Writer.AddStyleAttribute(HtmlTextWriterStyle.Width, "0%"); renderingContext.Writer.RenderBeginTag(HtmlTextWriterTag.Td); // Begin td renderingContext.Writer.Write(" "); renderingContext.Writer.RenderEndTag(); // End td }
private void RenderDatePickerCell(BocDateTimeValueRenderingContext renderingContext, bool hasDatePicker, IDatePickerButton datePickerButton) { if (!hasDatePicker) { return; } renderingContext.Writer.AddStyleAttribute(HtmlTextWriterStyle.Width, "0%"); renderingContext.Writer.AddStyleAttribute("padding-left", "0.3em"); renderingContext.Writer.RenderBeginTag(HtmlTextWriterTag.Td); // Begin td datePickerButton.RenderControl(renderingContext.Writer); renderingContext.Writer.RenderEndTag(); // End td }
private string GetTimeTextBoxSize(BocDateTimeValueRenderingContext renderingContext, int timeTextBoxWidthPercentage) { string timeTextBoxSize; if (!renderingContext.Control.TimeTextBoxStyle.Width.IsEmpty) { timeTextBoxSize = renderingContext.Control.TimeTextBoxStyle.Width.ToString(); } else { timeTextBoxSize = timeTextBoxWidthPercentage + "%"; } return(timeTextBoxSize); }
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; } }
public void SetUp() { Initialize(); _control = MockRepository.GenerateStub <IBocDateTimeValue>(); _control.Stub(stub => stub.ClientID).Return(c_dateValueID); _control.Stub(stub => stub.ControlType).Return("BocDateTimeValue"); _control.Stub(stub => stub.GetDateValueName()).Return(c_dateValueName); _control.Stub(stub => stub.GetTimeValueName()).Return(c_timeValueName); _dateStyle = new SingleRowTextBoxStyle(); _timeStyle = new SingleRowTextBoxStyle(); _control.Stub(stub => stub.DateTextBoxStyle).Return(_dateStyle); _control.Stub(stub => stub.TimeTextBoxStyle).Return(_timeStyle); var pageStub = MockRepository.GenerateStub <IPage>(); pageStub.Stub(stub => stub.WrappedInstance).Return(new PageMock()); pageStub.Stub(stub => stub.ClientScript).Return(MockRepository.GenerateStub <IClientScriptManager>()); _control.Stub(stub => stub.Page).Return(pageStub); var datePickerButton = MockRepository.GenerateStub <IDatePickerButton> (); datePickerButton.Stub(stub => stub.EnableClientScript).Return(true); datePickerButton.Stub(stub => stub.RenderControl(Html.Writer)).WhenCalled(invocation => Html.Writer.WriteLine("DatePicker")); _control.Stub(stub => stub.DatePickerButton).Return(datePickerButton); StateBag stateBag = new StateBag(); _control.Stub(stub => stub.Attributes).Return(new AttributeCollection(stateBag)); _control.Stub(stub => stub.Style).Return(_control.Attributes.CssStyle); _control.Stub(stub => stub.DateTextBoxStyle).Return(new TextBoxStyle()); _control.Stub(stub => stub.TimeTextBoxStyle).Return(new TextBoxStyle()); _control.Stub(stub => stub.DateTimeTextBoxStyle).Return(new TextBoxStyle()); _control.Stub(stub => stub.ControlStyle).Return(new Style(stateBag)); _control.Stub(stub => stub.ProvideMaxLength).Return(true); var dateTimeFormatter = new DateTimeFormatter(); _control.Stub(stub => stub.DateTimeFormatter).Return(dateTimeFormatter); _dateTextBox = new StubTextBox(); _timeTextBox = new StubTextBox(); _renderingContext = new BocDateTimeValueRenderingContext(HttpContext, Html.Writer, _control); }
/// <summary> /// Renders an inline table consisting of one row with up to three cells, depending on <see cref="IBocDateTimeValue.ActualValueType"/>. /// The first one for the date textbox, second for the <see cref="DatePickerButton"/> and third for the time textbox. /// The text boxes are rendered directly, the date picker is responsible for rendering itself. /// </summary> public void Render(BocDateTimeValueRenderingContext renderingContext) { ArgumentUtility.CheckNotNull("renderingContext", renderingContext); AddAttributesToRender(renderingContext, true); renderingContext.Writer.RenderBeginTag(HtmlTextWriterTag.Div); if (renderingContext.Control.IsReadOnly) { RenderReadOnlyValue(renderingContext); } else { RenderEditModeControls(renderingContext); } renderingContext.Writer.RenderEndTag(); }
private int GetDateTextBoxWidthPercentage(BocDateTimeValueRenderingContext renderingContext, bool hasDateField, bool hasTimeField) { int dateTextBoxWidthPercentage = 0; if (hasDateField && hasTimeField && renderingContext.Control.ShowSeconds) { dateTextBoxWidthPercentage = 55; } else if (hasDateField && hasTimeField) { dateTextBoxWidthPercentage = 60; } else if (hasDateField) { dateTextBoxWidthPercentage = 100; } return(dateTextBoxWidthPercentage); }
private void RenderEditModeControls(BocDateTimeValueRenderingContext renderingContext) { ArgumentUtility.CheckNotNull("renderingContext", renderingContext); var formatter = renderingContext.Control.DateTimeFormatter; var dateTextBox = new RenderOnlyTextBox { ID = renderingContext.Control.GetDateValueName(), ClientIDMode = ClientIDMode.Static }; Initialize(renderingContext, dateTextBox, renderingContext.Control.DateTextBoxStyle, formatter.GetDateMaxLength()); dateTextBox.Text = renderingContext.Control.Value.HasValue ? formatter.FormatDateValue(renderingContext.Control.Value.Value) : renderingContext.Control.DateString; dateTextBox.Page = renderingContext.Control.Page.WrappedInstance; var timeTextBox = new RenderOnlyTextBox { ID = renderingContext.Control.GetTimeValueName(), ClientIDMode = ClientIDMode.Static }; var showSeconds = renderingContext.Control.ShowSeconds; Initialize(renderingContext, timeTextBox, renderingContext.Control.TimeTextBoxStyle, formatter.GetTimeMaxLength(showSeconds)); timeTextBox.Text = renderingContext.Control.Value.HasValue ? formatter.FormatTimeValue(renderingContext.Control.Value.Value, showSeconds) : renderingContext.Control.TimeString; timeTextBox.Page = renderingContext.Control.Page.WrappedInstance; var datePickerButton = renderingContext.Control.DatePickerButton; datePickerButton.AlternateText = renderingContext.Control.GetDatePickerText(); datePickerButton.IsDesignMode = renderingContext.Control.IsDesignMode; RenderTableBeginTag(renderingContext, dateTextBox, timeTextBox); // Begin table renderingContext.Writer.RenderBeginTag(HtmlTextWriterTag.Tr); // Begin tr 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; } bool canScript = DetermineClientScriptLevel(datePickerButton, renderingContext); bool hasDatePicker = hasDateField && canScript; int dateTextBoxWidthPercentage = GetDateTextBoxWidthPercentage(renderingContext, hasDateField, hasTimeField); string dateTextBoxSize = GetDateTextBoxSize(renderingContext, dateTextBoxWidthPercentage); string timeTextBoxSize = GetTimeTextBoxSize(renderingContext, 100 - dateTextBoxWidthPercentage); RenderDateCell(renderingContext, hasDateField, dateTextBox, dateTextBoxSize); RenderDatePickerCell(renderingContext, hasDatePicker, datePickerButton); //HACK: Opera has problems with inline tables and may collapse contents unless a cell with width 0% is present InsertDummyCellForOpera(renderingContext, hasDatePicker); RenderTimeCell(renderingContext, hasDateField, hasTimeField, timeTextBox, timeTextBoxSize); renderingContext.Writer.RenderEndTag(); // End tr renderingContext.Writer.RenderEndTag(); // End table }
private void RenderReadOnlyValue(BocDateTimeValueRenderingContext renderingContext) { ArgumentUtility.CheckNotNull("renderingContext", renderingContext); Label label = new Label(); if (renderingContext.Control.IsDesignMode && string.IsNullOrEmpty(label.Text)) { label.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; DateTime dateTime = renderingContext.Control.Value.Value; if (renderingContext.Control.ActualValueType == BocDateTimeValueType.DateTime) { label.Text = formatter.FormatDateValue(dateTime) + ' ' + formatter.FormatTimeValue(dateTime, renderingContext.Control.ShowSeconds); } else if (renderingContext.Control.ActualValueType == BocDateTimeValueType.Date) { label.Text = formatter.FormatDateValue(dateTime); } else { label.Text = dateTime.ToString(); } } else { label.Text = " "; } } 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); }