123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- package e00_basics
- // @snippet_begin(ReloadWithFlashSample)
- import (
- "fmt"
- "time"
- "github.com/qor5/web"
- . "github.com/theplant/htmlgo"
- )
- var count int
- func ReloadWithFlash(ctx *web.EventContext) (pr web.PageResponse, err error) {
- var msg HTMLComponent
- if d, ok := ctx.Flash.(*Data1); ok {
- msg = Div().Text(d.Msg).Style("border: 5px solid orange;")
- } else {
- count = 0
- }
- pr.Body = Div(
- H1("Whole Page Reload With a Flash"),
- msg,
- Div().Text(time.Now().Format(time.RFC3339Nano)),
- Button("Do Something").
- Attr("@click", web.POST().EventFunc("update2").Go()),
- )
- return
- }
- type Data1 struct {
- Msg string
- }
- func update2(ctx *web.EventContext) (er web.EventResponse, err error) {
- count++
- ctx.Flash = &Data1{Msg: fmt.Sprintf("The page is reloaded: %d", count)}
- er.Reload = true
- return
- }
- var ReloadWithFlashPB = web.Page(ReloadWithFlash).EventFunc("update2", update2)
- const ReloadWithFlashPath = "/samples/reload_with_flash"
- // @snippet_end
|