Esempio n. 1
0
        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();
            }
        }
Esempio n. 2
0
        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();
        }
Esempio n. 3
0
        /// <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();
        }
Esempio n. 4
0
        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();
        }
Esempio n. 5
0
        /// <summary>
        /// Renders the control to the writer.
        /// </summary>
        protected override void RenderControl(IHtmlWriter writer)
        {
            writer.RenderBeginTag("select");

            var itemsSourceExpression = KnockoutBindingHelper.GetBindingExpressionOrNull(ItemsSourceProperty, this);
            if (KnockoutBindingHelper.IsKnockoutBinding(itemsSourceExpression))
            {
                // render items on client
                writer.AddBindingAttribute("options", KnockoutBindingHelper.TranslateToKnockoutProperty(this, ItemsSourceProperty, itemsSourceExpression));
                if (DisplayNullItem)
                {
                    writer.AddBindingAttribute("optionsCaption", NullItemText);
                }
                if (DisplayMemberBinding != null)
                {
                    writer.AddBindingAttribute("optionsText", KnockoutBindingHelper.TranslateToKnockoutProperty(this, DisplayMemberBindingProperty, DisplayMemberBinding));
                }
                if (ValueMemberBinding != null)
                {
                    writer.AddBindingAttribute("optionsValue", KnockoutBindingHelper.TranslateToKnockoutProperty(this, ValueMemberBindingProperty, ValueMemberBinding));
                }
            }
            else if (ItemsSource != null)
            {
                // render items on server
                if (DisplayNullItem)
                {
                    writer.RenderBeginTag("option");
                    writer.AddAttribute("value", "");
                    writer.WriteText(NullItemText, true);
                    writer.RenderEndTag();
                }

                // render on server
                foreach (var item in ItemsSource)
                {
                    var itemValue = EvaluateValueMember(item);
                    var itemText = (EvaluateDisplayMember(item) ?? "").ToString();
                    var isSelected = (itemValue == null && SelectedValue == null) || itemValue.Equals(SelectedValue);

                    writer.RenderBeginTag("option");
                    writer.AddAttribute("value", (itemValue ?? "").ToString());
                    writer.WriteText(itemText, true);
                    if (isSelected)
                    {
                        writer.AddAttribute("selected", "selected");
                    }
                    writer.RenderEndTag();
                }
            }
        }