예제 #1
0
        private void SetUpServerItem(IDotvvmRequestContext context, object item, int index, IValueBinding itemBinding, DataItemContainer container)
        {
            container.DataItemIndex = index;
            var bindingService = context.Configuration.ServiceLocator.GetService <BindingCompilationService>();

            container.SetBinding(DataContextProperty, ValueBindingExpression.CreateBinding(
                                     bindingService.WithoutInitialization(),
                                     j => item,
                                     itemBinding.KnockoutExpression.AssignParameters(p =>
                                                                                     p == JavascriptTranslator.CurrentIndexParameter ? new CodeParameterAssignment(index.ToString(), OperatorPrecedence.Max) :
                                                                                     default(CodeParameterAssignment))));
            container.SetValue(Internal.PathFragmentProperty, GetPathFragmentExpression() + "/[" + index + "]");
            container.ID = index.ToString();
        }
예제 #2
0
        /// <summary>
        /// Performs the data-binding and builds the controls inside the <see cref="Repeater"/>.
        /// </summary>
        private void DataBind(IDotvvmRequestContext context)
        {
            Children.Clear();
            emptyDataContainer = null;

            var dataSourceBinding = GetDataSourceBinding();
            var index             = 0;
            var dataSource        = DataSource;

            if (dataSource != null)
            {
                var itemBinding    = GetItemBinding();
                var bindingService = context.Configuration.ServiceLocator.GetService <BindingCompilationService>();
                foreach (var item in GetIEnumerableFromDataSource())
                {
                    var placeholder = new DataItemContainer {
                        DataItemIndex = index
                    };
                    ItemTemplate.BuildContent(context, placeholder);
                    placeholder.SetBinding(DataContextProperty, ValueBindingExpression.CreateBinding(
                                               bindingService,
                                               j => item,
                                               itemBinding.KnockoutExpression.AssignParameters(p =>
                                                                                               p == JavascriptTranslator.CurrentIndexParameter ? new CodeParameterAssignment(index.ToString(), OperatorPrecedence.Max) :
                                                                                               default(CodeParameterAssignment))));
                    placeholder.SetValue(Internal.PathFragmentProperty, GetPathFragmentExpression() + "/[" + index + "]");
                    placeholder.ID = index.ToString();
                    Children.Add(placeholder);
                    index++;
                }
                numberOfRows = index;
            }
            else
            {
                numberOfRows = 0;
            }

            // add empty item
            if (EmptyDataTemplate != null)
            {
                emptyDataContainer = new EmptyData();
                emptyDataContainer.SetValue(EmptyData.RenderWrapperTagProperty, GetValueRaw(RenderWrapperTagProperty));
                emptyDataContainer.SetValue(EmptyData.WrapperTagNameProperty, GetValueRaw(WrapperTagNameProperty));
                emptyDataContainer.SetBinding(DataSourceProperty, dataSourceBinding);
                EmptyDataTemplate.BuildContent(context, emptyDataContainer);
                Children.Add(emptyDataContainer);
            }
        }
