Example #1
0
func main() {
	dom.GetWindow().AddEventListener("load", false, func(dom.Event) {
		go func() {
			if err := rpcInit(); err != nil {
				xjs.Alert("Failed to connect to RPC server: %s", err)
				return
			}
			title, err := RPC.ServerName()
			if err != nil {
				xjs.Alert("Error retrieving server name: %s", err)
				return
			}
			body := dom.GetWindow().Document().(dom.HTMLDocument).Body()
			body.Underlying().Set("spellcheck", "false")
			xjs.RemoveChildren(body)
			body.AppendChild(xdom.H1())
			SetTitle(title)
			body.AppendChild(tabs.New([]tabs.Tab{
				{"Servers", ServersTab()},
				{"Maps", MapsTab()},
				{"Generators", GeneratorsTab},
				{"Settings", settingsTab},
			}))
		}()
	})
}
Example #2
0
func GeneratorsTab(c dom.Element) {
	go func() {
		xjs.RemoveChildren(c)
		gs, err := RPC.Generators()
		if err != nil {
			xjs.Alert("Error getting generator list: %s", err)
			return
		}
		ng := xdom.Button()
		xjs.SetInnerText(ng, "New Generator")
		ng.AddEventListener("click", false, func(dom.Event) {
			d := xdom.Div()
			o := overlay.New(d)
			o.OnClose(func() {
				GeneratorsTab(c)
			})
			d.AppendChild(transferFile("Map", "Upload/Download", 3, o))
			xjs.Body().AppendChild(o)
		})
		table := xjs.AppendChildren(xdom.Table(), xjs.AppendChildren(xdom.Tr(), xjs.SetInnerText(xdom.Th(), "Generator")))
		if len(gs) == 0 {
			table.AppendChild(xjs.AppendChildren(xdom.Tr(), xjs.SetInnerText(xdom.Td(), "No Generators")))
		} else {
			for _, g := range gs {
				td := xdom.Td()
				td.AddEventListener("click", false, func(g data.Generator) func(dom.Event) {
					return func(dom.Event) {
						d := xdom.Div()
						o := overlay.New(d)
						o.OnClose(func() {
							GeneratorsTab(c)
						})
						d.AppendChild(tabs.New([]tabs.Tab{
							{"Profile", generatorProfile(g.ID)},
							{"Misc", misc("generator", g.ID, o, RPC.RemoveGenerator)},
						}))
						xjs.Body().AppendChild(o)
					}
				}(g))
				table.AppendChild(xjs.AppendChildren(xdom.Tr(), xjs.SetInnerText(td, g.Name)))
			}
		}
		xjs.AppendChildren(c,
			xjs.SetInnerText(xdom.H2(), "Generators"),
			ng,
			table,
		)
	}()
}
Example #3
0
func rpcInit() error {
	conn, err := websocket.Dial("ws://" + js.Global.Get("location").Get("host").String() + "/rpc")
	if err != nil {
		return err
	}
	conn.WebSocket.Call("addEventListener", "close", func(*js.Object) {
		xjs.RemoveChildren(xdom.Body()).AppendChild(xjs.SetInnerText(xdom.H1(), "Connection Lost"))
	}, false)
	dom.GetWindow().AddEventListener("beforeunload", false, func(dom.Event) {
		switch conn.ReadyState {
		case websocket.Connecting, websocket.Open:
			conn.Close()
		}
	})
	RPC = jRPC{jsonrpc.NewClient(conn)}
	return nil
}