module_settings.go 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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: "thumbnails", Name: "Thumbnails", Show: true, Icon: assets.SysSvgIconList},
  24. {Mount: "api", Name: "API", Show: true, Icon: assets.SysSvgIconList},
  25. },
  26. }, nil, func(wrap *wrapper.Wrapper) (string, string, string) {
  27. content := ""
  28. sidebar := ""
  29. if wrap.CurrSubModule == "" || wrap.CurrSubModule == "default" {
  30. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  31. {Name: "Robots.txt"},
  32. })
  33. fcont := []byte(``)
  34. fcont, _ = ioutil.ReadFile(wrap.DTemplate + string(os.PathSeparator) + "robots.txt")
  35. content += builder.DataForm(wrap, []builder.DataFormField{
  36. {
  37. Kind: builder.DFKHidden,
  38. Name: "action",
  39. Value: "settings-robots-txt",
  40. },
  41. {
  42. Kind: builder.DFKText,
  43. CallBack: func(field *builder.DataFormField) string {
  44. 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>`
  45. },
  46. },
  47. {
  48. Kind: builder.DFKSubmit,
  49. CallBack: func(field *builder.DataFormField) string {
  50. 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>`
  51. },
  52. },
  53. })
  54. sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Save</button>`
  55. } else if wrap.CurrSubModule == "pagination" {
  56. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  57. {Name: "Pagination"},
  58. })
  59. content += builder.DataForm(wrap, []builder.DataFormField{
  60. {
  61. Kind: builder.DFKHidden,
  62. Name: "action",
  63. Value: "settings-pagination",
  64. },
  65. {
  66. Kind: builder.DFKNumber,
  67. Caption: "Blog main page",
  68. Name: "blog-index",
  69. Min: "1",
  70. Max: "100",
  71. Required: true,
  72. Value: utils.IntToStr((*wrap.Config).Blog.Pagination.Index),
  73. },
  74. {
  75. Kind: builder.DFKNumber,
  76. Caption: "Blog category page",
  77. Name: "blog-category",
  78. Min: "1",
  79. Max: "100",
  80. Required: true,
  81. Value: utils.IntToStr((*wrap.Config).Blog.Pagination.Category),
  82. },
  83. {
  84. Kind: builder.DFKText,
  85. Caption: "",
  86. Name: "",
  87. Value: "",
  88. CallBack: func(field *builder.DataFormField) string {
  89. return `<hr>`
  90. },
  91. },
  92. {
  93. Kind: builder.DFKNumber,
  94. Caption: "Shop main page",
  95. Name: "shop-index",
  96. Min: "1",
  97. Max: "100",
  98. Required: true,
  99. Value: utils.IntToStr((*wrap.Config).Shop.Pagination.Index),
  100. },
  101. {
  102. Kind: builder.DFKNumber,
  103. Caption: "Shop category page",
  104. Name: "shop-category",
  105. Min: "1",
  106. Max: "100",
  107. Required: true,
  108. Value: utils.IntToStr((*wrap.Config).Shop.Pagination.Category),
  109. },
  110. {
  111. Kind: builder.DFKSubmit,
  112. Value: "Save",
  113. Target: "add-edit-button",
  114. },
  115. })
  116. sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Save</button>`
  117. } else if wrap.CurrSubModule == "thumbnails" {
  118. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  119. {Name: "Thumbnails"},
  120. })
  121. // TODO: two fields in one line
  122. content += builder.DataForm(wrap, []builder.DataFormField{
  123. {
  124. Kind: builder.DFKHidden,
  125. Name: "action",
  126. Value: "settings-thumbnails",
  127. },
  128. {
  129. Kind: builder.DFKNumber,
  130. Caption: "Shop thumbnail 1 width",
  131. Name: "shop-thumbnail-w-1",
  132. Min: "10",
  133. Max: "1000",
  134. Required: true,
  135. Value: utils.IntToStr((*wrap.Config).Shop.Thumbnails.Thumbnail1[0]),
  136. },
  137. {
  138. Kind: builder.DFKNumber,
  139. Caption: "Shop thumbnail 1 height",
  140. Name: "shop-thumbnail-h-1",
  141. Min: "10",
  142. Max: "1000",
  143. Required: true,
  144. Value: utils.IntToStr((*wrap.Config).Shop.Thumbnails.Thumbnail1[1]),
  145. },
  146. {
  147. Kind: builder.DFKText,
  148. Caption: "",
  149. Name: "",
  150. Value: "",
  151. CallBack: func(field *builder.DataFormField) string {
  152. return `<hr>`
  153. },
  154. },
  155. {
  156. Kind: builder.DFKNumber,
  157. Caption: "Shop thumbnail 2 width",
  158. Name: "shop-thumbnail-w-2",
  159. Min: "10",
  160. Max: "1000",
  161. Required: true,
  162. Value: utils.IntToStr((*wrap.Config).Shop.Thumbnails.Thumbnail2[0]),
  163. },
  164. {
  165. Kind: builder.DFKNumber,
  166. Caption: "Shop thumbnail 2 height",
  167. Name: "shop-thumbnail-h-2",
  168. Min: "10",
  169. Max: "1000",
  170. Required: true,
  171. Value: utils.IntToStr((*wrap.Config).Shop.Thumbnails.Thumbnail2[1]),
  172. },
  173. {
  174. Kind: builder.DFKText,
  175. Caption: "",
  176. Name: "",
  177. Value: "",
  178. CallBack: func(field *builder.DataFormField) string {
  179. return `<hr>`
  180. },
  181. },
  182. {
  183. Kind: builder.DFKNumber,
  184. Caption: "Shop thumbnail 3 width",
  185. Name: "shop-thumbnail-w-3",
  186. Min: "10",
  187. Max: "1000",
  188. Required: true,
  189. Value: utils.IntToStr((*wrap.Config).Shop.Thumbnails.Thumbnail3[0]),
  190. },
  191. {
  192. Kind: builder.DFKNumber,
  193. Caption: "Shop thumbnail 3 height",
  194. Name: "shop-thumbnail-h-3",
  195. Min: "10",
  196. Max: "1000",
  197. Required: true,
  198. Value: utils.IntToStr((*wrap.Config).Shop.Thumbnails.Thumbnail3[1]),
  199. },
  200. {
  201. Kind: builder.DFKSubmit,
  202. Value: "Save",
  203. Target: "add-edit-button",
  204. },
  205. })
  206. sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Save</button>`
  207. } else if wrap.CurrSubModule == "api" {
  208. content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
  209. {Name: "API"},
  210. })
  211. content += builder.DataForm(wrap, []builder.DataFormField{
  212. {
  213. Kind: builder.DFKHidden,
  214. Name: "action",
  215. Value: "settings-api",
  216. },
  217. {
  218. Kind: builder.DFKCheckBox,
  219. Caption: "XML enabled",
  220. Name: "xml-enabled",
  221. Value: utils.IntToStr((*wrap.Config).API.XML.Enabled),
  222. Hint: "XML: <a href=\"/api/products/\" target=\"_blank\">/api/products/</a>",
  223. },
  224. {
  225. Kind: builder.DFKText,
  226. Caption: "XML name",
  227. Name: "xml-name",
  228. Value: (*wrap.Config).API.XML.Name,
  229. },
  230. {
  231. Kind: builder.DFKText,
  232. Caption: "XML company",
  233. Name: "xml-company",
  234. Value: (*wrap.Config).API.XML.Company,
  235. },
  236. {
  237. Kind: builder.DFKText,
  238. Caption: "XML url",
  239. Name: "xml-url",
  240. Value: (*wrap.Config).API.XML.Url,
  241. },
  242. {
  243. Kind: builder.DFKSubmit,
  244. Value: "Save",
  245. Target: "add-edit-button",
  246. },
  247. })
  248. sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Save</button>`
  249. }
  250. return this.getSidebarModules(wrap), content, sidebar
  251. })
  252. }