private IEnumerable <Control> getBasicRegionBlocks()
        {
            var rs = new UpdateRegionSet();
            var pb = PostBack.CreateIntermediate(rs.ToSingleElementArray(), DataUpdate, id: "basic");

            yield return(new Paragraph(new PostBackButton(pb, new ButtonActionControlStyle("Toggle Basic Region Below"), usesSubmitBehavior: false)));

            var regionControls    = new List <Control>();
            var dynamicFieldValue = new DataValue <string>();

            if (info.Toggled)
            {
                regionControls.Add(
                    FormItem.Create(
                        "Dynamic Field",
                        new EwfTextBox("This was just added!"),
                        validationGetter: control => new EwfValidation((pbv, validator) => dynamicFieldValue.Value = control.GetPostBackValue(pbv), pb)).ToControl());
            }
            else
            {
                regionControls.Add(new Paragraph("Nothing here yet."));
            }
            yield return
                (new NamingPlaceholder(
                     new Section("Basic Update Region", regionControls, style: SectionStyle.Box).ToSingleElementArray(),
                     updateRegionSets: rs.ToSingleElementArray()));

            pb.AddModificationMethod(() => parametersModification.Toggled = !parametersModification.Toggled);
            pb.AddModificationMethod(
                () =>
                AddStatusMessage(StatusMessageType.Info, info.Toggled ? "Dynamic field value was '{0}'.".FormatWith(dynamicFieldValue.Value) : "Dynamic field added."));
        }
        private IEnumerable <Control> getIdListRegionBlocks()
        {
            var rs = new UpdateRegionSet();

            yield return
                (new ControlLine(
                     new PostBackButton(
                         PostBack.CreateIntermediate(
                             rs.ToSingleElementArray(),
                             DataUpdate,
                             id: "idAdd",
                             firstModificationMethod:
                             () =>
                             parametersModification.ItemIds =
                                 (parametersModification.ItemIds.Any() ? parametersModification.ItemIds.Min() - 1 : 0).ToSingleElementArray().Concat(parametersModification.ItemIds)),
                         new ButtonActionControlStyle("Add Item"),
                         usesSubmitBehavior: false)));

            var stack = ControlStack.Create(
                true,
                itemInsertionUpdateRegions:
                new ItemInsertionUpdateRegion(rs.ToSingleElementArray(), () => parametersModification.ItemIds.First().ToString().ToSingleElementArray())
                .ToSingleElementArray());

            foreach (var i in info.ItemIds)
            {
                stack.AddItem(getIdItem(i));
            }

            yield return(new Section("Control List With ID Items", stack.ToSingleElementArray(), style: SectionStyle.Box));
        }
Ejemplo n.º 3
0
        private EwfTableItemGroup getItemGroup(int groupNumber)
        {
            var updateRegionSet = new UpdateRegionSet();

            return
                (new EwfTableItemGroup(
                     () =>
                     new EwfTableItemGroupRemainingData(
                         "Group {0}".FormatWith(groupNumber).GetLiteralControl(),
                         groupHeadClickScript:
                         ClickScript.CreatePostBackScript(
                             PostBack.CreateIntermediate(
                                 null,
                                 DataUpdate,
                                 id: "group{0}".FormatWith(groupNumber),
                                 firstModificationMethod: () => AddStatusMessage(StatusMessageType.Info, "You clicked group {0}.".FormatWith(groupNumber)))),
                         tailUpdateRegions: groupNumber == 1 ? new TailUpdateRegion(updateRegionSet.ToSingleElementArray(), 1).ToSingleElementArray() : null),
                     groupNumber == 1
                                                ? getItems(info.FirstGroupItemCount)
                     .Concat(
                         new Func <EwfTableItem>(
                             () =>
                             new EwfTableItem(
                                 new PostBackButton(
                                     PostBack.CreateIntermediate(
                                         updateRegionSet.ToSingleElementArray(),
                                         DataUpdate,
                                         id: "addRow",
                                         firstModificationMethod: () => parametersModification.FirstGroupItemCount += 1),
                                     new ButtonActionControlStyle("Add Row"),
                                     usesSubmitBehavior: false).ToCell(new TableCellSetup(fieldSpan: 2)))).ToSingleElementArray())
                                                : getItems(250)));
        }
