module_settings.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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.DFKMessage,
  47. CallBack: func(field *builder.DataFormField) string {
  48. return `<div class="row"><div class="col-12"><div class="sys-messages"></div></div></div>`
  49. },
  50. },
  51. {
  52. Kind: builder.DFKSubmit,
  53. CallBack: func(field *builder.DataFormField) string {
  54. return `<div class="row d-lg-none"><div class="col-12"><button type="submit" class="btn btn-primary" data-target="add-edit-button">Save</button></div></div>`
  55. },
  56. },
  57. })
  58. sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Save</button>`
  59. } else if wrap.CurrSubModule == "pagination" {
  60. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  61. {Name: "Pagination"},
  62. })
  63. content += builder.DataForm(wrap, []builder.DataFormField{
  64. {
  65. Kind: builder.DFKHidden,
  66. Name: "action",
  67. Value: "settings-pagination",
  68. },
  69. {
  70. Kind: builder.DFKNumber,
  71. Caption: "Blog main page",
  72. Name: "blog-index",
  73. Min: "1",
  74. Max: "100",
  75. Required: true,
  76. Value: utils.IntToStr((*wrap.Config).Blog.Pagination.Index),
  77. },
  78. {
  79. Kind: builder.DFKNumber,
  80. Caption: "Blog category page",
  81. Name: "blog-category",
  82. Min: "1",
  83. Max: "100",
  84. Required: true,
  85. Value: utils.IntToStr((*wrap.Config).Blog.Pagination.Category),
  86. },
  87. {
  88. Kind: builder.DFKText,
  89. Caption: "",
  90. Name: "",
  91. Value: "",
  92. CallBack: func(field *builder.DataFormField) string {
  93. return `<hr>`
  94. },
  95. },
  96. {
  97. Kind: builder.DFKNumber,
  98. Caption: "Shop main page",
  99. Name: "shop-index",
  100. Min: "1",
  101. Max: "100",
  102. Required: true,
  103. Value: utils.IntToStr((*wrap.Config).Shop.Pagination.Index),
  104. },
  105. {
  106. Kind: builder.DFKNumber,
  107. Caption: "Shop category page",
  108. Name: "shop-category",
  109. Min: "1",
  110. Max: "100",
  111. Required: true,
  112. Value: utils.IntToStr((*wrap.Config).Shop.Pagination.Category),
  113. },
  114. {
  115. Kind: builder.DFKMessage,
  116. },
  117. {
  118. Kind: builder.DFKSubmit,
  119. Value: "Save",
  120. Target: "add-edit-button",
  121. },
  122. })
  123. sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Save</button>`
  124. }
  125. return this.getSidebarModules(wrap), content, sidebar
  126. })
  127. }