Пример #1
0
        /// <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");
        }
Пример #2
0
        /// <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);
        }
Пример #3
0
 protected virtual void RenderCheckedValueAttribute(IHtmlWriter writer)
 {
     writer.AddKnockoutDataBind("checkedValue", this, CheckedValueProperty, () =>
     {
         var checkedValue = (CheckedValue ?? string.Empty).ToString();
         if (!string.IsNullOrEmpty(checkedValue))
         {
             writer.AddKnockoutDataBind("checkedValue", KnockoutHelper.MakeStringLiteral(checkedValue));
         }
     });
 }
Пример #4
0
 public static void RenderOptionsProperties(IHtmlWriter writer, SelectorBase selector)
 {
     writer.AddKnockoutDataBind("options", selector, ItemsControl.DataSourceProperty, renderEvenInServerRenderingMode: true);
     if (!String.IsNullOrEmpty(selector.DisplayMember))
     {
         writer.AddKnockoutDataBind("optionsText", "function (i) { return ko.unwrap(i)[" + KnockoutHelper.MakeStringLiteral(selector.DisplayMember) + "]; }");
     }
     if (!String.IsNullOrEmpty(selector.ValueMember))
     {
         writer.AddKnockoutDataBind("optionsValue", "function (i) { return ko.unwrap(i)[" + KnockoutHelper.MakeStringLiteral(selector.ValueMember) + "]; }");
     }
 }
Пример #5
0
 protected virtual void RenderCheckedItemsProperty(IHtmlWriter writer)
 {
     RenderCheckedItemsBinding(writer);
     writer.AddKnockoutDataBind("checkedArrayContainsObservables", "true");
     writer.AddKnockoutDataBind("dotvvm-checkbox-updateAfterPostback", "true");
     RenderDotvvmCheckedPointerBinding(writer);
     writer.AddKnockoutDataBind("checkedValue", this, CheckedValueProperty, () =>
     {
         var checkedValue = (CheckedValue ?? string.Empty).ToString();
         if (!string.IsNullOrEmpty(checkedValue))
         {
             writer.AddKnockoutDataBind("checkedValue", KnockoutHelper.MakeStringLiteral(checkedValue));
         }
     });
 }
Пример #6
0
 /// <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();
 }
Пример #7
0
        protected override void AddAttributesToRender(IHtmlWriter writer, RenderContext context)
        {
            RouteLinkHelpers.WriteRouteLinkHrefAttribute(RouteName, this, writer, context);

            writer.AddKnockoutDataBind("text", this, TextProperty, () => { });

            base.AddAttributesToRender(writer, context);
        }
Пример #8
0
 protected virtual void RenderGroupNameAttribute(IHtmlWriter writer)
 {
     var group = new KnockoutBindingGroup();
     group.Add("name", this, GroupNameProperty, () =>
     {
         writer.AddAttribute("name", GroupName);
     });
     writer.AddKnockoutDataBind("attr", group);
 }
Пример #9
0
        /// <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);
        }
Пример #10
0
        /// <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);
        }
Пример #11
0
 public static void RenderEnabledProperty(IHtmlWriter writer, SelectorBase selector)
 {
     writer.AddKnockoutDataBind("enable", selector, SelectorBase.EnabledProperty, () =>
     {
         if (!selector.Enabled)
         {
             writer.AddAttribute("disabled", "disabled");
         }
     });
 }
Пример #12
0
 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));
     }
 }
Пример #13
0
        /// <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);
        }
Пример #14
0
        protected override void AddAttributesToRender(IHtmlWriter writer, RenderContext context)
        {
            if (!RenderOnServer)
            {
                if (!string.IsNullOrWhiteSpace(EmptyItemText))
                {
                    writer.AddKnockoutDataBind("optionsCaption", KnockoutHelper.MakeStringLiteral(EmptyItemText));
                }
            }

            base.AddAttributesToRender(writer, context);
        }
Пример #15
0
        protected override void AddAttributesToRender(IHtmlWriter writer, IDotvvmRequestContext context)
        {
            RouteLinkHelpers.WriteRouteLinkHrefAttribute(RouteName, this, UrlSuffixProperty, writer, context);

            writer.AddKnockoutDataBind("text", this, TextProperty, () =>
            {
                shouldRenderText = true;
            });
            var enabledBinding = GetValueBinding(EnabledProperty);
            if (enabledBinding != null) WriteEnabledBinding(writer, enabledBinding);

            base.AddAttributesToRender(writer, context);
        }
Пример #16
0
 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));
     }
 }
