예제 #1
0
        private void AppendPopupEditor(IHtmlNode container, GridRenderingData renderingData)
        {
            var popup     = Editing.PopUp;
            var cancelUrl = renderingData.UrlBuilder.CancelUrl(null);

            new WindowBuilder(popup)
            .Content(renderingData.PopUpContainer.InnerHtml)
            .HtmlAttributes(new { style = "top:10%;left:50%;margin-left: -" + (popup.Width == 0 ? 360 : popup.Width) / 4 + "px" })
            .Buttons(buttons => buttons
                     .Close(cancelUrl)
                     );

            if (!IsClientBinding)
            {
                popup.ClientEvents.OnClose.InlineCodeBlock = obj => "function(e) { e.preventDefault();" + string.Format("window.location.href = \"{0}\";", cancelUrl) + "}";
            }

            if (!popup.Name.HasValue())
            {
                popup.Name = Name + "PopUp";
            }

            if (!popup.Title.HasValue())
            {
                popup.Title = CurrentItemMode == GridItemMode.Edit ? Localization.Edit : Localization.AddNew;
            }

            ScriptRegistrar.Current.Register(popup);

            new LiteralNode(popup.ToHtmlString()).AppendTo(container);
        }
예제 #2
0
        private void AppendPopupEditor(IHtmlNode container, GridRenderingData renderingData)
        {
            var popup     = Editable.PopUp;
            var cancelUrl = renderingData.UrlBuilder.CancelUrl(null);

            new WindowBuilder(popup)
            .Content(renderingData.PopUpContainer.InnerHtml)
            //TODO: Add positioning of the window
            //.HtmlAttributes(new { style = "top:10%;left:50%;margin-left: -" + (popup.Width == 0 ? 360 : popup.Width) / 4 + "px" })
            .Actions(buttons => buttons
                     .Close()
                     );

            if (!IsClientBinding)
            {
                popup.Events["activate"] = new ClientHandlerDescriptor {
                    TemplateDelegate = obj => "function(e){this.center();}"
                };
                popup.Events["close"] = new ClientHandlerDescriptor {
                    TemplateDelegate = obj => "function(e){e.preventDefault();" + string.Format("window.location.href = \"{0}\";", cancelUrl) + "}"
                };
            }

            if (!popup.Name.HasValue())
            {
                popup.Name = Name + "PopUp";
            }

            if (popup.Title == null || (string)(popup.Title) == "")
            {
                popup.Title = CurrentItemMode == GridItemMode.Edit ? Messages.Grid_Edit : Messages.Grid_Create;
            }

            new LiteralNode(popup.ToHtmlString()).AppendTo(container);
        }
        public void Should_not_call_callback_if_item_is_empty_row()
        {
            var called = false;
            var data = new GridRenderingData
            {
                Callback = item => called = true
            };

            factory.CreateBuilder(data, new GridItem {Type = GridItemType.EmptyRow});

            called.ShouldBeFalse();
        }
        public void Should_not_call_callback_if_item_is_empty_row()
        {
            var called = false;
            var data   = new GridRenderingData
            {
                Callback = item => called = true
            };

            factory.CreateBuilder(data, new GridItem {
                Type = GridItemType.EmptyRow
            });

            called.ShouldBeFalse();
        }
        public GridRowBuilderFactoryTests()
        {
            cellBuilderFactory = new Mock<IGridCellBuilderFactory>();
            decoratorsProvider = new Mock<IGridRowBuilderDecoratorProvider>();
            decoratorsProvider.Setup(p => p.ApplyDecorators(It.IsAny<IGridRowBuilder>(), It.IsAny<GridItem>(), It.IsAny<bool>()))
                .Returns((IGridRowBuilder b, GridItem item, bool hasDetailView) => b);

            factory = new GridRowBuilderFactory(new Mock<IGridTableBulderFactory>().Object, cellBuilderFactory.Object, decoratorsProvider.Object);
            renderingData = new GridRenderingData
            {
                Columns = new IGridColumn[0],
                Localization = new Mock<IGridLocalization>().Object,
                UrlBuilder = new Mock<IGridUrlBuilder>().Object,
                GroupMembers = new string[0],
                Callback = delegate { },
                EditFormHtmlAttributes = new Dictionary<string, object>(),
                Aggregates = new AggregateFunction[0]
            };
        }
        public GridRowBuilderFactoryTests()
        {
            cellBuilderFactory = new Mock <IGridCellBuilderFactory>();
            decoratorsProvider = new Mock <IGridRowBuilderDecoratorProvider>();
            decoratorsProvider.Setup(p => p.ApplyDecorators(It.IsAny <IGridRowBuilder>(), It.IsAny <GridItem>(), It.IsAny <bool>()))
            .Returns((IGridRowBuilder b, GridItem item, bool hasDetailView) => b);

            factory       = new GridRowBuilderFactory(new Mock <IGridTableBulderFactory>().Object, cellBuilderFactory.Object, decoratorsProvider.Object);
            renderingData = new GridRenderingData
            {
                Columns                = new IGridColumn[0],
                Localization           = new Mock <IGridLocalization>().Object,
                UrlBuilder             = new Mock <IGridUrlBuilder>().Object,
                GroupMembers           = new string[0],
                Callback               = delegate { },
                EditFormHtmlAttributes = new Dictionary <string, object>(),
                Aggregates             = new AggregateFunction[0]
            };
        }