Ejemplo n.º 4
0
        protected override void loadData()
        {
            var updateRegionSet = new UpdateRegionSet();

            EwfUiStatics.SetPageActions(
                new ActionButtonSetup(
                    "Remove Last Group",
                    new PostBackButton(
                        PostBack.CreateIntermediate(
                            updateRegionSet.ToSingleElementArray(),
                            DataUpdate,
                            id: "removeLastGroup",
                            firstModificationMethod: () => {
                if (info.GroupCount <= 0)
                {
                    throw new DataModificationException("No groups to remove.");
                }
                parametersModification.GroupCount -= 1;
            }))));

            place.Controls.Add(
                EwfTable.CreateWithItemGroups(
                    Enumerable.Range(1, info.GroupCount).Select(getItemGroup),
                    defaultItemLimit: DataRowLimit.Fifty,
                    caption: "Caption",
                    subCaption: "Sub caption",
                    fields:
                    new[]
                    { new EwfTableField(size: Unit.Percentage(1), toolTip: "First column!"), new EwfTableField(size: Unit.Percentage(2), toolTip: "Second column!") },
                    headItems: new EwfTableItem("First Column", "Second Column").ToSingleElementArray(),
                    tailUpdateRegions: new TailUpdateRegion(updateRegionSet.ToSingleElementArray(), 1).ToSingleElementArray()));
        }
        private IEnumerable <Control> getNonIdListRegionBlocks()
        {
            var addRs    = new UpdateRegionSet();
            var removeRs = new UpdateRegionSet();

            yield return
                (new ControlLine(
                     new PostBackButton(
                         PostBack.CreateIntermediate(
                             addRs.ToSingleElementArray(),
                             DataUpdate,
                             id: "nonIdAdd",
                             firstModificationMethod: () => parametersModification.NonIdItemStates = parametersModification.NonIdItemStates.Concat(new[] { 0, 0 })),
                         new ButtonActionControlStyle("Add Two Items"),
                         usesSubmitBehavior: false),
                     new PostBackButton(
                         PostBack.CreateIntermediate(
                             removeRs.ToSingleElementArray(),
                             DataUpdate,
                             id: "nonIdRemove",
                             firstModificationMethod:
                             () => parametersModification.NonIdItemStates = parametersModification.NonIdItemStates.Take(parametersModification.NonIdItemStates.Count() - 2)),
                         new ButtonActionControlStyle("Remove Two Items"),
                         usesSubmitBehavior: false)));

            var stack = ControlStack.Create(true, tailUpdateRegions: new[] { new TailUpdateRegion(addRs, 0), new TailUpdateRegion(removeRs, 2) });

            for (var i = 0; i < info.NonIdItemStates.Count(); i += 1)
            {
                stack.AddItem(getNonIdItem(i));
            }

            yield return(new Box("Control List With Non-ID Items", stack.ToSingleElementArray()));
        }
        private ControlListItem getIdItem(int id)
        {
            var rs = new UpdateRegionSet();
            var pb = PostBack.CreateIntermediate(rs.ToSingleElementArray(), DataUpdate, id: PostBack.GetCompositeId("id", id.ToString()));

            var itemStack = ControlStack.Create(true);

            itemStack.AddControls(new EwfTextBox("ID {0}".FormatWith(id)));
            itemStack.AddControls(
                new PostBackButton(pb, new ButtonActionControlStyle("Remove", buttonSize: ButtonActionControlStyle.ButtonSize.ShrinkWrap), usesSubmitBehavior: false));

            pb.AddModificationMethod(() => parametersModification.ItemIds = parametersModification.ItemIds.Where(i => i != id).ToArray());

            return(new ControlListItem(itemStack.ToSingleElementArray(), id.ToString(), removalUpdateRegionSet: rs));
        }
