/// <summary>
 /// Creates a control-list item.
 /// </summary>
 /// <param name="childControls">The item content.</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.</param>
 /// <param name="updateRegionSet">The intermediate-post-back update-region set that this item will be a part of.</param>
 /// <param name="removalUpdateRegionSet">The intermediate-post-back update-region set that this item's removal will be a part of.</param>
 public ControlListItem( IEnumerable<Control> childControls, string id, UpdateRegionSet updateRegionSet = null, UpdateRegionSet removalUpdateRegionSet = null )
 {
     ChildControls = childControls;
     Id = id;
     UpdateRegionSet = updateRegionSet;
     RemovalUpdateRegionSet = removalUpdateRegionSet;
 }
        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 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 ) );
 }
        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 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 );
        }
 /// <summary>
 /// Creates a control-list item.
 /// </summary>
 /// <param name="childControls">The item content.</param>
 /// <param name="updateRegionSet">The intermediate-post-back update-region set that this item will be a part of.</param>
 public ControlListItem( IEnumerable<Control> childControls, UpdateRegionSet updateRegionSet = null )
 {
     ChildControls = childControls;
     UpdateRegionSet = updateRegionSet;
 }
 /// <summary>
 /// Creates an item-insertion update region.
 /// </summary>
 /// <param name="set"></param>
 /// <param name="newItemIdGetter">A method that executes after the data modification and returns the IDs of the new item(s).</param>
 public ItemInsertionUpdateRegion( UpdateRegionSet set, Func<IEnumerable<string>> newItemIdGetter )
 {
     Set = set;
     NewItemIdGetter = newItemIdGetter;
 }
        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, () => parametersModification.ItemIds.First().ToString().ToSingleElementArray() ).ToSingleElementArray() );
            foreach( var i in info.ItemIds )
                stack.AddItem( getIdItem( i ) );

            yield return new Box( "Control List With ID Items", stack.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 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 );
        }
 /// <summary>
 /// Creates a naming placeholder. Add all child controls now; do not use AddControlsReturnThis at any time.
 /// </summary>
 /// <param name="childControls"></param>
 /// <param name="updateRegionSet">The intermediate-post-back update-region set that this naming placeholder will be a part of.</param>
 public NamingPlaceholder( IEnumerable<Control> childControls, UpdateRegionSet updateRegionSet = null )
 {
     this.childControls = childControls.ToArray();
     this.updateRegionSet = updateRegionSet;
 }
 internal PreModificationUpdateRegion( UpdateRegionSet set, Func<IEnumerable<Control>> controlGetter, Func<string> argumentGetter )
 {
     this.set = set;
     this.controlGetter = controlGetter;
     this.argumentGetter = argumentGetter;
 }