module_settings.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. package modules
  2. import (
  3. "html"
  4. "io/ioutil"
  5. "os"
  6. "golang-fave/assets"
  7. "golang-fave/consts"
  8. "golang-fave/engine/builder"
  9. "golang-fave/engine/wrapper"
  10. "golang-fave/utils"
  11. )
  12. func (this *Modules) RegisterModule_Settings() *Module {
  13. return this.newModule(MInfo{
  14. WantDB: false,
  15. Mount: "settings",
  16. Name: "Settings",
  17. Order: 801,
  18. System: true,
  19. Icon: assets.SysSvgIconGear,
  20. Sub: &[]MISub{
  21. {Mount: "default", Name: "Robots.txt", Show: true, Icon: assets.SysSvgIconBug},
  22. {Mount: "pagination", Name: "Pagination", Show: true, Icon: assets.SysSvgIconList},
  23. },
  24. }, nil, func(wrap *wrapper.Wrapper) (string, string, string) {
  25. content := ""
  26. sidebar := ""
  27. if wrap.CurrSubModule == "" || wrap.CurrSubModule == "default" {
  28. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  29. {Name: "Robots.txt"},
  30. })
  31. fcont := []byte(``)
  32. fcont, _ = ioutil.ReadFile(wrap.DTemplate + string(os.PathSeparator) + "robots.txt")
  33. content += builder.DataForm(wrap, []builder.DataFormField{
  34. {
  35. Kind: builder.DFKHidden,
  36. Name: "action",
  37. Value: "settings-robots-txt",
  38. },
  39. {
  40. Kind: builder.DFKText,
  41. CallBack: func(field *builder.DataFormField) string {
  42. return `<div class="form-group last"><div class="row"><div class="col-12"><textarea class="form-control autosize" id="lbl_content" name="content" placeholder="" autocomplete="off">` + html.EscapeString(string(fcont)) + `</textarea></div></div></div>`
  43. },
  44. },
  45. {
  46. Kind: builder.DFKSubmit,
  47. CallBack: func(field *builder.DataFormField) string {
  48. return `<div class="row d-lg-none"><div class="col-12"><div class="pt-3"><button type="submit" class="btn btn-primary" data-target="add-edit-button">Save</button></div></div></div>`
  49. },
  50. },
  51. })
  52. sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Save</button>`
  53. } else if wrap.CurrSubModule == "pagination" {
  54. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  55. {Name: "Pagination"},
  56. })
  57. content += builder.DataForm(wrap, []builder.DataFormField{
  58. {
  59. Kind: builder.DFKHidden,
  60. Name: "action",
  61. Value: "settings-pagination",
  62. },
  63. {
  64. Kind: builder.DFKNumber,
  65. Caption: "Blog main page",
  66. Name: "blog-index",
  67. Min: "1",
  68. Max: "100",
  69. Required: true,
  70. Value: utils.IntToStr((*wrap.Config).Blog.Pagination.Index),
  71. },
  72. {
  73. Kind: builder.DFKNumber,
  74. Caption: "Blog category page",
  75. Name: "blog-category",
  76. Min: "1",
  77. Max: "100",
  78. Required: true,
  79. Value: utils.IntToStr((*wrap.Config).Blog.Pagination.Category),
  80. },
  81. {
  82. Kind: builder.DFKText,
  83. Caption: "",
  84. Name: "",
  85. Value: "",
  86. CallBack: func(field *builder.DataFormField) string {
  87. return `<hr>`
  88. },
  89. },
  90. {
  91. Kind: builder.DFKNumber,
  92. Caption: "Shop main page",
  93. Name: "shop-index",
  94. Min: "1",
  95. Max: "100",
  96. Required: true,
  97. Value: utils.IntToStr((*wrap.Config).Shop.Pagination.Index),
  98. },
  99. {
  100. Kind: builder.DFKNumber,
  101. Caption: "Shop category page",
  102. Name: "shop-category",
  103. Min: "1",
  104. Max: "100",
  105. Required: true,
  106. Value: utils.IntToStr((*wrap.Config).Shop.Pagination.Category),
  107. },
  108. {
  109. Kind: builder.DFKSubmit,
  110. Value: "Save",
  111. Target: "add-edit-button",
  112. },
  113. })
  114. sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Save</button>`
  115. }
  116. return this.getSidebarModules(wrap), content, sidebar
  117. })
  118. }