aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjan <jan@ruken.pw>2015-12-30 15:49:59 (UTC)
committerjan <jan@ruken.pw>2015-12-30 15:49:59 (UTC)
commitee37b31502bc46527a5db51f73459f5f7946e1b2 (patch)
treee34ae3c9357ed536e1ab589483e999f8bf9d1df2
parentb203f34144896436db3925c63b3c91bda59f7e77 (diff)
hover für search-results. beim klicken auf ein gril wird ein request gestartet, fehlt nur noch die implementation, um ein gril zu einer liste hinzuzufügen.
-rw-r--r--assets/css/search.css8
-rw-r--r--assets/js/list.js11
-rw-r--r--assets/js/search.js4
-rw-r--r--modules/lists/lists.go43
-rw-r--r--views/instant_search_results.html2
-rw-r--r--views/list.html1
6 files changed, 68 insertions, 1 deletions
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 @@
5.search-results { 5.search-results {
6 top: -50px; 6 top: -50px;
7 z-index: 2; 7 z-index: 2;
8}
9
10.collection > .collection-item {
11 transition: background-color .35s;
12}
13
14.collection > .collection-item:hover {
15 background-color: #e1bee7;
8} \ No newline at end of file 16} \ 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 @@
1function clickSearchResult(resId) {
2 var xhr = new XMLHttpRequest();
3 xhr.onreadystatechange = function() {
4 if (xhr.readyState == XMLHttpRequest.DONE) {
5 alert(xhr.status + ": " + xhr.response);
6 }
7 }
8 xhr.open('POST', window.location, true);
9 xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
10 xhr.send('id=' + resId);
11} \ 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() {
27 xhr.open('GET', '/search/gril_instant/' + value, true); 27 xhr.open('GET', '/search/gril_instant/' + value, true);
28 xhr.send(null); 28 xhr.send(null);
29 strokeTimeout = null; 29 strokeTimeout = null;
30}
31
32function clickSearchResult(resId) {
33
30} \ No newline at end of file 34} \ 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 (
10 "fmt" 10 "fmt"
11 "github.com/julienschmidt/httprouter" 11 "github.com/julienschmidt/httprouter"
12 "github.com/lib/pq" 12 "github.com/lib/pq"
13 "io/ioutil"
13 "log" 14 "log"
14 "net/http" 15 "net/http"
16 "net/url"
15 "strconv" 17 "strconv"
16) 18)
17 19
@@ -58,6 +60,7 @@ func (m *Module) Init(g *grilist.Grilist) {
58 } 60 }
59 m.grils = grilsModule 61 m.grils = grilsModule
60 m.g.Router.GET("/list/:id", m.viewList) 62 m.g.Router.GET("/list/:id", m.viewList)
63 m.g.Router.POST("/list/:id", m.addGrilToList)
61} 64}
62 65
63func (m *Module) getListGrils(list *List) error { 66func (m *Module) getListGrils(list *List) error {
@@ -232,7 +235,47 @@ func (m *Module) viewList(w http.ResponseWriter, r *http.Request, p httprouter.P
232 m.g.Renderer.RenderPage("list", w, data) 235 m.g.Renderer.RenderPage("list", w, data)
233} 236}
234 237
238func (m *Module) addGrilToList(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
239 slistID := p.ByName("id")
240
241 listID, err := strconv.Atoi(slistID)
242 if err != nil {
243 log.Println("invalid list id")
244 return
245 }
246
247 values, err := readBody(r)
248 if err != nil {
249 log.Println("invalid POST data")
250 return
251 }
252
253 grilID, err := strconv.Atoi(values.Get("id"))
254 if err != nil {
255 log.Println("invalid gril id")
256 return
257 }
258
259 log.Println("implement: add gril", grilID, "to list", listID)
260 http.Error(w, "not implemented", 500)
261}
262
235// New erstellt eine neue Instanz des Modules 263// New erstellt eine neue Instanz des Modules
236func New() *Module { 264func New() *Module {
237 return &Module{} 265 return &Module{}
238} 266}
267
268func readBody(r *http.Request) (url.Values, error) {
269 defer r.Body.Close()
270 data, err := ioutil.ReadAll(r.Body)
271 if err != nil {
272 return nil, err
273 }
274
275 values, err := url.ParseQuery(string(data))
276 if err != nil {
277 return nil, err
278 }
279
280 return values, nil
281}
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 @@
1{{ define "instant_search_results" }} 1{{ define "instant_search_results" }}
2{{ range .results }} 2{{ range .results }}
3<li class="collection-item avatar hoverable valign-wrapper"> 3<li class="collection-item search-result avatar hoverable valign-wrapper" onClick="clickSearchResult({{ .ID }})" >
4 <img src="/{{ .ImagePath }}" alt="" class="circle"> 4 <img src="/{{ .ImagePath }}" alt="" class="circle">
5 <span class="title">{{ .Name }}</span> 5 <span class="title">{{ .Name }}</span>
6</li> 6</li>
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 @@
9 <link rel="stylesheet" href="/assets/css/search.css" /> 9 <link rel="stylesheet" href="/assets/css/search.css" />
10 <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"> 10 <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
11 <script src="/assets/js/search.js"></script> 11 <script src="/assets/js/search.js"></script>
12 <script src="/assets/js/list.js"></script>
12 <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"> 13 <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
13 </head> 14 </head>
14 <body> 15 <body>