private ComponentListItem getNonIdItem(int i) { var rs = new UpdateRegionSet(); var items = new List <ComponentListItem>(); if (info.NonIdItemStates.ElementAt(i) == 1) { items.Add(new TextControl("Item {0}".FormatWith(i), true).ToFormItem().ToListItem()); } else { items.Add("Item {0}".FormatWith(i).ToComponents().ToComponentListItem()); } items.Add( new EwfButton( new StandardButtonStyle("Toggle", buttonSize: ButtonSize.ShrinkWrap), behavior: new PostBackBehavior( postBack: PostBack.CreateIntermediate( rs.ToCollection(), id: PostBack.GetCompositeId("nonId", i.ToString()), firstModificationMethod: () => parametersModification.NonIdItemStates = parametersModification.NonIdItemStates.Select( (state, index) => index == i ? (state + 1) % 2 : state)))) .ToCollection() .ToComponentListItem()); return(new StackList(items).ToCollection().ToComponentListItem(updateRegionSets: rs.ToCollection())); }
// NOTE: Change table actions to be IEnumerable<namedType> rather than IEnumerable<Tuple<>>. private EwfTable( bool hideIfEmpty, EwfTableStyle style, IEnumerable <string> classes, string postBackIdBase, string caption, string subCaption, bool allowExportToExcel, IEnumerable <Tuple <string, Action> > tableActions, IEnumerable <EwfTableField> fields, IEnumerable <EwfTableItem> headItems, DataRowLimit defaultItemLimit, bool disableEmptyFieldDetection, IEnumerable <EwfTableItemGroup> itemGroups, IEnumerable <TailUpdateRegion> tailUpdateRegions) { this.hideIfEmpty = hideIfEmpty; this.style = style; this.classes = (classes ?? new string[0]).ToList().AsReadOnly(); this.postBackIdBase = PostBack.GetCompositeId("ewfTable", postBackIdBase); this.caption = caption; this.subCaption = subCaption; this.allowExportToExcel = allowExportToExcel; this.tableActions = (tableActions ?? new Tuple <string, Action> [0]).ToList().AsReadOnly(); if (fields != null) { if (!fields.Any()) { throw new ApplicationException("If fields are specified, there must be at least one of them."); } specifiedFields = fields.ToArray(); } this.headItems = (headItems ?? new EwfTableItem[0]).ToList(); this.defaultItemLimit = defaultItemLimit; this.disableEmptyFieldDetection = disableEmptyFieldDetection; this.itemGroups = itemGroups.ToImmutableArray(); this.tailUpdateRegions = tailUpdateRegions?.ToImmutableArray() ?? ImmutableArray <TailUpdateRegion> .Empty; // When we migrate EwfTable to the new component model, consider having ElementComponent (or ElementNode) store the current DMs and execute the // elementDataGetter with them. This would save developers from having to manually do this when creating intermediate post-backs for click scripts. dataModifications = FormState.Current.DataModifications; }
// NOTE: Change table actions to be IEnumerable<namedType> rather than IEnumerable<Tuple<>>. private EwfTable( bool hideIfEmpty, EwfTableStyle style, IEnumerable <string> classes, string postBackIdBase, string caption, string subCaption, bool allowExportToExcel, IEnumerable <Tuple <string, Action> > tableActions, IEnumerable <EwfTableField> fields, IEnumerable <EwfTableItem> headItems, DataRowLimit defaultItemLimit, bool disableEmptyFieldDetection, IEnumerable <EwfTableItemGroup> itemGroups, IEnumerable <TailUpdateRegion> tailUpdateRegions) { this.hideIfEmpty = hideIfEmpty; this.style = style; this.classes = (classes ?? new string[0]).ToList().AsReadOnly(); this.postBackIdBase = PostBack.GetCompositeId("ewfTable", postBackIdBase); this.caption = caption; this.subCaption = subCaption; this.allowExportToExcel = allowExportToExcel; this.tableActions = (tableActions ?? new Tuple <string, Action> [0]).ToList().AsReadOnly(); if (fields != null) { if (!fields.Any()) { throw new ApplicationException("If fields are specified, there must be at least one of them."); } specifiedFields = fields.ToArray(); } this.headItems = (headItems ?? new EwfTableItem[0]).ToList(); this.defaultItemLimit = defaultItemLimit; this.disableEmptyFieldDetection = disableEmptyFieldDetection; this.itemGroups = itemGroups.ToImmutableArray(); this.tailUpdateRegions = tailUpdateRegions != null?tailUpdateRegions.ToImmutableArray() : ImmutableArray <TailUpdateRegion> .Empty; }
/// <summary> /// Adds a new column on the left of the table containing a checkbox for each row. /// Adds an action link to the top of the table that acts on all rows that are checked. /// Each row must specify the UniqueIdentifier for its row setup. This will be passed back to the given action method. /// Adding multiple actions results in just one column of checkboxes. /// The checkbox column consumes 5% of the table width. /// The action method automatically executes in an EhModifyData method, so your implementation does not need to do this. /// </summary> public void AddSelectedRowsAction(string label, RowMethod action) { var postBack = PostBack.CreateFull(id: PostBack.GetCompositeId(PostBackIdBase, label)); selectedRowDataModificationsToMethods.Add(postBack, action); selectedRowActionButtonsToAdd.Add(new PostBackButton(postBack, new TextActionControlStyle(label), usesSubmitBehavior: false)); }
private FlowComponent getCommentFooter(CommentsTableRetrieval.Row comment, UsersTableRetrieval.Row author, UpdateRegionSet deleteUpdateRegions) => new GenericFlowContainer( new GenericFlowContainer( new GenericPhrasingContainer( new EwfHyperlink( Profile.GetInfo(comment.AuthorId), new ImageHyperlinkStyle( new ExternalResource( author.ProfilePictureUrl.Any() ? author.ProfilePictureUrl : "https://static.productionready.io/images/smiley-cyrus.jpg"), "")).ToCollection()) .Append( new GenericPhrasingContainer( new EwfHyperlink(Profile.GetInfo(comment.AuthorId), new StandardHyperlinkStyle(author.Username)).ToCollection())) .Append(new GenericPhrasingContainer(comment.CreationDateAndTime.ToDayMonthYearString(false).ToComponents())) .Materialize()).Concat <FlowComponent>( comment.AuthorId == AppTools.User?.UserId ? new EwfButton( new StandardButtonStyle("Delete", icon: new ActionComponentIcon(new FontAwesomeIcon("fa-trash"))), behavior: new PostBackBehavior( postBack: PostBack.CreateIntermediate( deleteUpdateRegions.ToCollection(), id: PostBack.GetCompositeId("delete", comment.CommentId.ToString()), modificationMethod: () => CommentsModification.DeleteRows(new CommentsTableEqualityConditions.CommentId(comment.CommentId))))) .ToCollection() : Enumerable.Empty <PhrasingComponent>()) .Materialize());
/// <summary> /// Creates a file collection manager. /// </summary> /// <param name="sortByName"></param> /// <param name="postBackIdBase">Do not pass null.</param> public BlobFileCollectionManager(bool sortByName = false, string postBackIdBase = "") { Caption = ""; this.sortByName = sortByName; this.postBackIdBase = PostBack.GetCompositeId("ewfFileCollection", postBackIdBase); dataModifications = FormState.Current.DataModifications; }
/// <summary> /// Adds a new column on the left of the table containing a checkbox for each row. /// Adds an action link to the top of the table that acts on all rows that are checked. /// Each row must specify the UniqueIdentifier for its row setup. This will be passed back to the given action method. /// Adding multiple actions results in just one column of checkboxes. /// The checkbox column consumes 5% of the table width. /// The action method automatically executes in an EhModifyData method, so your implementation does not need to do this. /// </summary> public void AddSelectedRowsAction(string label, RowMethod action) { var postBack = PostBack.CreateFull(id: PostBack.GetCompositeId(PostBackIdBase, label)); selectedRowDataModificationsToMethods.Add(postBack, action); selectedRowActionButtonsToAdd.Add( new EwfButton(new StandardButtonStyle(label, buttonSize: ButtonSize.ShrinkWrap), behavior: new PostBackBehavior(postBack: postBack))); }
private EwfTableItemGroup getItemGroup(int groupNumber) { var updateRegionSet = new UpdateRegionSet(); return(EwfTableItemGroup.Create( () => new EwfTableItemGroupRemainingData( "Group {0}".FormatWith(groupNumber).ToComponents(), groupActions: groupNumber == 2 ? new ButtonSetup( "Action 1", behavior: new PostBackBehavior( postBack: PostBack.CreateIntermediate( null, id: PostBack.GetCompositeId(groupNumber.ToString(), "action1"), modificationMethod: () => AddStatusMessage(StatusMessageType.Info, "Action 1")))).Append( new ButtonSetup( "Action 2", behavior: new PostBackBehavior( postBack: PostBack.CreateIntermediate( null, id: PostBack.GetCompositeId(groupNumber.ToString(), "action2"), modificationMethod: () => AddStatusMessage(StatusMessageType.Info, "Action 2"))))) .Materialize() : null, groupHeadActivationBehavior: ElementActivationBehavior.CreateButton( new PostBackBehavior( postBack: PostBack.CreateIntermediate( null, id: "group{0}".FormatWith(groupNumber), modificationMethod: () => AddStatusMessage(StatusMessageType.Info, "You clicked group {0}.".FormatWith(groupNumber))))), tailUpdateRegions: groupNumber == 1 ? new TailUpdateRegion(updateRegionSet.ToCollection(), 1).ToCollection() : null), groupNumber == 1 ? getItems(FirstGroupItemCount, true) .Concat( new Func <EwfTableItem>( () => EwfTableItem.Create( new EwfButton( new StandardButtonStyle("Add Row"), behavior: new PostBackBehavior( postBack: PostBack.CreateIntermediate( updateRegionSet.ToCollection(), id: "addRow", modificationMethod: () => parametersModification.FirstGroupItemCount += 1))).ToCollection() .ToCell(), "".ToCell())).ToCollection()) : getItems(250, false), selectedItemActions: groupNumber == 1 ? SelectedItemAction.CreateWithIntermediatePostBackBehavior <int>( "Echo group IDs", null, ids => AddStatusMessage( StatusMessageType.Info, StringTools.GetEnglishListPhrase(ids.Select(i => i.ToString()), true))) .ToCollection() : Enumerable.Empty <SelectedItemAction <int> >().Materialize())); }
// NOTE: EVERYTHING should be done here. We shouldn't have LoadData. We should audit everyone using this control and see if we can improve things. // NOTE: This should also be full of delegates that run when events (such as deleting a file) are occurring. // NOTE: There should be a way to tell if a file was uploaded. void ControlTreeDataLoader.LoadData() { if (fileCollectionId != null) { file = BlobFileOps.GetFirstFileFromCollection(fileCollectionId.Value); } var controlStack = ControlStack.Create(true); if (file != null) { var download = new PostBackButton( PostBack.CreateFull( id: PostBack.GetCompositeId("ewfFile", file.FileId.ToString()), actionGetter: () => { // Refresh the file here in case a new one was uploaded on the same post-back. return (new PostBackAction( new SecondaryResponse(new BlobFileResponse(BlobFileOps.GetFirstFileFromCollection(fileCollectionId.Value).FileId, () => true), false))); }), new TextActionControlStyle(Translation.DownloadExisting + " (" + file.FileName + ")"), false); controlStack.AddControls(download); } else if (!HideNoExistingFileMessage) { controlStack.AddControls(new Label { Text = Translation.NoExistingFile }); } uploadedFile = new EwfFileUpload(); if (file != null) { uploadedFile.SetInitialDisplay(false); var replaceExistingFileLink = new ToggleButton( uploadedFile.ToSingleElementArray(), new TextActionControlStyle(Translation.ClickHereToReplaceExistingFile)) { AlternateText = "" }; controlStack.AddControls(replaceExistingFileLink); } controlStack.AddControls(uploadedFile); var thumbnailControl = BlobFileOps.GetThumbnailControl(file, ThumbnailResourceInfoCreator); if (thumbnailControl != null) { Controls.Add(thumbnailControl); } Controls.Add(controlStack); }
private void addFileRow(DynamicTable table, BlobFile file, ActionPostBack deletePb, List <Func <bool> > deleteModMethods) { var cells = new List <EwfTableCell>(); var thumbnailControl = BlobFileOps.GetThumbnailControl(file, ThumbnailResourceInfoCreator); if (thumbnailControl != null) { cells.Add(thumbnailControl); } var fileIsUnread = fileIdsMarkedAsRead != null && !fileIdsMarkedAsRead.Contains(file.FileId); cells.Add( new PostBackButton( PostBack.CreateFull( id: PostBack.GetCompositeId(postBackIdBase, file.FileId.ToString()), firstModificationMethod: () => { if (fileIsUnread && markFileAsReadMethod != null) { markFileAsReadMethod(file.FileId); } }, actionGetter: () => new PostBackAction(new SecondaryResponse(new BlobFileResponse(file.FileId, () => true), false))), new TextActionControlStyle(file.FileName), false) { ToolTip = file.FileName }); cells.Add(file.UploadedDate.ToDayMonthYearString(false)); cells.Add((fileIsUnread ? "New!" : "").ToCell(new TableCellSetup(classes: "ewfNewness".ToSingleElementArray()))); var delete = false; var deleteCheckBox = FormItem.Create( "", new EwfCheckBox(false, postBack: deletePb), validationGetter: control => new EwfValidation((pbv, v) => { delete = control.IsCheckedInPostBack(pbv); }, deletePb)).ToControl(); cells.Add(ReadOnly ? null : deleteCheckBox); deleteModMethods.Add( () => { if (!delete) { return(false); } BlobFileOps.SystemProvider.DeleteFile(file.FileId); return(true); }); table.AddRow(cells.ToArray()); }
public BlobFileManager(int?fileCollectionId) { this.fileCollectionId = fileCollectionId; if (fileCollectionId != null) { file = BlobFileOps.GetFirstFileFromCollection(fileCollectionId.Value); } var controlStack = ControlStack.Create(true); if (file != null) { var download = new PostBackButton( new TextActionControlStyle(Translation.DownloadExisting + " (" + file.FileName + ")"), usesSubmitBehavior: false, postBack: PostBack.CreateFull( id: PostBack.GetCompositeId("ewfFile", file.FileId.ToString()), actionGetter: () => { // Refresh the file here in case a new one was uploaded on the same post-back. return (new PostBackAction( new SecondaryResponse(new BlobFileResponse(BlobFileOps.GetFirstFileFromCollection(fileCollectionId.Value).FileId, () => true), false))); })); controlStack.AddControls(download); } else if (!HideNoExistingFileMessage) { controlStack.AddControls(new Label { Text = Translation.NoExistingFile }); } uploadedFile = new EwfFileUpload(); if (file != null) { uploadedFile.SetInitialDisplay(false); var replaceExistingFileLink = new ToggleButton( uploadedFile.ToCollection(), new TextActionControlStyle(Translation.ClickHereToReplaceExistingFile), false, (postBackValue, validator) => { }) { AlternateText = "" }; controlStack.AddControls(replaceExistingFileLink); } controlStack.AddControls(uploadedFile); this.AddControlsReturnThis(BlobFileOps.GetThumbnailControl(file, ThumbnailResourceInfoCreator)); Controls.Add(controlStack); }
private IReadOnlyCollection <PhrasingComponent> getTagListComponents(DataValue <IReadOnlyCollection <int> > tagIds, UpdateRegionSet removeUpdateRegions) => tagIds.Value.Select( tagId => new GenericPhrasingContainer( new EwfButton( new CustomButtonStyle(children: new FontAwesomeIcon("fa-times").ToCollection()), behavior: new PostBackBehavior( postBack: PostBack.CreateIntermediate( removeUpdateRegions.ToCollection(), id: PostBack.GetCompositeId("removeTag", tagId.ToString()), modificationMethod: () => tagIds.Value = tagIds.Value.Where(i => i != tagId).Materialize()))) .Concat(" {0}".FormatWith(TagsTableRetrieval.GetRowMatchingId(tagId).TagName).ToComponents()) .Materialize(), classes: ElementClasses.EditorTag)) .Materialize();
private ControlListItem getIdItem(int id) { var rs = new UpdateRegionSet(); var pb = PostBack.CreateIntermediate(rs.ToCollection(), id: PostBack.GetCompositeId("id", id.ToString())); var itemStack = ControlStack.Create(true); itemStack.AddControls(new EwfTextBox("ID {0}".FormatWith(id))); itemStack.AddControls( new PostBackButton(new ButtonActionControlStyle("Remove", buttonSize: ButtonSize.ShrinkWrap), usesSubmitBehavior: false, postBack: pb)); pb.AddModificationMethod(() => parametersModification.ItemIds = parametersModification.ItemIds.Where(i => i != id).ToArray()); return(new ControlListItem(itemStack.ToCollection(), id.ToString(), removalUpdateRegionSets: rs.ToCollection())); }
/// <summary> /// Returns a link to download a file with the given file ID. /// If no file is associated with the given file collection ID, returns a literal control with textIfNoFile text. /// The file name is used as the label unless labelOverride is specified. /// SystemBlobFileManagementProvider must be implemented. /// </summary> public static Control GetFileLinkFromFileId(int fileId, string labelOverride = null, string textIfNoFile = "") { var file = SystemProvider.GetFile(fileId); if (file == null) { return(textIfNoFile.GetLiteralControl()); } return (new PostBackButton( PostBack.CreateFull( id: PostBack.GetCompositeId("ewfFile", file.FileId.ToString()), actionGetter: () => new PostBackAction(new SecondaryResponse(new BlobFileResponse(fileId, () => true), false))), new TextActionControlStyle(labelOverride ?? file.FileName), false)); }
/// <summary> /// Returns a link to download a file with the given file ID. /// If no file is associated with the given file collection ID, returns a literal control with textIfNoFile text. /// The file name is used as the label unless labelOverride is specified. /// SystemBlobFileManagementProvider must be implemented. /// </summary> public static Control GetFileLinkFromFileId(int fileId, string labelOverride = null, string textIfNoFile = "") { var file = SystemProvider.GetFile(fileId); if (file == null) { return(new PlaceHolder().AddControlsReturnThis(textIfNoFile.ToComponents().GetControls())); } return(new PostBackButton( new TextActionControlStyle(labelOverride ?? file.FileName), usesSubmitBehavior: false, postBack: PostBack.CreateFull( id: PostBack.GetCompositeId("ewfFile", file.FileId.ToString()), actionGetter: () => new PostBackAction(new SecondaryResponse(new BlobFileResponse(fileId, () => true), false))))); }
private Control getItemLimitButton(DataRowLimit itemLimit) { var text = itemLimit == DataRowLimit.Unlimited ? "All" : ((int)itemLimit).ToString(); if (itemLimit == (DataRowLimit)CurrentItemLimit) { return(text.GetLiteralControl()); } return (new PostBackButton( PostBack.CreateFull( id: PostBack.GetCompositeId(postBackIdBase, itemLimit.ToString()), firstModificationMethod: () => EwfPage.Instance.PageState.SetValue(this, itemLimitPageStateKey, (int)itemLimit)), new TextActionControlStyle(text), false)); }
private ControlList getUploadControlList() { var dm = PostBack.CreateFull(id: PostBack.GetCompositeId(postBackIdBase, "add")); RsFile file = null; var fi = FormItem.Create( "", new EwfFileUpload(), validationGetter: control => new EwfValidation( (pbv, validator) => { BlobFileOps.ValidateUploadedFile(validator, control, acceptableFileExtensions, ValidateImage, AcceptOnlyImages); file = control.GetPostBackValue(pbv); }, dm)); dm.AddModificationMethod( () => { if (file == null) { return; } var existingFile = files.SingleOrDefault(i => i.FileName == file.FileName); int newFileId; if (existingFile != null) { BlobFileOps.SystemProvider.UpdateFile(existingFile.FileId, file.FileName, file.Contents, BlobFileOps.GetContentTypeForPostedFile(file)); newFileId = existingFile.FileId; } else { newFileId = BlobFileOps.SystemProvider.InsertFile(fileCollectionId, file.FileName, file.Contents, BlobFileOps.GetContentTypeForPostedFile(file)); } if (NewFileNotificationMethod != null) { NewFileNotificationMethod(newFileId); } EwfPage.AddStatusMessage(StatusMessageType.Info, "File uploaded successfully."); }); return(ControlList.CreateWithControls( true, "Select and upload a new file:", fi.ToControl(), new PostBackButton(dm, new ButtonActionControlStyle("Upload new file"), false))); }
private Control getDataRowLimitControl(DataRowLimit dataRowLimit) { if (dataRowLimit == (DataRowLimit)CurrentDataRowLimit) { return new Literal { Text = getDataRowLimitText(dataRowLimit) } } ; return (new PostBackButton( PostBack.CreateFull( id: PostBack.GetCompositeId(PostBackIdBase, dataRowLimit.ToString()), firstModificationMethod: () => EwfPage.Instance.PageState.SetValue(this, pageStateKey, (int)dataRowLimit)), new TextActionControlStyle(getDataRowLimitText(dataRowLimit)), usesSubmitBehavior: false)); }
private Control getDataRowLimitControl(DataRowLimit dataRowLimit) { if (dataRowLimit == (DataRowLimit)CurrentDataRowLimit) { return new Literal { Text = getDataRowLimitText(dataRowLimit) } } ; return(new PlaceHolder().AddControlsReturnThis( new EwfButton( new StandardButtonStyle(getDataRowLimitText(dataRowLimit), buttonSize: ButtonSize.ShrinkWrap), behavior: new PostBackBehavior( postBack: PostBack.CreateFull( id: PostBack.GetCompositeId(PostBackIdBase, dataRowLimit.ToString()), firstModificationMethod: () => EwfPage.Instance.PageState.SetValue(this, pageStateKey, (int)dataRowLimit)))).ToCollection() .GetControls())); }
private ComponentListItem getIdItem(int id) { var rs = new UpdateRegionSet(); var items = new List <ComponentListItem>(); items.Add(new TextControl("ID {0}".FormatWith(id), true).ToFormItem().ToListItem()); items.Add( new EwfButton( new StandardButtonStyle("Remove", buttonSize: ButtonSize.ShrinkWrap), behavior: new PostBackBehavior( postBack: PostBack.CreateIntermediate( rs.ToCollection(), id: PostBack.GetCompositeId("id", id.ToString()), modificationMethod: () => parametersModification.ItemIds = parametersModification.ItemIds.Where(i => i != id).ToArray()))).ToCollection() .ToComponentListItem()); return(new StackList(items).ToCollection().ToComponentListItem(id.ToString(), removalUpdateRegionSets: rs.ToCollection())); }
private ComponentListItem getItemLimitButtonItem(DataRowLimit itemLimit, UpdateRegionSet updateRegionSet) { var text = itemLimit == DataRowLimit.Unlimited ? "All" : ((int)itemLimit).ToString(); if (itemLimit == (DataRowLimit)CurrentItemLimit) { return(text.ToComponents().ToComponentListItem()); } return (new EwfButton( new StandardButtonStyle(text, buttonSize: ButtonSize.ShrinkWrap), behavior: new PostBackBehavior( postBack: PostBack.CreateIntermediate( updateRegionSet.ToCollection(), id: PostBack.GetCompositeId(postBackIdBase, itemLimit.ToString()), firstModificationMethod: () => EwfPage.Instance.PageState.SetValue(this, itemLimitPageStateKey, (int)itemLimit)))).ToCollection() .ToComponentListItem()); }
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 FlowComponent getTagSection(DataValue <string> filter, UpdateRegionSet resultUpdateRegions) { var tags = ArticleTagsTableRetrieval.GetRows() .Select(i => i.TagId) .GroupBy(i => i) .OrderByDescending(i => i.Count()) .Take(20) .Select(i => TagsTableRetrieval.GetRowMatchingId(i.Key)); return(new Section( "Popular Tags", new WrappingList( tags.Select( i => (WrappingListItem) new EwfButton( new StandardButtonStyle(i.TagName, buttonSize: ButtonSize.ShrinkWrap), behavior: new PostBackBehavior( postBack: PostBack.CreateIntermediate( resultUpdateRegions.ToCollection(), id: PostBack.GetCompositeId("tag", i.TagId.ToString()), modificationMethod: () => filter.Value = "tag{0}".FormatWith(i.TagId)))).ToComponentListItem()), generalSetup: new ComponentListSetup(classes: ElementClasses.Tag)).ToCollection(), style: SectionStyle.Box)); }
private ControlListItem getNonIdItem(int i) { var rs = new UpdateRegionSet(); var pb = PostBack.CreateIntermediate(rs.ToCollection(), 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(new ButtonActionControlStyle("Toggle", buttonSize: ButtonSize.ShrinkWrap), usesSubmitBehavior: false, postBack: pb)); pb.AddModificationMethod( () => parametersModification.NonIdItemStates = parametersModification.NonIdItemStates.Select((state, index) => index == i ? (state + 1) % 2 : state)); return(new ControlListItem(itemStack.ToCollection(), updateRegionSets: rs.ToCollection())); }
private static PhrasingComponent getFavoriteActionComponent( ArticlesRetrieval.Row article, ILookup <int, FavoritesTableRetrieval.Row> favoritesByArticleId) { var count = favoritesByArticleId[article.ArticleId].Count().ToString(); if (AppTools.User == null) { return(new EwfHyperlink(User.GetInfo(), new StandardHyperlinkStyle(count, icon: new ActionComponentIcon(new FontAwesomeIcon("fa-heart-o"))))); } var rs = new UpdateRegionSet(); EwfButton button; if (FavoritesTableRetrieval.GetRowMatchingPk(AppTools.User.UserId, article.ArticleId, returnNullIfNoMatch: true) == null) { button = new EwfButton( new StandardButtonStyle(count, icon: new ActionComponentIcon(new FontAwesomeIcon("fa-heart-o"))), behavior: new PostBackBehavior( postBack: PostBack.CreateIntermediate( rs.ToCollection(), id: PostBack.GetCompositeId("favorite", article.ArticleId.ToString()), modificationMethod: () => FavoritesModification.InsertRow(AppTools.User.UserId, article.ArticleId)))); } else { button = new EwfButton( new StandardButtonStyle(count, icon: new ActionComponentIcon(new FontAwesomeIcon("fa-heart"))), behavior: new PostBackBehavior( postBack: PostBack.CreateIntermediate( rs.ToCollection(), id: PostBack.GetCompositeId("unfavorite", article.ArticleId.ToString()), modificationMethod: () => FavoritesModification.DeleteRows( new FavoritesTableEqualityConditions.UserId(AppTools.User.UserId), new FavoritesTableEqualityConditions.ArticleId(article.ArticleId))))); } return(new PhrasingIdContainer(button.ToCollection(), updateRegionSets: rs.ToCollection())); }
void ControlTreeDataLoader.LoadData() { var modifiedCaption = caption; // Display the caption and the sub caption. if (defaultDataRowLimit != DataRowLimit.Unlimited) { var formattedDataRowCount = dataRowCount.ToString("N0"); if (caption.Length > 0) { modifiedCaption += " (" + formattedDataRowCount + ")"; } else { modifiedCaption = formattedDataRowCount + " items"; } } if (modifiedCaption.Length > 0) { captionTable.Visible = true; captionStack.AddControls(new Label { Text = modifiedCaption, CssClass = "ewfCaption" }); } if (subCaption.Length > 0) { captionTable.Visible = true; captionStack.AddText(subCaption); } // Row limiting if (defaultDataRowLimit != DataRowLimit.Unlimited) { captionStack.AddControls( new ControlLine( new LiteralControl("Show:"), getDataRowLimitControl(DataRowLimit.Fifty), getDataRowLimitControl(DataRowLimit.FiveHundred), getDataRowLimitControl(DataRowLimit.Unlimited))); } // Excel export if (allowExportToExcel) { actionLinks.Add( new ActionButtonSetup( "Export to Excel", new PostBackButton(PostBack.CreateFull(id: PostBack.GetCompositeId(PostBackIdBase, "excel"), actionGetter: ExportToExcel)))); } // Action links foreach (var actionLink in actionLinks) { captionTable.Visible = true; actionLinkStack.AddControls(actionLink.BuildButton(text => new TextActionControlStyle(text), false)); } // Selected row actions foreach (var button in selectedRowActionButtonsToAdd) { captionTable.Visible = true; actionLinkStack.AddControls(button); } foreach (var buttonToMethod in selectedRowDataModificationsToMethods) { var dataModification = buttonToMethod.Key; var method = buttonToMethod.Value; dataModification.AddModificationMethod( () => { foreach (var rowSetup in rowSetups) { if (rowSetup.UniqueIdentifier != null && ((EwfCheckBox)rowSetup.UnderlyingTableRow.Cells[0].Controls[0]).IsCheckedInPostBack( AppRequestState.Instance.EwfPageRequestState.PostBackValues)) { method(DataAccessState.Current.PrimaryDatabaseConnection, rowSetup.UniqueIdentifier); } } }); } if (selectedRowDataModificationsToMethods.Any()) { foreach (var rowSetup in rowSetups) { var cell = new TableCell { Width = Unit.Percentage(5), CssClass = EwfTable.CssElementCreator.AllCellAlignmentsClass.ConcatenateWithSpace("ewfNotClickable") }; if (rowSetup.UniqueIdentifier != null) { var firstDm = selectedRowDataModificationsToMethods.First().Key; var pb = firstDm as PostBack; cell.Controls.Add(new EwfCheckBox(false, postBack: pb ?? EwfPage.Instance.DataUpdatePostBack)); } rowSetup.UnderlyingTableRow.Cells.AddAt(0, cell); } } // Reordering var filteredRowSetups = rowSetups.Where(rs => rs.RankId.HasValue).ToList(); for (var i = 0; i < filteredRowSetups.Count; i++) { var previousRowSetup = (i == 0 ? null : filteredRowSetups[i - 1]); var rowSetup = filteredRowSetups[i]; var nextRowSetup = ((i == filteredRowSetups.Count - 1) ? null : filteredRowSetups[i + 1]); var controlLine = new ControlLine(new Control[0]); if (previousRowSetup != null) { var upButton = new PostBackButton( PostBack.CreateFull( id: PostBack.GetCompositeId(PostBackIdBase, rowSetup.RankId.Value.ToString(), "up"), firstModificationMethod: () => RankingMethods.SwapRanks(previousRowSetup.RankId.Value, rowSetup.RankId.Value)), new ButtonActionControlStyle(@"/\", ButtonActionControlStyle.ButtonSize.ShrinkWrap), usesSubmitBehavior: false); controlLine.AddControls(upButton); } if (nextRowSetup != null) { var downButton = new PostBackButton( PostBack.CreateFull( id: PostBack.GetCompositeId(PostBackIdBase, rowSetup.RankId.Value.ToString(), "down"), firstModificationMethod: () => RankingMethods.SwapRanks(rowSetup.RankId.Value, nextRowSetup.RankId.Value)), new ButtonActionControlStyle(@"\/", ButtonActionControlStyle.ButtonSize.ShrinkWrap), usesSubmitBehavior: false); controlLine.AddControls(downButton); } // NOTE: What about rows that don't have a RankId? They need to have an empty cell so all rows have the same cell count. var cell = new TableCell { Width = Unit.Percentage(10), CssClass = EwfTable.CssElementCreator.AllCellAlignmentsClass.ConcatenateWithSpace("ewfNotClickable") }; cell.Controls.Add(controlLine); rowSetup.UnderlyingTableRow.Cells.Add(cell); } if (HideIfEmpty && !HasContentRows) { Visible = false; } }
/// <summary> /// Creates a file collection manager. /// </summary> /// <param name="sortByName"></param> /// <param name="postBackIdBase">Do not pass null.</param> public BlobFileCollectionManager(bool sortByName = false, string postBackIdBase = "") { Caption = ""; this.sortByName = sortByName; this.postBackIdBase = PostBack.GetCompositeId("ewfFileCollection", postBackIdBase); }
void ControlTreeDataLoader.LoadData() { using (MiniProfiler.Current.Step("EWF - Load table data")) { FormState.ExecuteWithDataModificationsAndDefaultAction( dataModifications, () => { 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().ToCollection(); } addColumnSpecifications(fields); var allVisibleItems = new List <EwfTableItem>(); var itemLimitingUpdateRegionSet = new UpdateRegionSet(); var headRows = buildRows( getItemLimitingAndGeneralActionsItem(fields.Count, itemLimitingUpdateRegionSet).Concat(getItemActionsItem(fields.Count)).ToList(), Enumerable.Repeat(new EwfTableField(), fields.Count).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.Count), Enumerable.Repeat(new EwfTableField(), fields.Count).ToArray(), null, true, null, null, allVisibleItems).Concat(new NamingPlaceholder(groupBodyRows).ToCollection())); bodyRowGroupsAndRows.Add(Tuple.Create(rowGroup, groupBodyRows)); var cachedVisibleGroupIndex = visibleGroupIndex; EwfPage.Instance.AddUpdateRegionLinker( new LegacyUpdateRegionLinker( rowGroup, "tail", from region in groupAndItems.Item1.RemainingData.Value.TailUpdateRegions let staticRowCount = itemGroups[cachedVisibleGroupIndex].Items.Count - region.UpdatingItemCount select new LegacyPreModificationUpdateRegion(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 LegacyUpdateRegionLinker( this, "itemLimitingTail", new LegacyPreModificationUpdateRegion( itemLimitingUpdateRegionSet.ToCollection(), () => itemLimitingTailUpdateRegionControlGetter(lowerItemLimit.Value), () => lowerItemLimit.Value.ToString()).ToCollection(), arg => itemLimitingTailUpdateRegionControlGetter(int.Parse(arg)))); } EwfPage.Instance.AddUpdateRegionLinker( new LegacyUpdateRegionLinker( 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 LegacyPreModificationUpdateRegion( 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 button = new PostBackButton( new TextActionControlStyle("Show " + itemIncrementCount + " more item" + (itemIncrementCount != 1 ? "s" : "")), usesSubmitBehavior: false, postBack: PostBack.CreateIntermediate( itemLimitingUpdateRegionSet.ToCollection(), id: PostBack.GetCompositeId(postBackIdBase, "showMore"), firstModificationMethod: () => EwfPage.Instance.PageState.SetValue(this, itemLimitPageStateKey, (int)nextLimit))); var item = new EwfTableItem(button.ToCell(new TableCellSetup(fieldSpan: fields.Count))); var useContrast = visibleItemGroupsAndItems.Sum(i => i.Item2.Count) % 2 == 1; itemLimitingRowGroup.Add( new WebControl(HtmlTextWriterTag.Tbody).AddControlsReturnThis( buildRows( item.ToCollection().ToList(), Enumerable.Repeat(new EwfTableField(), fields.Count).ToArray(), useContrast, false, null, null, allVisibleItems))); } Controls.Add( new NamingPlaceholder( itemLimitingRowGroup, updateRegionSets: itemLimitingUpdateRegionSet.ToCollection() .Concat( itemGroups.SelectMany(i => i.RemainingData.Value.TailUpdateRegions).ToImmutableArray().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.Count); if (!disableEmptyFieldDetection) { AssertAtLeastOneCellPerField(fields, cellPlaceholderListsForItems); } }); } }
internal static PostBack GetLinkPostBack(ResourceInfo destination) { var id = PostBack.GetCompositeId("ewfLink", destination.GetUrl()); return(EwfPage.Instance.GetPostBack(id) ?? PostBack.CreateFull(id: id, actionGetter: () => new PostBackAction(destination))); }
void ControlTreeDataLoader.LoadData() { CssClass = CssClass.ConcatenateWithSpace("ewfStandardFileCollectionManager"); if (AppRequestState.Instance.Browser.IsInternetExplorer()) { base.Controls.Add( new HtmlGenericControl("p") { InnerText = "Because you are using Internet Explorer, clicking on a file below will result in a yellow warning bar appearing near the top of the browser. You will need to then click the warning bar and tell Internet Explorer you are sure you want to download the file." }); } var columnSetups = new List <ColumnSetup>(); if (ThumbnailResourceInfoCreator != null) { columnSetups.Add(new ColumnSetup { Width = Unit.Percentage(10) }); } columnSetups.Add(new ColumnSetup { CssClassOnAllCells = "ewfOverflowedCell" }); columnSetups.Add(new ColumnSetup { Width = Unit.Percentage(13) }); columnSetups.Add(new ColumnSetup { Width = Unit.Percentage(7) }); columnSetups.Add(new ColumnSetup { Width = Unit.Percentage(23), CssClassOnAllCells = "ewfRightAlignCell" }); var table = new DynamicTable(columnSetups.ToArray()) { Caption = Caption }; files = BlobFileOps.SystemProvider.GetFilesLinkedToFileCollection(fileCollectionId); files = (sortByName ? files.OrderByName() : files.OrderByUploadedDateDescending()).ToArray(); var deletePb = PostBack.CreateFull(id: PostBack.GetCompositeId(postBackIdBase, "delete")); var deleteModMethods = new List <Func <bool> >(); foreach (var file in files) { addFileRow(table, file, deletePb, deleteModMethods); } if (!ReadOnly) { table.AddRow( getUploadControlList().ToCell(new TableCellSetup(fieldSpan: ThumbnailResourceInfoCreator != null ? 3 : 2)), (files.Any() ? new PostBackButton(deletePb, new ButtonActionControlStyle("Delete Selected Files"), usesSubmitBehavior: false) : null).ToCell( new TableCellSetup(fieldSpan: 2, classes: "ewfRightAlignCell".ToSingleElementArray()))); } deletePb.AddModificationMethod( () => { if (deleteModMethods.Aggregate(false, (deletesOccurred, method) => method() || deletesOccurred)) { EwfPage.AddStatusMessage(StatusMessageType.Info, "Selected files deleted successfully."); } }); Controls.Add(table); if (ReadOnly && !files.Any()) { Visible = false; } }