コード例 #1
0
        private void WriteHtml(IHtmlWriter html, DebugRegion region, int depth)
        {
            if (region.Element != null)
            {
                html.WriteElementLine("p", "zone inherits from '" + region.Element.Name + "' region");
                if (depth != 1)
                {
                    StartIndent(html, false);
                    WriteDebugInfo(html, region.Element.GetDebugInfo(), 2);
                    EndIndent(html);
                }
            }

            if (region.RepeatType != null)
            {
                html.WriteOpenTag("p");
                html.WriteText("Repeat region for each ");
                html.WriteElement("i", region.RepeatType.DisplayName());
                if (!string.IsNullOrEmpty(region.RepeatScope))
                {
                    html.WriteText(" in '" + region.RepeatScope + "' scope");
                }
                html.WriteText(" from ");
                html.WriteElement("i", region.ListType.DisplayName());
                if (!string.IsNullOrEmpty(region.ListScope))
                {
                    html.WriteText(" in '" + region.ListScope + "' scope");
                }
                html.WriteCloseTag("p");
                html.WriteLine();
            }

            if (region.Scope != null)
            {
                if (region.Scope.Scopes != null)
                {
                    html.WriteElementLine("p", "zone data scope");
                    StartIndent(html, false);
                    WriteDebugInfo(html, region.Scope, 3);
                    EndIndent(html);
                }
            }

            if (region.Children != null && region.Children.Count > 0)
            {
                html.WriteElementLine("p", "zone has contents");
                if (depth != 1)
                {
                    StartIndent(html, true);
                    WriteDebugInfo(html, region.Children[0], depth - 1);
                    EndIndent(html);
                }
            }
        }
コード例 #2
0
        protected override void RenderContents(IHtmlWriter writer, IDotvvmRequestContext context)
        {
            AddAttributesToInput(writer);
            RenderInputTag(writer);

            if (isLabelRequired)
            {
                if (HasValueBinding(TextProperty))
                {
                    writer.AddKnockoutDataBind("text", GetValueBinding(TextProperty).GetKnockoutBindingExpression(this));
                    writer.RenderBeginTag(TagName);
                    writer.RenderEndTag();
                }
                else if (!string.IsNullOrEmpty(Text))
                {
                    writer.RenderBeginTag(TagName);
                    writer.WriteText(Text);
                    writer.RenderEndTag();
                }
                else if (!HasOnlyWhiteSpaceContent())
                {
                    writer.RenderBeginTag(TagName);
                    RenderChildren(writer, context);
                    writer.RenderEndTag();
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// Writes text iff the property contains hard-coded value OR
        /// writes knockout text binding iff the property contains binding
        /// </summary>
        /// <param name="writer">HTML output writer</param>
        /// <param name="obj">Dotvvm control which contains the <see cref="DotvvmProperty"/> with value to be written</param>
        /// <param name="property">Value of this property will be written</param>
        /// <param name="wrapperTag">Name of wrapper tag, null => knockout binding comment</param>
        public static void WriteTextOrBinding(this IHtmlWriter writer, DotvvmBindableObject obj, DotvvmProperty property, string wrapperTag = null)
        {
            var valueBinding = obj.GetValueBinding(property);

            if (valueBinding != null)
            {
                if (wrapperTag == null)
                {
                    writer.WriteKnockoutDataBindComment("text", valueBinding.GetKnockoutBindingExpression(obj));
                    writer.WriteKnockoutDataBindEndComment();
                }
                else
                {
                    writer.AddKnockoutDataBind("text", valueBinding.GetKnockoutBindingExpression(obj));
                    writer.RenderBeginTag(wrapperTag);
                    writer.RenderEndTag();
                }
            }
            else
            {
                if (wrapperTag != null)
                {
                    writer.RenderBeginTag(wrapperTag);
                }
                writer.WriteText(obj.GetValue(property).ToString());
                if (wrapperTag != null)
                {
                    writer.RenderEndTag();
                }
            }
        }
コード例 #4
0
ファイル: TextBox.cs プロジェクト: vnwonah/dotvvm
 protected override void RenderContents(IHtmlWriter writer, IDotvvmRequestContext context)
 {
     if (Type == TextBoxType.MultiLine && GetValueBinding(TextProperty) == null)
     {
         writer.WriteText(Text);
     }
 }
コード例 #5
0
ファイル: TextBox.cs プロジェクト: jechtom/Redwood
        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();
        }
コード例 #6
0
        protected override void RenderContents(IHtmlWriter writer, IDotvvmRequestContext context)
        {
            if (TagName is null)
            {
                throw new DotvvmControlException(this, "CheckableControlBase must have a tag name");
            }
            AddAttributesToInput(writer);
            RenderInputTag(writer);

            if (isLabelRequired)
            {
                if (GetValueBinding(TextProperty) is IValueBinding textBinding)
                {
                    writer.AddKnockoutDataBind("text", textBinding.GetKnockoutBindingExpression(this));
                    writer.RenderBeginTag(TagName);
                    writer.RenderEndTag();
                }
                else if (!string.IsNullOrEmpty(Text))
                {
                    writer.RenderBeginTag(TagName);
                    writer.WriteText(Text);
                    writer.RenderEndTag();
                }
                else if (!HasOnlyWhiteSpaceContent())
                {
                    writer.RenderBeginTag(TagName);
                    RenderChildren(writer, context);
                    writer.RenderEndTag();
                }
            }
        }
コード例 #7
0
        /// <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);
                }
            }
        }
