Пример #1
0
        protected override void RenderContents(IHtmlWriter writer, IDotvvmRequestContext context)
        {
            var properties =
                GetDeclaredProperties()
                .Where(p => !p.DeclaringType.IsAssignableFrom(typeof(DotvvmMarkupControl)))
                .Select(GetPropertySerializationInfo)
                .Where(p => p.IsSerializable)
                .Select(p => JsonConvert.SerializeObject(p.Property.Name) + ": " + p.Js);

            writer.WriteKnockoutDataBindComment("dotvvm_withControlProperties", "{ " + string.Join(", ", properties) + " }");
            base.RenderContents(writer, context);
            writer.WriteKnockoutDataBindEndComment();
        }
Пример #2
0
        protected override void RenderBeginTag(IHtmlWriter writer, IDotvvmRequestContext context)
        {
            TagName = WrapperTagName;

            if (!RenderOnServer)
            {
                if (RenderWrapperTag)
                {
                    //writer.AddKnockoutForeachDataBind(javascriptDataSourceExpression);

                    writer.AddKnockoutDataBind("foreach", GetForeachKnockoutBindingGroup());
                }
                else
                {
                    writer.WriteKnockoutDataBindComment("foreach", GetForeachKnockoutBindingGroup().ToString());
                }
            }

            if (RenderWrapperTag)
            {
                base.RenderBeginTag(writer, context);
            }
        }
Пример #3
0
 public static void WriteKnockoutWithComment(this IHtmlWriter writer, string binding)
 {
     writer.WriteKnockoutDataBindComment("with", binding);
 }
Пример #4
0
 /// <summary>
 /// Add knockout data bind comment dotvvm_withControlProperties with the specified properties
 /// </summary>
 public static void AddCommentAliasBinding(IHtmlWriter writer, IDictionary <string, string> properties)
 {
     writer.WriteKnockoutDataBindComment("dotvvm_introduceAlias", "{" + string.Join(", ", properties.Select(p => JsonConvert.ToString(p.Key) + ":" + properties.Values)) + "}");
 }
Пример #5
0
        protected override void RenderContents(IHtmlWriter writer, IDotvvmRequestContext context)
        {
            // render the header
            head?.Render(writer, context);

            // render body
            if (!RenderOnServer)
            {
                writer.AddKnockoutForeachDataBind("dotvvm.evaluator.getDataSourceItems($gridViewDataSet)");
            }
            writer.RenderBeginTag("tbody");

            // render contents
            if (RenderOnServer)
            {
                // render on server
                var index = 0;
                foreach (var child in Children.Except(new[] { head, emptyDataContainer }))
                {
                    child.Render(writer, context);
                    index++;
                }
            }
            else
            {
                // render on client
                if (InlineEditing)
                {
                    var placeholder = new DataItemContainer { DataContext = null };
                    placeholder.SetValue(Internal.PathFragmentProperty, JavascriptCompilationHelper.AddIndexerToViewModel(GetPathFragmentExpression(), "$index"));
                    placeholder.SetValue(Internal.ClientIDFragmentProperty, "$index()");
                    writer.WriteKnockoutDataBindComment("if", "ko.unwrap(ko.unwrap($gridViewDataSet).EditRowId) !== ko.unwrap($data[ko.unwrap(ko.unwrap($gridViewDataSet).PrimaryKeyPropertyName)])");
                    CreateTemplates(context, placeholder);
                    Children.Add(placeholder);
                    placeholder.Render(writer, context);
                    writer.WriteKnockoutDataBindEndComment();

                    var placeholderEdit = new DataItemContainer { DataContext = null };
                    placeholderEdit.SetValue(Internal.PathFragmentProperty, JavascriptCompilationHelper.AddIndexerToViewModel(GetPathFragmentExpression(), "$index"));
                    placeholderEdit.SetValue(Internal.ClientIDFragmentProperty, "$index()");
                    writer.WriteKnockoutDataBindComment("if", "ko.unwrap(ko.unwrap($gridViewDataSet).EditRowId) === ko.unwrap($data[ko.unwrap(ko.unwrap($gridViewDataSet).PrimaryKeyPropertyName)])");
                    CreateTemplates(context, placeholderEdit, true);
                    Children.Add(placeholderEdit);
                    placeholderEdit.Render(writer, context);
                    writer.WriteKnockoutDataBindEndComment();
                }
                else
                {
                    var placeholder = new DataItemContainer { DataContext = null };
                    placeholder.SetValue(Internal.PathFragmentProperty, JavascriptCompilationHelper.AddIndexerToViewModel(GetPathFragmentExpression(), "$index"));
                    placeholder.SetValue(Internal.ClientIDFragmentProperty, "$index()");
                    CreateRowWithCells(context, placeholder);
                    Children.Add(placeholder);
                    placeholder.Render(writer, context);

                }
            }

            writer.RenderEndTag();
        }
Пример #6
0
        protected override void RenderContents(IHtmlWriter writer, IDotvvmRequestContext context)
        {
            // render the header
            head?.Render(writer, context);

            // render body
            if (!RenderOnServer)
            {
                writer.AddKnockoutForeachDataBind("dotvvm.evaluator.getDataSourceItems($gridViewDataSet)");
            }
            writer.RenderBeginTag("tbody");

            // render contents
            if (RenderOnServer)
            {
                // render on server
                var index = 0;
                foreach (var child in Children.Except(new[] { head, emptyDataContainer }))
                {
                    child.Render(writer, context);
                    index++;
                }
            }
            else
            {
                // render on client
                if (InlineEditing)
                {
                    var propertySerialization = context.Services
                                                .GetRequiredService <IPropertySerialization>();
                    var primaryKeyProperty     = ResolvePrimaryKeyProperty();
                    var primaryKeyPropertyName = propertySerialization.ResolveName(primaryKeyProperty);

                    var placeholder = new DataItemContainer {
                        DataContext = null
                    };
                    placeholder.SetDataContextTypeFromDataSource(GetBinding(DataSourceProperty));
                    placeholder.SetValue(Internal.PathFragmentProperty, GetPathFragmentExpression() + "/[$index]");
                    placeholder.SetValue(Internal.ClientIDFragmentProperty, GetValueRaw(Internal.CurrentIndexBindingProperty));
                    writer.WriteKnockoutDataBindComment("if", "ko.unwrap(ko.unwrap($gridViewDataSet).RowEditOptions().EditRowId) " +
                                                        $"!== ko.unwrap($data['{primaryKeyPropertyName}'])");
                    CreateTemplates(context, placeholder);
                    Children.Add(placeholder);
                    placeholder.Render(writer, context);
                    writer.WriteKnockoutDataBindEndComment();

                    var placeholderEdit = new DataItemContainer {
                        DataContext = null
                    };
                    placeholderEdit.SetDataContextTypeFromDataSource(GetBinding(DataSourceProperty));
                    placeholderEdit.SetValue(Internal.PathFragmentProperty, GetPathFragmentExpression() + "/[$index]");
                    placeholderEdit.SetValue(Internal.ClientIDFragmentProperty, GetValueRaw(Internal.CurrentIndexBindingProperty));
                    writer.WriteKnockoutDataBindComment("if", "ko.unwrap(ko.unwrap($gridViewDataSet).RowEditOptions().EditRowId) " +
                                                        $"=== ko.unwrap($data['{primaryKeyPropertyName}'])");
                    CreateTemplates(context, placeholderEdit, true);
                    Children.Add(placeholderEdit);
                    placeholderEdit.Render(writer, context);
                    writer.WriteKnockoutDataBindEndComment();
                }
                else
                {
                    var placeholder = new DataItemContainer {
                        DataContext = null
                    };
                    placeholder.SetDataContextTypeFromDataSource(GetBinding(DataSourceProperty));
                    placeholder.SetValue(Internal.PathFragmentProperty, GetPathFragmentExpression() + "/[$index]");
                    placeholder.SetValue(Internal.ClientIDFragmentProperty, GetValueRaw(Internal.CurrentIndexBindingProperty));
                    Children.Add(placeholder);
                    CreateRowWithCells(context, placeholder);
                    placeholder.Render(writer, context);
                }
            }

            writer.RenderEndTag();
        }
