manipulate-page-url.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. package e00_basics
  2. // @snippet_begin(MultiStatePageSample)
  3. import (
  4. "net/url"
  5. "github.com/qor5/web"
  6. . "github.com/theplant/htmlgo"
  7. )
  8. func MultiStatePage(ctx *web.EventContext) (pr web.PageResponse, err error) {
  9. title := "Multi State Page"
  10. if len(ctx.R.URL.Query().Get("title")) > 0 {
  11. title = ctx.R.URL.Query().Get("title")
  12. }
  13. var panel HTMLComponent
  14. if len(ctx.R.URL.Query().Get("panel")) > 0 {
  15. panel = Div(
  16. Fieldset(
  17. Div(
  18. Label("Name"),
  19. Input("").Type("text"),
  20. ),
  21. Div(
  22. Label("Date"),
  23. Input("").Type("date"),
  24. ),
  25. ),
  26. Button("Update").Attr("@click", web.POST().EventFunc("update5").Go()),
  27. ).Style("border: 5px solid orange; height: 200px;")
  28. }
  29. pr.Body = Div(
  30. H1(title),
  31. Ol(
  32. Li(
  33. A().Text("change page title").Href("javascript:;").
  34. Attr("@click", web.POST().Queries(url.Values{"title": []string{"Hello"}}).Go()),
  35. ),
  36. Li(
  37. A().Text("show panel").Href("javascript:;").Attr("@click", web.POST().EventFunc("openPanel").Go()),
  38. ),
  39. ),
  40. panel,
  41. Table(
  42. Thead(
  43. Th("Name"),
  44. Th("Date"),
  45. ),
  46. Tbody(
  47. Tr(
  48. Td(Text("Felix")),
  49. Td(Text("2019-01-02")),
  50. ),
  51. ),
  52. ),
  53. )
  54. return
  55. }
  56. func openPanel(ctx *web.EventContext) (er web.EventResponse, err error) {
  57. er.PushState = web.Location(url.Values{"panel": []string{"1"}}).MergeQuery(true)
  58. return
  59. }
  60. func update5(ctx *web.EventContext) (er web.EventResponse, err error) {
  61. er.PushState = web.Location(url.Values{"panel": []string{""}}).MergeQuery(true)
  62. return
  63. }
  64. var MultiStatePagePB = web.Page(MultiStatePage).
  65. EventFunc("openPanel", openPanel).
  66. EventFunc("update5", update5)
  67. const MultiStatePagePath = "/samples/multi_state_page"
  68. // @snippet_end