예제 #3
0
        /// <summary>
        /// Performs the data-binding and builds the controls inside the <see cref="Repeater"/>.
        /// </summary>
        private void DataBind(IDotvvmRequestContext context)
        {
            Children.Clear();
            emptyDataContainer = null;

            var dataSourceBinding = GetDataSourceBinding();
            var index             = 0;
            var dataSource        = DataSource;

            if (dataSource != null)
            {
                var items = GetIEnumerableFromDataSource(dataSource).Cast <object>().ToArray();
                var javascriptDataSourceExpression = dataSourceBinding.GetKnockoutBindingExpression();
                foreach (var item in items)
                {
                    var placeholder = new DataItemContainer {
                        DataItemIndex = index
                    };
                    ItemTemplate.BuildContent(context, placeholder);
                    placeholder.SetBinding(DataContextProperty, GetItemBinding((IList)items, javascriptDataSourceExpression, index));
                    placeholder.SetValue(Internal.PathFragmentProperty, JavascriptCompilationHelper.AddIndexerToViewModel(GetPathFragmentExpression(), index));
                    placeholder.ID = index.ToString();
                    Children.Add(placeholder);
                    index++;
                }
                numberOfRows = index;
            }
            else
            {
                numberOfRows = 0;
            }

            // add empty item
            if (EmptyDataTemplate != null)
            {
                emptyDataContainer = new EmptyData();
                emptyDataContainer.SetValue(EmptyData.RenderWrapperTagProperty, GetValueRaw(RenderWrapperTagProperty));
                emptyDataContainer.SetValue(EmptyData.WrapperTagNameProperty, GetValueRaw(WrapperTagNameProperty));
                emptyDataContainer.SetBinding(DataSourceProperty, dataSourceBinding);
                EmptyDataTemplate.BuildContent(context, emptyDataContainer);
                Children.Add(emptyDataContainer);
            }
        }
예제 #4
0
파일: GridView.cs 프로젝트: darilek/dotvvm
        private void DataBind(Hosting.IDotvvmRequestContext context)
        {
            Children.Clear();
            emptyDataContainer = null;
            head = null;

            var dataSourceBinding = GetDataSourceBinding();
            var dataSource = DataSource;

            Action<string> sortCommand = null;
            var set = dataSource as IGridViewDataSet;
            if (set != null)
            {
                sortCommand = set.SetSortExpression;
            }
            else
            {
                sortCommand = SortChanged;
            }

            // WORKAROUND: DataSource is null => don't throw exception
            if (sortCommand == null && dataSource == null)
            {
                sortCommand = s =>
                {
                    throw new DotvvmControlException(this, "Cannot sort when DataSource is null.");
                };
            }

            CreateHeaderRow(context, sortCommand);
            var index = 0;
            if (dataSource != null)
            {
                // create header row
                var items = GetIEnumerableFromDataSource(dataSource);
                var javascriptDataSourceExpression = dataSourceBinding.GetKnockoutBindingExpression();

                foreach (var item in items)
                {
                    // create row
                    var placeholder = new DataItemContainer { DataItemIndex = index };
                    placeholder.SetBinding(DataContextProperty, GetItemBinding((IList)items, javascriptDataSourceExpression, index));
                    placeholder.SetValue(Internal.PathFragmentProperty, JavascriptCompilationHelper.AddIndexerToViewModel(GetPathFragmentExpression(), index));
                    placeholder.ID = index.ToString();
                    CreateRowWithCells(context, placeholder);
                    Children.Add(placeholder);

                    index++;
                }
                numberOfRows = index;
            }
            else
            {
                numberOfRows = 0;
            }

            // add empty item
            if (EmptyDataTemplate != null)
            {
                emptyDataContainer = new EmptyData();
                emptyDataContainer.SetBinding(DataSourceProperty, dataSourceBinding);
                EmptyDataTemplate.BuildContent(context, emptyDataContainer);
                Children.Add(emptyDataContainer);
            }
        }
