private void WriteHtml(IHtmlWriter html, DebugRegion region, int depth) { if (region.Element != null) { html.WriteElementLine("p", "zone inherits from '" + region.Element.Name + "' region"); if (depth != 1) { StartIndent(html, false); WriteDebugInfo(html, region.Element.GetDebugInfo(), 2); EndIndent(html); } } if (region.RepeatType != null) { html.WriteOpenTag("p"); html.WriteText("Repeat region for each "); html.WriteElement("i", region.RepeatType.DisplayName()); if (!string.IsNullOrEmpty(region.RepeatScope)) { html.WriteText(" in '" + region.RepeatScope + "' scope"); } html.WriteText(" from "); html.WriteElement("i", region.ListType.DisplayName()); if (!string.IsNullOrEmpty(region.ListScope)) { html.WriteText(" in '" + region.ListScope + "' scope"); } html.WriteCloseTag("p"); html.WriteLine(); } if (region.Scope != null) { if (region.Scope.Scopes != null) { html.WriteElementLine("p", "zone data scope"); StartIndent(html, false); WriteDebugInfo(html, region.Scope, 3); EndIndent(html); } } if (region.Children != null && region.Children.Count > 0) { html.WriteElementLine("p", "zone has contents"); if (depth != 1) { StartIndent(html, true); WriteDebugInfo(html, region.Children[0], depth - 1); EndIndent(html); } } }
protected override void RenderContents(IHtmlWriter writer, IDotvvmRequestContext context) { AddAttributesToInput(writer); RenderInputTag(writer); if (isLabelRequired) { if (HasValueBinding(TextProperty)) { writer.AddKnockoutDataBind("text", GetValueBinding(TextProperty).GetKnockoutBindingExpression(this)); writer.RenderBeginTag(TagName); writer.RenderEndTag(); } else if (!string.IsNullOrEmpty(Text)) { writer.RenderBeginTag(TagName); writer.WriteText(Text); writer.RenderEndTag(); } else if (!HasOnlyWhiteSpaceContent()) { writer.RenderBeginTag(TagName); RenderChildren(writer, context); writer.RenderEndTag(); } } }
/// <summary> /// Writes text iff the property contains hard-coded value OR /// writes knockout text binding iff the property contains binding /// </summary> /// <param name="writer">HTML output writer</param> /// <param name="obj">Dotvvm control which contains the <see cref="DotvvmProperty"/> with value to be written</param> /// <param name="property">Value of this property will be written</param> /// <param name="wrapperTag">Name of wrapper tag, null => knockout binding comment</param> public static void WriteTextOrBinding(this IHtmlWriter writer, DotvvmBindableObject obj, DotvvmProperty property, string wrapperTag = null) { var valueBinding = obj.GetValueBinding(property); if (valueBinding != null) { if (wrapperTag == null) { writer.WriteKnockoutDataBindComment("text", valueBinding.GetKnockoutBindingExpression(obj)); writer.WriteKnockoutDataBindEndComment(); } else { writer.AddKnockoutDataBind("text", valueBinding.GetKnockoutBindingExpression(obj)); writer.RenderBeginTag(wrapperTag); writer.RenderEndTag(); } } else { if (wrapperTag != null) { writer.RenderBeginTag(wrapperTag); } writer.WriteText(obj.GetValue(property).ToString()); if (wrapperTag != null) { writer.RenderEndTag(); } } }
protected override void RenderContents(IHtmlWriter writer, IDotvvmRequestContext context) { if (Type == TextBoxType.MultiLine && GetValueBinding(TextProperty) == null) { writer.WriteText(Text); } }
protected override void RenderControl(IHtmlWriter writer) { // begin if (Mode == TextMode.MultiLine) { writer.RenderBeginTag("textarea"); } else { writer.RenderBeginTag("input"); writer.AddAttribute("type", Mode.ToString().ToLower()); } // content var expr = KnockoutBindingHelper.GetBindingExpressionOrNull(TextProperty, this); if (!KnockoutBindingHelper.IsKnockoutBinding(expr)) { if (Mode == TextMode.MultiLine) { writer.WriteText(Text, true); } else { writer.AddAttribute("value", Text); } } else { writer.AddBindingAttribute("value", KnockoutBindingHelper.TranslateToKnockoutProperty(this, TextProperty, expr)); } // end writer.RenderEndTag(); }
protected override void RenderContents(IHtmlWriter writer, IDotvvmRequestContext context) { if (TagName is null) { throw new DotvvmControlException(this, "CheckableControlBase must have a tag name"); } AddAttributesToInput(writer); RenderInputTag(writer); if (isLabelRequired) { if (GetValueBinding(TextProperty) is IValueBinding textBinding) { writer.AddKnockoutDataBind("text", textBinding.GetKnockoutBindingExpression(this)); writer.RenderBeginTag(TagName); writer.RenderEndTag(); } else if (!string.IsNullOrEmpty(Text)) { writer.RenderBeginTag(TagName); writer.WriteText(Text); writer.RenderEndTag(); } else if (!HasOnlyWhiteSpaceContent()) { writer.RenderBeginTag(TagName); RenderChildren(writer, context); writer.RenderEndTag(); } } }
/// <summary> /// Renders the contents inside the control begin and end tags. /// </summary> protected override void RenderContents(IHtmlWriter writer, RenderContext context) { if (RenderOnServer) { // render items bool first = true; foreach (var item in GetIEnumerableFromDataSource(DataSource)) { var value = string.IsNullOrEmpty(ValueMember) ? item : ReflectionUtils.GetObjectProperty(item, ValueMember); var text = string.IsNullOrEmpty(DisplayMember) ? item : ReflectionUtils.GetObjectProperty(item, DisplayMember); if (first) { writer.WriteUnencodedText(Environment.NewLine); first = false; } writer.WriteUnencodedText(" "); //Indent writer.AddAttribute("value", value != null ? value.ToString() : ""); writer.RenderBeginTag("option"); writer.WriteText(text != null ? text.ToString() : ""); writer.RenderEndTag(); writer.WriteUnencodedText(Environment.NewLine); } } }
public virtual void WriteText(string text) { if (StartTagSkipped) { return; } writer.WriteText(text); }
protected override void RenderContents(IHtmlWriter writer, IDotvvmRequestContext context) { if (Text is string t) { writer.WriteText(t); } base.RenderContents(writer, context); }
/// <summary> /// Renders the children. /// </summary> protected override void RenderControl(IHtmlWriter writer, RenderContext context) { // label var textBinding = GetValueBinding(TextProperty); var labelRequired = textBinding != null || !string.IsNullOrEmpty(Text) || !HasOnlyWhiteSpaceContent(); if (labelRequired) { writer.RenderBeginTag("label"); } // prepare changed event attribute var changedBinding = GetCommandBinding(ChangedProperty); if (changedBinding != null) { writer.AddAttribute("onclick", KnockoutHelper.GenerateClientPostBackScript(nameof(Changed), changedBinding, context, this, true, true, isOnChange: true)); } // handle enabled attribute writer.AddKnockoutDataBind("enable", this, EnabledProperty, () => { if (!Enabled) { writer.AddAttribute("disabled", "disabled"); } }); // add ID AddAttributesToRender(writer, context); // render the radio button RenderInputTag(writer); // render the label if (labelRequired) { if (textBinding != null) { writer.AddKnockoutDataBind("text", textBinding); writer.RenderBeginTag("span"); writer.RenderEndTag(); } else if (!string.IsNullOrEmpty(Text)) { writer.WriteText(Text); } else if (!HasOnlyWhiteSpaceContent()) { RenderChildren(writer, context); } writer.RenderEndTag(); } }
protected override void RenderControl(IHtmlWriter writer) { if (InternalScriptUrls != null) { foreach (var script in InternalScriptUrls) { writer.RenderBeginTag("script"); writer.AddAttribute("type", "text/javascript"); writer.AddAttribute("src", script); writer.RenderEndTag(true); } } writer.RenderBeginTag("script"); writer.AddAttribute("type", "text/javascript"); writer.WriteText("(function () { var viewModelData = ", false); writer.WriteText(SerializedViewModel, false); writer.WriteText(";var vm = Redwood.CreateViewModel(viewModelData, new " + ViewModelClientName + "());ko.applyBindings(vm);Redwood.ViewModels['Default'] = vm;})();", false); writer.RenderEndTag(); }
protected override void RenderContents(IHtmlWriter writer, IDotvvmRequestContext context) { if (HasOnlyWhiteSpaceContent()) { writer.WriteText(Text); } else { base.RenderContents(writer, context); } }
private void RenderUploadButton(IHtmlWriter writer) { // render upload button writer.AddAttribute("class", "dotvvm-upload-button"); writer.AddKnockoutDataBind("visible", "!IsBusy()"); writer.RenderBeginTag("span"); writer.AddAttribute("href", "#"); writer.AddAttribute("onclick", "dotvvm.fileUpload.showUploadDialog(this); return false;"); writer.RenderBeginTag("a"); writer.WriteText(UploadButtonText); writer.RenderEndTag(); writer.RenderEndTag(); }
/// <summary> /// Renders the contents inside the control begin and end tags. /// </summary> protected override void RenderContents(IHtmlWriter writer, RenderContext context) { var textBinding = GetBinding(TextProperty); if (textBinding == null && !string.IsNullOrEmpty(Text)) { // render static value of the text property writer.WriteText(Text); } else { // render control contents RenderChildren(writer, context); } }
protected override void RenderContents(IHtmlWriter writer, RenderContext context) { if (shouldRenderText) { if (!HasOnlyWhiteSpaceContent()) { base.RenderContents(writer, context); } else { writer.WriteText(Text); } } }
protected override void RenderContents(IHtmlWriter writer, RenderContext context) { if (RenderOnServer) { if (!string.IsNullOrWhiteSpace(EmptyItemText)) { writer.RenderBeginTag("option"); writer.WriteText(EmptyItemText); writer.RenderEndTag(); } } base.RenderContents(writer, context); }
protected override void RenderContents(IHtmlWriter writer, RenderContext context) { var textBinding = GetBinding(TextProperty); if (textBinding?.Javascript == null) { if (!string.IsNullOrEmpty(Text)) { writer.WriteText(Text); } else { base.RenderContents(writer, context); } } }
/// <summary> /// Renders the contents inside the control begin and end tags. /// </summary> protected override void RenderContents(IHtmlWriter writer, IDotvvmRequestContext context) { if (!HasValueBinding(TextProperty) || RenderOnServer) { if (!string.IsNullOrEmpty(Text)) { // render static value of the text property writer.WriteText(Text); } else { // render control contents RenderChildren(writer, context); } } }
/// <summary> /// Renders the contents inside the control begin and end tags. /// </summary> protected override void RenderContents(IHtmlWriter writer, RenderContext context) { if (shouldRenderText) { if (!string.IsNullOrEmpty(Text)) { // render static value of the text property writer.WriteText(Text); } else { // render control contents RenderChildren(writer, context); } } }
protected override void RenderContents(IHtmlWriter writer, IDotvvmRequestContext context) { if (!HasValueBinding(TextProperty) && IsPropertySet(TextProperty)) { if (!HasOnlyWhiteSpaceContent()) { throw new DotvvmControlException(this, "Text property and inner content of the <pwa:OfflineAlert> control cannot be set at the same time!"); } writer.WriteText(Text); } else { base.RenderContents(writer, context); } }
protected override void RenderContents(IHtmlWriter writer, RenderContext context) { if (!renderAsKnockoutBinding) { var textToDisplay = ""; if (!string.IsNullOrEmpty(FormatString)) { textToDisplay = string.Format("{0:" + FormatString + "}", GetValue(TextProperty)); } else { textToDisplay = GetValue(TextProperty)?.ToString() ?? ""; } writer.WriteText(textToDisplay); } }
private void RenderLabel(IHtmlWriter writer) { writer.AddAttribute("class", "control-label col-sm-2"); var textBinding = GetBinding(LabelTextProperty); if (textBinding != null) { writer.AddKnockoutDataBind("text", this, LabelTextProperty, () => { }); writer.RenderBeginTag("label"); writer.RenderEndTag(); } else { writer.RenderBeginTag("label"); writer.WriteText(LabelText); writer.RenderEndTag(); } }
protected override void RenderContents(IHtmlWriter writer, RenderContext context) { if (ButtonTagName == ButtonTagName.button) { if (!HasBinding(TextProperty)) { // render contents inside if (IsPropertySet(TextProperty)) { writer.WriteText(Text); } else { base.RenderContents(writer, context); } } } }
static void WriteResourceInfo(NamedResource resource, IHtmlWriter writer, bool preload) { var comment = $"Resource {resource.Name} of type {resource.Resource.GetType().Name}."; if (resource.Resource is ILinkResource linkResource) { comment += $" Pointing to {string.Join(", ", linkResource.GetLocations().Select(l => l.GetType().Name))}."; } if (preload) { comment = "[preload link] " + comment; } writer.WriteUnencodedText("\n <!-- "); writer.WriteText(comment); writer.WriteUnencodedText(" -->\n "); // ^~~~ most likely this info will be written directly in the <body> or <head>, so it should be indented by one level. // we don't have any better way to know how we should indent }
protected override void RenderContents(IHtmlWriter writer, IDotvvmRequestContext context) { if (ButtonTagName == ButtonTagName.button) { if (!HasValueBinding(TextProperty) && IsPropertySet(TextProperty)) { // render contents inside if (!HasOnlyWhiteSpaceContent()) { throw new DotvvmControlException(this, "Text property and inner content of the <dot:Button> control cannot be set at the same time!"); } writer.WriteText(Text); } else { base.RenderContents(writer, context); } } }
protected override void RenderControl(IHtmlWriter writer) { var textExpression = KnockoutBindingHelper.GetBindingExpressionOrNull(TextProperty, this); var needsLabel = KnockoutBindingHelper.IsKnockoutBinding(textExpression) || !string.IsNullOrEmpty(Text); // render the checkbox writer.RenderBeginTag("input"); writer.AddAttribute("type", "checkbox"); var isCheckedExpression = KnockoutBindingHelper.GetBindingExpressionOrNull(IsCheckedProperty, this); if (KnockoutBindingHelper.IsKnockoutBinding(isCheckedExpression)) { writer.AddBindingAttribute("checked", KnockoutBindingHelper.TranslateToKnockoutProperty(this, IsCheckedProperty, isCheckedExpression)); } else { writer.AddAttribute("checked", IsChecked ? "checked" : ""); } if (needsLabel) { EnsureHasID(); writer.AddAttribute("id", ID); } writer.RenderEndTag(); // render the label if (needsLabel) { writer.RenderBeginTag("label"); writer.AddAttribute("for", ID); if (KnockoutBindingHelper.IsKnockoutBinding(textExpression)) { writer.AddBindingAttribute("", KnockoutBindingHelper.TranslateToKnockoutProperty(this, TextProperty, textExpression)); } else { writer.WriteText(Text, true); } writer.RenderEndTag(); } }
protected override void RenderContents(IHtmlWriter writer, IDotvvmRequestContext context) { if (!renderAsKnockoutBinding) { var textToDisplay = ""; if (isFormattingRequired) { var formatString = FormatString; if (string.IsNullOrEmpty(formatString)) { formatString = "G"; } textToDisplay = string.Format("{0:" + formatString + "}", GetValue(TextProperty)); } else { textToDisplay = GetValue(TextProperty)?.ToString() ?? ""; } writer.WriteText(textToDisplay); } }
protected override void RenderContents(IHtmlWriter writer, IDotvvmRequestContext context) { if (ButtonTagName == ButtonTagName.button) { if (!HasValueBinding(TextProperty)) { // render contents inside if (IsPropertySet(TextProperty)) { if (!HasOnlyWhiteSpaceContent()) { throw new DotvvmControlException(this, "Text property and inner content of the <dot:Button> control cannot be set at the same time!"); } writer.WriteText(Text); } else { base.RenderContents(writer, context); } } } }
protected override void RenderContents(IHtmlWriter writer, IDotvvmRequestContext context) { writer.WriteText(Text); base.RenderContents(writer, context); }
protected override void RenderContents(IHtmlWriter writer, IDotvvmRequestContext context) { if (shouldRenderText) { if (!HasOnlyWhiteSpaceContent()) { base.RenderContents(writer, context); } else { writer.WriteText(Text); } } }
/// <summary> /// Renders the children. /// </summary> protected override void RenderControl(IHtmlWriter writer, RenderContext context) { // label var textBinding = GetBinding(TextProperty); var labelRequired = textBinding != null || !string.IsNullOrEmpty(Text) || !HasOnlyWhiteSpaceContent(); if (labelRequired) { writer.RenderBeginTag("label"); } // prepare changed event attribute var changedBinding = GetCommandBinding(ChangedProperty); if (changedBinding != null) { writer.AddAttribute("onclick", KnockoutHelper.GenerateClientPostBackScript(changedBinding, context, this, true, true)); } // handle enabled attribute writer.AddKnockoutDataBind("enable", this, EnabledProperty, () => { if (!Enabled) { writer.AddAttribute("disabled", "disabled"); } }); // add ID AddControlIdAttribute(writer); // render the radio button RenderInputTag(writer); // render the label if (labelRequired) { if (textBinding != null) { writer.AddKnockoutDataBind("text", this, TextProperty, () => { }); writer.RenderBeginTag("span"); writer.RenderEndTag(); } else if (!string.IsNullOrEmpty(Text)) { writer.WriteText(Text); } else if (!HasOnlyWhiteSpaceContent()) { RenderChildren(writer, context); } writer.RenderEndTag(); } }
/// <summary> /// Renders the control into the specified writer. /// </summary> protected override void RenderControl(IHtmlWriter writer, RenderContext context) { var textBinding = GetBinding(TextProperty); if (textBinding != null && !RenderOnServer && textBinding.Javascript != null) { var expression = textBinding.Javascript; if (!string.IsNullOrEmpty(FormatString)) { expression = "dotvvm.formatString(" + JsonConvert.SerializeObject(FormatString) + ", " + expression + ")"; } writer.AddKnockoutDataBind(HtmlEncode ? "text" : "html", expression); AddAttributesToRender(writer, context); writer.RenderBeginTag("span"); writer.RenderEndTag(); } else { if (AlwaysRenderSpan) { AddAttributesToRender(writer, context); writer.RenderBeginTag("span"); } var textToDisplay = ""; if (!string.IsNullOrEmpty(FormatString)) { textToDisplay = string.Format("{0:" + FormatString + "}", GetValue(TextProperty)); } else { textToDisplay = GetValue(TextProperty)?.ToString() ?? ""; } if (HtmlEncode) { writer.WriteText(textToDisplay); } else { writer.WriteUnencodedText(textToDisplay); } if (AlwaysRenderSpan) { writer.RenderEndTag(); } } }
/// <summary> /// Renders the control to the writer. /// </summary> protected override void RenderControl(IHtmlWriter writer) { writer.RenderBeginTag("select"); var itemsSourceExpression = KnockoutBindingHelper.GetBindingExpressionOrNull(ItemsSourceProperty, this); if (KnockoutBindingHelper.IsKnockoutBinding(itemsSourceExpression)) { // render items on client writer.AddBindingAttribute("options", KnockoutBindingHelper.TranslateToKnockoutProperty(this, ItemsSourceProperty, itemsSourceExpression)); if (DisplayNullItem) { writer.AddBindingAttribute("optionsCaption", NullItemText); } if (DisplayMemberBinding != null) { writer.AddBindingAttribute("optionsText", KnockoutBindingHelper.TranslateToKnockoutProperty(this, DisplayMemberBindingProperty, DisplayMemberBinding)); } if (ValueMemberBinding != null) { writer.AddBindingAttribute("optionsValue", KnockoutBindingHelper.TranslateToKnockoutProperty(this, ValueMemberBindingProperty, ValueMemberBinding)); } } else if (ItemsSource != null) { // render items on server if (DisplayNullItem) { writer.RenderBeginTag("option"); writer.AddAttribute("value", ""); writer.WriteText(NullItemText, true); writer.RenderEndTag(); } // render on server foreach (var item in ItemsSource) { var itemValue = EvaluateValueMember(item); var itemText = (EvaluateDisplayMember(item) ?? "").ToString(); var isSelected = (itemValue == null && SelectedValue == null) || itemValue.Equals(SelectedValue); writer.RenderBeginTag("option"); writer.AddAttribute("value", (itemValue ?? "").ToString()); writer.WriteText(itemText, true); if (isSelected) { writer.AddAttribute("selected", "selected"); } writer.RenderEndTag(); } } }
protected override void RenderControl(IHtmlWriter writer, IDotvvmRequestContext context) { RenderState r = default; r.RenderSpanElement = true; foreach (var(prop, value) in properties) { TouchProperty(prop, value, ref r); } r.HtmlState.RendersHtmlTag = r.RenderSpanElement; if (base.RenderBeforeControl(in r.BaseState, writer, context)) { return; } base.AddAttributesCore(writer, ref r.HtmlState); var textBinding = r.Text as IValueBinding; var isFormattingRequired = (r.HasFormattingStuff || textBinding != null) && this.IsFormattingRequired; // render Knockout data-bind string expression = null; if (textBinding != null && !r.HtmlState.RenderOnServer(this)) { expression = textBinding.GetKnockoutBindingExpression(this); if (isFormattingRequired) { // almost always the Literal will be rendered before script resources are, so requesting the resource in render should be safe. In case it's not, user can always add it manually (the error message should be quite clear). context.ResourceManager.AddCurrentCultureGlobalizationResource(); expression = "dotvvm.globalize.formatString(" + JsonConvert.ToString(FormatString) + ", " + expression + ")"; } if (r.RenderSpanElement) { writer.AddKnockoutDataBind("text", expression); } } // render start tag if (r.RenderSpanElement) { writer.RenderBeginTag(TagName); } else if (expression != null) { writer.WriteKnockoutDataBindComment("text", expression); } if (expression == null) { string textToDisplay; if (isFormattingRequired) { var formatString = FormatString; if (string.IsNullOrEmpty(formatString)) { formatString = "G"; } textToDisplay = string.Format("{0:" + formatString + "}", EvalPropertyValue(TextProperty, r.Text)); } else { textToDisplay = EvalPropertyValue(TextProperty, r.Text)?.ToString() ?? ""; } writer.WriteText(textToDisplay); } // render end tag if (r.RenderSpanElement) { writer.RenderEndTag(); } else if (expression != null) { writer.WriteKnockoutDataBindEndComment(); } base.RenderAfterControl(in r.BaseState, writer); }
/// <summary> /// Renders the control into the specified writer. /// </summary> protected override void RenderControl(IHtmlWriter writer, RenderContext context) { var textBinding = GetBinding(TextProperty); if (textBinding != null && !RenderOnServer) { var expression = textBinding.TranslateToClientScript(this, TextProperty); if (!string.IsNullOrEmpty(FormatString)) { expression = "redwood.formatString(" + JsonConvert.SerializeObject(FormatString) + ", " + expression + ")"; } writer.AddKnockoutDataBind(HtmlEncode ? "text" : "html", expression); writer.RenderBeginTag("span"); writer.RenderEndTag(); } else { var textToDisplay = Text; if (!string.IsNullOrEmpty(FormatString)) { textToDisplay = string.Format("{0:" + FormatString + "}", textToDisplay); } if (HtmlEncode) { writer.WriteText(textToDisplay); } else { writer.WriteUnencodedText(textToDisplay); } } }
protected override void RenderContents(IHtmlWriter writer, RenderContext context) { writer.WriteText(Text); base.RenderContents(writer, context); }
/// <summary> /// Renders the contents inside the control begin and end tags. /// </summary> protected override void RenderContents(IHtmlWriter writer, RenderContext context) { if (Type == TextBoxType.MultiLine && GetValueBinding(TextProperty) == null) { writer.WriteText(Text); } }