Пример #17
0
        /// <summary>
        /// Adds all attributes that should be added to the control begin tag.
        /// </summary>
        protected override void AddAttributesToRender(IHtmlWriter writer, RenderContext context)
        {
            var validatedValueBinding = GetValueBinding(ValidatedValueProperty);
            if (validatedValueBinding != null)
            {
                writer.AddKnockoutDataBind("dotvvmValidation", this, ValidatedValueProperty, () => { });
                
                var options = string.Format("{{'mode':'{0}', 'cssClass':{1}}}", KnockoutHelper.ConvertToCamelCase(Mode.ToString()), KnockoutHelper.MakeStringLiteral(InvalidCssClass));
                writer.AddKnockoutDataBind("dotvvmValidationOptions", options);
            }

            base.AddAttributesToRender(writer, context);
        }
Пример #18
0
        /// <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);
        }
Пример #19
0
        /// <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);
        }
Пример #20
0
        protected override void AddAttributesToRender(IHtmlWriter writer, IDotvvmRequestContext context)
        {
            if (!RenderOnServer)
            {
                writer.AddKnockoutDataBind("visible", $"!({ GetForeachDataBindJavascriptExpression() }).length");

                if (DataSource != null && GetIEnumerableFromDataSource(DataSource).OfType<object>().Any())
                {
                    writer.AddStyleAttribute("display", "none");
                }
            }

            base.AddAttributesToRender(writer, context);
        }
Пример #21
0
        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");
        }
Пример #22
0
        protected override void AddAttributesToRender(IHtmlWriter writer, RenderContext context)
        {
            writer.AddKnockoutDataBind("with", this, UploadedFilesProperty, () =>
            {
                throw new Exception("The UploadedFiles property of the FileUpload control must be bound!");   // TODO: Exception handling
            });
            writer.AddAttribute("class", "rw-upload", true);

            var uploadCompletedBinding = GetCommandBinding(UploadCompletedProperty);
            if (uploadCompletedBinding != null)
            {
                writer.AddAttribute("data-upload-completed", KnockoutHelper.GenerateClientPostBackScript(uploadCompletedBinding, context, this, true, null));
            }

            base.AddAttributesToRender(writer, context);
        }
Пример #23
0
        protected override void AddAttributesToRender(IHtmlWriter writer, IDotvvmRequestContext context)
        {
            TagName = WrapperTagName;

            base.AddAttributesToRender(writer, context);

            if (!RenderWrapperTag && !RenderOnServer && HasBinding(HtmlProperty))
            {
                throw new DotvvmControlException(this, "The HtmlLiteral control doesn't support client-side rendering without wrapper tag. Enable server rendering or the wrapper tag.");
            }

            if (RenderWrapperTag && HasBinding(HtmlProperty))
            {
                writer.AddKnockoutDataBind("html", this, HtmlProperty);
            }
        }
Пример #24
0
 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();
     }
 }
Пример #25
0
        private static void AddValidatedValue(IHtmlWriter writer, IDotvvmRequestContext context, DotvvmProperty prop, DotvvmControl control)
        {
            writer.AddKnockoutDataBind("dotvvmValidation", control, ValueProperty);

            // render options
            var bindingGroup = new KnockoutBindingGroup();
            foreach (var property in ValidationOptionProperties)
            {
                var javascriptName = KnockoutHelper.ConvertToCamelCase(property.Name);
                var optionValue = control.GetValue(property);
                if (!object.Equals(optionValue, property.DefaultValue))
                {
                    bindingGroup.Add(javascriptName, JsonConvert.SerializeObject(optionValue));
                }
            }
            writer.AddKnockoutDataBind("dotvvmValidationOptions", bindingGroup);
        }
Пример #26
0
 protected virtual void RenderCheckedAttribute(IHtmlWriter writer)
 {
     var checkedItemBinding = GetValueBinding(CheckedItemProperty);
     if (checkedItemBinding == null)
     {
         writer.AddKnockoutDataBind("checked", this, CheckedProperty, () => { });
         if (!IsPropertySet(CheckedValueProperty))
         {
             throw new DotvvmControlException(this, "The 'CheckedValue' of the RadioButton control must be set. Remember that all RadioButtons with the same GroupName have to be bound to the same property in the viewmodel.");
         }
     }
     else
     {
         // selected item mode
         writer.AddKnockoutDataBind("checked", checkedItemBinding);
     }
 }
Пример #27
0
        /// <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);
        }
