module_settings_act_thumbnails.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. package modules
  2. import (
  3. "strconv"
  4. "golang-fave/engine/wrapper"
  5. "golang-fave/utils"
  6. )
  7. func (this *Modules) RegisterAction_SettingsThumbnails() *Action {
  8. return this.newAction(AInfo{
  9. WantDB: true,
  10. Mount: "settings-thumbnails",
  11. WantAdmin: true,
  12. }, func(wrap *wrapper.Wrapper) {
  13. pf_shop_thumbnail_w_1 := wrap.R.FormValue("shop-thumbnail-w-1")
  14. pf_shop_thumbnail_h_1 := wrap.R.FormValue("shop-thumbnail-h-1")
  15. pf_shop_thumbnail_w_2 := wrap.R.FormValue("shop-thumbnail-w-2")
  16. pf_shop_thumbnail_h_2 := wrap.R.FormValue("shop-thumbnail-h-2")
  17. pf_shop_thumbnail_w_3 := wrap.R.FormValue("shop-thumbnail-w-3")
  18. pf_shop_thumbnail_h_3 := wrap.R.FormValue("shop-thumbnail-h-3")
  19. if _, err := strconv.Atoi(pf_shop_thumbnail_w_1); err != nil {
  20. wrap.MsgError(`Must be integer number`)
  21. return
  22. }
  23. if _, err := strconv.Atoi(pf_shop_thumbnail_h_1); err != nil {
  24. wrap.MsgError(`Must be integer number`)
  25. return
  26. }
  27. if _, err := strconv.Atoi(pf_shop_thumbnail_w_2); err != nil {
  28. wrap.MsgError(`Must be integer number`)
  29. return
  30. }
  31. if _, err := strconv.Atoi(pf_shop_thumbnail_h_2); err != nil {
  32. wrap.MsgError(`Must be integer number`)
  33. return
  34. }
  35. if _, err := strconv.Atoi(pf_shop_thumbnail_w_3); err != nil {
  36. wrap.MsgError(`Must be integer number`)
  37. return
  38. }
  39. if _, err := strconv.Atoi(pf_shop_thumbnail_h_3); err != nil {
  40. wrap.MsgError(`Must be integer number`)
  41. return
  42. }
  43. pfi_shop_thumbnail_w_1 := utils.StrToInt(pf_shop_thumbnail_w_1)
  44. pfi_shop_thumbnail_h_1 := utils.StrToInt(pf_shop_thumbnail_h_1)
  45. pfi_shop_thumbnail_w_2 := utils.StrToInt(pf_shop_thumbnail_w_2)
  46. pfi_shop_thumbnail_h_2 := utils.StrToInt(pf_shop_thumbnail_h_2)
  47. pfi_shop_thumbnail_w_3 := utils.StrToInt(pf_shop_thumbnail_w_3)
  48. pfi_shop_thumbnail_h_3 := utils.StrToInt(pf_shop_thumbnail_h_3)
  49. // Correct some values
  50. if pfi_shop_thumbnail_w_1 < 10 {
  51. pfi_shop_thumbnail_w_1 = 10
  52. }
  53. if pfi_shop_thumbnail_h_1 > 1000 {
  54. pfi_shop_thumbnail_h_1 = 1000
  55. }
  56. if pfi_shop_thumbnail_w_2 < 10 {
  57. pfi_shop_thumbnail_w_2 = 10
  58. }
  59. if pfi_shop_thumbnail_h_2 > 1000 {
  60. pfi_shop_thumbnail_h_2 = 1000
  61. }
  62. if pfi_shop_thumbnail_w_3 < 10 {
  63. pfi_shop_thumbnail_w_3 = 10
  64. }
  65. if pfi_shop_thumbnail_h_3 > 1000 {
  66. pfi_shop_thumbnail_h_3 = 1000
  67. }
  68. (*wrap.Config).Shop.Thumbnails.Thumbnail1[0] = pfi_shop_thumbnail_w_1
  69. (*wrap.Config).Shop.Thumbnails.Thumbnail1[1] = pfi_shop_thumbnail_h_1
  70. (*wrap.Config).Shop.Thumbnails.Thumbnail2[0] = pfi_shop_thumbnail_w_2
  71. (*wrap.Config).Shop.Thumbnails.Thumbnail2[1] = pfi_shop_thumbnail_h_2
  72. (*wrap.Config).Shop.Thumbnails.Thumbnail3[0] = pfi_shop_thumbnail_w_3
  73. (*wrap.Config).Shop.Thumbnails.Thumbnail3[1] = pfi_shop_thumbnail_h_3
  74. if err := wrap.ConfigSave(); err != nil {
  75. wrap.MsgError(err.Error())
  76. return
  77. }
  78. // TODO: Reset images cache if changed
  79. // Reload current page
  80. wrap.Write(`window.location.reload(false);`)
  81. })
  82. }