module_settings_act_pagination.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package modules
  2. import (
  3. "strconv"
  4. "golang-fave/engine/wrapper"
  5. "golang-fave/utils"
  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 := wrap.R.FormValue("blog-index")
  14. pf_blog_category := wrap.R.FormValue("blog-category")
  15. if _, err := strconv.Atoi(pf_blog_index); err != nil {
  16. wrap.MsgError(`Blog posts count per page on main page must be integer number`)
  17. return
  18. }
  19. if _, err := strconv.Atoi(pf_blog_category); err != nil {
  20. wrap.MsgError(`Blog posts count per page on category page must be integer number`)
  21. return
  22. }
  23. pfi_blog_index := utils.StrToInt(pf_blog_index)
  24. pfi_blog_category := utils.StrToInt(pf_blog_category)
  25. // Correct some values
  26. if pfi_blog_index < 0 {
  27. pfi_blog_index = 1
  28. }
  29. if pfi_blog_index > 100 {
  30. pfi_blog_index = 100
  31. }
  32. if pfi_blog_category < 0 {
  33. pfi_blog_category = 1
  34. }
  35. if pfi_blog_category > 100 {
  36. pfi_blog_category = 100
  37. }
  38. (*wrap.Config).Blog.Pagination.Index = pfi_blog_index
  39. (*wrap.Config).Blog.Pagination.Category = pfi_blog_category
  40. if err := wrap.ConfigSave(); err != nil {
  41. wrap.MsgError(err.Error())
  42. return
  43. }
  44. // Reload current page
  45. wrap.Write(`window.location.reload(false);`)
  46. })
  47. }