This commit is contained in:
syuilo
2017-03-11 18:47:21 +09:00
parent ae53687b01
commit ff29e7bb14
4 changed files with 49 additions and 28 deletions

View File

@@ -90,27 +90,32 @@
this.oninput = (i, e) => {
this.choices[i] = e.target.value;
}
};
this.add = () => {
this.choices.push('');
this.update();
this.refs.choices.childNodes[this.choices.length - 1].childNodes[0].focus();
}
};
this.remove = (i) => {
this.choices = this.choices.filter((_, _i) => _i != i);
this.update();
}
};
this.destroy = () => {
this.opts.ondestroy();
}
};
this.get = () => {
return {
choices: this.choices.filter(choice => choice != '')
}
}
};
this.set = data => {
if (data.choices.length == 0) return;
this.choices = data.choices;
};
</script>
</mk-poll-editor>

View File

@@ -78,9 +78,9 @@
this.toggleResult = () => {
this.result = !this.result;
}
};
this.vote = (id) => {
this.vote = id => {
if (this.poll.choices.some(c => c.is_voted)) return;
this.api('posts/polls/vote', {
post_id: this.post.id,
@@ -99,6 +99,6 @@
total: this.total + 1
});
});
}
};
</script>
</mk-poll>