swirl/controller/setting.go

48 lines
1.2 KiB
Go
Raw Normal View History

2017-09-26 12:50:09 +00:00
package controller
import (
"github.com/cuigh/auxo/net/web"
"github.com/cuigh/swirl/biz"
2017-11-22 03:38:24 +00:00
"github.com/cuigh/swirl/misc"
2017-09-26 12:50:09 +00:00
"github.com/cuigh/swirl/model"
)
2017-10-11 03:26:03 +00:00
// SettingController is a controller of system setting
2017-09-26 12:50:09 +00:00
type SettingController struct {
Index web.HandlerFunc `path:"/" name:"setting.edit" authorize:"!" desc:"settings edit page"`
Update web.HandlerFunc `path:"/" name:"setting.update" method:"post" authorize:"!" desc:"update settings"`
}
2017-10-11 03:26:03 +00:00
// Setting creates an instance of SettingController
2017-09-26 12:50:09 +00:00
func Setting() (c *SettingController) {
2017-10-11 03:26:03 +00:00
return &SettingController{
Index: settingIndex,
Update: settingUpdate,
2017-09-26 12:50:09 +00:00
}
2017-10-11 03:26:03 +00:00
}
2017-09-26 12:50:09 +00:00
2017-10-11 03:26:03 +00:00
func settingIndex(ctx web.Context) error {
setting, err := biz.Setting.Get()
if err != nil {
return err
2017-09-26 12:50:09 +00:00
}
2017-11-22 03:38:24 +00:00
m := newModel(ctx).Set("Setting", setting).Set("TimeZones", misc.TimeZones)
2017-10-11 03:26:03 +00:00
return ctx.Render("system/setting/index", m)
}
func settingUpdate(ctx web.Context) error {
setting := &model.Setting{}
err := ctx.Bind(setting)
if err == nil {
2017-11-22 03:38:24 +00:00
for _, tz := range misc.TimeZones {
if tz.Name == setting.TimeZone.Name {
setting.TimeZone.Offset = tz.Offset
break
}
}
2017-10-11 03:26:03 +00:00
err = biz.Setting.Update(setting, ctx.User())
}
return ajaxResult(ctx, err)
2017-09-26 12:50:09 +00:00
}