diff options
author | ngharo <nick@ngha.ro> | 2017-12-31 22:16:32 -0600 |
---|---|---|
committer | ngharo <nick@ngha.ro> | 2017-12-31 22:16:32 -0600 |
commit | f920c7da0618fd9f4181c2c78ef054e324185355 (patch) | |
tree | eba4a9f21fb8fd47e8a53f01e8a4dfae25a333e2 /www/lib | |
parent | 75d05326d067857d22474cc91d069003d7b64b17 (diff) | |
download | imOk-www-f920c7da0618fd9f4181c2c78ef054e324185355.tar.xz imOk-www-f920c7da0618fd9f4181c2c78ef054e324185355.zip |
Makefile: compile Babel and Sass source files to index.*
Diffstat (limited to 'www/lib')
-rw-r--r-- | www/lib/app.js | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/www/lib/app.js b/www/lib/app.js new file mode 100644 index 0000000..2ec1af2 --- /dev/null +++ b/www/lib/app.js @@ -0,0 +1,64 @@ +function create() { + this.ready = false; + fetch('/v1/button', {method: 'POST'}).then(response => { + if (response.ok) { + response.json().then(button => { + this.buttons.push(button); + this.ready = true; + }); + } + }); +} + +function update(index) { + var button = this.buttons[index]; + + this.ready = false; + var payload = new FormData(); + payload.append('id', button.id); + payload.append('status', button.status); + + fetch('/v1/button/', { + method: 'PUT', + body: payload + }).then(response => { + this.ready = true; + }) +}; + +function remove(index) { + var button = this.buttons[index]; + + this.ready = false; + fetch('/v1/button/' + button.id, {method: 'DELETE'}).then(response => { + if (response.ok) { + response.json().then(ok => { + this.buttons.splice(index, 1); + this.ready = true; + }); + } + }); +} + +const $app = new Vue({ + el: '#container', + data: { + ready: false, + buttons: [] + }, + methods: { + create, + remove, + update + } +}); + +// GET /button +fetch('/v1/button').then(response => { + if (response.ok) { + response.json().then(buttons => { + $app.buttons = buttons; + $app.ready = true; + }) + } +}); |