module_settings_act_pagination.go 2.3 KB

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