mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE: automatically close a poll on a given date and time
This commit is contained in:
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user