Last active
August 23, 2016 05:32
-
-
Save elarif/2eac0321b6c720b0bcb639444d6a7fad to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<dom-module id="creer-tache"> | |
<template> | |
<paper-input label="Titre" name="title" value="{{title}}"></paper-input> | |
<paper-input label="Description" name="description" value="{{description}}"></paper-input> | |
<paper-button raised on-click="create">Valider</paper-button> | |
<iron-ajax | |
id="ajax" | |
url="{{url}}" | |
handle-as="json" | |
body='{"title":"{{title}}", "description": "{{description}}"}' | |
method="POST" | |
last-response="{{response}}" | |
on-response="handleResponse" | |
debounce-duration="300"></iron-ajax> | |
</template> | |
<script> | |
Polymer({ | |
is: 'creer-tache', | |
create: function(e){ | |
this.$.ajax.generateRequest() | |
}, | |
handleResponse: function(event, detail) { | |
console.log(event.type+"::"+detail.response.Title); | |
var todo = detail.response; | |
console.log(todo.Title+"::"+todo.Description); | |
}, | |
properties: { | |
title: { | |
value: 'toto' | |
}, | |
description: { | |
value: 'tata' | |
}, | |
url:{ | |
value:'http://localhost:8089/create' | |
} | |
} | |
}); | |
</script> | |
</dom-module> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<title>Ajout de tâche</title> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<link rel="manifest" href="/manifest.json"> | |
<script src="/bower_components/webcomponentsjs/webcomponents-lite.js"></script> | |
<link rel="import" href="../../bower_components/polymer/polymer.html"> | |
<link rel="import" href="../../bower_components/iron-ajax/iron-ajax.html"> | |
<link rel="import" href="../../bower_components/paper-input/paper-input.html"> | |
<link rel="import" href="../../bower_components/paper-button/paper-button.html"> | |
<link rel="import" href="/src/creer-tache.html" media="screen" title="no title" charset="utf-8"> | |
</head> | |
<body> | |
<creer-tache url="http://192.168.1.53:8089/create"></creer-tache> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"encoding/json" | |
"log" | |
"net/http" | |
"io" | |
) | |
type Task struct { | |
Title, Description string | |
} | |
func create(w http.ResponseWriter, r *http.Request) { | |
dec := json.NewDecoder(r.Body) | |
var t Task | |
if err := dec.Decode(&t); err != io.EOF && err != nil { | |
log.Fatal(err) | |
} | |
log.Print(t) | |
w.Header().Set("Access-Control-Allow-Origin", "*") | |
json.NewEncoder(w).Encode(t) | |
} | |
func main() { | |
http.HandleFunc("/create", create) | |
log.Fatal(http.ListenAndServe(":8089", nil)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment