module_settings.go 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. {Mount: "api", Name: "API", Show: true, Icon: assets.SysSvgIconList},
  24. },
  25. }, nil, func(wrap *wrapper.Wrapper) (string, string, string) {
  26. content := ""
  27. sidebar := ""
  28. if wrap.CurrSubModule == "" || wrap.CurrSubModule == "default" {
  29. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  30. {Name: "Robots.txt"},
  31. })
  32. fcont := []byte(``)
  33. fcont, _ = ioutil.ReadFile(wrap.DTemplate + string(os.PathSeparator) + "robots.txt")
  34. content += builder.DataForm(wrap, []builder.DataFormField{
  35. {
  36. Kind: builder.DFKHidden,
  37. Name: "action",
  38. Value: "settings-robots-txt",
  39. },
  40. {
  41. Kind: builder.DFKText,
  42. CallBack: func(field *builder.DataFormField) string {
  43. 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>`
  44. },
  45. },
  46. {
  47. Kind: builder.DFKSubmit,
  48. CallBack: func(field *builder.DataFormField) string {
  49. 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>`
  50. },
  51. },
  52. })
  53. sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Save</button>`
  54. } else if wrap.CurrSubModule == "pagination" {
  55. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  56. {Name: "Pagination"},
  57. })
  58. content += builder.DataForm(wrap, []builder.DataFormField{
  59. {
  60. Kind: builder.DFKHidden,
  61. Name: "action",
  62. Value: "settings-pagination",
  63. },
  64. {
  65. Kind: builder.DFKNumber,
  66. Caption: "Blog main page",
  67. Name: "blog-index",
  68. Min: "1",
  69. Max: "100",
  70. Required: true,
  71. Value: utils.IntToStr((*wrap.Config).Blog.Pagination.Index),
  72. },
  73. {
  74. Kind: builder.DFKNumber,
  75. Caption: "Blog category page",
  76. Name: "blog-category",
  77. Min: "1",
  78. Max: "100",
  79. Required: true,
  80. Value: utils.IntToStr((*wrap.Config).Blog.Pagination.Category),
  81. },
  82. {
  83. Kind: builder.DFKText,
  84. Caption: "",
  85. Name: "",
  86. Value: "",
  87. CallBack: func(field *builder.DataFormField) string {
  88. return `<hr>`
  89. },
  90. },
  91. {
  92. Kind: builder.DFKNumber,
  93. Caption: "Shop main page",
  94. Name: "shop-index",
  95. Min: "1",
  96. Max: "100",
  97. Required: true,
  98. Value: utils.IntToStr((*wrap.Config).Shop.Pagination.Index),
  99. },
  100. {
  101. Kind: builder.DFKNumber,
  102. Caption: "Shop category page",
  103. Name: "shop-category",
  104. Min: "1",
  105. Max: "100",
  106. Required: true,
  107. Value: utils.IntToStr((*wrap.Config).Shop.Pagination.Category),
  108. },
  109. {
  110. Kind: builder.DFKSubmit,
  111. Value: "Save",
  112. Target: "add-edit-button",
  113. },
  114. })
  115. sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Save</button>`
  116. } else if wrap.CurrSubModule == "api" {
  117. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  118. {Name: "API"},
  119. })
  120. content += builder.DataForm(wrap, []builder.DataFormField{
  121. {
  122. Kind: builder.DFKHidden,
  123. Name: "action",
  124. Value: "settings-api",
  125. },
  126. {
  127. Kind: builder.DFKCheckBox,
  128. Caption: "XML enabled",
  129. Name: "xml-enabled",
  130. Value: utils.IntToStr((*wrap.Config).API.XML.Enabled),
  131. Hint: "XML: <a href=\"/api/products/\" target=\"_blank\">/api/products/</a>",
  132. },
  133. {
  134. Kind: builder.DFKText,
  135. Caption: "XML name",
  136. Name: "xml-name",
  137. Value: (*wrap.Config).API.XML.Name,
  138. },
  139. {
  140. Kind: builder.DFKText,
  141. Caption: "XML company",
  142. Name: "xml-company",
  143. Value: (*wrap.Config).API.XML.Company,
  144. },
  145. {
  146. Kind: builder.DFKText,
  147. Caption: "XML url",
  148. Name: "xml-url",
  149. Value: (*wrap.Config).API.XML.Url,
  150. },
  151. {
  152. Kind: builder.DFKSubmit,
  153. Value: "Save",
  154. Target: "add-edit-button",
  155. },
  156. })
  157. sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Save</button>`
  158. }
  159. return this.getSidebarModules(wrap), content, sidebar
  160. })
  161. }