FEATURE: automatically close a poll on a given date and time

This commit is contained in:
Régis Hanol
2018-05-03 02:12:19 +02:00
parent de6dd2dc02
commit ba14c80b9c
15 changed files with 204 additions and 217 deletions

View File

@@ -22,6 +22,13 @@ function initializePolls(api) {
}
});
let _glued = [];
let _interval = null;
function rerender() {
_glued.forEach(g => g.queueRerender());
}
api.modifyClass('model:post', {
_polls: null,
pollsObject: null,
@@ -41,12 +48,12 @@ function initializePolls(api) {
}
});
this.set("pollsObject", this._polls);
_glued.forEach(g => g.queueRerender());
rerender();
}
}
});
const _glued = [];
function attachPolls($elem, helper) {
const $polls = $('.poll', $elem);
if (!$polls.length) { return; }
@@ -60,6 +67,8 @@ function initializePolls(api) {
const polls = post.get("pollsObject");
if (!polls) { return; }
_interval = _interval || setInterval(rerender, 30000);
$polls.each((idx, pollElem) => {
const $poll = $(pollElem);
const pollName = $poll.data("poll-name");
@@ -81,7 +90,13 @@ function initializePolls(api) {
}
function cleanUpPolls() {
if (_interval) {
clearInterval(_interval);
_interval = null;
}
_glued.forEach(g => g.cleanUp());
_glued = [];
}
api.includePostAttributes("polls", "polls_votes");