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() { FormState.ExecuteWithDataModificationsAndDefaultAction( dataModifications, () => { 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 ButtonSetup( "Export to Excel", behavior: new PostBackBehavior( postBack: PostBack.CreateFull(id: PostBack.GetCompositeId(PostBackIdBase, "excel"), actionGetter: ExportToExcel)))); } // Action links foreach (var actionLink in actionLinks) { captionTable.Visible = true; var actionComponent = actionLink.GetActionComponent( (text, icon) => new ButtonHyperlinkStyle(text, buttonSize: ButtonSize.ShrinkWrap, icon: icon), (text, icon) => new StandardButtonStyle(text, buttonSize: ButtonSize.ShrinkWrap, icon: icon)); if (actionComponent == null) { continue; } actionLinkStack.AddControls(new PlaceHolder().AddControlsReturnThis(actionComponent.ToCollection().GetControls())); } // Selected row actions foreach (var button in selectedRowActionButtonsToAdd) { captionTable.Visible = true; actionLinkStack.AddControls(new PlaceHolder().AddControlsReturnThis(button.ToCollection().GetControls())); } var checkedRowSetups = new HashSet <RowSetup>(); foreach (var buttonToMethod in selectedRowDataModificationsToMethods) { var dataModification = buttonToMethod.Key; var method = buttonToMethod.Value; dataModification.AddModificationMethod( () => { foreach (var rowSetup in rowSetups) { if (checkedRowSetups.Contains(rowSetup)) { method(rowSetup.UniqueIdentifier); } } }); } if (selectedRowDataModificationsToMethods.Any()) { foreach (var rowSetup in rowSetups) { var cell = new TableCell { Width = Unit.Percentage(5), CssClass = TableCssElementCreator.AllCellAlignmentsClass.ClassName.ConcatenateWithSpace("ewfAec") }; if (rowSetup.UniqueIdentifier != null) { cell.Controls.Add( new PlaceHolder().AddControlsReturnThis( FormState.ExecuteWithDataModificationsAndDefaultAction( selectedRowDataModificationsToMethods.Keys, () => new Checkbox( false, Enumerable.Empty <PhrasingComponent>().Materialize(), validationMethod: (postBackValue, validator) => { if (postBackValue.Value) { checkedRowSetups.Add(rowSetup); } }), formControlDefaultActionOverride: new SpecifiedValue <NonPostBackFormAction>(null)) .PageComponent.ToCollection() .GetControls())); } 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 EwfButton( new StandardButtonStyle(@"/\", ButtonSize.ShrinkWrap), behavior: new PostBackBehavior( postBack: PostBack.CreateFull( id: PostBack.GetCompositeId(PostBackIdBase, rowSetup.RankId.Value.ToString(), "up"), firstModificationMethod: () => RankingMethods.SwapRanks(previousRowSetup.RankId.Value, rowSetup.RankId.Value)))); controlLine.AddControls(new PlaceHolder().AddControlsReturnThis(upButton.ToCollection().GetControls())); } if (nextRowSetup != null) { var downButton = new EwfButton( new StandardButtonStyle(@"\/", ButtonSize.ShrinkWrap), behavior: new PostBackBehavior( postBack: PostBack.CreateFull( id: PostBack.GetCompositeId(PostBackIdBase, rowSetup.RankId.Value.ToString(), "down"), firstModificationMethod: () => RankingMethods.SwapRanks(rowSetup.RankId.Value, nextRowSetup.RankId.Value)))); controlLine.AddControls(new PlaceHolder().AddControlsReturnThis(downButton.ToCollection().GetControls())); } // 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 = TableCssElementCreator.AllCellAlignmentsClass.ClassName.ConcatenateWithSpace("ewfAec") }; cell.Controls.Add(controlLine); rowSetup.UnderlyingTableRow.Cells.Add(cell); } if (HideIfEmpty && !HasContentRows) { Visible = false; } }); }