action.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. package presets
  2. type ActionBuilder struct {
  3. NameLabel
  4. buttonCompFunc ComponentFunc
  5. updateFunc ActionUpdateFunc
  6. compFunc ActionComponentFunc
  7. dialogWidth string
  8. buttonColor string
  9. }
  10. func getAction(actions []*ActionBuilder, name string) *ActionBuilder {
  11. for _, f := range actions {
  12. if f.name == name {
  13. return f
  14. }
  15. }
  16. return nil
  17. }
  18. func (b *ActionBuilder) Label(v string) (r *ActionBuilder) {
  19. b.label = v
  20. return b
  21. }
  22. // ButtonCompFunc defines the components of the button area.
  23. func (b *ActionBuilder) ButtonCompFunc(v ComponentFunc) (r *ActionBuilder) {
  24. b.buttonCompFunc = v
  25. return b
  26. }
  27. // UpdateFunc defines event when the button is clicked.
  28. func (b *ActionBuilder) UpdateFunc(v ActionUpdateFunc) (r *ActionBuilder) {
  29. b.updateFunc = v
  30. return b
  31. }
  32. // ComponentFunc defines the components in dialog of button click.
  33. func (b *ActionBuilder) ComponentFunc(v ActionComponentFunc) (r *ActionBuilder) {
  34. b.compFunc = v
  35. return b
  36. }
  37. func (b *ActionBuilder) DialogWidth(v string) (r *ActionBuilder) {
  38. b.dialogWidth = v
  39. return b
  40. }
  41. // ButtonColor defines the color of default button if buttonCompFunc is not defined.
  42. func (b *ActionBuilder) ButtonColor(v string) (r *ActionBuilder) {
  43. b.buttonColor = v
  44. return b
  45. }
  46. func (b *ListingBuilder) Action(name string) (r *ActionBuilder) {
  47. builder := getAction(b.actions, name)
  48. if builder != nil {
  49. return builder
  50. }
  51. r = &ActionBuilder{}
  52. r.name = name
  53. b.actions = append(b.actions, r)
  54. return
  55. }
  56. func (b *DetailingBuilder) Action(name string) (r *ActionBuilder) {
  57. builder := getAction(b.actions, name)
  58. if builder != nil {
  59. return builder
  60. }
  61. r = &ActionBuilder{}
  62. r.name = name
  63. b.actions = append(b.actions, r)
  64. return
  65. }