コード例 #8
0
 public virtual void WriteText(string text)
 {
     if (StartTagSkipped)
     {
         return;
     }
     writer.WriteText(text);
 }
コード例 #9
0
ファイル: SelectorItem.cs プロジェクト: vnwonah/dotvvm
 protected override void RenderContents(IHtmlWriter writer, IDotvvmRequestContext context)
 {
     if (Text is string t)
     {
         writer.WriteText(t);
     }
     base.RenderContents(writer, context);
 }
コード例 #10
0
        /// <summary>
        /// Renders the children.
        /// </summary>
        protected override void RenderControl(IHtmlWriter writer, RenderContext context)
        {
            // label
            var textBinding   = GetValueBinding(TextProperty);
            var labelRequired = textBinding != null || !string.IsNullOrEmpty(Text) || !HasOnlyWhiteSpaceContent();

            if (labelRequired)
            {
                writer.RenderBeginTag("label");
            }

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

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

            // handle enabled attribute
            writer.AddKnockoutDataBind("enable", this, EnabledProperty, () =>
            {
                if (!Enabled)
                {
                    writer.AddAttribute("disabled", "disabled");
                }
            });

            // add ID
            AddAttributesToRender(writer, context);

            // render the radio button
            RenderInputTag(writer);

            // render the label
            if (labelRequired)
            {
                if (textBinding != null)
                {
                    writer.AddKnockoutDataBind("text", textBinding);
                    writer.RenderBeginTag("span");
                    writer.RenderEndTag();
                }
                else if (!string.IsNullOrEmpty(Text))
                {
                    writer.WriteText(Text);
                }
                else if (!HasOnlyWhiteSpaceContent())
                {
                    RenderChildren(writer, context);
                }

                writer.RenderEndTag();
            }
        }
コード例 #11
0
ファイル: IntegrationScripts.cs プロジェクト: jechtom/Redwood
        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();
        }
コード例 #12
0
 protected override void RenderContents(IHtmlWriter writer, IDotvvmRequestContext context)
 {
     if (HasOnlyWhiteSpaceContent())
     {
         writer.WriteText(Text);
     }
     else
     {
         base.RenderContents(writer, context);
     }
 }
