diff options
author | raylu <raylu@mixpanel.com> | 2011-08-06 04:14:13 -0700 |
---|---|---|
committer | raylu <raylu@mixpanel.com> | 2011-08-06 04:14:13 -0700 |
commit | 4639fcf237c9ba232dd4d8d826731cc33d678e8e (patch) | |
tree | 84aa0dd93095469c31816beb8f4174a488c8ca67 | |
parent | c96ff0fd7d0f8068dfdfd3689a372b9348f241b9 (diff) | |
download | audioaxis-4639fcf237c9ba232dd4d8d826731cc33d678e8e.tar.xz |
remove works
-rw-r--r-- | main.go | 25 | ||||
-rw-r--r-- | static/script.js | 12 | ||||
-rw-r--r-- | templates/p.html | 2 |
3 files changed, 37 insertions, 2 deletions
@@ -136,6 +136,24 @@ func add(w http.ResponseWriter, r *http.Request) { w.Write([]byte("1")) } +func remove(w http.ResponseWriter, r *http.Request) { + q := r.URL.Query() + pid := getpid(q.Get("pid")) + if pid == -1 { + http.Error(w, "invalid pid", http.StatusInternalServerError) + return + } + + sql :="DELETE FROM `song` WHERE `pid` = %d AND yid = '%s'" + sql = fmt.Sprintf(sql, pid, q.Get("yid")) + err := db.Query(sql) + if err != nil { + http.Error(w, err.String(), http.StatusInternalServerError) + return + } + w.Write([]byte("1")) +} + func main() { templates = make(map[string]*template.Template) for _, path := range []string{"p"} { @@ -157,5 +175,10 @@ func main() { http.HandleFunc("/", home) http.HandleFunc("/p/", playlist) http.HandleFunc("/add/", add) - http.ListenAndServe(":8000", nil) + http.HandleFunc("/remove/", remove) + err = http.ListenAndServe(":8000", nil) + if err != nil { + fmt.Println(err) + os.Exit(1) + } } diff --git a/static/script.js b/static/script.js index a958a44..354e030 100644 --- a/static/script.js +++ b/static/script.js @@ -174,3 +174,15 @@ function add(id, title) { } ); } + +function remove(id) { + var user = $('#user').val(); + params = { + 'pid': pid, + 'yid': id, + } + $.getJSON('/remove/', params, + function(data) { + } + ); +} diff --git a/templates/p.html b/templates/p.html index c6f6004..b595377 100644 --- a/templates/p.html +++ b/templates/p.html @@ -30,7 +30,7 @@ <div class="user"> {{.User}} </div> - <div class="remove">×</div> + <div class="remove" onclick="remove('{{.Yid}}')">×</div> <br class="clear"> <div class="thumb"> <img src="http://i.ytimg.com/vi/{{.Yid}}/1.jpg" alt="{{.Yid}}"> |