Exemple #1
0
 private object JoinValuesOrBindings(IList <object> fragments)
 {
     if (fragments.All(f => f is string))
     {
         return(string.Join("_", fragments));
     }
     else
     {
         BindingCompilationService service = null;
         var result = new ParametrizedCode.Builder();
         var first  = true;
         foreach (var f in fragments)
         {
             if (!first | (first = false))
             {
                 result.Add("+'_'+");
             }
             if (f is IValueBinding binding)
             {
                 service = service ?? binding.GetProperty <BindingCompilationService>(ErrorHandlingMode.ReturnNull);
                 result.Add(binding.GetParametrizedKnockoutExpression(this, unwraped: true), 14);
             }
             else
             {
                 result.Add(JavascriptCompilationHelper.CompileConstant(f));
             }
         }
         if (service == null)
         {
             throw new NotSupportedException();
         }
         return(ValueBindingExpression.CreateBinding <string>(service.WithoutInitialization(), h => null, result.Build(new OperatorPrecedence())));
     }
 }
Exemple #2
0
        private void DataBind(Hosting.IDotvvmRequestContext context)
        {
            if (DataSet is IRefreshableGridViewDataSet refreshableDataSet)
            {
                CallGridViewDataSetRefreshRequest(refreshableDataSet);
            }

            Children.Clear();

            content = new HtmlGenericControl("ul");
            var dataContextType = DataContextStack.Create(typeof(IPageableGridViewDataSet), this.GetDataContextType());

            content.SetDataContextType(dataContextType);
            content.SetBinding(DataContextProperty, GetDataSetBinding());
            Children.Add(content);

            var bindings = context.Services.GetService <CommonBindings>();

            var dataSet = DataSet;

            if (dataSet != null)
            {
                object enabledValue = HasValueBinding(EnabledProperty) ?
                                      (object)ValueBindingExpression.CreateBinding <bool>(
                    bindingService.WithoutInitialization(),
                    h => (bool)GetValueBinding(EnabledProperty).Evaluate(this),
                    new JsSymbolicParameter(JavascriptTranslator.KnockoutContextParameter).Member("$pagerEnabled")) :
                                      Enabled;

                // first button
                firstLi = new HtmlGenericControl("li");
                var firstLink = new LinkButton();
                SetButtonContent(context, firstLink, "««", FirstPageTemplate);
                firstLink.SetBinding(ButtonBase.ClickProperty, bindings.GoToFirstPageCommand);
                if (!true.Equals(enabledValue))
                {
                    firstLink.SetValue(LinkButton.EnabledProperty, enabledValue);
                }
                firstLi.Children.Add(firstLink);
                content.Children.Add(firstLi);

                // previous button
                previousLi = new HtmlGenericControl("li");
                var previousLink = new LinkButton();
                SetButtonContent(context, previousLink, "«", PreviousPageTemplate);
                previousLink.SetBinding(ButtonBase.ClickProperty, bindings.GoToPrevPageCommand);
                if (!true.Equals(enabledValue))
                {
                    previousLink.SetValue(LinkButton.EnabledProperty, enabledValue);
                }
                previousLi.Children.Add(previousLink);
                content.Children.Add(previousLi);

                // number fields
                numbersPlaceHolder = new PlaceHolder();
                content.Children.Add(numbersPlaceHolder);

                var i = 0;
                foreach (var number in dataSet.PagingOptions.NearPageIndexes)
                {
                    var li = new HtmlGenericControl("li");
                    li.SetBinding(DataContextProperty, GetNearIndexesBinding(context, i, dataContextType));
                    if (number == dataSet.PagingOptions.PageIndex)
                    {
                        li.Attributes["class"] = "active";
                    }
                    var link = new LinkButton()
                    {
                        Text = (number + 1).ToString()
                    };
                    link.SetBinding(ButtonBase.ClickProperty, bindings.GoToThisPageCommand);
                    if (!true.Equals(enabledValue))
                    {
                        link.SetValue(LinkButton.EnabledProperty, enabledValue);
                    }
                    li.Children.Add(link);
                    numbersPlaceHolder.Children.Add(li);

                    i++;
                }

                // next button
                nextLi = new HtmlGenericControl("li");
                var nextLink = new LinkButton();
                SetButtonContent(context, nextLink, "»", NextPageTemplate);
                nextLink.SetBinding(ButtonBase.ClickProperty, bindings.GoToNextPageCommand);
                if (!true.Equals(enabledValue))
                {
                    nextLink.SetValue(LinkButton.EnabledProperty, enabledValue);
                }
                nextLi.Children.Add(nextLink);
                content.Children.Add(nextLi);

                // last button
                lastLi = new HtmlGenericControl("li");
                var lastLink = new LinkButton();
                SetButtonContent(context, lastLink, "»»", LastPageTemplate);
                if (!true.Equals(enabledValue))
                {
                    lastLink.SetValue(LinkButton.EnabledProperty, enabledValue);
                }
                lastLink.SetBinding(ButtonBase.ClickProperty, bindings.GoToLastPageCommand);
                lastLi.Children.Add(lastLink);
                content.Children.Add(lastLi);
            }
        }
