diff options
author | ngharo <nick@ngha.ro> | 2017-12-29 00:02:05 -0600 |
---|---|---|
committer | ngharo <nick@ngha.ro> | 2017-12-29 00:02:05 -0600 |
commit | 75d05326d067857d22474cc91d069003d7b64b17 (patch) | |
tree | 150958928ea0d3f129b55d3694227b3344adf978 /www/imok.js | |
parent | 67c7dbdd19afcc17816e43ff66873e76101704a5 (diff) | |
download | imOk-www-75d05326d067857d22474cc91d069003d7b64b17.tar.xz imOk-www-75d05326d067857d22474cc91d069003d7b64b17.zip |
VueJS front-end work in progress
Diffstat (limited to 'www/imok.js')
-rw-r--r-- | www/imok.js | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/www/imok.js b/www/imok.js new file mode 100644 index 0000000..d985798 --- /dev/null +++ b/www/imok.js @@ -0,0 +1,64 @@ +function create() { + this.ready = false; + fetch('/v1/button', {method: 'PUT'}).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: 'POST', + 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; + }) + } +}); |