/// <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, 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> /// 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(); }
protected override void AddAttributesToRender(IHtmlWriter writer, RenderContext context) { writer.AddAttribute("class", "form-horizontal"); writer.AddAttribute("role", "form"); base.AddAttributesToRender(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", "radio"); var valueExpression = KnockoutBindingHelper.GetBindingExpressionOrNull(ValueProperty, this); if (KnockoutBindingHelper.IsKnockoutBinding(valueExpression)) { writer.AddBindingAttribute("value", KnockoutBindingHelper.TranslateToKnockoutProperty(this, ValueProperty, valueExpression)); } else { writer.AddAttribute("value", Value); } writer.AddAttribute("name", GroupName); var selectedValueExpression = KnockoutBindingHelper.GetBindingExpressionOrNull(SelectedValueProperty, this); if (KnockoutBindingHelper.IsKnockoutBinding(selectedValueExpression)) { writer.AddBindingAttribute("checked", KnockoutBindingHelper.TranslateToKnockoutProperty(this, SelectedValueProperty, selectedValueExpression)); } 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(); } }
/// <summary> /// Adds all attributes that should be added to the control begin tag. /// </summary> protected override void AddAttributesToRender(IHtmlWriter writer, RenderContext context) { writer.AddAttribute("type", IsSubmitButton ? "submit" : "button"); var clickBinding = GetCommandBinding(ClickProperty); if (clickBinding != null) { writer.AddAttribute("onclick", KnockoutHelper.GenerateClientPostBackScript(clickBinding, context, this)); } writer.AddKnockoutDataBind("value", this, TextProperty, () => writer.AddAttribute("value", Text)); base.AddAttributesToRender(writer, context); }
/// <summary> /// Adds all attributes that should be added to the control begin tag. /// </summary> protected override void AddAttributesToRender(IHtmlWriter writer, RenderContext context) { writer.AddAttribute("href", "#"); var clickBinding = GetCommandBinding(ClickProperty); if (clickBinding != null) { writer.AddAttribute("onclick", KnockoutHelper.GenerateClientPostBackScript(clickBinding, context, this)); } writer.AddKnockoutDataBind("text", this, TextProperty, () => { }); 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 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> /// 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 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 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)); } }
/// <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(); }
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)); } }
protected override void AddAttributesToRender(IHtmlWriter writer, RenderContext context) { writer.AddAttribute("id", ID); writer.AddAttribute("name", Constants.SpaContentPlaceHolderID); writer.AddAttribute(Constants.SpaContentPlaceHolderDataAttributeName, GetSpaContentPlaceHolderUniqueId()); if (!string.IsNullOrEmpty(DefaultRouteName)) { var route = context.RequestContext.Configuration.RouteTable[DefaultRouteName]; if (route.ParameterNames.Any()) { throw new ArgumentException(string.Format("The route {0} specified in SpaContentPlaceHolder DefaultRouteName property cannot contain route parameters!", DefaultRouteName)); } writer.AddAttribute(Constants.SpaContentPlaceHolderDefaultRouteDataAttributeName, route.Url); } base.AddAttributesToRender(writer, context); }
protected virtual void RenderGroupNameAttribute(IHtmlWriter writer) { var group = new KnockoutBindingGroup(); group.Add("name", this, GroupNameProperty, () => { writer.AddAttribute("name", GroupName); }); writer.AddKnockoutDataBind("attr", group); }
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); }
/// <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); 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) { if ((HasBinding(TextProperty) || !string.IsNullOrEmpty(Text)) && !HasOnlyWhiteSpaceContent()) { throw new DotvvmControlException(this, "Text property and inner content of the <dot:Button> control cannot be set at the same time!"); } if (ButtonTagName == ButtonTagName.button) { TagName = "button"; } writer.AddAttribute("type", IsSubmitButton ? "submit" : "button"); var clickBinding = GetCommandBinding(ClickProperty); if (clickBinding != null) { writer.AddAttribute("onclick", KnockoutHelper.GenerateClientPostBackScript(nameof(Click), clickBinding, this)); } writer.AddKnockoutDataBind(ButtonTagName == ButtonTagName.input ? "value" : "text", this, TextProperty, () => { if (!HasOnlyWhiteSpaceContent()) { if (ButtonTagName == ButtonTagName.input) { // 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; } } if (ButtonTagName == ButtonTagName.input) { writer.AddAttribute("value", Text); } }); 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"); } }); }
protected override void RenderContents(IHtmlWriter writer, RenderContext context) { RenderLabel(writer); writer.AddAttribute("class", "col-sm-10"); writer.RenderBeginTag("div"); 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(); }
public static void WriteRouteLinkHrefAttribute(string routeName, HtmlGenericControl control, IHtmlWriter writer, RenderContext context) { if (!control.RenderOnServer) { writer.AddKnockoutDataBind("attr", "{ href: " + GenerateKnockoutHrefExpression(routeName, control, context) + "}"); } else { writer.AddAttribute("href", EvaluateRouteUrl(routeName, control, context)); } }
/// <summary> /// Adds all attributes that should be added to the control begin tag. /// </summary> protected override void AddAttributesToRender(IHtmlWriter writer, IDotvvmRequestContext context) { writer.AddKnockoutDataBind("dotvvmEnable", this, EnabledProperty, () => { if (!Enabled) { writer.AddAttribute("disabled", "disabled"); } }); base.AddAttributesToRender(writer, context); }
/// <summary> /// Renders the control into the specified writer. /// </summary> protected override void RenderControl(IHtmlWriter writer, RenderContext context) { // render resource links var resources = context.ResourceManager.GetResourcesInOrder().Where(r => r.GetRenderPosition() == ResourceRenderPosition.Body); foreach (var resource in resources) { resource.Render(writer); } // render the serialized viewmodel var serializedViewModel = context.RequestContext.GetSerializedViewModel(); writer.AddAttribute("type", "hidden"); writer.AddAttribute("id", "__rw_viewmodel_" + context.CurrentPageArea); writer.AddAttribute("value", serializedViewModel); writer.RenderSelfClosingTag("input"); // init on load writer.RenderBeginTag("script"); writer.WriteUnencodedText(string.Format("redwood.onDocumentReady(function () {{ redwood.init('{0}', '{1}'); }});", context.CurrentPageArea, Thread.CurrentThread.CurrentUICulture.Name)); writer.RenderEndTag(); }
public static void WriteRouteLinkHrefAttribute(string routeName, HtmlGenericControl control, DotvvmProperty urlSuffixProperty, IHtmlWriter writer, IDotvvmRequestContext context) { if (!control.RenderOnServer) { var group = new KnockoutBindingGroup(); group.Add("href", GenerateKnockoutHrefExpression(routeName, control, urlSuffixProperty, context)); writer.AddKnockoutDataBind("attr", group); } else { writer.AddAttribute("href", EvaluateRouteUrl(routeName, control, urlSuffixProperty, context)); } }
private void AddChangedPropertyToRender(IHtmlWriter writer, IDotvvmRequestContext context) { // prepare changed event attribute var changedBinding = GetCommandBinding(ChangedProperty); base.AddAttributesToRender(writer, context); if (changedBinding != null) { writer.AddAttribute("onchange", KnockoutHelper.GenerateClientPostBackScript(nameof(Changed), changedBinding, this, useWindowSetTimeout: true, isOnChange: true), true, ";"); } }
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)); } } }
protected virtual void RenderCheckedProperty(IHtmlWriter writer) { var checkedBinding = GetValueBinding(CheckedProperty); writer.AddKnockoutDataBind("dotvvm-CheckState", checkedBinding !, this); writer.AddKnockoutDataBind("checkedValue", "true"); // Boolean mode can have prerendered `checked` attribute if (RenderOnServer && true.Equals(GetValue(CheckedProperty))) { writer.AddAttribute("checked", null); } }
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"); } }
private void AddHtmlAttribute(IHtmlWriter writer, string name, object value) { if (value is string || value == null) { writer.AddAttribute(name, (string)value, true); } else if (value is IEnumerable <string> ) { foreach (var vv in (IEnumerable <string>)value) { writer.AddAttribute(name, vv); } } else if (value is IStaticValueBinding) { AddHtmlAttribute(writer, name, ((IStaticValueBinding)value).Evaluate(this)); } else { throw new NotSupportedException($"Attribute value of type '{value.GetType().FullName}' is not supported."); } }
protected override void RenderControl(IHtmlWriter writer) { writer.RenderBeginTag("input"); var expr = KnockoutBindingHelper.GetBindingExpressionOrNull(TextProperty, this); if (KnockoutBindingHelper.IsKnockoutBinding(expr)) { writer.AddBindingAttribute("value", KnockoutBindingHelper.TranslateToKnockoutProperty(this, TextProperty, expr)); } else { writer.AddAttribute("value", Text); } var expr2 = KnockoutBindingHelper.GetCommandExpressionOrNull(OnClickProperty, this); if (KnockoutBindingHelper.IsKnockoutCommand(expr2)) { writer.AddBindingAttribute("click", KnockoutBindingHelper.TranslateToKnockoutCommand(this, OnClickProperty, expr2)); } writer.AddAttribute("type", "button"); writer.RenderEndTag(); }
private void AddCustomAttributes(IHtmlWriter writer) { var customBinding = GetValueBinding(CustomProperty); if (customBinding != null) { writer.AddKnockoutDataBind("customAttr", this, CustomProperty); } else { // render the value in the HTML writer.AddAttribute("customAttr", Custom); } }
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 virtual void RenderGroupNameAttribute(IHtmlWriter writer) { var groupNameBinding = GetValueBinding(GroupNameProperty); if (groupNameBinding != null) { // TODO: do not overwrite existing attribute bindings writer.AddKnockoutDataBind("attr", new[] { new KeyValuePair <string, IValueBinding>("name", groupNameBinding) }, this, GroupNameProperty); } else { writer.AddAttribute("name", GroupName); } }
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 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) { 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); }
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"); }
/// <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); }
protected virtual void WriteOnClickAttribute(IHtmlWriter writer, IDotvvmRequestContext context) { // a hack that makes the RouteLink work even in container with Events.Click. This does not solve the problem in general, but better than nothing. var onclickAttribute = "event.stopPropagation();"; if ((bool)GetValue(Internal.IsSpaPageProperty) && (bool)GetValue(Internal.UseHistoryApiSpaNavigationProperty)) { onclickAttribute += "return !this.hasAttribute('disabled') && dotvvm.handleSpaNavigation(this);"; } else { onclickAttribute += "return !this.hasAttribute('disabled');"; } writer.AddAttribute("onclick", onclickAttribute); }
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, ";"); } }
/// <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.Body); foreach (var resource in resources) { resource.Render(writer, context); } // 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', '{Thread.CurrentThread.CurrentUICulture.Name}'); }});"); writer.RenderEndTag(); }
/// <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(); } }
protected override void RenderInputTag(IHtmlWriter writer) { var checkedItemBinding = GetBinding(CheckedItemProperty); if (checkedItemBinding != null) { // selected item mode writer.AddKnockoutDataBind("checked", this, CheckedItemProperty, () => { }); writer.AddKnockoutDataBind("checkedValue", this, CheckedValueProperty, () => { var checkedValue = (CheckedValue ?? string.Empty).ToString(); if (!string.IsNullOrEmpty(checkedValue)) { writer.AddKnockoutDataBind("checkedValue", KnockoutHelper.MakeStringLiteral(checkedValue)); } }); } else { writer.AddKnockoutDataBind("checked", this, CheckedProperty, () => { }); } // render the input tag writer.AddAttribute("type", "radio"); var groupNameBinding = GetBinding(GroupNameProperty); if (groupNameBinding != null) { writer.AddKnockoutDataBind("attr", new[] { new KeyValuePair<string, IValueBinding>("name", groupNameBinding as IValueBinding) }, this, GroupNameProperty); } else { writer.AddAttribute("name", GroupName); } writer.RenderSelfClosingTag("input"); }
protected override void AddAttributesToRender(IHtmlWriter writer, IDotvvmRequestContext context) { base.AddAttributesToRender(writer, context); writer.AddAttribute("class", "dotvvm-contrib-Switch", true); KnockoutBindingGroup group = new KnockoutBindingGroup() { }; group.AddSimpleBinding("value", this, ValueProperty); group.AddSimpleBinding("orientation", this, OrientationProperty); group.AddSimpleBinding("direction", this, DirectionProperty); group.AddSimpleBinding("enabled", this, EnabledProperty); writer.AddKnockoutDataBind("dotvvm-contrib-Switch", group); }
public static void WriteRouteLinkHrefAttribute(RouteLink control, IHtmlWriter writer, IDotvvmRequestContext context) { // Render client-side knockout expression only if there exists a parameter with value binding var containsBindingParam = control.Params.RawValues.Any(p => p.Value is IValueBinding); if (containsBindingParam) { var group = new KnockoutBindingGroup(); group.Add("href", GenerateKnockoutHrefExpression(control.RouteName, control, context)); writer.AddKnockoutDataBind("attr", group); } if (control.RenderOnServer || !containsBindingParam) { writer.AddAttribute("href", EvaluateRouteUrl(control.RouteName, control, context)); } }
public override void Render(IHtmlWriter writer, IDotvvmRequestContext context, string resourceName) { RenderLink(Location, writer, context, resourceName); if (LocationFallback != null) { foreach (var fallback in LocationFallback.AlternativeLocations) { var link = RenderLinkToString(fallback, context, resourceName); if (!string.IsNullOrEmpty(link)) { writer.AddAttribute("type", "text/javascript"); writer.RenderBeginTag("script"); writer.WriteUnencodedText($"{LocationFallback.JavascriptCondition} || document.write({JsonConvert.ToString(link, '\'').Replace("<", "\\u003c")})"); writer.RenderEndTag(); } } } }
protected override void RenderContents(IHtmlWriter writer, IDotvvmRequestContext context) { writer.AddAttribute("class", "draggable-list-item", true); writer.RenderBeginTag("div"); var placeholder = new DataItemContainer() { DataContext = null }; placeholder.SetValue(Internal.PathFragmentProperty, GetPathFragmentExpression() + "/[$index]"); placeholder.SetValue(Internal.ClientIDFragmentProperty, GetValueRaw(Internal.CurrentIndexBindingProperty)); ItemTemplate.BuildContent(context, placeholder); Children.Add(placeholder); placeholder.Render(writer, context); writer.RenderEndTag(); }
protected override void AddAttributesToRender(IHtmlWriter writer, IDotvvmRequestContext context) { var parameters = new RouteValueDictionary(); foreach (var param in context.Parameters) { parameters[param.Key] = param.Value; } foreach (var item in Params.RawValues) { parameters[item.Key] = item.Value; } var url = WebFormsRouteLinkHelpers.EvaluateRouteUrl(RouteName, this, context); writer.AddAttribute("href", url); WebFormsRouteLinkHelpers.WriteRouteLinkHrefAttribute(this, writer, context); base.AddAttributesToRender(writer, context); }
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(); } } } }
public virtual void AddAttribute(string name, string value, bool append = false, string appendSeparator = null) { if (!validator.CheckAttribute(name, value)) { return; } if (Attributes.ContainsKey(name)) { if (append) { Attributes[name] += appendSeparator ?? string.Empty + value; } else { Attributes[name] = value; } } else { Attributes.Add(name, value); } writer.AddAttribute(name, value, append, appendSeparator); }
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, ", "); }
public override void Render(IHtmlWriter writer, IDotvvmRequestContext context, string resourceName) { writer.AddAttribute("async", null); base.Render(writer, context, resourceName); }
/// <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); }
protected virtual void RenderTypeAttribute(IHtmlWriter writer) { // render the input tag writer.AddAttribute("type", "radio"); }
protected override void AddAttributesToRender(IHtmlWriter writer, IDotvvmRequestContext context) { base.AddAttributesToRender(writer, context); writer.AddKnockoutDataBind("size", this, SizeProperty, () => writer.AddAttribute("size", Size.ToString())); }
protected virtual void RenderMultipleAttribute(IHtmlWriter writer) { writer.AddAttribute("multiple", "multiple"); }