ToolbarButton.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. using System;
  2. namespace FastReport.Web.Toolbar
  3. {
  4. /// <summary>
  5. /// Button for the toolbar
  6. /// </summary>
  7. public class ToolbarButton : ToolbarElement
  8. {
  9. /// <summary>
  10. /// The image of the button that appears in the toolbar
  11. /// </summary>
  12. public ToolbarElementImage Image { get; set; } = new ToolbarElementImage();
  13. /// <summary>
  14. /// Action that is triggered when the button is clicked
  15. /// </summary>
  16. public IClickAction OnClickAction { get; set; }
  17. internal override string Render(string template_FR)
  18. {
  19. if (!Enabled) return default;
  20. var action = OnClickAction is ElementScript scriptButton
  21. ? scriptButton.Script
  22. : $"{template_FR}.customMethodInvoke('{ID}', this.value)";
  23. return $@"<div class=""fr-toolbar-item fr-toolbar-pointer {template_FR}-toolbar-item {template_FR}-pointer {ElementClasses}"" style=""{ElementCustomStyle}"" onclick=""{action}"">
  24. <img src=""{Image.RenderedImage}"" title=""{Title}"" class=""{template_FR}-toolbar-image"">
  25. </div>";
  26. }
  27. }
  28. }