コード例 #13
0
 private void RenderUploadButton(IHtmlWriter writer)
 {
     // render upload button
     writer.AddAttribute("class", "dotvvm-upload-button");
     writer.AddKnockoutDataBind("visible", "!IsBusy()");
     writer.RenderBeginTag("span");
     writer.AddAttribute("href", "#");
     writer.AddAttribute("onclick", "dotvvm.fileUpload.showUploadDialog(this); return false;");
     writer.RenderBeginTag("a");
     writer.WriteText(UploadButtonText);
     writer.RenderEndTag();
     writer.RenderEndTag();
 }
コード例 #14
0
ファイル: LinkButton.cs プロジェクト: holajan/dotvvm
 /// <summary>
 /// Renders the contents inside the control begin and end tags.
 /// </summary>
 protected override void RenderContents(IHtmlWriter writer, RenderContext context)
 {
     var textBinding = GetBinding(TextProperty);
     if (textBinding == null && !string.IsNullOrEmpty(Text))
     {
         // render static value of the text property
         writer.WriteText(Text);
     }
     else
     {
         // render control contents
         RenderChildren(writer, context);
     }
 }
コード例 #15
0
 protected override void RenderContents(IHtmlWriter writer, RenderContext context)
 {
     if (shouldRenderText)
     {
         if (!HasOnlyWhiteSpaceContent())
         {
             base.RenderContents(writer, context);
         }
         else
         {
             writer.WriteText(Text);
         }
     }
 }
コード例 #16
0
ファイル: ComboBox.cs プロジェクト: adamjez/dotvvm
        protected override void RenderContents(IHtmlWriter writer, RenderContext context)
        {
            if (RenderOnServer)
            {
                if (!string.IsNullOrWhiteSpace(EmptyItemText))
                {
                    writer.RenderBeginTag("option");
                    writer.WriteText(EmptyItemText);
                    writer.RenderEndTag();
                }
            }

            base.RenderContents(writer, context);
        }
コード例 #17
0
ファイル: ComboBox.cs プロジェクト: gitter-badger/dotvvm
        protected override void RenderContents(IHtmlWriter writer, RenderContext context)
        {
            if (RenderOnServer)
            {
                if (!string.IsNullOrWhiteSpace(EmptyItemText))
                {
                    writer.RenderBeginTag("option");
                    writer.WriteText(EmptyItemText);
                    writer.RenderEndTag();
                }
            }

            base.RenderContents(writer, context);
        }
コード例 #18
0
ファイル: RouteLink.cs プロジェクト: holajan/dotvvm
 protected override void RenderContents(IHtmlWriter writer, RenderContext context)
 {
     var textBinding = GetBinding(TextProperty);
     if (textBinding?.Javascript == null)
     {
         if (!string.IsNullOrEmpty(Text))
         {
             writer.WriteText(Text);
         }
         else
         {
             base.RenderContents(writer, context);
         }
     }
 }
コード例 #19
0
ファイル: LinkButton.cs プロジェクト: llenroc/dotvvm
 /// <summary>
 /// Renders the contents inside the control begin and end tags.
 /// </summary>
 protected override void RenderContents(IHtmlWriter writer, IDotvvmRequestContext context)
 {
     if (!HasValueBinding(TextProperty) || RenderOnServer)
     {
         if (!string.IsNullOrEmpty(Text))
         {
             // render static value of the text property
             writer.WriteText(Text);
         }
         else
         {
             // render control contents
             RenderChildren(writer, context);
         }
     }
 }
コード例 #20
0
ファイル: LinkButton.cs プロジェクト: darilek/dotvvm
 /// <summary>
 /// Renders the contents inside the control begin and end tags.
 /// </summary>
 protected override void RenderContents(IHtmlWriter writer, IDotvvmRequestContext context)
 {
     if (!HasValueBinding(TextProperty) || RenderOnServer)
     {
         if (!string.IsNullOrEmpty(Text))
         {
             // render static value of the text property
             writer.WriteText(Text);
         }
         else
         {
             // render control contents
             RenderChildren(writer, context);
         }
     }
 }
コード例 #21
0
ファイル: LinkButton.cs プロジェクト: gitter-badger/dotvvm
 /// <summary>
 /// Renders the contents inside the control begin and end tags.
 /// </summary>
 protected override void RenderContents(IHtmlWriter writer, RenderContext context)
 {
     if (shouldRenderText)
     {
         if (!string.IsNullOrEmpty(Text))
         {
             // render static value of the text property
             writer.WriteText(Text);
         }
         else
         {
             // render control contents
             RenderChildren(writer, context);
         }
     }
 }
コード例 #22
0
        protected override void RenderContents(IHtmlWriter writer, IDotvvmRequestContext context)
        {
            if (!HasValueBinding(TextProperty) && IsPropertySet(TextProperty))
            {
                if (!HasOnlyWhiteSpaceContent())
                {
                    throw new DotvvmControlException(this,
                                                     "Text property and inner content of the <pwa:OfflineAlert> control cannot be set at the same time!");
                }

                writer.WriteText(Text);
            }
            else
            {
                base.RenderContents(writer, context);
            }
        }
コード例 #23
0
ファイル: Literal.cs プロジェクト: gitter-badger/dotvvm
        protected override void RenderContents(IHtmlWriter writer, RenderContext context)
        {
            if (!renderAsKnockoutBinding)
            {
                var textToDisplay = "";
                if (!string.IsNullOrEmpty(FormatString))
                {
                    textToDisplay = string.Format("{0:" + FormatString + "}", GetValue(TextProperty));
                }
                else
                {
                    textToDisplay = GetValue(TextProperty)?.ToString() ?? "";
                }

                writer.WriteText(textToDisplay);
            }
        }
コード例 #24
0
ファイル: FormGroup.cs プロジェクト: adamjez/dotvvm
 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
 protected override void RenderContents(IHtmlWriter writer, RenderContext context)
 {
     if (ButtonTagName == ButtonTagName.button)
     {
         if (!HasBinding(TextProperty))
         {
             // render contents inside
             if (IsPropertySet(TextProperty))
             {
                 writer.WriteText(Text);
             }
             else
             {
                 base.RenderContents(writer, context);
             }
         }
     }
 }
コード例 #26
0
        static void WriteResourceInfo(NamedResource resource, IHtmlWriter writer, bool preload)
        {
            var comment = $"Resource {resource.Name} of type {resource.Resource.GetType().Name}.";

            if (resource.Resource is ILinkResource linkResource)
            {
                comment += $" Pointing to {string.Join(", ", linkResource.GetLocations().Select(l => l.GetType().Name))}.";
            }

            if (preload)
            {
                comment = "[preload link] " + comment;
            }

            writer.WriteUnencodedText("\n    <!-- ");
            writer.WriteText(comment);
            writer.WriteUnencodedText(" -->\n    ");
            //                               ^~~~ most likely this info will be written directly in the <body> or <head>, so it should be indented by one level.
            //                                    we don't have any better way to know how we should indent
        }
コード例 #27
0
        protected override void RenderContents(IHtmlWriter writer, IDotvvmRequestContext context)
        {
            if (ButtonTagName == ButtonTagName.button)
            {
                if (!HasValueBinding(TextProperty) && IsPropertySet(TextProperty))
                {
                    // render contents inside
                    if (!HasOnlyWhiteSpaceContent())
                    {
                        throw new DotvvmControlException(this, "Text property and inner content of the <dot:Button> control cannot be set at the same time!");
                    }

                    writer.WriteText(Text);
                }
                else
                {
                    base.RenderContents(writer, context);
                }
            }
        }
