protected override void AddAttributesToRender(IHtmlWriter writer, RenderContext context) { writer.AddAttribute("class", "form-horizontal"); writer.AddAttribute("role", "form"); base.AddAttributesToRender(writer, context); }
/// <summary> /// Renders the input tag. /// </summary> protected override void RenderInputTag(IHtmlWriter writer) { var checkedBinding = GetValueBinding(CheckedProperty); var checkedItemsBinding = GetValueBinding(CheckedItemsProperty); if (checkedBinding != null && checkedItemsBinding == null) { // boolean mode writer.AddKnockoutDataBind("checked", this, CheckedProperty, () => { }); writer.AddKnockoutDataBind("checkedValue", "true"); } else if (checkedBinding == null && checkedItemsBinding != null) { // collection mode writer.AddKnockoutDataBind("checked", this, CheckedItemsProperty, () => { }); writer.AddKnockoutDataBind("checkedValue", this, CheckedValueProperty, () => { var checkedValue = (CheckedValue ?? string.Empty).ToString(); if (!string.IsNullOrEmpty(checkedValue)) { writer.AddKnockoutDataBind("checkedValue", KnockoutHelper.MakeStringLiteral(checkedValue)); } }); } else { throw new Exception("Either the Checked or the CheckedItems property of a CheckBox must be set."); } // render the input tag writer.AddAttribute("type", "checkbox"); writer.RenderSelfClosingTag("input"); }
/// <summary> /// Renders the contents inside the control begin and end tags. /// </summary> protected override void RenderContents(IHtmlWriter writer, IDotvvmRequestContext context) { // render template writer.AddKnockoutDataBind("text", "errorMessage"); writer.RenderBeginTag("li"); writer.RenderEndTag(); }
/// <summary> /// Adds all attributes that should be added to the control begin tag. /// </summary> protected override void AddAttributesToRender(IHtmlWriter writer, RenderContext context) { if (!RenderOnServer) { writer.AddKnockoutDataBind("options", this, DataSourceProperty, () => { }); if (!string.IsNullOrEmpty(DisplayMember)) { writer.AddKnockoutDataBind("optionsText", KnockoutHelper.MakeStringLiteral(DisplayMember)); } if (!string.IsNullOrEmpty(ValueMember)) { writer.AddKnockoutDataBind("optionsValue", KnockoutHelper.MakeStringLiteral(ValueMember)); } } // changed event var selectionChangedBinding = GetCommandBinding(SelectionChangedProperty); if (selectionChangedBinding != null) { writer.AddAttribute("onchange", KnockoutHelper.GenerateClientPostBackScript(selectionChangedBinding, context, this)); } // selected value writer.AddKnockoutDataBind("value", this, SelectedValueProperty, () => { }); base.AddAttributesToRender(writer, context); }
/// <summary> /// Renders the resource in the specified <see cref="IHtmlWriter" />. /// </summary> public override void Render(IHtmlWriter writer, string friendlyName = null) { writer.AddAttribute("type", "text/javascript"); writer.RenderBeginTag("script"); writer.WriteUnencodedText(Code); 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); } } }
/// <summary> /// Renders the resource in the specified <see cref="IHtmlWriter" />. /// </summary> public override void Render(IHtmlWriter writer, IDotvvmRequestContext context) { writer.AddAttribute("href", GetUrl()); writer.AddAttribute("rel", "stylesheet"); writer.AddAttribute("type", "text/css"); writer.RenderSelfClosingTag("link"); }
/// <summary> /// Renders the resource in the specified <see cref="IHtmlWriter" />. /// </summary> public override void Render(IHtmlWriter writer, string friendlyName = null) { writer.AddAttribute("href", GetUrl(friendlyName)); writer.AddAttribute("rel", "stylesheet"); writer.AddAttribute("type", "text/css"); writer.RenderSelfClosingTag("link"); }
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(); }
private void SetupDataBind(IHtmlWriter htmlWriter) { htmlWriter .Prop("id", this.propertyName) .Prop("name", this.propertyName) .Prop("data-bind", "value:" + this.field.PropertyName); }
protected override void RenderControl(IHtmlWriter writer, IDotvvmRequestContext context) { if (!RenderOnServer || GetIEnumerableFromDataSource(DataSource)?.GetEnumerator()?.MoveNext() != true) { base.RenderControl(writer, context); } }
/// <summary> /// Renders the resource in the specified <see cref="IHtmlWriter" />. /// </summary> public override void Render(IHtmlWriter writer, IDotvvmRequestContext context) { if (CdnUrl != null) { writer.AddAttribute("src", CdnUrl); writer.AddAttribute("type", "text/javascript"); writer.RenderBeginTag("script"); writer.RenderEndTag(); if (Url != null && GlobalObjectName != null) { writer.RenderBeginTag("script"); var url = context.TranslateVirtualPath(GetUrl()); writer.WriteUnencodedText(string.Format(CdnFallbackScript, GlobalObjectName, url)); writer.RenderEndTag(); } } else if (Url != null) { writer.AddAttribute("src", GetUrl()); writer.AddAttribute("type", "text/javascript"); writer.RenderBeginTag("script"); writer.RenderEndTag(); } }
/// <summary> /// Adds all attributes that should be added to the control begin tag. /// </summary> protected override void AddAttributesToRender(IHtmlWriter writer, IDotvvmRequestContext context) { object id; if (!IsPropertySet(ClientIDProperty)) { SetValueRaw(ClientIDProperty, id = CreateClientId()); } else { id = GetValueRaw(ClientIDProperty); } if (id != null) Attributes["id"] = id; CheckInnerTextUsage(); // verify that the properties are used only where they should if (!RendersHtmlTag) { EnsureNoAttributesSet(); } else { var attrBindingGroup = new KnockoutBindingGroup(); // render hard-coded HTML attributes foreach (var attribute in Attributes) { if (attribute.Value is IValueBinding) { var binding = attribute.Value as IValueBinding; attrBindingGroup.Add(attribute.Key, binding.GetKnockoutBindingExpression()); if (!RenderOnServer) continue; } AddHtmlAttribute(writer, attribute.Key, attribute.Value); } if (!attrBindingGroup.IsEmpty) { writer.AddKnockoutDataBind("attr", attrBindingGroup); } // handle Visible property AddVisibleAttributeOrBinding(writer); // handle Text property writer.AddKnockoutDataBind("text", this, InnerTextProperty, () => { // inner Text is rendered as attribute only if contains binding // otherwise it is rendered directly as encoded content if (!string.IsNullOrWhiteSpace(InnerText)) { Children.Clear(); Children.Add(new Literal(InnerText)); } }); } base.AddAttributesToRender(writer, context); }
private void AddEventAttributeToRender(IHtmlWriter writer, RenderContext context, string name, RedwoodProperty property) { var binding = GetCommandBinding(property); if (binding != null) { writer.AddAttribute(name, KnockoutHelper.GenerateClientPostBackScript(binding, context, this)); } }
public static void RenderChangedEvent(IHtmlWriter writer, SelectorBase selector) { var selectionChangedBinding = selector.GetCommandBinding(SelectorBase.SelectionChangedProperty); if (selectionChangedBinding != null) { writer.AddAttribute("onchange", KnockoutHelper.GenerateClientPostBackScript(nameof(SelectorBase.SelectionChanged), selectionChangedBinding, selector, isOnChange: true, useWindowSetTimeout: true)); } }
protected override void AddAttributesToRender(IHtmlWriter writer, RenderContext context) { RouteLinkHelpers.WriteRouteLinkHrefAttribute(RouteName, this, writer, context); writer.AddKnockoutDataBind("text", this, TextProperty, () => { }); base.AddAttributesToRender(writer, context); }
protected override void RenderControl(IHtmlWriter writer) { writer.RenderBeginTag(Element); if (htmlAttributesStorage != null) htmlAttributesStorage.Render(writer); base.RenderControl(writer); writer.RenderEndTag(true); }
/// <summary> /// Renders the resource in the specified <see cref="IHtmlWriter" />. /// </summary> public override void Render(IHtmlWriter writer, IDotvvmRequestContext context) { if (string.IsNullOrWhiteSpace(Code)) return; writer.AddAttribute("type", "text/javascript"); writer.RenderBeginTag("script"); writer.WriteUnencodedText(Code); writer.RenderEndTag(); }
protected override void AddAttributesToRender(IHtmlWriter writer, RenderContext context) { AddEventAttributeToRender(writer, context, "onclick", ClickProperty); AddEventAttributeToRender(writer, context, "onchange", ValueChangedProperty); base.AddAttributesToRender(writer, context); }
/// <summary> /// Renders the specified writer. /// </summary> protected override void RenderControl(IHtmlWriter writer) { writer.RenderBeginTag("table"); if (ItemTemplate != null) { var itemsSourceExpression = KnockoutBindingHelper.GetBindingExpressionOrNull(ItemsSourceProperty, this); if (KnockoutBindingHelper.IsKnockoutBinding(itemsSourceExpression)) { // knockout template writer.RenderBeginTag("tbody"); writer.AddBindingAttribute("foreach", KnockoutBindingHelper.TranslateToKnockoutProperty(this, ItemsSourceProperty, itemsSourceExpression)); if (string.IsNullOrEmpty(KeyPropertyName)) { ItemTemplate.DataContext = CreateClientTemplateInstanceDataContextBinding(); } else { ItemTemplate.DataContext = CreateClientTemplateInstanceDataContextBinding(KeyPropertyName); } ItemTemplate.Render(writer); writer.RenderEndTag(); } else if (ItemsSource != null) { writer.RenderBeginTag("tbody"); var index = 0; var rawItemsSourceValue = this.GetRawValue(ItemsSourceProperty); foreach (var item in ItemsSource) { // render on server side writer.RenderBeginTag("tr"); if (string.IsNullOrEmpty(KeyPropertyName) || item == null) { ItemTemplate.DataContext = CreateServerTemplateInstanceDataContextBinding(index); } else { var keyValue = GetKeyValue(item); ItemTemplate.DataContext = CreateServerTemplateInstanceDataContextBinding(KeyPropertyName, keyValue); } ItemTemplate.Render(writer); writer.RenderEndTag(); index++; } writer.RenderEndTag(); } } writer.RenderEndTag(); }
protected override void RenderInputTag(IHtmlWriter writer) { RenderCheckedAttribute(writer); RenderCheckedValueAttribute(writer); RenderTypeAttribute(writer); RenderGroupNameAttribute(writer); writer.RenderSelfClosingTag("input"); }
protected virtual void RenderGroupNameAttribute(IHtmlWriter writer) { var group = new KnockoutBindingGroup(); group.Add("name", this, GroupNameProperty, () => { writer.AddAttribute("name", GroupName); }); writer.AddKnockoutDataBind("attr", group); }
/// <summary> /// Renders the control into the specified writer. /// </summary> protected override void RenderControl(IHtmlWriter writer, IDotvvmRequestContext context) { // render resource links var resources = context.ResourceManager.GetResourcesInOrder().Where(r => r.GetRenderPosition() == ResourceRenderPosition.Head); foreach (var resource in resources) { resource.Render(writer, context); } }
/// <summary> /// Adds all attributes that should be added to the control begin tag. /// </summary> protected override void AddAttributesToRender(IHtmlWriter writer, IDotvvmRequestContext context) { RenderEnabledProperty(writer); RenderOptionsProperties(writer); RenderChangedEvent(writer); RenderSelectedValueProperty(writer); base.AddAttributesToRender(writer, context); }
protected override void AddAttributesToRender(IHtmlWriter writer, RenderContext context) { if (Icon != GlyphIcons.Empty) { var iconName = KnockoutHelper.ConvertToCamelCase(Icon.ToString().Replace("_", "-")); writer.AddAttribute("class", "glyphicon glyphicon-" + iconName); } base.AddAttributesToRender(writer, context); }
public static void RenderEnabledProperty(IHtmlWriter writer, SelectorBase selector) { writer.AddKnockoutDataBind("enable", selector, SelectorBase.EnabledProperty, () => { if (!selector.Enabled) { writer.AddAttribute("disabled", "disabled"); } }); }
/// <summary> /// Adds all attributes that should be added to the control begin tag. /// </summary> protected override void AddAttributesToRender(IHtmlWriter writer, RenderContext context) { var expression = KnockoutHelper.GetValidationTargetExpression(this, true); if (expression != null) { writer.AddKnockoutDataBind("foreach", expression + ".$validationErrors"); } base.AddAttributesToRender(writer, context); }
/// <summary> /// Adds all attributes that should be added to the control begin tag. /// </summary> protected override void AddAttributesToRender(IHtmlWriter writer, IDotvvmRequestContext context) { var expression = KnockoutHelper.GetValidationTargetExpression(this); if (expression != null) { writer.AddKnockoutDataBind("foreach", "dotvvm.validation.getValidationErrors(" + expression + ", " + IncludeErrorsFromChildren.ToString().ToLower() + ")"); } base.AddAttributesToRender(writer, context); }
protected override void RenderContents(IHtmlWriter writer, RenderContext context) { RenderLabel(writer); writer.AddAttribute("class", "col-sm-10"); writer.RenderBeginTag("div"); RenderChildren(writer, context); writer.RenderEndTag(); }
/// <summary> /// Adds all attributes that should be added to the control begin tag. /// </summary> protected override void AddAttributesToRender(IHtmlWriter writer, RenderContext context) { TagName = WrapperTagName; if (!RenderOnServer) { writer.AddKnockoutForeachDataBind(GetDataSourceBinding().TranslateToClientScript(this, DataSourceProperty)); } base.AddAttributesToRender(writer, context); }
private void AddFormatBindingToRender(IHtmlWriter writer, IDotvvmRequestContext context) { // if format is set then use different value binding which supports the format writer.AddKnockoutDataBind("dotvvm-textbox-text", this, TextProperty, () => { if (Type != TextBoxType.MultiLine) { writer.AddAttribute("value", Text); } }, UpdateTextAfterKeydown ? "afterkeydown" : null, renderEvenInServerRenderingMode: true); var binding = GetValueBinding(TextProperty); var formatString = FormatString; if (string.IsNullOrEmpty(formatString)) { if (Type == TextBoxType.Date) { formatString = "yyyy-MM-dd"; } else { formatString = "G"; } } writer.AddAttribute("data-dotvvm-format", formatString); if (ValueType != FormatValueType.Text) { writer.AddAttribute("data-dotvvm-value-type", ValueType.ToString().ToLowerInvariant()); } else if (binding?.ResultType == typeof(DateTime)) { writer.AddAttribute("data-dotvvm-value-type", "datetime"); } else if (ReflectionUtils.IsNumericType(binding?.ResultType)) { writer.AddAttribute("data-dotvvm-value-type", "number"); } }
public static void AddKnockoutDataBind(this IHtmlWriter writer, string name, DotvvmBindableObject control, DotvvmProperty property, Action nullBindingAction = null, string valueUpdate = null, bool renderEvenInServerRenderingMode = false, bool setValueBack = false) { var expression = control.GetValueBinding(property); if (expression != null && (!control.RenderOnServer || renderEvenInServerRenderingMode)) { writer.AddAttribute("data-bind", name + ": " + expression.GetKnockoutBindingExpression(control), true, ", "); if (valueUpdate != null) { writer.AddAttribute("data-bind", "valueUpdate: '" + valueUpdate + "'", true, ", "); } } else { nullBindingAction?.Invoke(); if (setValueBack && expression != null) { control.SetValue(property, expression.Evaluate(control)); } } }
private void AddEnabledPropertyToRender(IHtmlWriter writer) { switch (this.GetValueRaw(EnabledProperty)) { case bool value: if (!value) { writer.AddAttribute("disabled", "disabled"); } break; case IValueBinding binding: writer.AddKnockoutDataBind("enable", binding.GetKnockoutBindingExpression(this)); break; default: if (!Enabled) { writer.AddAttribute("disabled", "disabled"); } break; } }
protected override void RenderControl(IHtmlWriter writer, IDotvvmRequestContext context) { // render resource links var resourceManager = context.ResourceManager; if (resourceManager.BodyRendered) return; resourceManager.BodyRendered = true; // set the flag before the resources are rendered, so they can't add more resources to the list during the render ResourcesRenderer.RenderResources(resourceManager, writer, context, ResourceRenderPosition.Body); // render the serialized viewmodel var serializedViewModel = ((DotvvmRequestContext) context).GetSerializedViewModel(); writer.AddAttribute("type", "hidden"); writer.AddAttribute("id", "__dot_viewmodel_root"); writer.AddAttribute("value", serializedViewModel); writer.RenderSelfClosingTag("input"); // init on load writer.RenderBeginTag("script"); writer.WriteUnencodedText($@" window.dotvvm.domUtils.onDocumentReady(function () {{ window.dotvvm.init('root', {JsonConvert.ToString(CultureInfo.CurrentCulture.Name, '"', StringEscapeHandling.EscapeHtml)}); }});"); writer.RenderEndTag(); }
protected override void RenderBeginTag(IHtmlWriter writer, IDotvvmRequestContext context) { TagName = WrapperTagName; if (!RenderOnServer) { if (RenderWrapperTag) { //writer.AddKnockoutForeachDataBind(javascriptDataSourceExpression); writer.AddKnockoutDataBind("foreach", GetForeachKnockoutBindingGroup()); } else { writer.WriteKnockoutDataBindComment("foreach", GetForeachKnockoutBindingGroup().ToString()); } } if (RenderWrapperTag) { base.RenderBeginTag(writer, context); } }
protected override void RenderBeginTag(IHtmlWriter writer, RenderContext context) { TagName = WrapperTagName; if (!RenderOnServer) { var javascriptDataSourceExpression = GetForeachDataBindJavascriptExpression(); if (RenderWrapperTag) { writer.AddKnockoutForeachDataBind(javascriptDataSourceExpression); } else { writer.WriteKnockoutForeachComment(javascriptDataSourceExpression); } } if (RenderWrapperTag) { base.RenderBeginTag(writer, context); } }
protected override void RenderControl(IHtmlWriter writer, IDotvvmRequestContext context) { var doNotTrack = false; if (context.HttpContext.Request.Headers.TryGetValue("DNT", out var doNotTrackHeaderValue)) { doNotTrack = string.Equals(doNotTrackHeaderValue, "1"); } if (!doNotTrack) { var options = ResolveOptions(context); string additionalJS = options.PageViewEnabled ? PageViewJavascriptSnippet :string.Empty; var snippet = options.AsyncVersionEnabled ? AsyncJavascriptSnippet : JavascriptSnippet; var script = string.Format(snippet, options.TrackingId, additionalJS); writer.WriteUnencodedText(script); } base.RenderControl(writer, context); }
public void Write(IHtmlWriter writer) { if (_elements == null) { return; } var hasNamespace = !string.IsNullOrEmpty(NamespaceName); if (hasNamespace) { writer.Write(Line1()); writer.Write(Line2()); writer.IndentLevel++; } foreach (var element in _elements) { writer.WriteLine(); element.Write(writer); } if (hasNamespace) { writer.WriteLine(); foreach (var element in _elements.Where(e => e.IsPublic && !string.IsNullOrEmpty(e.Name))) { writer.WriteLine("exported." + element.Name + " = " + element.Name + ";"); } writer.IndentLevel--; writer.WriteLine(LineN2()); writer.WriteLine(LineN1()); writer.WriteLine(); } }
public override void Render(IHtmlWriter writer, IDotvvmRequestContext context, string resourceName) { RenderLink(Location, writer, context, resourceName); if (LocationFallback != null) { if (Location is ILocalResourceLocation && LocationFallback.AlternativeLocations.Count > 0) { throw new NotSupportedException("LocationFallback is not supported on " + "resources with Location of type ILocalResourceLocation."); } foreach (var fallback in LocationFallback.AlternativeLocations) { var link = RenderLinkToString(fallback, context, resourceName); if (!string.IsNullOrEmpty(link)) { writer.AddAttribute("type", "text/javascript"); writer.RenderBeginTag("script"); var script = JsonConvert.ToString(link, '\'').Replace("<", "\\u003c"); writer.WriteUnencodedText( $@"if (!({LocationFallback.JavascriptCondition})) {{ var wrapper = document.createElement('div'); wrapper.innerHTML = {script}; var originalScript = wrapper.children[0]; var script = document.createElement('script'); script.src = originalScript.src; script.type = originalScript.type; script.text = originalScript.text; script.id = originalScript.id; document.head.appendChild(script); }}"); writer.RenderEndTag(); } } } }
protected override void AddAttributesToRender(IHtmlWriter writer, IDotvvmRequestContext context) { writer.AddAttribute("type", IsSubmitButton ? "submit" : "button"); if (ButtonTagName == ButtonTagName.button) { TagName = "button"; } if (ButtonTagName == ButtonTagName.input) { writer.AddKnockoutDataBind("value", this, TextProperty, () => { if (!HasOnlyWhiteSpaceContent()) { // if there is only a text content, extract it into the Text property; if there is HTML, we don't support it string textContent; if (!TryGetTextContent(out textContent)) { throw new DotvvmControlException(this, "The <dot:Button> control cannot have inner HTML connect unless the 'ButtonTagName' property is set to 'button'!"); } Text = textContent; } writer.AddAttribute("value", Text); }); } base.AddAttributesToRender(writer, context); var clickBinding = GetCommandBinding(ClickProperty); if (clickBinding != null) { writer.AddAttribute("onclick", KnockoutHelper.GenerateClientPostBackScript(nameof(Click), clickBinding, this), true, ";"); } }
protected override void AddAttributesToRender(IHtmlWriter writer, IDotvvmRequestContext context) { if (!context.IsInPartialRenderingMode) { writer.AddStyleAttribute("display", "none"); } writer.AddKnockoutDataBind("if", "dotvvm.isSpaReady"); if (Children.Count > 0) { writer.AddAttribute(HostingConstants.SpaContentAttributeName, string.Empty); } if (!string.IsNullOrEmpty(DefaultRouteName)) { var route = context.Configuration.RouteTable[DefaultRouteName]; if (route.ParameterNames.Any()) { throw new DotvvmControlException(this, $"The route '{DefaultRouteName}' specified in SpaContentPlaceHolder DefaultRouteName property cannot contain route parameters!"); } writer.AddAttribute(HostingConstants.SpaContentPlaceHolderDefaultRouteDataAttributeName, route.Url); } base.AddAttributesToRender(writer, context); }
protected override void RenderEndTag(IHtmlWriter writer, IDotvvmRequestContext context) { if (RenderWrapperTag) { base.RenderEndTag(writer, context); } else { writer.WriteKnockoutDataBindEndComment(); } if (!RenderOnServer && clientSeparator != null) { writer.AddAttribute("type", "text/html"); writer.AddAttribute("id", GetValueRaw(Internal.UniqueIDProperty) + "_separator"); var unique = GetValueRaw(Internal.UniqueIDProperty); var id = GetValueRaw(Internal.ClientIDFragmentProperty); writer.RenderBeginTag("script"); clientSeparator.Render(writer, context); writer.RenderEndTag(); } emptyDataContainer?.Render(writer, context); }
protected override void AddAttributesToRender(IHtmlWriter writer, IDotvvmRequestContext context) { RouteLinkHelpers.WriteRouteLinkHrefAttribute(this, writer, context); writer.AddKnockoutDataBind("text", this, TextProperty, () => { shouldRenderText = true; }); var enabledBinding = GetValueRaw(EnabledProperty); if (enabledBinding is bool) { WriteEnabledBinding(writer, (bool)enabledBinding); } else if (enabledBinding is IValueBinding) { WriteEnabledBinding(writer, (IValueBinding)enabledBinding); } WriteOnClickAttribute(writer, context); base.AddAttributesToRender(writer, context); }
/// <summary> /// Renders the resource in the specified <see cref="IHtmlWriter" />. /// </summary> public override void Render(IHtmlWriter writer) { if (CdnUrl != null) { writer.AddAttribute("src", CdnUrl); writer.AddAttribute("type", "text/javascript"); writer.RenderBeginTag("script"); writer.RenderEndTag(); if (Url != null && GlobalObjectName != null) { writer.RenderBeginTag("script"); writer.WriteUnencodedText(string.Format(CdnFallbackScript, GlobalObjectName, GetUrl())); writer.RenderEndTag(); } } else if (Url != null) { writer.AddAttribute("src", GetUrl()); writer.AddAttribute("type", "text/javascript"); writer.RenderBeginTag("script"); writer.RenderEndTag(); } }
public static void RenderResources(IEnumerable <NamedResource> resources, IHtmlWriter writer, IDotvvmRequestContext context, ResourceRenderPosition position) { var writeDebugInfo = context.Configuration.Debug; foreach (var resource in resources) { if (resource.Resource.RenderPosition == position) { if (writeDebugInfo) { WriteResourceInfo(resource, writer, preload: false); } resource.RenderResourceCached(writer, context); } else if (position == ResourceRenderPosition.Head && resource.Resource.RenderPosition != ResourceRenderPosition.Head && resource.Resource is IPreloadResource preloadResource) { if (writeDebugInfo) { WriteResourceInfo(resource, writer, preload: true); } preloadResource.RenderPreloadLink(writer, context, resource.Name); } } }
private void AddTypeAttributeToRender(IHtmlWriter writer) { var type = this.Type; if (type.TryGetTagName(out var tagName)) { TagName = tagName; // do not overwrite type attribute if (type == TextBoxType.Normal && !Attributes.ContainsKey("type")) { writer.AddAttribute("type", "text"); } return; } if (type.TryGetInputType(out var inputType)) { writer.AddAttribute("type", inputType); TagName = "input"; return; } throw new NotSupportedException($"TextBox Type '{ type }' not supported"); }
protected override void RenderControl(IHtmlWriter writer, IDotvvmRequestContext context) { var resourceManager = context.ResourceManager; if (resourceManager.HeadRendered) { return; } // set the flag before the resources are rendered, so they can't add more resources to the list during the render resourceManager.HeadRendered = true; // render resource links and preloads foreach (var resource in resourceManager.GetNamedResourcesInOrder()) { if (resource.Resource.RenderPosition == ResourceRenderPosition.Head) { resource.RenderResourceCached(writer, context); } else if (resource.Resource is IPreloadResource preloadResource) { preloadResource.RenderPreloadLink(writer, context, resource.Name); } } }
/// <summary> /// Adds all attributes that should be added to the control begin tag. /// </summary> protected override void AddAttributesToRender(IHtmlWriter writer, IDotvvmRequestContext context) { if ((HasBinding(TextProperty) || !string.IsNullOrEmpty(Text)) && !HasOnlyWhiteSpaceContent()) { throw new DotvvmControlException(this, "The <dot:LinkButton> control cannot have both inner content and the Text property set!"); } writer.AddAttribute("href", "#"); var clickBinding = GetCommandBinding(ClickProperty); if (clickBinding != null) { writer.AddAttribute("onclick", KnockoutHelper.GenerateClientPostBackScript(nameof(Click), clickBinding, this)); } var textbinding = GetValueBinding(TextProperty); if (textbinding != null) { writer.AddKnockoutDataBind("text", textbinding.GetKnockoutBindingExpression(this)); } base.AddAttributesToRender(writer, context); }
public static void AddKnockoutForeachDataBind(this IHtmlWriter writer, string expression) { writer.AddKnockoutDataBind("foreach", expression); }
public static void WriteKnockoutDataBindEndComment(this IHtmlWriter writer) { writer.WriteUnencodedText("<!-- /ko -->"); }
public static void WriteKnockoutWithComment(this IHtmlWriter writer, string binding) { writer.WriteKnockoutDataBindComment("with", binding); }
public static void AddKnockoutDataBind(this IHtmlWriter writer, string name, IEnumerable <KeyValuePair <string, IValueBinding> > expressions, DotvvmBindableObject control, DotvvmProperty?property = null) { writer.AddKnockoutDataBind(name, $"{{{String.Join(",", expressions.Select(e => "'" + e.Key + "': " + e.Value.GetKnockoutBindingExpression(control)))}}}"); }
public static void AddKnockoutDataBind(this IHtmlWriter writer, string name, IValueBinding valueBinding, DotvvmBindableObject control) { writer.AddKnockoutDataBind(name, valueBinding.GetKnockoutBindingExpression(control)); }
public static void AddKnockoutDataBind(this IHtmlWriter writer, string name, IValueBinding valueBinding) { writer.AddKnockoutDataBind(name, valueBinding.GetKnockoutBindingExpression()); }
public static void WriteKnockoutDataBindComment(this IHtmlWriter writer, string name, DotvvmControl control, DotvvmProperty property) { writer.WriteUnencodedText($"<!-- ko { name }: { control.GetValueBinding(property).GetKnockoutBindingExpression() } -->"); }
public static void WriteKnockoutDataBindComment(this IHtmlWriter writer, string name, string expression) { writer.WriteUnencodedText($"<!-- ko { name }: { expression } -->"); }
public static void AddKnockoutDataBind(this IHtmlWriter writer, string name, IEnumerable <KeyValuePair <string, IValueBinding> > expressions, DotvvmControl control, DotvvmProperty property) { writer.AddAttribute("data-bind", name + ": {" + String.Join(",", expressions.Select(e => "'" + e.Key + "': " + e.Value.GetKnockoutBindingExpression())) + "}", true, ", "); }
/// <summary> /// Add knockout data bind comment dotvvm_withControlProperties with the specified properties /// </summary> public static void AddCommentAliasBinding(IHtmlWriter writer, IDictionary <string, string> properties) { writer.WriteKnockoutDataBindComment("dotvvm_introduceAlias", "{" + string.Join(", ", properties.Select(p => JsonConvert.ToString(p.Key) + ":" + properties.Values)) + "}"); }
protected override void RenderContents(IHtmlWriter writer, IDotvvmRequestContext context) { writer.AddKnockoutDataBind("css", "{ 'disabled': PagingOptions().IsFirstPage() }"); firstLi.Render(writer, context); writer.AddKnockoutDataBind("css", "{ 'disabled': PagingOptions().IsFirstPage() }"); previousLi.Render(writer, context); // render template writer.WriteKnockoutForeachComment("PagingOptions().NearPageIndexes"); // render page number numbersPlaceHolder.Children.Clear(); HtmlGenericControl li; var currentPageTextContext = DataContextStack.Create(typeof(int), numbersPlaceHolder.GetDataContextType()); var currentPageTextBinding = ValueBindingExpression.CreateBinding(bindingService.WithoutInitialization(), vm => ((int)vm[0] + 1).ToString(), currentPageTextJs, currentPageTextContext); if (!RenderLinkForCurrentPage) { writer.AddKnockoutDataBind("visible", "$data == $parent.PagingOptions().PageIndex()"); writer.AddKnockoutDataBind("css", "{'active': $data == $parent.PagingOptions().PageIndex()}"); li = new HtmlGenericControl("li"); var literal = new Literal(); literal.DataContext = 0; literal.SetDataContextType(currentPageTextContext); literal.SetBinding(Literal.TextProperty, currentPageTextBinding); li.Children.Add(literal); numbersPlaceHolder.Children.Add(li); li.Render(writer, context); writer.AddKnockoutDataBind("visible", "$data != $parent.PagingOptions().PageIndex()"); } writer.AddKnockoutDataBind("css", "{ 'active': $data == $parent.PagingOptions().PageIndex()}"); li = new HtmlGenericControl("li"); li.SetValue(Internal.PathFragmentProperty, "PagingOptions.NearPageIndexes[$index]"); var link = new LinkButton(); li.Children.Add(link); link.SetDataContextType(currentPageTextContext); link.SetBinding(ButtonBase.TextProperty, currentPageTextBinding); link.SetBinding(ButtonBase.ClickProperty, commonBindings.GoToThisPageCommand); object enabledValue = HasValueBinding(EnabledProperty) ? (object)ValueBindingExpression.CreateBinding(bindingService.WithoutInitialization(), h => GetValueBinding(EnabledProperty).Evaluate(this), new JsSymbolicParameter(JavascriptTranslator.KnockoutContextParameter).Member("$pagerEnabled")) : Enabled; if (!true.Equals(enabledValue)) { link.SetValue(LinkButton.EnabledProperty, enabledValue); } numbersPlaceHolder.Children.Add(li); li.Render(writer, context); writer.WriteKnockoutDataBindEndComment(); writer.AddKnockoutDataBind("css", "{ 'disabled': PagingOptions().IsLastPage() }"); nextLi.Render(writer, context); writer.AddKnockoutDataBind("css", "{ 'disabled': PagingOptions().IsLastPage() }"); lastLi.Render(writer, context); }
/// <summary> /// Adds all attributes that should be added to the control begin tag. /// </summary> protected override void AddAttributesToRender(IHtmlWriter writer, RenderContext context) { // verify that the properties are used only where they should if (!RendersHtmlTag) { EnsureNoAttributesSet(); } CheckInnerTextUsage(); // render hard-coded HTML attributes foreach (var attribute in Attributes.Where(a => a.Value is string || a.Value == null)) { writer.AddAttribute(attribute.Key, (string)attribute.Value, true); } foreach (var attrList in Attributes.Where(a => a.Value is string[])) { foreach (var value in (string[])attrList.Value) { writer.AddAttribute(attrList.Key, value); } } // render binding HTML attributes var propertyValuePairs = Attributes.Where(a => a.Value is IValueBinding) .Select(a => new KeyValuePair <string, IValueBinding>(a.Key, (IValueBinding)a.Value)).ToList(); if (!RenderOnServer) { if (propertyValuePairs.Any()) { writer.AddKnockoutDataBind("attr", propertyValuePairs, this, null); } } else { foreach (var prop in propertyValuePairs) { writer.AddAttribute(prop.Key, prop.Value.Evaluate(this, null)?.ToString()); } } // handle Visible property AddVisibleAttributeOrBinding(writer); // handle Text property writer.AddKnockoutDataBind("text", this, InnerTextProperty, () => { // inner Text is rendered as attribute only if contains binding // otherwise it is rendered directly as encoded content if (!string.IsNullOrWhiteSpace(InnerText)) { Children.Clear(); Children.Add(new Literal(InnerText)); } }); // hadle Id property RenderClientId(writer); base.AddAttributesToRender(writer, context); }