module_settings_act_pagination.go 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. package modules
  2. import (
  3. "strconv"
  4. "golang-fave/engine/utils"
  5. "golang-fave/engine/wrapper"
  6. )
  7. func (this *Modules) RegisterAction_SettingsPagination() *Action {
  8. return this.newAction(AInfo{
  9. Mount: "settings-pagination",
  10. WantAdmin: true,
  11. }, func(wrap *wrapper.Wrapper) {
  12. pf_blog_index := utils.Trim(wrap.R.FormValue("blog-index"))
  13. pf_blog_category := utils.Trim(wrap.R.FormValue("blog-category"))
  14. pf_shop_index := utils.Trim(wrap.R.FormValue("shop-index"))
  15. pf_shop_category := utils.Trim(wrap.R.FormValue("shop-category"))
  16. if _, err := strconv.Atoi(pf_blog_index); err != nil {
  17. wrap.MsgError(`Blog posts count per page on main page must be integer number`)
  18. return
  19. }
  20. if _, err := strconv.Atoi(pf_blog_category); err != nil {
  21. wrap.MsgError(`Blog posts count per page on category page must be integer number`)
  22. return
  23. }
  24. if _, err := strconv.Atoi(pf_shop_index); err != nil {
  25. wrap.MsgError(`Shop products count per page on main page must be integer number`)
  26. return
  27. }
  28. if _, err := strconv.Atoi(pf_shop_category); err != nil {
  29. wrap.MsgError(`Shop products count per page on category page must be integer number`)
  30. return
  31. }
  32. pfi_blog_index := utils.StrToInt(pf_blog_index)
  33. pfi_blog_category := utils.StrToInt(pf_blog_category)
  34. pfi_shop_index := utils.StrToInt(pf_shop_index)
  35. pfi_shop_category := utils.StrToInt(pf_shop_category)
  36. // Correct some values
  37. if pfi_blog_index < 0 {
  38. pfi_blog_index = 1
  39. }
  40. if pfi_blog_index > 100 {
  41. pfi_blog_index = 100
  42. }
  43. if pfi_blog_category < 0 {
  44. pfi_blog_category = 1
  45. }
  46. if pfi_blog_category > 100 {
  47. pfi_blog_category = 100
  48. }
  49. if pfi_shop_index < 0 {
  50. pfi_shop_index = 1
  51. }
  52. if pfi_shop_index > 100 {
  53. pfi_shop_index = 100
  54. }
  55. if pfi_shop_category < 0 {
  56. pfi_shop_category = 1
  57. }
  58. if pfi_shop_category > 100 {
  59. pfi_shop_category = 100
  60. }
  61. (*wrap.Config).Blog.Pagination.Index = pfi_blog_index
  62. (*wrap.Config).Blog.Pagination.Category = pfi_blog_category
  63. (*wrap.Config).Shop.Pagination.Index = pfi_shop_index
  64. (*wrap.Config).Shop.Pagination.Category = pfi_shop_category
  65. if err := wrap.ConfigSave(); err != nil {
  66. wrap.MsgError(err.Error())
  67. return
  68. }
  69. wrap.ResetCacheBlocks()
  70. // Reload current page
  71. wrap.Write(`window.location.reload(false);`)
  72. })
  73. }