module_settings_act_thumbnails.go 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. package modules
  2. import (
  3. "strconv"
  4. "golang-fave/engine/utils"
  5. "golang-fave/engine/wrapper"
  6. )
  7. func (this *Modules) RegisterAction_SettingsThumbnails() *Action {
  8. return this.newAction(AInfo{
  9. Mount: "settings-thumbnails",
  10. WantAdmin: true,
  11. }, func(wrap *wrapper.Wrapper) {
  12. pf_shop_thumbnail_w_1 := utils.Trim(wrap.R.FormValue("shop-thumbnail-w-1"))
  13. pf_shop_thumbnail_h_1 := utils.Trim(wrap.R.FormValue("shop-thumbnail-h-1"))
  14. pf_shop_thumbnail_r_1 := utils.Trim(wrap.R.FormValue("shop-thumbnail-r-1"))
  15. pf_shop_thumbnail_w_2 := utils.Trim(wrap.R.FormValue("shop-thumbnail-w-2"))
  16. pf_shop_thumbnail_h_2 := utils.Trim(wrap.R.FormValue("shop-thumbnail-h-2"))
  17. pf_shop_thumbnail_r_2 := utils.Trim(wrap.R.FormValue("shop-thumbnail-r-2"))
  18. pf_shop_thumbnail_w_3 := utils.Trim(wrap.R.FormValue("shop-thumbnail-w-3"))
  19. pf_shop_thumbnail_h_3 := utils.Trim(wrap.R.FormValue("shop-thumbnail-h-3"))
  20. pf_shop_thumbnail_r_3 := utils.Trim(wrap.R.FormValue("shop-thumbnail-r-3"))
  21. pf_shop_thumbnail_w_full := utils.Trim(wrap.R.FormValue("shop-thumbnail-w-full"))
  22. pf_shop_thumbnail_h_full := utils.Trim(wrap.R.FormValue("shop-thumbnail-h-full"))
  23. pf_shop_thumbnail_r_full := utils.Trim(wrap.R.FormValue("shop-thumbnail-r-full"))
  24. if _, err := strconv.Atoi(pf_shop_thumbnail_w_1); err != nil {
  25. wrap.MsgError(`Must be integer number`)
  26. return
  27. }
  28. if _, err := strconv.Atoi(pf_shop_thumbnail_h_1); err != nil {
  29. wrap.MsgError(`Must be integer number`)
  30. return
  31. }
  32. if _, err := strconv.Atoi(pf_shop_thumbnail_r_1); err != nil {
  33. wrap.MsgError(`Must be integer number`)
  34. return
  35. }
  36. if _, err := strconv.Atoi(pf_shop_thumbnail_w_2); err != nil {
  37. wrap.MsgError(`Must be integer number`)
  38. return
  39. }
  40. if _, err := strconv.Atoi(pf_shop_thumbnail_h_2); err != nil {
  41. wrap.MsgError(`Must be integer number`)
  42. return
  43. }
  44. if _, err := strconv.Atoi(pf_shop_thumbnail_r_2); err != nil {
  45. wrap.MsgError(`Must be integer number`)
  46. return
  47. }
  48. if _, err := strconv.Atoi(pf_shop_thumbnail_w_3); err != nil {
  49. wrap.MsgError(`Must be integer number`)
  50. return
  51. }
  52. if _, err := strconv.Atoi(pf_shop_thumbnail_h_3); err != nil {
  53. wrap.MsgError(`Must be integer number`)
  54. return
  55. }
  56. if _, err := strconv.Atoi(pf_shop_thumbnail_r_3); err != nil {
  57. wrap.MsgError(`Must be integer number`)
  58. return
  59. }
  60. if _, err := strconv.Atoi(pf_shop_thumbnail_w_full); err != nil {
  61. wrap.MsgError(`Must be integer number`)
  62. return
  63. }
  64. if _, err := strconv.Atoi(pf_shop_thumbnail_h_full); err != nil {
  65. wrap.MsgError(`Must be integer number`)
  66. return
  67. }
  68. if _, err := strconv.Atoi(pf_shop_thumbnail_r_full); err != nil {
  69. wrap.MsgError(`Must be integer number`)
  70. return
  71. }
  72. pfi_shop_thumbnail_w_1 := utils.StrToInt(pf_shop_thumbnail_w_1)
  73. pfi_shop_thumbnail_h_1 := utils.StrToInt(pf_shop_thumbnail_h_1)
  74. pfi_shop_thumbnail_r_1 := utils.StrToInt(pf_shop_thumbnail_r_1)
  75. pfi_shop_thumbnail_w_2 := utils.StrToInt(pf_shop_thumbnail_w_2)
  76. pfi_shop_thumbnail_h_2 := utils.StrToInt(pf_shop_thumbnail_h_2)
  77. pfi_shop_thumbnail_r_2 := utils.StrToInt(pf_shop_thumbnail_r_2)
  78. pfi_shop_thumbnail_w_3 := utils.StrToInt(pf_shop_thumbnail_w_3)
  79. pfi_shop_thumbnail_h_3 := utils.StrToInt(pf_shop_thumbnail_h_3)
  80. pfi_shop_thumbnail_r_3 := utils.StrToInt(pf_shop_thumbnail_r_3)
  81. pfi_shop_thumbnail_w_full := utils.StrToInt(pf_shop_thumbnail_w_full)
  82. pfi_shop_thumbnail_h_full := utils.StrToInt(pf_shop_thumbnail_h_full)
  83. pfi_shop_thumbnail_r_full := utils.StrToInt(pf_shop_thumbnail_r_full)
  84. // Correct some values
  85. if pfi_shop_thumbnail_w_1 < 10 {
  86. pfi_shop_thumbnail_w_1 = 10
  87. }
  88. if pfi_shop_thumbnail_h_1 > 1000 {
  89. pfi_shop_thumbnail_h_1 = 1000
  90. }
  91. if pfi_shop_thumbnail_r_1 > 2 {
  92. pfi_shop_thumbnail_r_1 = 1
  93. }
  94. if pfi_shop_thumbnail_r_1 < 0 {
  95. pfi_shop_thumbnail_r_1 = 0
  96. }
  97. if pfi_shop_thumbnail_w_2 < 10 {
  98. pfi_shop_thumbnail_w_2 = 10
  99. }
  100. if pfi_shop_thumbnail_h_2 > 1000 {
  101. pfi_shop_thumbnail_h_2 = 1000
  102. }
  103. if pfi_shop_thumbnail_r_2 > 2 {
  104. pfi_shop_thumbnail_r_2 = 1
  105. }
  106. if pfi_shop_thumbnail_r_2 < 0 {
  107. pfi_shop_thumbnail_r_2 = 0
  108. }
  109. if pfi_shop_thumbnail_w_3 < 10 {
  110. pfi_shop_thumbnail_w_3 = 10
  111. }
  112. if pfi_shop_thumbnail_h_3 > 1000 {
  113. pfi_shop_thumbnail_h_3 = 1000
  114. }
  115. if pfi_shop_thumbnail_r_3 > 2 {
  116. pfi_shop_thumbnail_r_3 = 1
  117. }
  118. if pfi_shop_thumbnail_r_3 < 0 {
  119. pfi_shop_thumbnail_r_3 = 0
  120. }
  121. if pfi_shop_thumbnail_w_full < 10 {
  122. pfi_shop_thumbnail_w_full = 10
  123. }
  124. if pfi_shop_thumbnail_h_full > 1000 {
  125. pfi_shop_thumbnail_h_full = 1000
  126. }
  127. if pfi_shop_thumbnail_r_full > 2 {
  128. pfi_shop_thumbnail_r_full = 1
  129. }
  130. if pfi_shop_thumbnail_r_full < 0 {
  131. pfi_shop_thumbnail_r_full = 0
  132. }
  133. is_changed_tb1 := false
  134. is_changed_tb2 := false
  135. is_changed_tb3 := false
  136. is_changed_tbf := false
  137. if (*wrap.Config).Shop.Thumbnails.Thumbnail1[0] != pfi_shop_thumbnail_w_1 || (*wrap.Config).Shop.Thumbnails.Thumbnail1[1] != pfi_shop_thumbnail_h_1 || (*wrap.Config).Shop.Thumbnails.Thumbnail1[2] != pfi_shop_thumbnail_r_1 {
  138. is_changed_tb1 = true
  139. }
  140. if (*wrap.Config).Shop.Thumbnails.Thumbnail2[0] != pfi_shop_thumbnail_w_2 || (*wrap.Config).Shop.Thumbnails.Thumbnail2[1] != pfi_shop_thumbnail_h_2 || (*wrap.Config).Shop.Thumbnails.Thumbnail2[2] != pfi_shop_thumbnail_r_2 {
  141. is_changed_tb2 = true
  142. }
  143. if (*wrap.Config).Shop.Thumbnails.Thumbnail3[0] != pfi_shop_thumbnail_w_3 || (*wrap.Config).Shop.Thumbnails.Thumbnail3[1] != pfi_shop_thumbnail_h_3 || (*wrap.Config).Shop.Thumbnails.Thumbnail3[2] != pfi_shop_thumbnail_r_3 {
  144. is_changed_tb3 = true
  145. }
  146. if (*wrap.Config).Shop.Thumbnails.ThumbnailFull[0] != pfi_shop_thumbnail_w_full || (*wrap.Config).Shop.Thumbnails.ThumbnailFull[1] != pfi_shop_thumbnail_h_full || (*wrap.Config).Shop.Thumbnails.ThumbnailFull[2] != pfi_shop_thumbnail_r_full {
  147. is_changed_tbf = true
  148. }
  149. (*wrap.Config).Shop.Thumbnails.Thumbnail1[0] = pfi_shop_thumbnail_w_1
  150. (*wrap.Config).Shop.Thumbnails.Thumbnail1[1] = pfi_shop_thumbnail_h_1
  151. (*wrap.Config).Shop.Thumbnails.Thumbnail1[2] = pfi_shop_thumbnail_r_1
  152. (*wrap.Config).Shop.Thumbnails.Thumbnail2[0] = pfi_shop_thumbnail_w_2
  153. (*wrap.Config).Shop.Thumbnails.Thumbnail2[1] = pfi_shop_thumbnail_h_2
  154. (*wrap.Config).Shop.Thumbnails.Thumbnail2[2] = pfi_shop_thumbnail_r_2
  155. (*wrap.Config).Shop.Thumbnails.Thumbnail3[0] = pfi_shop_thumbnail_w_3
  156. (*wrap.Config).Shop.Thumbnails.Thumbnail3[1] = pfi_shop_thumbnail_h_3
  157. (*wrap.Config).Shop.Thumbnails.Thumbnail3[2] = pfi_shop_thumbnail_r_3
  158. (*wrap.Config).Shop.Thumbnails.ThumbnailFull[0] = pfi_shop_thumbnail_w_full
  159. (*wrap.Config).Shop.Thumbnails.ThumbnailFull[1] = pfi_shop_thumbnail_h_full
  160. (*wrap.Config).Shop.Thumbnails.ThumbnailFull[2] = pfi_shop_thumbnail_r_full
  161. if err := wrap.ConfigSave(); err != nil {
  162. wrap.MsgError(err.Error())
  163. return
  164. }
  165. // Reset products images cache
  166. if is_changed_tb1 || is_changed_tb2 || is_changed_tb3 || is_changed_tbf {
  167. if is_changed_tb1 && is_changed_tb2 && is_changed_tb3 && is_changed_tbf {
  168. if err := wrap.RemoveProductImageThumbnails("*", "thumb-*"); err != nil {
  169. wrap.MsgError(err.Error())
  170. return
  171. }
  172. } else {
  173. if is_changed_tb1 {
  174. if err := wrap.RemoveProductImageThumbnails("*", "thumb-1-*"); err != nil {
  175. wrap.MsgError(err.Error())
  176. return
  177. }
  178. }
  179. if is_changed_tb2 {
  180. if err := wrap.RemoveProductImageThumbnails("*", "thumb-2-*"); err != nil {
  181. wrap.MsgError(err.Error())
  182. return
  183. }
  184. }
  185. if is_changed_tb3 {
  186. if err := wrap.RemoveProductImageThumbnails("*", "thumb-3-*"); err != nil {
  187. wrap.MsgError(err.Error())
  188. return
  189. }
  190. }
  191. if is_changed_tbf {
  192. if err := wrap.RemoveProductImageThumbnails("*", "thumb-full-*"); err != nil {
  193. wrap.MsgError(err.Error())
  194. return
  195. }
  196. }
  197. }
  198. }
  199. // Reload current page
  200. wrap.Write(`window.location.reload(false);`)
  201. })
  202. }