コード例 #28
0
ファイル: CheckBox.cs プロジェクト: jechtom/Redwood
        protected override void RenderControl(IHtmlWriter writer)
        {
            var textExpression = KnockoutBindingHelper.GetBindingExpressionOrNull(TextProperty, this);
            var needsLabel = KnockoutBindingHelper.IsKnockoutBinding(textExpression) || !string.IsNullOrEmpty(Text);

            // render the checkbox
            writer.RenderBeginTag("input");
            writer.AddAttribute("type", "checkbox");
            var isCheckedExpression = KnockoutBindingHelper.GetBindingExpressionOrNull(IsCheckedProperty, this);
            if (KnockoutBindingHelper.IsKnockoutBinding(isCheckedExpression))
            {
                writer.AddBindingAttribute("checked", KnockoutBindingHelper.TranslateToKnockoutProperty(this, IsCheckedProperty, isCheckedExpression));
            }
            else
            {
                writer.AddAttribute("checked", IsChecked ? "checked" : "");
            }
            if (needsLabel)
            {
                EnsureHasID();
                writer.AddAttribute("id", ID);
            }
            writer.RenderEndTag();

            // render the label
            if (needsLabel)
            {
                writer.RenderBeginTag("label");
                writer.AddAttribute("for", ID);
                if (KnockoutBindingHelper.IsKnockoutBinding(textExpression))
                {
                    writer.AddBindingAttribute("", KnockoutBindingHelper.TranslateToKnockoutProperty(this, TextProperty, textExpression));
                }
                else
                {
                    writer.WriteText(Text, true);
                }
                writer.RenderEndTag();
            }
        }
コード例 #29
0
ファイル: Literal.cs プロジェクト: samdubey/dotvvm
        protected override void RenderContents(IHtmlWriter writer, IDotvvmRequestContext context)
        {
            if (!renderAsKnockoutBinding)
            {
                var textToDisplay = "";
                if (isFormattingRequired)
                {
                    var formatString = FormatString;
                    if (string.IsNullOrEmpty(formatString))
                    {
                        formatString = "G";
                    }
                    textToDisplay = string.Format("{0:" + formatString + "}", GetValue(TextProperty));
                }
                else
                {
                    textToDisplay = GetValue(TextProperty)?.ToString() ?? "";
                }

                writer.WriteText(textToDisplay);
            }
        }
コード例 #30
0
ファイル: Button.cs プロジェクト: darilek/dotvvm
 protected override void RenderContents(IHtmlWriter writer, IDotvvmRequestContext context)
 {
     if (ButtonTagName == ButtonTagName.button)
     {
         if (!HasValueBinding(TextProperty))
         {
             // render contents inside
             if (IsPropertySet(TextProperty))
             {
                 if (!HasOnlyWhiteSpaceContent())
                 {
                     throw new DotvvmControlException(this, "Text property and inner content of the <dot:Button> control cannot be set at the same time!");
                 }
                 writer.WriteText(Text);
             }
             else
             {
                 base.RenderContents(writer, context);
             }
         }
     }
 }
コード例 #31
0
ファイル: SelectorItem.cs プロジェクト: darilek/dotvvm
 protected override void RenderContents(IHtmlWriter writer, IDotvvmRequestContext context)
 {
     writer.WriteText(Text);
     base.RenderContents(writer, context);
 }
コード例 #32
0
ファイル: RouteLink.cs プロジェクト: darilek/dotvvm
 protected override void RenderContents(IHtmlWriter writer, IDotvvmRequestContext context)
 {
     if (shouldRenderText)
     {
         if (!HasOnlyWhiteSpaceContent())
         {
             base.RenderContents(writer, context);
         }
         else
         {
             writer.WriteText(Text);
         }
     }
 }
コード例 #33
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();
            }
        }