Ejemplo n.º 7
0
        private Control getItemLimitButton(DataRowLimit itemLimit, UpdateRegionSet updateRegionSet)
        {
            var text = itemLimit == DataRowLimit.Unlimited ? "All" : ((int)itemLimit).ToString();

            if (itemLimit == (DataRowLimit)CurrentItemLimit)
            {
                return(text.GetLiteralControl());
            }
            var validationDm = EwfPage.Instance.DataUpdate;             // This is a hack, but should be easily corrected when EnduraCode goal 768 is done.

            return
                (new PostBackButton(
                     PostBack.CreateIntermediate(
                         updateRegionSet.ToSingleElementArray(),
                         validationDm,
                         id: PostBack.GetCompositeId(postBackIdBase, itemLimit.ToString()),
                         firstModificationMethod: () => EwfPage.Instance.PageState.SetValue(this, itemLimitPageStateKey, (int)itemLimit)),
                     new TextActionControlStyle(text),
                     usesSubmitBehavior: false));
        }
        private ControlListItem getNonIdItem(int i)
        {
            var rs = new UpdateRegionSet();
            var pb = PostBack.CreateIntermediate(rs.ToSingleElementArray(), DataUpdate, id: PostBack.GetCompositeId("nonId", i.ToString()));

            var itemStack = ControlStack.Create(true);

            if (info.NonIdItemStates.ElementAt(i) == 1)
            {
                itemStack.AddControls(new EwfTextBox("Item {0}".FormatWith(i)));
            }
            else
            {
                itemStack.AddText("Item {0}".FormatWith(i));
            }
            itemStack.AddControls(
                new PostBackButton(pb, new ButtonActionControlStyle("Toggle", buttonSize: ButtonActionControlStyle.ButtonSize.ShrinkWrap), usesSubmitBehavior: false));

            pb.AddModificationMethod(
                () => parametersModification.NonIdItemStates = parametersModification.NonIdItemStates.Select((state, index) => index == i ? (state + 1) % 2 : state));

            return(new ControlListItem(itemStack.ToSingleElementArray(), updateRegionSet: rs));
        }