Пример #28
0
        /// <summary>
        /// Adds all attributes that should be added to the control begin tag.
        /// </summary>
        protected override void AddAttributesToRender(IHtmlWriter writer, RenderContext context)
        {
            writer.AddKnockoutDataBind("value", this, TextProperty, () =>
            {
                if (Type != TextBoxType.MultiLine)
                {
                    writer.AddAttribute("value", "Text");
                }
            }, UpdateTextAfterKeydown ? "afterkeydown" : null);

            if (Type == TextBoxType.Normal)
            {
                TagName = "input";
                if (!Attributes.ContainsKey("type"))
                {
                    writer.AddAttribute("type", "text");
                }
            }
            else if (Type == TextBoxType.Password)
            {
                writer.AddAttribute("type", "password");
                TagName = "input";
            }
            else if (Type == TextBoxType.MultiLine)
            {
                TagName = "textarea";
            }

            // prepare changed event attribute
            var changedBinding = GetCommandBinding(ChangedProperty);
            if (changedBinding != null)
            {
                writer.AddAttribute("onchange", KnockoutHelper.GenerateClientPostBackScript(changedBinding, context, this, true, isOnChange: true));
            }

            base.AddAttributesToRender(writer, context);
        }
Пример #29
0
        protected override void RenderContents(IHtmlWriter writer, IDotvvmRequestContext context)
        {
            AddItemCssClass(writer, context);
            AddKnockoutDisabledCssDataBind(writer, context, "PagingOptions().IsFirstPage()");
            firstLi.Render(writer, context);

            AddItemCssClass(writer, context);
            AddKnockoutDisabledCssDataBind(writer, context, "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()");
                AddItemCssClass(writer, context);
                AddKnockoutActiveCssDataBind(writer, context, "$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()");
            }
            AddItemCssClass(writer, context);
            AddKnockoutActiveCssDataBind(writer, context, "$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();

            AddItemCssClass(writer, context);
            AddKnockoutDisabledCssDataBind(writer, context, "PagingOptions().IsLastPage()");
            nextLi.Render(writer, context);

            AddItemCssClass(writer, context);
            AddKnockoutDisabledCssDataBind(writer, context, "PagingOptions().IsLastPage()");
            lastLi.Render(writer, context);
        }
Пример #30
0
        protected override void AddAttributesToRender(IHtmlWriter writer, IDotvvmRequestContext context)
        {
            base.AddAttributesToRender(writer, context);

            writer.AddKnockoutDataBind("dotvvm-contrib-Select2", this, SelectedValuesProperty, renderEvenInServerRenderingMode: true);
        }
Пример #31
0
 /// <param name="property">This parameter is here for historical reasons, it's not useful for anything</param>
 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)))}}}");
 }
Пример #32
0
 private static void AddHasFocusBinding(IHtmlWriter writer, IDotvvmRequestContext context, DotvvmProperty property, DotvvmControl control)
 {
     writer.AddKnockoutDataBind("hasFocus", control, property);
 }
Пример #33
0
        protected override void AddAttributesToRender(IHtmlWriter writer, IDotvvmRequestContext context)
        {
            writer.AddKnockoutDataBind("dotvvm-UpdateProgress-Visible", "true");

            base.AddAttributesToRender(writer, context);
        }
Пример #34
0
 protected virtual void RenderDotvvmCheckedPointerBinding(IHtmlWriter writer)
 {
     writer.AddKnockoutDataBind("dotvvm-checked-pointer", GetDotvvmCheckedPointerBindingValue());
 }
Пример #35
0
 protected virtual void WriteEnabledBinding(IHtmlWriter writer, IValueBinding binding)
 {
     writer.AddKnockoutDataBind("dotvvmEnable", binding.GetKnockoutBindingExpression(this));
 }
