From 71dbf8712d7f8a181c6f724cbb9ea002a280edb1 Mon Sep 17 00:00:00 2001 From: cel Date: Thu, 14 Jun 2018 22:58:09 -0400 Subject: Fix polls --- lib/render-msg.js | 26 ++++++++++++++++---------- lib/serve.js | 1 + 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/lib/render-msg.js b/lib/render-msg.js index 91e7386..cda8eab 100644 --- a/lib/render-msg.js +++ b/lib/render-msg.js @@ -1747,23 +1747,29 @@ RenderMsg.prototype.poll = function (cb) { return self.wrap(h('div', h('h3', {innerHTML: unwrapP(self.render.markdown(self.c.title))}), h('div', {innerHTML: unwrapP(self.render.markdown(self.c.body, self.c.mentions))}), + h('p', 'closes at: ', h('span', { + title: closeDate.toLocaleString() + }, closeDate.toString())), details.type === 'chooseOne' ? h('form', {method: 'post', action: ''}, + h('p', 'Choose one'), h('input', {type: 'hidden', name: 'action', value: 'poll-position'}), h('input', {type: 'hidden', name: 'poll_root', value: self.msg.key}), h('input', {type: 'hidden', name: 'poll_type', value: 'chooseOne'}), - choices.map(function (choice) { - return [h('input', {type: 'submit', name: 'poll_choice', value: choice}), ' '] - }) - ) : h('div', 'unknown poll type'), - h('p', 'closes at: ', h('span', { - title: closeDate.toLocaleString() - }, closeDate.toString())) + choices.map(function (choice, i) { + return h('div', + h('input', {type: 'radio', name: 'poll_choice', value: i}), ' ', String(choice)) + }), + h('p', 'reason: ', + h('div', h('textarea', {name: 'poll_reason'})) + ), + h('p', h('input', {type: 'submit', value: 'preview publish position'})) + ) : h('div', 'unknown poll type') ), cb) } RenderMsg.prototype.pollPosition = function (cb) { var self = this - var details = self.c.pollDetails || self.c.details || {} + var details = self.c.pollDetails || self.c.details || self.c var reason = self.c.reason || '' var done = multicb({pluck: 1, spread: true}) self.link(self.c.root, done()) @@ -1776,9 +1782,9 @@ RenderMsg.prototype.pollPosition = function (cb) { done(function (err, rootLink, branchLinks, rootMsg) { if (err) return cb(err) var rootContent = rootMsg && rootMsg.value.content || {} - var rootDetails = rootContent.pollDetails || rootContent.details || {} + var rootDetails = rootContent.pollDetails || rootContent.details || rootContent var choices = u.toArray(rootDetails.choices) - var choice = details.choice && choices && choices[details.choice] + var choice = details.choice != null && choices && choices[details.choice] return self.wrap(h('div', rootLink ? h('div', h('small', h('span.symbol', '→'), ' ', rootLink)) : '', branchLinks.map(function (a, i) { diff --git a/lib/serve.js b/lib/serve.js index a05739a..448b18b 100644 --- a/lib/serve.js +++ b/lib/serve.js @@ -232,6 +232,7 @@ Serve.prototype.publishPollPosition = function (cb) { version: 'v1', channel: this.data.channel || undefined, root: this.data.poll_root, + reason: this.data.poll_reason, details: { type: this.data.poll_type, choice: this.data.poll_choice -- cgit v1.2.3