Пример #7
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);
        }
Пример #8
0
        protected override void RenderContents(IHtmlWriter writer, RenderContext context)
        {
            // render the header
            head?.Render(writer, context);

            // render body
            if (!RenderOnServer)
            {
                writer.AddKnockoutForeachDataBind("dotvvm.evaluator.getDataSourceItems($data)");
            }
            writer.RenderBeginTag("tbody");


            // render contents
            if (RenderOnServer)
            {
                // render on server
                var index = 0;
                foreach (var child in Children.Except(new[] { head, emptyDataContainer }))
                {
                    child.Render(writer, context);
                    index++;
                }
            }
            else
            {
                // render on client
                if (InlineEditing)
                {
                    var placeholder = new DataItemContainer {
                        DataContext = null
                    };
                    placeholder.SetValue(Internal.PathFragmentProperty, JavascriptCompilationHelper.AddIndexerToViewModel(GetPathFragmentExpression(), "$index"));
                    placeholder.SetValue(Internal.ClientIDFragmentProperty, "'i' + $index()");
                    writer.WriteKnockoutDataBindComment("if", "ko.unwrap($parent.EditRowId) !== ko.unwrap($data[ko.unwrap($parent.PrimaryKeyPropertyName)])");
                    CreateTemplates(context.RequestContext, placeholder);
                    Children.Add(placeholder);
                    placeholder.Render(writer, context);
                    writer.WriteKnockoutDataBindEndComment();

                    var placeholderEdit = new DataItemContainer {
                        DataContext = null
                    };
                    placeholderEdit.SetValue(Internal.PathFragmentProperty, JavascriptCompilationHelper.AddIndexerToViewModel(GetPathFragmentExpression(), "$index"));
                    placeholderEdit.SetValue(Internal.ClientIDFragmentProperty, "'i' + $index()");
                    writer.WriteKnockoutDataBindComment("if", "ko.unwrap($parent.EditRowId) === ko.unwrap($data[ko.unwrap($parent.PrimaryKeyPropertyName)])");
                    CreateTemplates(context.RequestContext, placeholderEdit, true);
                    Children.Add(placeholderEdit);
                    placeholderEdit.Render(writer, context);
                    writer.WriteKnockoutDataBindEndComment();
                }
                else
                {
                    var placeholder = new DataItemContainer {
                        DataContext = null
                    };
                    placeholder.SetValue(Internal.PathFragmentProperty, JavascriptCompilationHelper.AddIndexerToViewModel(GetPathFragmentExpression(), "$index"));
                    placeholder.SetValue(Internal.ClientIDFragmentProperty, "'i' + $index()");
                    CreateRow(context.RequestContext, placeholder);
                    Children.Add(placeholder);
                    placeholder.Render(writer, context);
                }
            }

            writer.RenderEndTag();
        }
Пример #9
0
        protected override void RenderBeginTag(IHtmlWriter writer, IDotvvmRequestContext context)
        {
            if (HasValueBinding(EnabledProperty))
                writer.WriteKnockoutDataBindComment("dotvvm_introduceAlias", $"{{ '$pagerEnabled': { GetValueBinding(EnabledProperty).GetKnockoutBindingExpression() }}}");

            if (HideWhenOnlyOnePage)
            {
                writer.AddKnockoutDataBind("visible", "ko.unwrap(" + GetDataSetBinding().GetKnockoutBindingExpression() + ").PagesCount() > 1");
            }

            writer.AddKnockoutDataBind("with", this, DataSetProperty, renderEvenInServerRenderingMode: true);
            writer.RenderBeginTag("ul");
        }