コード例 #34
0
ファイル: Literal.cs プロジェクト: holajan/dotvvm
        /// <summary>
        /// Renders the control into the specified writer.
        /// </summary>
        protected override void RenderControl(IHtmlWriter writer, RenderContext context)
        {
            var textBinding = GetBinding(TextProperty);
            if (textBinding != null && !RenderOnServer && textBinding.Javascript != null)
            {
                var expression = textBinding.Javascript;
                if (!string.IsNullOrEmpty(FormatString))
                {
                    expression = "dotvvm.formatString(" + JsonConvert.SerializeObject(FormatString) + ", " + expression + ")";
                }

                writer.AddKnockoutDataBind(HtmlEncode ? "text" : "html", expression);
                AddAttributesToRender(writer, context);
                writer.RenderBeginTag("span");
                writer.RenderEndTag();
            }
            else
            {
                if (AlwaysRenderSpan)
                {
                    AddAttributesToRender(writer, context);
                    writer.RenderBeginTag("span");
                }

                var textToDisplay = "";
                if (!string.IsNullOrEmpty(FormatString))
                {
                    textToDisplay = string.Format("{0:" + FormatString + "}", GetValue(TextProperty));
                }
                else
                {
                    textToDisplay = GetValue(TextProperty)?.ToString() ?? "";
                }

                if (HtmlEncode)
                {
                    writer.WriteText(textToDisplay);
                }
                else
                {
                    writer.WriteUnencodedText(textToDisplay);
                }

                if (AlwaysRenderSpan)
                {
                    writer.RenderEndTag();
                }
            }
        }
コード例 #35
0
ファイル: DropDownList.cs プロジェクト: jechtom/Redwood
        /// <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();
                }
            }
        }
コード例 #36
0
ファイル: Literal.cs プロジェクト: hccntt/dotvvm
        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);
        }
コード例 #37
0
ファイル: Literal.cs プロジェクト: adamjez/dotvvm
        /// <summary>
        /// Renders the control into the specified writer.
        /// </summary>
        protected override void RenderControl(IHtmlWriter writer, RenderContext context)
        {
            var textBinding = GetBinding(TextProperty);
            if (textBinding != null && !RenderOnServer)
            {
                var expression = textBinding.TranslateToClientScript(this, TextProperty);
                if (!string.IsNullOrEmpty(FormatString))
                {
                    expression = "redwood.formatString(" + JsonConvert.SerializeObject(FormatString) + ", " + expression + ")";
                }

                writer.AddKnockoutDataBind(HtmlEncode ? "text" : "html", expression);
                writer.RenderBeginTag("span");
                writer.RenderEndTag();
            }
            else
            {
                var textToDisplay = Text;
                if (!string.IsNullOrEmpty(FormatString))
                {
                    textToDisplay = string.Format("{0:" + FormatString + "}", textToDisplay);
                }

                if (HtmlEncode)
                {
                    writer.WriteText(textToDisplay);
                }
                else
                {
                    writer.WriteUnencodedText(textToDisplay);
                }
            }
        }
コード例 #38
0
 protected override void RenderContents(IHtmlWriter writer, RenderContext context)
 {
     writer.WriteText(Text);
     base.RenderContents(writer, context);
 }
コード例 #39
0
ファイル: TextBox.cs プロジェクト: holajan/dotvvm
 /// <summary>
 /// Renders the contents inside the control begin and end tags.
 /// </summary>
 protected override void RenderContents(IHtmlWriter writer, RenderContext context)
 {
     if (Type == TextBoxType.MultiLine && GetValueBinding(TextProperty) == null)
     {
         writer.WriteText(Text);
     }
 }
コード例 #40
0
ファイル: Literal.cs プロジェクト: darilek/dotvvm
        protected override void RenderContents(IHtmlWriter writer, IDotvvmRequestContext context)
        {
            if (!renderAsKnockoutBinding)
            {
                var textToDisplay = "";
                if (isFormattingRequired)
                {
                    var formatString = FormatString;
                    if (string.IsNullOrEmpty(formatString))
                    {
                        formatString = "G";
                    }
                    textToDisplay = string.Format("{0:" + formatString + "}", GetValue(TextProperty));
                }
                else
                {
                    textToDisplay = GetValue(TextProperty)?.ToString() ?? "";
                }

                writer.WriteText(textToDisplay);
            }
        }