Exemple #3
0
        protected virtual void DataBind(Hosting.IDotvvmRequestContext context)
        {
            Children.Clear();

            var dataContextType = DataContextStack.Create(typeof(IPageableGridViewDataSet), this.GetDataContextType());

            ContentWrapper = CreateWrapperList(dataContextType);
            Children.Add(ContentWrapper);

            var bindings = context.Services.GetRequiredService <CommonBindings>();

            object enabledValue = (HasValueBinding(EnabledProperty) ?
                                   (object)ValueBindingExpression.CreateBinding <bool>(
                                       bindingService.WithoutInitialization(),
                                       h => (bool)GetValueBinding(EnabledProperty).Evaluate(this),
                                       new JsSymbolicParameter(JavascriptTranslator.KnockoutContextParameter).Member("$pagerEnabled")) :
                                   Enabled);


            GoToFirstPageButton = CreateNavigationButton("««", FirstPageTemplate, enabledValue, bindings.GoToFirstPageCommand, context);
            ContentWrapper.Children.Add(GoToFirstPageButton);

            GoToPreviousPageButton = CreateNavigationButton("«", PreviousPageTemplate, enabledValue, bindings.GoToPrevPageCommand, context);
            ContentWrapper.Children.Add(GoToPreviousPageButton);

            // number fields
            NumberButtonsPlaceHolder = new PlaceHolder();
            ContentWrapper.Children.Add(NumberButtonsPlaceHolder);

            var dataSet = DataSet;

            if (dataSet != null)
            {
                var i = 0;
                foreach (var number in dataSet.PagingOptions.NearPageIndexes)
                {
                    var li = new HtmlGenericControl("li");
                    li.SetBinding(DataContextProperty, GetNearIndexesBinding(context, i, dataContextType));
                    if (number == dataSet.PagingOptions.PageIndex)
                    {
                        li.Attributes["class"] = "active";
                    }
                    var link = new LinkButton()
                    {
                        Text = (number + 1).ToString()
                    };
                    link.SetBinding(ButtonBase.ClickProperty, bindings.GoToThisPageCommand);
                    if (!true.Equals(enabledValue))
                    {
                        link.SetValue(LinkButton.EnabledProperty, enabledValue);
                    }
                    li.Children.Add(link);
                    NumberButtonsPlaceHolder.Children.Add(li);

                    i++;
                }
            }

            GoToNextPageButton = CreateNavigationButton("»", NextPageTemplate, enabledValue, bindings.GoToNextPageCommand, context);
            ContentWrapper.Children.Add(GoToNextPageButton);

            GoToLastPageButton = CreateNavigationButton("»»", LastPageTemplate, enabledValue, bindings.GoToLastPageCommand, context);
            ContentWrapper.Children.Add(GoToLastPageButton);
        }