Пример #10
0
 protected override void RenderBeginTag(IHtmlWriter writer, IDotvvmRequestContext context)
 {
     if (RenderWrapperTag)
     {
         base.RenderBeginTag(writer, context);
     }
     else if (HasBinding(HtmlProperty))
     {
         writer.WriteKnockoutDataBindComment("html", this, HtmlProperty);
     }
 }
Пример #11
0
 /// <summary>
 /// Add knockout data bind comment dotvvm_withControlProperties with the specified properties
 /// </summary>
 public static void AddCommentAliasBinding(IHtmlWriter writer, IDictionary<string, string> properties)
 {
     writer.WriteKnockoutDataBindComment("dotvvm_introduceAlias", "{" + string.Join(", ", properties.Select(p => JsonConvert.ToString(p.Key) + ":" + properties.Values)) + "}");
 }
Пример #12
0
 public static void WriteKnockoutDataBindComment(this IHtmlWriter writer, string name, DotvvmBindableObject control, DotvvmProperty property)
 {
     writer.WriteKnockoutDataBindComment(name, control.GetValueBinding(property).GetKnockoutBindingExpression(control));
 }
Пример #13
0
        protected override void RenderContents(IHtmlWriter writer, RenderContext context)
        {
            writer.AddKnockoutDataBind("css", "{ 'disabled': IsFirstPage() }");
            firstLi.Render(writer, context);

            writer.AddKnockoutDataBind("css", "{ 'disabled': IsFirstPage() }");
            previousLi.Render(writer, context);

            // render template
            writer.WriteKnockoutDataBindComment("foreach", "NearPageIndexes");
            context.PathFragments.Push("NearPageIndexes[$index]");

            // render page number
            numbersPlaceholder.Children.Clear();
            HtmlGenericControl li;
            if (!RenderLinkForCurrentPage)
            {
                writer.AddKnockoutDataBind("visible", "$data == $parent.PageIndex()");
                li = new HtmlGenericControl("li");
                li.SetValue(Internal.IsDataContextBoundaryProperty, true);
                var literal = new Literal();
                literal.SetBinding(Literal.TextProperty, new ValueBindingExpression("_this + 1"));
                li.Children.Add(literal);
                numbersPlaceholder.Children.Add(li);
                li.Render(writer, context);

                writer.AddKnockoutDataBind("visible", "$data != $parent.PageIndex()");
            }
            writer.AddKnockoutDataBind("css", "{ 'active': $data == $parent.PageIndex()}");
            li = new HtmlGenericControl("li");
            li.SetValue(Internal.IsDataContextBoundaryProperty, true);
            var link = new LinkButton();
            link.SetBinding(ButtonBase.TextProperty, new ValueBindingExpression("_this + 1"));
            link.SetBinding(ButtonBase.ClickProperty, new CommandBindingExpression("_parent.GoToPage(_this)"));
            li.Children.Add(link);
            numbersPlaceholder.Children.Add(li);
            li.Render(writer, context);

            context.PathFragments.Pop();
            writer.WriteKnockoutDataBindEndComment();

            writer.AddKnockoutDataBind("css", "{ 'disabled': IsLastPage() }");
            nextLi.Render(writer, context);

            writer.AddKnockoutDataBind("css", "{ 'disabled': IsLastPage() }");
            lastLi.Render(writer, context);
        }
Пример #14
0
 protected override void RenderBeginTag(IHtmlWriter writer, IDotvvmRequestContext context)
 {
     if (RenderSpanElement)
     {
         base.RenderBeginTag(writer, context);
     }
     else if (renderAsKnockoutBinding)
     {
         writer.WriteKnockoutDataBindComment("text", knockoutBindingExpression);
     }
 }