/// <summary>
        /// Creates a list item containing these components.
        /// </summary>
        /// <param name="children"></param>
        /// <param name="id">The ID of the item. This is required if you're adding the item on an intermediate post-back or want to remove the item on an
        /// intermediate post-back. Do not pass null or the empty string.</param>
        /// <param name="displaySetup"></param>
        /// <param name="classes">The classes on the item.</param>
        /// <param name="visualOrderRank"></param>
        /// <param name="updateRegionSets">The intermediate-post-back update-region sets that this item will be a part of.</param>
        /// <param name="removalUpdateRegionSets">The intermediate-post-back update-region sets that this item's removal will be a part of.</param>
        /// <param name="etherealChildren"></param>
        public static ComponentListItem ToComponentListItem(
            this IEnumerable <FlowComponentOrNode> children, string id, DisplaySetup displaySetup = null, ElementClassSet classes   = null, int?visualOrderRank = null,
            IEnumerable <UpdateRegionSet> updateRegionSets            = null, IEnumerable <UpdateRegionSet> removalUpdateRegionSets = null,
            IEnumerable <EtherealComponentOrElement> etherealChildren = null)
        {
            return(new ComponentListItem(
                       (includeContentContainer, itemTypeClasses, width) => {
                FlowComponentOrNode component = null;
                component =
                    new IdentifiedFlowComponent(
                        () =>
                        new IdentifiedComponentData <FlowComponentOrNode>(
                            id,
                            new UpdateRegionLinker(
                                "",
                                new PreModificationUpdateRegion(updateRegionSets, component.ToCollection, () => "").ToCollection(),
                                arg => component.ToCollection()).ToCollection(),
                            ImmutableArray <EwfValidation> .Empty,
                            errorsByValidation => new DisplayableElement(
                                context => {
                    var attributes = new List <Tuple <string, string> >();
                    if (visualOrderRank.HasValue || width != null)
                    {
                        attributes.Add(
                            Tuple.Create(
                                "style",
                                StringTools.ConcatenateWithDelimiter(
                                    ", ",
                                    visualOrderRank.HasValue ? "order: {0}".FormatWith(visualOrderRank.Value) : "",
                                    width != null ? "width: {0}".FormatWith(width.Value) : "")));
                    }

                    return new DisplayableElementData(
                        displaySetup,
                        () => new DisplayableElementLocalData("li", attributes: attributes),
                        classes: CssElementCreator.ItemClass.Add(itemTypeClasses).Add(classes ?? ElementClassSet.Empty),
                        children:
                        includeContentContainer
                                                                                                                              ? new DisplayableElement(
                            innerContext =>
                            new DisplayableElementData(
                                null,
                                () => new DisplayableElementLocalData("div"),
                                classes: CssElementCreator.ItemClass,
                                children: children,
                                etherealChildren: etherealChildren)).ToCollection()
                                                                                                                              : children,
                        etherealChildren: includeContentContainer ? null : etherealChildren);
                }).ToCollection()));
                return component;
            },
                       id,
                       removalUpdateRegionSets));
        }
 /// <summary>
 /// Creates an ID container.
 /// </summary>
 /// <param name="children"></param>
 /// <param name="updateRegionSets">The intermediate-post-back update-region sets that this component will be a part of.</param>
 public FlowIdContainer(IEnumerable <FlowComponent> children, IEnumerable <UpdateRegionSet> updateRegionSets = null)
 {
     identifiedComponent = new IdentifiedFlowComponent(
         () => new IdentifiedComponentData <FlowComponentOrNode>(
             "",
             new UpdateRegionLinker(
                 "",
                 new PreModificationUpdateRegion(updateRegionSets, identifiedComponent.ToCollection, () => "").ToCollection(),
                 arg => identifiedComponent.ToCollection()).ToCollection(),
             new ErrorSourceSet(),
             errorsBySource => children));
 }
        internal static ComponentListItem ToComponentListItem(
            this IReadOnlyCollection <FlowComponent> content, string id, DisplaySetup displaySetup, ElementClassSet classes, int?visualOrderRank,
            IEnumerable <UpdateRegionSet> updateRegionSets, IEnumerable <UpdateRegionSet> removalUpdateRegionSets,
            IReadOnlyCollection <EtherealComponent> etherealContent,
            Func <ElementContext, string, IReadOnlyCollection <Tuple <string, string> >, DisplayableElementLocalData> localDataGetter)
        {
            return(new ComponentListItem(
                       (includeContentContainer, itemTypeClasses, width) => {
                FlowComponentOrNode component = null;
                component = new IdentifiedFlowComponent(
                    () => new IdentifiedComponentData <FlowComponentOrNode>(
                        id,
                        new UpdateRegionLinker(
                            "",
                            new PreModificationUpdateRegion(updateRegionSets, component.ToCollection, () => "").ToCollection(),
                            arg => component.ToCollection()).ToCollection(),
                        new ErrorSourceSet(),
                        errorsBySource => new DisplayableElement(
                            context => {
                    var attributes = new List <Tuple <string, string> >();
                    if (visualOrderRank.HasValue || width != null)
                    {
                        attributes.Add(
                            Tuple.Create(
                                "style",
                                StringTools.ConcatenateWithDelimiter(
                                    ", ",
                                    visualOrderRank.HasValue ? "order: {0}".FormatWith(visualOrderRank.Value) : "",
                                    width != null ? "width: {0}".FormatWith(width.Value) : "")));
                    }

                    return new DisplayableElementData(
                        displaySetup,
                        () => !includeContentContainer && localDataGetter != null
                                                                                              ? localDataGetter(context, "li", attributes)
                                                                                              : new DisplayableElementLocalData("li", focusDependentData: new DisplayableElementFocusDependentData(attributes: attributes)),
                        classes: CssElementCreator.ItemClass.Add(itemTypeClasses).Add(classes ?? ElementClassSet.Empty),
                        children: includeContentContainer
                                                                                                  ? new DisplayableElement(
                            innerContext => new DisplayableElementData(
                                null,
                                () => localDataGetter != null ? localDataGetter(innerContext, "div", null) : new DisplayableElementLocalData("div"),
                                classes: CssElementCreator.ItemClass,
                                children: content,
                                etherealChildren: etherealContent)).ToCollection()
                                                                                                  : content,
                        etherealChildren: includeContentContainer ? null : etherealContent);
                }).ToCollection()));
                return component;
            },
                       id,
                       removalUpdateRegionSets));
        }
