From ee37b31502bc46527a5db51f73459f5f7946e1b2 Mon Sep 17 00:00:00 2001 From: jan Date: Wed, 30 Dec 2015 16:49:59 +0100 Subject: =?UTF-8?q?hover=20f=C3=BCr=20search-results.=20beim=20klicken=20a?= =?UTF-8?q?uf=20ein=20gril=20wird=20ein=20request=20gestartet,=20fehlt=20n?= =?UTF-8?q?ur=20noch=20die=20implementation,=20um=20ein=20gril=20zu=20eine?= =?UTF-8?q?r=20liste=20hinzuzuf=C3=BCgen.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit diff --git a/assets/css/search.css b/assets/css/search.css index 6bca026..e76a7d1 100644 --- a/assets/css/search.css +++ b/assets/css/search.css @@ -5,4 +5,12 @@ .search-results { top: -50px; z-index: 2; +} + +.collection > .collection-item { + transition: background-color .35s; +} + +.collection > .collection-item:hover { + background-color: #e1bee7; } \ No newline at end of file diff --git a/assets/js/list.js b/assets/js/list.js new file mode 100644 index 0000000..3a58971 --- /dev/null +++ b/assets/js/list.js @@ -0,0 +1,11 @@ +function clickSearchResult(resId) { + var xhr = new XMLHttpRequest(); + xhr.onreadystatechange = function() { + if (xhr.readyState == XMLHttpRequest.DONE) { + alert(xhr.status + ": " + xhr.response); + } + } + xhr.open('POST', window.location, true); + xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); + xhr.send('id=' + resId); +} \ No newline at end of file diff --git a/assets/js/search.js b/assets/js/search.js index 8dc95cb..edd181e 100644 --- a/assets/js/search.js +++ b/assets/js/search.js @@ -27,4 +27,8 @@ function doSearch() { xhr.open('GET', '/search/gril_instant/' + value, true); xhr.send(null); strokeTimeout = null; +} + +function clickSearchResult(resId) { + } \ No newline at end of file diff --git a/modules/lists/lists.go b/modules/lists/lists.go index 4c4288f..2b1ced3 100644 --- a/modules/lists/lists.go +++ b/modules/lists/lists.go @@ -10,8 +10,10 @@ import ( "fmt" "github.com/julienschmidt/httprouter" "github.com/lib/pq" + "io/ioutil" "log" "net/http" + "net/url" "strconv" ) @@ -58,6 +60,7 @@ func (m *Module) Init(g *grilist.Grilist) { } m.grils = grilsModule m.g.Router.GET("/list/:id", m.viewList) + m.g.Router.POST("/list/:id", m.addGrilToList) } func (m *Module) getListGrils(list *List) error { @@ -232,7 +235,47 @@ func (m *Module) viewList(w http.ResponseWriter, r *http.Request, p httprouter.P m.g.Renderer.RenderPage("list", w, data) } +func (m *Module) addGrilToList(w http.ResponseWriter, r *http.Request, p httprouter.Params) { + slistID := p.ByName("id") + + listID, err := strconv.Atoi(slistID) + if err != nil { + log.Println("invalid list id") + return + } + + values, err := readBody(r) + if err != nil { + log.Println("invalid POST data") + return + } + + grilID, err := strconv.Atoi(values.Get("id")) + if err != nil { + log.Println("invalid gril id") + return + } + + log.Println("implement: add gril", grilID, "to list", listID) + http.Error(w, "not implemented", 500) +} + // New erstellt eine neue Instanz des Modules func New() *Module { return &Module{} } + +func readBody(r *http.Request) (url.Values, error) { + defer r.Body.Close() + data, err := ioutil.ReadAll(r.Body) + if err != nil { + return nil, err + } + + values, err := url.ParseQuery(string(data)) + if err != nil { + return nil, err + } + + return values, nil +} diff --git a/views/instant_search_results.html b/views/instant_search_results.html index 9c5a476..0472879 100644 --- a/views/instant_search_results.html +++ b/views/instant_search_results.html @@ -1,6 +1,6 @@ {{ define "instant_search_results" }} {{ range .results }} -
  • +
  • {{ .Name }}
  • diff --git a/views/list.html b/views/list.html index 7963004..daa56cd 100644 --- a/views/list.html +++ b/views/list.html @@ -9,6 +9,7 @@ + -- cgit v0.10.1