module_settings_act_general.go 925 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package modules
  2. import (
  3. "strconv"
  4. "golang-fave/engine/wrapper"
  5. "golang-fave/utils"
  6. )
  7. func (this *Modules) RegisterAction_SettingsGeneral() *Action {
  8. return this.newAction(AInfo{
  9. WantDB: true,
  10. Mount: "settings-general",
  11. WantAdmin: true,
  12. }, func(wrap *wrapper.Wrapper) {
  13. pf_module_at_home := wrap.R.FormValue("module-at-home")
  14. if _, err := strconv.Atoi(pf_module_at_home); err != nil {
  15. wrap.MsgError(`Must be integer number`)
  16. return
  17. }
  18. pfi_module_at_home := utils.StrToInt(pf_module_at_home)
  19. // Correct some values
  20. if pfi_module_at_home < 0 {
  21. pfi_module_at_home = 0
  22. }
  23. if pfi_module_at_home > 2 {
  24. pfi_module_at_home = 2
  25. }
  26. (*wrap.Config).Engine.MainModule = pfi_module_at_home
  27. if err := wrap.ConfigSave(); err != nil {
  28. wrap.MsgError(err.Error())
  29. return
  30. }
  31. wrap.ResetCacheBlocks()
  32. // Reload current page
  33. wrap.Write(`window.location.reload(false);`)
  34. })
  35. }