Пример #36
0
        /// <summary>
        /// Adds the corresponding attribute for the Id property.
        /// </summary>
        protected virtual void RenderClientId(IHtmlWriter writer)
        {
            if (!string.IsNullOrEmpty(ID))
            {
                // build the client ID
                var dataContextChanges = 0;
                var hasExpressions     = false;
                var fragments          = new List <ClientIDFragment>();
                foreach (var ancestor in new[] { this }.Concat(GetAllAncestors()))
                {
                    if (ancestor.HasBinding(DataContextProperty))
                    {
                        dataContextChanges++;
                    }

                    if (this == ancestor || IsNamingContainer(ancestor))
                    {
                        var clientIdExpression = (string)ancestor.GetValue(Internal.ClientIDFragmentProperty);
                        if (clientIdExpression != null)
                        {
                            // generate the expression
                            var expression = new StringBuilder();
                            for (int i = 0; i < dataContextChanges; i++)
                            {
                                expression.Append("$parentContext.");
                            }
                            expression.Append(clientIdExpression);
                            fragments.Add(new ClientIDFragment()
                            {
                                Value = expression.ToString(), IsExpression = true
                            });
                            hasExpressions = true;
                        }
                        else if (!string.IsNullOrEmpty(ancestor.ID))
                        {
                            // add the ID fragment
                            fragments.Add(new ClientIDFragment()
                            {
                                Value = ancestor.ID
                            });
                        }
                    }

                    if (ancestor.ClientIDMode == ClientIDMode.Static)
                    {
                        break;
                    }
                }

                if (!hasExpressions)
                {
                    // generate ID attribute
                    var sb = new StringBuilder();
                    for (int i = fragments.Count - 1; i >= 0; i--)
                    {
                        if (sb.Length > 0)
                        {
                            sb.Append("_");
                        }
                        sb.Append(fragments[i].Value);
                    }
                    writer.AddAttribute("id", sb.ToString());
                }
                else
                {
                    // generate ID binding
                    var sb = new StringBuilder();
                    for (int i = fragments.Count - 1; i >= 0; i--)
                    {
                        if (sb.Length > 0)
                        {
                            sb.Append(",");
                        }

                        if (fragments[i].IsExpression)
                        {
                            sb.Append(fragments[i].Value);
                        }
                        else
                        {
                            sb.Append("'");
                            sb.Append(fragments[i].Value);
                            sb.Append("'");
                        }
                    }
                    var group = new KnockoutBindingGroup();
                    group.Add("id", $"dotvvm.evaluator.buildClientId(this, [{sb.ToString()}])");
                    writer.AddKnockoutDataBind("attr", group);
                }
            }
        }
Пример #37
0
 public static void AddKnockoutForeachDataBind(this IHtmlWriter writer, string expression)
 {
     writer.AddKnockoutDataBind("foreach", expression);
 }
Пример #38
0
 protected override void AddAttributesToRender(IHtmlWriter writer, IDotvvmRequestContext context)
 {
     writer.AddKnockoutDataBind("withGridViewDataSet", GetDataSourceBinding().GetKnockoutBindingExpression(this));
     base.AddAttributesToRender(writer, context);
 }
Пример #39
0
 public static void AddKnockoutDataBind(this IHtmlWriter writer, string name, IValueBinding valueBinding)
 {
     writer.AddKnockoutDataBind(name, valueBinding.GetKnockoutBindingExpression());
 }
Пример #40
0
 protected virtual void WriteEnabledBinding(IHtmlWriter writer, IValueBinding binding)
 {
     writer.AddKnockoutDataBind("dotvvmEnable", binding.GetKnockoutBindingExpression(this));
     writer.AddAttribute("onclick", "return !this.hasAttribute('disabled');");
 }
Пример #41
0
 protected virtual void WriteEnabledBinding(IHtmlWriter writer, bool binding)
 {
     writer.AddKnockoutDataBind("dotvvmEnable", binding.ToString().ToLower());
     writer.AddAttribute("onclick", "return !this.hasAttribute('disabled');");
 }
Пример #42
0
 protected virtual void AddKnockoutActiveCssDataBind(IHtmlWriter writer, IDotvvmRequestContext context, string expression)
 {
     writer.AddKnockoutDataBind("css", $"{{ 'active': {expression} }}");
 }
Пример #43
0
        /// <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);
                }

                KnockoutBindingGroup cssClassBindingGroup = null;
                foreach (var cssClass in CssClasses.Properties)
                {
                    if (cssClassBindingGroup == null)
                    {
                        cssClassBindingGroup = new KnockoutBindingGroup();
                    }
                    cssClassBindingGroup.Add(cssClass.GroupMemberName, this, cssClass, null);
                }
                if (cssClassBindingGroup != null)
                {
                    writer.AddKnockoutDataBind("css", cssClassBindingGroup);
                }

                // 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);
        }
Пример #44
0
 protected virtual void RenderSelectedValueProperty(IHtmlWriter writer)
 {
     writer.AddKnockoutDataBind("selectedOptions", this, SelectedValuesProperty, renderEvenInServerRenderingMode: true);
 }
        protected override void AddAttributesToRender(IHtmlWriter writer, IDotvvmRequestContext context)
        {
            writer.AddKnockoutDataBind("cc-ExpressionTextBox", "true");

            base.AddAttributesToRender(writer, context);
        }