예제 #7
0
        private GridRenderingData CreateRenderingData()
        {
            var renderingData = new GridRenderingData
            {
                TableHtmlAttributes = TableHtmlAttributes,
                DataKeyStore        = DataKeyStore,
                HtmlHelper          = new GridHtmlHelper <T>(ViewContext, DataKeyStore),
                UrlBuilder          = UrlBuilder,
                DataSource          = DataProcessor.ProcessedDataSource,
                Columns             = VisibleColumns.Cast <IGridColumn>(),
                GroupMembers        = DataProcessor.GroupDescriptors.Select(g => g.Member),
                Mode                   = CurrentItemMode,
                EditMode               = Editing.Mode,
                HasDetailView          = HasDetailView,
                Colspan                = Colspan - Columns.Count(column => column.Hidden),
                DetailViewTemplate     = MapDetailViewTemplate(HasDetailView ? DetailView.Template : null),
                NoRecordsTemplate      = FormatNoRecordsTemplate(),
                Localization           = Localization,
                ScrollingHeight        = Scrolling.Height,
                EditFormHtmlAttributes = Editing.FormHtmlAttributes,
                ShowFooter             = Footer && VisibleColumns.Any(c => c.FooterTemplate.HasValue() || c.ClientFooterTemplate.HasValue()),
                AggregateResults       = DataProcessor.AggregatesResults,
                Aggregates             = Aggregates.SelectMany(aggregate => aggregate.Aggregates),
                GroupsCount            = DataProcessor.GroupDescriptors.Count,
                ShowGroupFooter        = Aggregates.Any() && VisibleColumns.OfType <IGridBoundColumn>().Any(c => c.GroupFooterTemplate.HasValue()),
                PopUpContainer         = new HtmlFragment(),
#if MVC2 || MVC3
                CreateNewDataItem  = () => Editing.DefaultDataItem(),
                InsertRowPosition  = Editing.InsertRowPosition,
                EditTemplateName   = Editing.TemplateName,
                AdditionalViewData = Editing.AdditionalViewData,
                FormId             = ViewContext.FormContext.FormId,
#endif
                Callback = RowActionCallback
            };

            if (RowTemplate.HasValue())
            {
                renderingData.RowTemplate = (dataItem, container) => RowTemplate.Apply((T)dataItem, container);
            }

            return(renderingData);
        }