module_settings_act_general.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package modules
  2. import (
  3. "golang-fave/engine/wrapper"
  4. "golang-fave/utils"
  5. )
  6. func (this *Modules) RegisterAction_SettingsGeneral() *Action {
  7. return this.newAction(AInfo{
  8. WantDB: true,
  9. Mount: "settings-general",
  10. WantAdmin: true,
  11. }, func(wrap *wrapper.Wrapper) {
  12. pf_module_at_home := wrap.R.FormValue("module-at-home")
  13. pf_price_fomat := wrap.R.FormValue("price-fomat")
  14. pf_price_round := wrap.R.FormValue("price-round")
  15. if !utils.IsNumeric(pf_module_at_home) {
  16. wrap.MsgError(`Must be integer number`)
  17. return
  18. }
  19. if !utils.IsNumeric(pf_price_fomat) {
  20. wrap.MsgError(`Must be integer number`)
  21. return
  22. }
  23. if !utils.IsNumeric(pf_price_round) {
  24. wrap.MsgError(`Must be integer number`)
  25. return
  26. }
  27. pfi_module_at_home := utils.StrToInt(pf_module_at_home)
  28. pfi_price_fomat := utils.StrToInt(pf_price_fomat)
  29. pfi_price_round := utils.StrToInt(pf_price_round)
  30. // Correct values
  31. if pfi_module_at_home < 0 {
  32. pfi_module_at_home = 0
  33. }
  34. if pfi_module_at_home > 2 {
  35. pfi_module_at_home = 2
  36. }
  37. if pfi_price_fomat < 0 {
  38. pfi_price_fomat = 0
  39. }
  40. if pfi_price_fomat > 4 {
  41. pfi_price_fomat = 4
  42. }
  43. if pfi_price_round < 0 {
  44. pfi_price_round = 0
  45. }
  46. if pfi_price_round > 2 {
  47. pfi_price_round = 2
  48. }
  49. (*wrap.Config).Engine.MainModule = pfi_module_at_home
  50. (*wrap.Config).Shop.Price.Format = pfi_price_fomat
  51. (*wrap.Config).Shop.Price.Round = pfi_price_round
  52. if err := wrap.ConfigSave(); err != nil {
  53. wrap.MsgError(err.Error())
  54. return
  55. }
  56. wrap.ResetCacheBlocks()
  57. // Reload current page
  58. wrap.Write(`window.location.reload(false);`)
  59. })
  60. }