예제 #5
0
파일: Repeater.cs 프로젝트: darilek/dotvvm
        /// <summary>
        /// Performs the data-binding and builds the controls inside the <see cref="Repeater"/>.
        /// </summary>
        private void DataBind(Hosting.IDotvvmRequestContext context)
        {
            Children.Clear();
            emptyDataContainer = null;

            var dataSourceBinding = GetDataSourceBinding();
            var index = 0;
            var dataSource = DataSource;
            if (dataSource != null)
            {
                var items = GetIEnumerableFromDataSource(dataSource).Cast<object>().ToArray();
                var javascriptDataSourceExpression = dataSourceBinding.GetKnockoutBindingExpression();
                foreach (var item in items)
                {
                    var placeholder = new DataItemContainer { DataItemIndex = index };
                    ItemTemplate.BuildContent(context, placeholder);
                    placeholder.SetBinding(DataContextProperty, GetItemBinding((IList)items, javascriptDataSourceExpression, index));
                    placeholder.SetValue(Internal.PathFragmentProperty, JavascriptCompilationHelper.AddIndexerToViewModel(GetPathFragmentExpression(), index));
                    placeholder.ID = index.ToString();
                    Children.Add(placeholder);
                    index++;
                }
                numberOfRows = index;
            }
            else
            {
                numberOfRows = 0;
            }

            // add empty item
            if (EmptyDataTemplate != null)
            {
                emptyDataContainer = new EmptyData();
                emptyDataContainer.SetBinding(DataSourceProperty, dataSourceBinding);
                EmptyDataTemplate.BuildContent(context, emptyDataContainer);
                Children.Add(emptyDataContainer);
            }
        }
예제 #6
0
        private void DataBind(IDotvvmRequestContext context)
        {
            Children.Clear();
            emptyDataContainer = null;
            head = null;

            var dataSourceBinding = GetDataSourceBinding();
            var dataSource        = DataSource;

            Action <string> sortCommand = null;

            if (dataSource is IGridViewDataSet)
            {
                sortCommand = ((IGridViewDataSet)dataSource).SetSortExpression;
            }
            else
            {
                sortCommand = SortChanged;
            }

            // WORKAROUND: DataSource is null => don't throw exception
            if (sortCommand == null && dataSource == null)
            {
                sortCommand = s => { throw new Exception("can't sort null data source"); };
            }

            CreateHeaderRow(context, sortCommand);
            var index = 0;

            if (dataSource != null)
            {
                // create header row
                var items = GetIEnumerableFromDataSource(dataSource);
                var javascriptDataSourceExpression = dataSourceBinding.GetKnockoutBindingExpression();

                foreach (var item in items)
                {
                    // create row
                    var placeholder = new DataItemContainer {
                        DataItemIndex = index
                    };
                    placeholder.SetBinding(DataContextProperty, GetItemBinding((IList)items, javascriptDataSourceExpression, index));
                    placeholder.SetValue(Internal.PathFragmentProperty, JavascriptCompilationHelper.AddIndexerToViewModel(GetPathFragmentExpression(), index));
                    placeholder.ID = "i" + index;
                    CreateRow(context, placeholder);
                    Children.Add(placeholder);

                    index++;
                }
                numberOfRows = index;
            }
            else
            {
                numberOfRows = 0;
            }

            // add empty item
            if (EmptyDataTemplate != null)
            {
                emptyDataContainer = new EmptyData();
                emptyDataContainer.SetBinding(DataSourceProperty, dataSourceBinding);
                EmptyDataTemplate.BuildContent(context, emptyDataContainer);
                Children.Add(emptyDataContainer);
            }
        }
