using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace FastReport.Web.Toolbar { /// /// Element that opens a drop-down list when you hover over it /// public class ToolbarSelect : ToolbarElement { /// /// The image of the button that appears in the toolbar /// public ToolbarElementImage Image { get; set; } = new ToolbarElementImage(); /// /// Contains items that will be displayed in the drop-down list /// /// List of ToolbarSelectItems /// public List Items { get; set; } = new List(); internal override string Render(string template_FR) { if (!Enabled) return default; var sb = new StringBuilder(); sb.Append( $@"
"); foreach (var item in Items.Where(item => item.Enabled)) sb.Append(item.Render(template_FR)); sb.Append("
"); return sb.ToString(); } } /// /// The element that appears in the drop-down list /// public class ToolbarSelectItem { public ToolbarSelectItem() { Name = ID.ToString(); } internal Guid ID { get; } = Guid.NewGuid(); /// /// Name of toolbar item required to interact with the items list /// public string Name { get; set; } /// /// The inscription displayed in the drop-down list /// public string Title { get; set; } /// /// Defines the visibility of the item in the drop-down list /// public bool Enabled { get; set; } = true; /// /// Action that is triggered when the item is clicked /// public IClickAction OnClickAction { get; set; } internal string Render(string template_FR) { var action = OnClickAction is ElementScript scriptButton ? scriptButton.Script : $"{template_FR}.customMethodInvoke('{ID}', this.value)"; return $@"{Title}"; } } }