Submit a task

This commit is contained in:
Bel LaPointe
2019-11-13 13:17:56 -07:00
parent ee77d9d3b7
commit cf1fd1dfed
13 changed files with 259 additions and 49 deletions

View File

@@ -4,6 +4,7 @@ import (
"local/storage"
"local/todo-server/config"
"net/http"
"net/url"
)
type Ajax struct {
@@ -20,56 +21,63 @@ func New() (*Ajax, error) {
func (a *Ajax) HandleAjax(w http.ResponseWriter, r *http.Request) {
params := r.URL.Query()
var foo func(http.ResponseWriter, *http.Request) error
if v := params.Get("loadLists"); v != "" {
if has(params, "loadLists") {
foo = a.loadLists
} else if v := params.Get("loadTasks"); v != "" {
} else if has(params, "loadTasks") {
foo = a.loadTasks
} else if v := params.Get("newTask"); v != "" {
} else if has(params, "newTask") {
foo = a.newTask
} else if v := params.Get("fullNewTask"); v != "" {
} else if has(params, "fullNewTask") {
foo = a.newTask
} else if v := params.Get("deleteTask"); v != "" {
} else if has(params, "deleteTask") {
foo = a.deleteTask
} else if v := params.Get("completeTask"); v != "" {
} else if has(params, "completeTask") {
foo = a.completeTask
} else if v := params.Get("editNote"); v != "" {
} else if has(params, "editNote") {
foo = a.editNote
} else if v := params.Get("editTask"); v != "" {
} else if has(params, "editTask") {
foo = a.editTask
} else if v := params.Get("changeOrder"); v != "" {
} else if has(params, "changeOrder") {
foo = a.changeOrder
} else if v := params.Get("suggestTags"); v != "" {
} else if has(params, "suggestTags") {
foo = a.suggestTags
} else if v := params.Get("setPrio"); v != "" {
} else if has(params, "setPrio") {
foo = a.setPrio
} else if v := params.Get("tagCloud"); v != "" {
} else if has(params, "tagCloud") {
foo = a.tagCloud
} else if v := params.Get("addList"); v != "" {
} else if has(params, "addList") {
foo = a.addList
} else if v := params.Get("renameList"); v != "" {
} else if has(params, "renameList") {
foo = a.renameList
} else if v := params.Get("deleteList"); v != "" {
} else if has(params, "deleteList") {
foo = a.deleteList
} else if v := params.Get("setSort"); v != "" {
} else if has(params, "setSort") {
foo = a.setSort
} else if v := params.Get("publishList"); v != "" {
} else if has(params, "publishList") {
foo = a.publishList
} else if v := params.Get("moveTask"); v != "" {
} else if has(params, "moveTask") {
foo = a.moveTask
} else if v := params.Get("changeListOrder"); v != "" {
} else if has(params, "changeListOrder") {
foo = a.changeListOrder
} else if v := params.Get("parseTaskStr"); v != "" {
} else if has(params, "parseTaskStr") {
foo = a.parseTaskStr
} else if v := params.Get("clearCompletedInList"); v != "" {
} else if has(params, "clearCompletedInList") {
foo = a.clearCompletedInList
} else if v := params.Get("setShowNotesInList"); v != "" {
} else if has(params, "setShowNotesInList") {
foo = a.setShowNotesInList
} else if v := params.Get("setHideList"); v != "" {
} else if has(params, "setHideList") {
foo = a.setHideList
}
if err := foo(w, r); err == storage.ErrNotFound {
if foo == nil {
http.NotFound(w, r)
} else if err := foo(w, r); err == storage.ErrNotFound {
http.Error(w, err.Error(), http.StatusNotFound)
} else if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}
func has(params url.Values, k string) bool {
_, ok := params[k]
return ok
}