bulk_action.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package presets
  2. const defaultBulkActionDialogWidth = "600"
  3. type BulkActionBuilder struct {
  4. NameLabel
  5. buttonCompFunc ComponentFunc
  6. updateFunc BulkActionUpdateFunc
  7. compFunc BulkActionComponentFunc
  8. selectedIdsProcessorFunc BulkActionSelectedIdsProcessorFunc
  9. selectedIdsProcessorNoticeFunc BulkActionSelectedIdsProcessorNoticeFunc
  10. dialogWidth string
  11. buttonColor string
  12. }
  13. func getBulkAction(actions []*BulkActionBuilder, name string) *BulkActionBuilder {
  14. for _, f := range actions {
  15. if f.name == name {
  16. return f
  17. }
  18. }
  19. return nil
  20. }
  21. func (b *BulkActionBuilder) Label(v string) (r *BulkActionBuilder) {
  22. b.label = v
  23. return b
  24. }
  25. func (b *BulkActionBuilder) ButtonCompFunc(v ComponentFunc) (r *BulkActionBuilder) {
  26. b.buttonCompFunc = v
  27. return b
  28. }
  29. func (b *BulkActionBuilder) UpdateFunc(v BulkActionUpdateFunc) (r *BulkActionBuilder) {
  30. b.updateFunc = v
  31. return b
  32. }
  33. func (b *BulkActionBuilder) ComponentFunc(v BulkActionComponentFunc) (r *BulkActionBuilder) {
  34. b.compFunc = v
  35. return b
  36. }
  37. func (b *BulkActionBuilder) SelectedIdsProcessorFunc(v BulkActionSelectedIdsProcessorFunc) (r *BulkActionBuilder) {
  38. b.selectedIdsProcessorFunc = v
  39. return b
  40. }
  41. func (b *BulkActionBuilder) SelectedIdsProcessorNoticeFunc(v BulkActionSelectedIdsProcessorNoticeFunc) (r *BulkActionBuilder) {
  42. b.selectedIdsProcessorNoticeFunc = v
  43. return b
  44. }
  45. func (b *BulkActionBuilder) DialogWidth(v string) (r *BulkActionBuilder) {
  46. b.dialogWidth = v
  47. return b
  48. }
  49. func (b *BulkActionBuilder) ButtonColor(v string) (r *BulkActionBuilder) {
  50. b.buttonColor = v
  51. return b
  52. }
  53. func (b *ListingBuilder) BulkAction(name string) (r *BulkActionBuilder) {
  54. builder := getBulkAction(b.bulkActions, name)
  55. if builder != nil {
  56. return builder
  57. }
  58. r = &BulkActionBuilder{}
  59. r.name = name
  60. r.dialogWidth = defaultBulkActionDialogWidth
  61. b.bulkActions = append(b.bulkActions, r)
  62. return
  63. }