Esempio n. 4
0
        // Web Forms compatibility. Remove when EnduraCode goal 790 is complete.
        private static IReadOnlyCollection <Control> getControls(FlowComponentOrNode component)
        {
            var control = component as Control;

            if (control != null)
            {
                return(control.ToCollection());
            }

            var flowComponent = component as FlowComponent;

            if (flowComponent != null)
            {
                return(flowComponent.GetChildren().GetControls().ToImmutableArray());
            }

            var     identifiedComponent = (IdentifiedFlowComponent)component;
            var     componentData       = identifiedComponent.ComponentDataGetter();
            Control ph = null;

            ph = new PlaceholderControl(
                () => {
                foreach (var linker in componentData.UpdateRegionLinkers)
                {
                    EwfPage.Instance.AddUpdateRegionLinker(
                        new LegacyUpdateRegionLinker(
                            ph,
                            linker.KeySuffix,
                            linker.PreModificationRegions.Select(
                                region =>
                                new LegacyPreModificationUpdateRegion(
                                    region.Sets,
                                    () => region.ComponentGetter().SelectMany(i => EwfPage.Instance.ControlsByComponent[i]),
                                    region.ArgumentGetter)),
                            arg => linker.PostModificationRegionGetter(arg).SelectMany(i => EwfPage.Instance.ControlsByComponent[i])));
                }

                var validationIndex = 0;
                var errorDictionary = new Dictionary <EwfValidation, IReadOnlyCollection <string> >();
                foreach (var i in componentData.Validations)
                {
                    errorDictionary.Add(i, EwfPage.Instance.AddModificationErrorDisplayAndGetErrors(ph, validationIndex.ToString(), i).ToImmutableArray());
                    validationIndex += 1;
                }

                var children = componentData.ChildGetter(new ModificationErrorDictionary(errorDictionary.ToImmutableDictionary())).GetControls();
                if (componentData.Id == null)
                {
                    return(children);
                }
                var np = new NamingPlaceholder(children);
                if (componentData.Id.Any())
                {
                    np.ID = componentData.Id + "np";
                }
                return(np.ToCollection());
            });
            if (!string.IsNullOrEmpty(componentData.Id))
            {
                ph.ID = componentData.Id;
            }
            return(ph.ToCollection());
        }
        // Web Forms compatibility. Remove when EnduraCode goal 790 is complete.
        private static IReadOnlyCollection <Control> getControls(FlowComponentOrNode component)
        {
            if (component is Control control)
            {
                return(control.ToCollection());
            }

            if (component is FlowComponent flowComponent)
            {
                var controls = flowComponent.GetChildren().GetControls().ToImmutableArray();
                if (component is FlowAutofocusRegion autofocusRegion)
                {
                    foreach (var i in controls)
                    {
                        if (!EwfPage.Instance.AutofocusConditionsByControl.TryGetValue(i, out var conditions))
                        {
                            conditions = new List <AutofocusCondition>();
                            EwfPage.Instance.AutofocusConditionsByControl.Add(i, conditions);
                        }
                        conditions.Add(autofocusRegion.Condition);
                    }
                }
                return(controls);
            }

            var     identifiedComponent = (IdentifiedFlowComponent)component;
            var     componentData       = identifiedComponent.ComponentDataGetter();
            Control ph = null;

            ph = new PlaceholderControl(
                () => {
                foreach (var linker in componentData.UpdateRegionLinkers)
                {
                    EwfPage.Instance.AddUpdateRegionLinker(
                        new LegacyUpdateRegionLinker(
                            ph,
                            linker.KeySuffix,
                            linker.PreModificationRegions.Select(
                                region => new LegacyPreModificationUpdateRegion(
                                    region.Sets,
                                    () => region.ComponentGetter().SelectMany(i => EwfPage.Instance.ControlsByComponent[i]),
                                    region.ArgumentGetter)),
                            arg => linker.PostModificationRegionGetter(arg).SelectMany(i => EwfPage.Instance.ControlsByComponent[i])));
                }

                var validationIndex = 0;
                var errorDictionary = new Dictionary <EwfValidation, IReadOnlyCollection <string> >();
                foreach (var i in componentData.ErrorSources.Validations)
                {
                    var errors = EwfPage.Instance.AddModificationErrorDisplayAndGetErrors(ph, validationIndex.ToString(), i).ToImmutableArray();
                    errorDictionary.Add(i, errors);
                    if (errors.Any())
                    {
                        EwfPage.Instance.ValidationsWithErrors.Add(i);
                    }
                    validationIndex += 1;
                }

                var children = componentData.ChildGetter(
                    new ModificationErrorDictionary(
                        errorDictionary.ToImmutableDictionary(),
                        componentData.ErrorSources.IncludeGeneralErrors
                                                                        ? AppRequestState.Instance.EwfPageRequestState.GeneralModificationErrors
                                                                        : ImmutableArray <TrustedHtmlString> .Empty))
                               .GetControls();
                if (componentData.Id == null)
                {
                    return(children);
                }
                return(new NamingPlaceholder(children)
                {
                    ID = "{0}np".FormatWith(ph.UniqueID.Separate("$", false).Last())
                }.ToCollection());
            });
            if (!string.IsNullOrEmpty(componentData.Id))
            {
                ph.ID = componentData.Id;
            }
            return(ph.ToCollection());
        }