Ejemplo n.º 9
0
        void ControlTreeDataLoader.LoadData()
        {
            using (MiniProfiler.Current.Step("EWF - Load table data")) {
                if (hideIfEmpty && itemGroups.All(itemGroup => !itemGroup.Items.Any()))
                {
                    Visible = false;
                    return;
                }

                SetUpTableAndCaption(this, style, classes, caption, subCaption);

                var visibleItemGroupsAndItems = new List <Tuple <EwfTableItemGroup, IReadOnlyCollection <EwfTableItem> > >();
                foreach (var itemGroup in itemGroups)
                {
                    var visibleItems = itemGroup.Items.Take(CurrentItemLimit - visibleItemGroupsAndItems.Sum(i => i.Item2.Count)).Select(i => i());
                    visibleItemGroupsAndItems.Add(Tuple.Create <EwfTableItemGroup, IReadOnlyCollection <EwfTableItem> >(itemGroup, visibleItems.ToImmutableArray()));
                    if (visibleItemGroupsAndItems.Sum(i => i.Item2.Count) == CurrentItemLimit)
                    {
                        break;
                    }
                }

                var fields = GetFields(specifiedFields, headItems.AsReadOnly(), visibleItemGroupsAndItems.SelectMany(i => i.Item2));
                if (!fields.Any())
                {
                    fields = new EwfTableField().ToSingleElementArray();
                }

                addColumnSpecifications(fields);

                var allVisibleItems = new List <EwfTableItem>();

                var itemLimitingUpdateRegionSet = new UpdateRegionSet();
                var headRows =
                    buildRows(
                        getItemLimitingAndGeneralActionsItem(fields.Length, itemLimitingUpdateRegionSet).Concat(getItemActionsItem(fields.Length)).ToList(),
                        Enumerable.Repeat(new EwfTableField(), fields.Length).ToArray(),
                        null,
                        false,
                        null,
                        null,
                        allVisibleItems).Concat(buildRows(headItems, fields, null, true, null, null, allVisibleItems)).ToArray();
                if (headRows.Any())
                {
                    Controls.Add(new WebControl(HtmlTextWriterTag.Thead).AddControlsReturnThis(headRows));
                }

                var bodyRowGroupsAndRows = new List <Tuple <WebControl, ImmutableArray <Control> > >();
                var updateRegionSetListsAndStaticRowGroupCounts = new List <Tuple <IReadOnlyCollection <UpdateRegionSet>, int> >();
                for (var visibleGroupIndex = 0; visibleGroupIndex < visibleItemGroupsAndItems.Count; visibleGroupIndex += 1)
                {
                    var groupAndItems          = visibleItemGroupsAndItems[visibleGroupIndex];
                    var useContrastForFirstRow = visibleItemGroupsAndItems.Where((group, i) => i < visibleGroupIndex).Sum(i => i.Item2.Count) % 2 == 1;
                    var groupBodyRows          = buildRows(groupAndItems.Item2, fields, useContrastForFirstRow, false, null, null, allVisibleItems).ToImmutableArray();
                    var rowGroup =
                        new WebControl(HtmlTextWriterTag.Tbody).AddControlsReturnThis(
                            buildRows(
                                groupAndItems.Item1.GetHeadItems(fields.Length),
                                Enumerable.Repeat(new EwfTableField(), fields.Length).ToArray(),
                                null,
                                true,
                                null,
                                null,
                                allVisibleItems).Concat(new NamingPlaceholder(groupBodyRows).ToSingleElementArray()));
                    bodyRowGroupsAndRows.Add(Tuple.Create(rowGroup, groupBodyRows));

                    var cachedVisibleGroupIndex = visibleGroupIndex;
                    EwfPage.Instance.AddUpdateRegionLinker(
                        new UpdateRegionLinker(
                            rowGroup,
                            "tail",
                            from region in groupAndItems.Item1.RemainingData.Value.TailUpdateRegions
                            let staticRowCount = itemGroups[cachedVisibleGroupIndex].Items.Count - region.UpdatingItemCount
                                                 select new PreModificationUpdateRegion(region.Sets, () => groupBodyRows.Skip(staticRowCount), staticRowCount.ToString),
                            arg => groupBodyRows.Skip(int.Parse(arg))));

                    // If item limiting is enabled, include all subsequent item groups in tail update regions since any number of items could be appended.
                    if (defaultItemLimit != DataRowLimit.Unlimited)
                    {
                        updateRegionSetListsAndStaticRowGroupCounts.Add(
                            Tuple.Create <IReadOnlyCollection <UpdateRegionSet>, int>(
                                groupAndItems.Item1.RemainingData.Value.TailUpdateRegions.SelectMany(i => i.Sets).ToImmutableArray(),
                                visibleGroupIndex + 1));
                    }
                }
                Controls.Add(new NamingPlaceholder(bodyRowGroupsAndRows.Select(i => i.Item1)));

                if (defaultItemLimit != DataRowLimit.Unlimited)
                {
                    var oldItemLimit   = CurrentItemLimit;
                    var lowerItemLimit = new Lazy <int>(() => Math.Min(oldItemLimit, CurrentItemLimit));

                    var itemLimitingTailUpdateRegionControlGetter = new Func <int, IEnumerable <Control> >(
                        staticItemCount => {
                        var rowCount = 0;
                        for (var groupIndex = 0; groupIndex < bodyRowGroupsAndRows.Count; groupIndex += 1)
                        {
                            var rows  = bodyRowGroupsAndRows[groupIndex].Item2;
                            rowCount += rows.Length;
                            if (rowCount < staticItemCount)
                            {
                                continue;
                            }
                            return(rows.Skip(rows.Length - (rowCount - staticItemCount)).Concat(bodyRowGroupsAndRows.Skip(groupIndex + 1).Select(i => i.Item1)));
                        }
                        return(ImmutableArray <Control> .Empty);
                    });

                    EwfPage.Instance.AddUpdateRegionLinker(
                        new UpdateRegionLinker(
                            this,
                            "itemLimitingTail",
                            new PreModificationUpdateRegion(
                                itemLimitingUpdateRegionSet.ToSingleElementArray(),
                                () => itemLimitingTailUpdateRegionControlGetter(lowerItemLimit.Value),
                                () => lowerItemLimit.Value.ToString()).ToSingleElementArray(),
                            arg => itemLimitingTailUpdateRegionControlGetter(int.Parse(arg))));
                }

                EwfPage.Instance.AddUpdateRegionLinker(
                    new UpdateRegionLinker(
                        this,
                        "tail",
                        from region in
                        tailUpdateRegions.Select(i => new { sets = i.Sets, staticRowGroupCount = itemGroups.Count - i.UpdatingItemCount })
                        .Concat(updateRegionSetListsAndStaticRowGroupCounts.Select(i => new { sets = i.Item1, staticRowGroupCount = i.Item2 }))
                        select
                        new PreModificationUpdateRegion(
                            region.sets,
                            () => bodyRowGroupsAndRows.Skip(region.staticRowGroupCount).Select(i => i.Item1),
                            region.staticRowGroupCount.ToString),
                        arg => bodyRowGroupsAndRows.Skip(int.Parse(arg)).Select(i => i.Item1)));

                var itemCount            = itemGroups.Sum(i => i.Items.Count);
                var itemLimitingRowGroup = new List <Control>();
                if (CurrentItemLimit < itemCount)
                {
                    var nextLimit          = EnumTools.GetValues <DataRowLimit>().First(i => i > (DataRowLimit)CurrentItemLimit);
                    var itemIncrementCount = Math.Min((int)nextLimit, itemCount) - CurrentItemLimit;
                    var validationDm       = EwfPage.Instance.DataUpdate;               // This is a hack, but should be easily corrected when EnduraCode goal 768 is done.
                    var button             =
                        new PostBackButton(
                            PostBack.CreateIntermediate(
                                itemLimitingUpdateRegionSet.ToSingleElementArray(),
                                validationDm,
                                id: PostBack.GetCompositeId(postBackIdBase, "showMore"),
                                firstModificationMethod: () => EwfPage.Instance.PageState.SetValue(this, itemLimitPageStateKey, (int)nextLimit)),
                            new TextActionControlStyle("Show " + itemIncrementCount + " more item" + (itemIncrementCount != 1 ? "s" : "")),
                            usesSubmitBehavior: false);
                    var item        = new EwfTableItem(button.ToCell(new TableCellSetup(fieldSpan: fields.Length)));
                    var useContrast = visibleItemGroupsAndItems.Sum(i => i.Item2.Count) % 2 == 1;
                    itemLimitingRowGroup.Add(
                        new WebControl(HtmlTextWriterTag.Tbody).AddControlsReturnThis(
                            buildRows(
                                item.ToSingleElementArray().ToList(),
                                Enumerable.Repeat(new EwfTableField(), fields.Length).ToArray(),
                                useContrast,
                                false,
                                null,
                                null,
                                allVisibleItems)));
                }
                Controls.Add(
                    new NamingPlaceholder(
                        itemLimitingRowGroup,
                        updateRegionSets:
                        itemLimitingUpdateRegionSet.ToSingleElementArray()
                        .Concat(itemGroups.SelectMany(i => i.RemainingData.Value.TailUpdateRegions).Concat(tailUpdateRegions).SelectMany(i => i.Sets))));

                // Assert that every visible item in the table has the same number of cells and store a data structure for below.
                var cellPlaceholderListsForItems = TableOps.BuildCellPlaceholderListsForItems(allVisibleItems, fields.Length);

                if (!disableEmptyFieldDetection)
                {
                    AssertAtLeastOneCellPerField(fields, cellPlaceholderListsForItems);
                }
            }
        }