Пример #46
0
 /// <summary>
 /// Adds all attributes that should be added to the control begin tag.
 /// </summary>
 protected override void AddAttributesToRender(IHtmlWriter writer, IDotvvmRequestContext context)
 {
     base.AddAttributesToRender(writer, context);
     writer.AddKnockoutDataBind("size", this, SizeProperty, () => writer.AddAttribute("size", Size.ToString()));
 }
Пример #47
0
        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);
        }
Пример #48
0
 protected virtual void WriteEnabledBinding(IHtmlWriter writer, bool binding)
 {
     writer.AddKnockoutDataBind("dotvvmEnable", binding.ToString().ToLower());
 }
Пример #49
0
        protected virtual void RenderCheckedItemsBinding(IHtmlWriter writer)
        {
            var checkedItemsBinding = GetValueBinding(CheckedItemsProperty);

            writer.AddKnockoutDataBind("checked", checkedItemsBinding !.GetKnockoutBindingExpression(this));
        }
 protected override void AddAttributesToRender(IHtmlWriter writer, IDotvvmRequestContext context)
 {
     writer.AddKnockoutDataBind("doneTyping", "function () { " + KnockoutHelper.GenerateClientPostBackScript(nameof(DoneTyping), GetCommandBinding(DoneTypingProperty), this, true, null, false, "$element") + " } ");
     writer.AddAttribute("delay", SearchDelayInMs.ToString());
     base.AddAttributesToRender(writer, context);
 }
Пример #51
0
        /// <summary>
        /// Adds all attributes that should be added to the control begin tag.
        /// </summary>
        protected override void AddAttributesToRender(IHtmlWriter writer, IDotvvmRequestContext context)
        {
            writer.AddKnockoutDataBind("enable", this, EnabledProperty, () =>
            {
                if (!Enabled)
                {
                    writer.AddAttribute("disabled", "disabled");
                }
            });

            AddValueAndFormatBindingAttribute(writer, context);

            if (Type == TextBoxType.MultiLine)
            {
                TagName = "textarea";
            }
            else if (Type == TextBoxType.Normal)
            {
                TagName = "input";

                // do not overwrite type attribute
                if (!Attributes.ContainsKey("type"))
                {
                    writer.AddAttribute("type", "text");
                }
            }
            else
            {
                string type = null;
                switch (Type)
                {
                case TextBoxType.Password:
                    type = "password";
                    break;

                case TextBoxType.Telephone:
                    type = "tel";
                    break;

                case TextBoxType.Url:
                    type = "url";
                    break;

                case TextBoxType.Email:
                    type = "email";
                    break;

                case TextBoxType.Date:
                    type = "date";
                    break;

                case TextBoxType.Time:
                    type = "time";
                    break;

                case TextBoxType.Color:
                    type = "color";
                    break;

                case TextBoxType.Search:
                    type = "search";
                    break;

                case TextBoxType.Number:
                    type = "number";
                    break;

                default:
                    throw new NotSupportedException($"TextBox Type '{ Type }' not supported");
                }
                writer.AddAttribute("type", type);
                TagName = "input";
            }

            // prepare changed event attribute
            var changedBinding = GetCommandBinding(ChangedProperty);

            if (changedBinding != null)
            {
                writer.AddAttribute("onchange", KnockoutHelper.GenerateClientPostBackScript(nameof(Changed), changedBinding, this, useWindowSetTimeout: true, isOnChange: true));
            }

            base.AddAttributesToRender(writer, context);
        }
Пример #52
0
        protected override void AddAttributesToRender(IHtmlWriter writer, IDotvvmRequestContext context)
        {
            writer.AddKnockoutDataBind("withGridViewDataSet", GetDataSourceBinding());

            if (!ShowHeaderWhenNoData && !IsPropertySet(VisibleProperty))
            {
                writer.AddKnockoutDataBind("visible", $"dotvvm.evaluator.getDataSourceItems({GetDataSourceBinding().GetKnockoutBindingExpression()}).length");
            }

            base.AddAttributesToRender(writer, context);
        }
Пример #53
0
 protected virtual void RenderSelectedValueProperty(IHtmlWriter writer)
 {
     writer.AddKnockoutDataBind("value", this, SelectedValueProperty, renderEvenInServerRenderingMode: true);
     writer.AddKnockoutDataBind("valueAllowUnset", "true");
 }
Пример #54
0
        /// <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();
            }
        }
Пример #55
0
 public static void AddKnockoutDataBind(this IHtmlWriter writer, string name, IValueBinding valueBinding, DotvvmBindableObject control)
 {
     writer.AddKnockoutDataBind(name, valueBinding.GetKnockoutBindingExpression(control));
 }