summaryrefslogtreecommitdiff
path: root/www/src/app.js
diff options
context:
space:
mode:
Diffstat (limited to 'www/src/app.js')
-rw-r--r--www/src/app.js68
1 files changed, 68 insertions, 0 deletions
diff --git a/www/src/app.js b/www/src/app.js
new file mode 100644
index 0000000..214572c
--- /dev/null
+++ b/www/src/app.js
@@ -0,0 +1,68 @@
+//const Vue = require('vue');
+//const buttonList = require('./buttonList.vue');
+const r = require('./request.js')('/v1');
+
+function create() {
+ this.ready = false;
+ r.post('/button').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;
+ r.put('/button', button).then(() => {
+ this.ready = true;
+ });
+}
+
+function remove(index) {
+ var button = this.buttons[index];
+
+ this.ready = false;
+ r.delete('/button', button).then(response => {
+ if (response.ok) {
+ response.json().then(() => {
+ this.buttons.splice(index, 1);
+ this.ready = true;
+ });
+ }
+ });
+}
+
+const $app = new Vue({
+ el: '#container',
+ data: {
+ ready: false,
+ buttons: []
+ },
+ methods: {
+ create,
+ remove,
+ update
+ }
+});
+
+// GET /button
+r.get('/button').then(response => {
+ if (response.ok) {
+ return response.json();
+ }
+
+ throw new Error(response.status);
+
+}).then(data => {
+ $app.buttons = data;
+ $app.ready = true;
+
+}).catch(err => {
+ console.log('Request failed with error:', err.message);
+});
+