예제 #7
0
        private void DataBind(IDotvvmRequestContext context)
        {
            Children.Clear();
            emptyDataContainer = null;
            head = null;

            var dataSourceBinding = GetDataSourceBinding();
            var dataSource        = DataSource;


            if (dataSource is IRefreshableGridViewDataSet refreshableDataSet)
            {
                CallGridViewDataSetRefreshRequest(refreshableDataSet);
            }

            var sortCommand =
                dataSource is ISortableGridViewDataSet sortableGridViewDataSet ?
                sortableGridViewDataSet.SetSortExpression :
                SortChanged;

            // WORKAROUND: DataSource is null => don't throw exception
            if (sortCommand == null && dataSource == null)
            {
                sortCommand = s => {
                    throw new DotvvmControlException(this, "Cannot sort when DataSource is null.");
                };
            }

            CreateHeaderRow(context, sortCommand);
            var index = 0;

            if (dataSource != null)
            {
                var itemBinding    = GetItemBinding();
                var bindingService = context.Configuration.ServiceLocator.GetService <BindingCompilationService>();
                foreach (var item in GetIEnumerableFromDataSource())
                {
                    // create row
                    var placeholder = new DataItemContainer {
                        DataItemIndex = index
                    };
                    placeholder.SetBinding(DataContextProperty, ValueBindingExpression.CreateBinding(
                                               bindingService,
                                               j => item,
                                               itemBinding.KnockoutExpression.AssignParameters(p =>
                                                                                               p == JavascriptTranslator.CurrentIndexParameter ? new CodeParameterAssignment(index.ToString(), OperatorPrecedence.Max) :
                                                                                               default(CodeParameterAssignment))));
                    placeholder.SetValue(Internal.PathFragmentProperty, GetPathFragmentExpression() + "/[" + index + "]");
                    placeholder.ID = index.ToString();
                    Children.Add(placeholder);
                    CreateRowWithCells(context, placeholder);

                    index++;
                }
                numberOfRows = index;
            }
            else
            {
                numberOfRows = 0;
            }

            // add empty item
            if (EmptyDataTemplate != null)
            {
                emptyDataContainer = new EmptyData();
                emptyDataContainer.SetBinding(DataSourceProperty, dataSourceBinding);
                EmptyDataTemplate.BuildContent(context, emptyDataContainer);
                Children.Add(emptyDataContainer);
            }
        }
예제 #8
0
파일: GridView.cs 프로젝트: holajan/dotvvm
        private void DataBind(DotvvmRequestContext context)
        {
            Children.Clear();

            var dataSourceBinding = GetDataSourceBinding();
            // var dataSourcePath = dataSourceBinding.GetViewModelPathExpression(this, DataSourceProperty);
            var dataSource = DataSource;

            Action<string> sortCommand = null;
            if (dataSource is IGridViewDataSet)
            {
                sortCommand = ((IGridViewDataSet)dataSource).SetSortExpression; // dataSourcePath + ".SetSortExpression";
            }
            else
            {
                var sortCommandBinding = GetCommandBinding(SortChangedProperty);
                if (sortCommandBinding != null)
                {
                    sortCommand = s => sortCommandBinding.Delegate(new []{ s }.Concat(BindingExpression.GetDataContexts(this, true)).ToArray(), null);
                }
            }

            var index = 0;
            if (dataSource != null)
            {
                // create header row
                CreateHeaderRow(context, sortCommand);
                var items = GetIEnumerableFromDataSource(dataSource);
                foreach (var item in items)
                {
                    // create row
                    var placeholder = new DataItemContainer { DataItemIndex = index };
                    placeholder.SetBinding(DataContextProperty, GetItemBinding((IList)items, dataSourceBinding.GetKnockoutBindingExpression(), index));
                    Children.Add(placeholder);

                    CreateRow(context, placeholder);

                    index++;
                }
            }
        }
예제 #9
0
파일: Repeater.cs 프로젝트: holajan/dotvvm
        /// <summary>
        /// Performs the data-binding and builds the controls inside the <see cref="Repeater"/>.
        /// </summary>
        private void DataBind(DotvvmRequestContext context)
        {
            var dataSourceBinding = GetDataSourceBinding();

            var index = 0;
            var dataSource = DataSource;
            if (dataSource != null)
            {
                var items = GetIEnumerableFromDataSource(dataSource).Cast<object>().ToArray();
                if (lastBoundArray != null)
                {
                    if (lastBoundArray.SequenceEqual(items)) return;
                }
                Children.Clear();
                foreach (var item in items)
                {
                    var placeholder = new DataItemContainer { DataItemIndex = index };
                    ItemTemplate.BuildContent(context, placeholder);
                    Children.Add(placeholder);
                    placeholder.SetBinding(DataContextProperty, GetItemBinding((IList)items, dataSourceBinding.GetKnockoutBindingExpression(), index));
                    Debug.Assert(placeholder.properties[DataContextProperty] != null);
                    index++;
                }
            }
        }