Ejemplo n.º 1
0
// Update scripts from server
func (ss ScriptStore) Update(net string, callback func(net string)) {
	console.Log("Loading scripts for", net)
	jquery.Ajax(map[string]interface{}{
		"type": "GET",
		"url":  fmt.Sprintf("/script/%s/", net),
		jquery.SUCCESS: func(scriptsRaw string) {
			var scripts []script
			err := json.Unmarshal([]byte(scriptsRaw), &scripts)
			if err != nil {
				console.Error("Failed to unmarshal scripts:", err)
				return
			}

			for _, script := range scripts {
				ss[script.Name] = script.Script
			}

			console.Log("Successfully updated scripts for", net)

			if callback != nil {
				callback(net)
			}
		},
		jquery.ERROR: func(info map[string]interface{}, textStatus, errorThrown string) {
			console.Error("Failed to update scripts: HTTP", info["status"])
			console.Error(info)
		},
	})
}
Ejemplo n.º 2
0
func main() {
	console.Info("mauIRC", data.Version, "loading...")

	console.Log("Loading templates")
	templates.LoadAll()

	console.Log("Checking notification permission")
	js.Global.Get("Notification").Call("requestPermission")

	console.Log("Applying templates")
	templates.Apply("login", "#container", nil)
	templates.Apply("settings", "#settings", nil)

	console.Info("Init done")

	conn.CheckAuth()
}
Ejemplo n.º 3
0
// Delete the script with the given name
func (ss ScriptStore) Delete(net, name string, callback func(net string)) {
	jquery.Ajax(map[string]interface{}{
		"type": "DELETE",
		"url":  fmt.Sprintf("/script/%s/%s/", net, name),
		jquery.SUCCESS: func() {
			delete(ss, name)
			console.Log("Successfully deleted script", name, "@", net)
			if callback != nil {
				callback(net)
			}
		},
		jquery.ERROR: func(info map[string]interface{}, textStatus, errorThrown string) {
			console.Error("Failed to delete script: HTTP", info["status"])
			console.Error(info)
		},
	})
}
Ejemplo n.º 4
0
// Put the given script under the given name
func (ss ScriptStore) Put(net, name, script string, callback func(net string)) {
	jquery.Ajax(map[string]interface{}{
		"type": "PUT",
		"url":  fmt.Sprintf("/script/%s/%s/", net, name),
		"data": script,
		jquery.SUCCESS: func(data string) {
			ss[name] = script
			console.Log("Successfully updated script", name, "@", net)
			if callback != nil {
				callback(net)
			}
		},
		jquery.ERROR: func(info map[string]interface{}, textStatus, errorThrown string) {
			console.Error("Failed to update script: HTTP", info["status"])
			console.Error(info)
		},
	})
}
Ejemplo n.º 5
0
// Rename the script with the given name
func (ss ScriptStore) Rename(net, oldName, newName string, callback func(net string)) {
	jquery.Ajax(map[string]interface{}{
		"type": "POST",
		"url":  fmt.Sprintf("/script/%s/%s/", net, oldName),
		"data": fmt.Sprintf("%s,%s", net, newName),
		jquery.SUCCESS: func() {
			console.Log("Successfully renamed script", oldName, "@", net, "to", newName)

			ss[newName] = ss[oldName]
			delete(ss, oldName)
			if callback != nil {
				callback(net)
			}
		},
		jquery.ERROR: func(info map[string]interface{}, textStatus, errorThrown string) {
			console.Error("Failed to rename script: HTTP", info["status"])
			console.Error(info)
		},
	})
}