diff options
-rw-r--r-- | lib/render-msg.js | 85 | ||||
-rw-r--r-- | lib/serve.js | 8 |
2 files changed, 77 insertions, 16 deletions
diff --git a/lib/render-msg.js b/lib/render-msg.js index aee5e4d..d02497e 100644 --- a/lib/render-msg.js +++ b/lib/render-msg.js @@ -307,6 +307,7 @@ RenderMsg.prototype.message = function (cb) { case 'web-init': return this.webInit(cb) case 'web-root': return this.webRoot(cb) case 'poll': return this.poll(cb) + case 'poll-resolution': return this.pollResolution(cb) case 'position': return this.position(cb) case 'scat_message': return this.scat(cb) case 'share': return this.share(cb) @@ -1801,27 +1802,46 @@ RenderMsg.prototype.webRoot = function (cb) { ), cb) } +function dateSpan(date) { + return h('span', { + title: date.toLocaleString() + }, date.toString()) +} + RenderMsg.prototype.poll = function (cb) { var self = this var closeDate = new Date(self.c.closesAt) var details = self.c.pollDetails || self.c.details || {} var choices = u.toArray(details.choices) + var pollType = details.type + var max = Number(details.maxChoiceScore) || 2 + var numDots = Number(details.numDots) || 1 return self.wrap(h('div', h('h3', {innerHTML: u.unwrapP(self.render.markdown(self.c.title))}), h('div', {innerHTML: u.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('p', 'Closes at ', dateSpan(closeDate)), + pollType === 'chooseOne' || pollType === 'meetingTime' /*|| pollType === 'dot' || pollType === 'range'*/ ? + h('form', {method: 'post', action: ''}, 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'}), + h('input', {type: 'hidden', name: 'poll_type', value: pollType}), choices.map(function (choice, i) { return h('div', - h('input', {type: 'radio', name: 'poll_choice', value: i}), ' ', String(choice)) + pollType === 'chooseOne' ? [ + h('input', {type: 'radio', name: 'poll_choice', value: i}), ' ', + String(choice) + ] : pollType === 'meetingTime' /*|| pollType === 'dot'*/ ? [ + h('input', {type: 'checkbox', name: 'poll_choices', value: i}), ' ', + dateSpan(new Date(choice)) + /* + ] : pollType === 'range' ? [ + h('input', {type: 'number', name: 'poll_choice_' + i, min: 0, max: max}), ' ', + String(choice) + */ + ] : String(choice) + ) }), - h('p', 'reason: ', + pollType === 'meetingTime' ? '' : h('p', 'reason: ', h('div', h('textarea', {name: 'poll_reason'})) ), u.toArray(this.opts.branches).filter(function (branch) { @@ -1829,7 +1849,7 @@ RenderMsg.prototype.poll = function (cb) { }).map(function (branch) { return h('input', {type: 'hidden', name: 'branches', value: branch}) }), - h('p', h('input', {type: 'submit', value: 'preview publish position'})) + h('p.msg-right', h('input', {type: 'submit', value: 'preview'})) ) : h('div', 'unknown poll type') ), cb) } @@ -1856,21 +1876,58 @@ RenderMsg.prototype.pollPosition = function (cb) { var rootContent = rootMsg && rootMsg.value.content || {} var rootDetails = rootContent.pollDetails || rootContent.details || rootContent var choices = u.toArray(rootDetails.choices) - var choice = details.choice != null && choices && choices[details.choice] + var pickedChoices = u.toArray(details.choices || details.choice) + .map(function (i) { return choices[i] != null ? choices[i] : i }) + var positionType = details.type return self.wrap(h('div', rootLink ? h('div', h('small', h('span.symbol', '→'), ' ', rootLink)) : '', branchLinks.map(function (a, i) { return h('div', h('small', h('span.symbol', ' ↳'), ' ', a)) }), - h('p', - 'picked ', - choice ? h('q', choice) : ['choice ', String(details.choice || '?')] - ), + h('ul', pickedChoices.map(function (choice) { + return h('li', + positionType === 'meetingTime' ? dateSpan(new Date(choice)) + : String(choice) + ) + })), reason ? h('div', {innerHTML: self.render.markdown(reason, self.c.mentions)}) : '' ), cb) }) } +RenderMsg.prototype.pollResolution = function (cb) { + var self = this + var done = multicb({pluck: 1, spread: true}) + self.link(self.c.root, done()) + self.links(self.c.branch, done()) + var msgCb = done() + self.app.getMsg(self.c.root, function (err, msg) { + msgCb(null, msg) + }) + done(function (err, rootLink, branchLinks, rootMsg) { + if (err) return cb(err) + var rootContent = rootMsg && rootMsg.value.content || {} + var rootDetails = rootContent.pollDetails || rootContent.details || rootContent + var choices = u.toArray(rootDetails.choices) + var pickedChoices = u.toArray(self.c.choices || self.c.choice) + .map(function (i) { return choices[i] != null ? choices[i] : i }) + var pollType = rootDetails.type + return self.wrap(h('div', + rootLink ? h('div', h('small', h('span.symbol', '→'), ' ', rootLink)) : '', + branchLinks.map(function (a, i) { + return h('div', h('small', h('span.symbol', ' ↳'), ' ', a)) + }), + h('div', 'Resolved:'), + h('ul', pickedChoices.map(function (choice) { + return h('li', + pollType === 'meetingTime' ? dateSpan(new Date(choice)) + : String(choice) + ) + })) + ), cb) + }) +} + RenderMsg.prototype.scat = function (cb) { this.wrapMini([ this.c.action ? '' : 'chats ', diff --git a/lib/serve.js b/lib/serve.js index 424e9f3..e9c719a 100644 --- a/lib/serve.js +++ b/lib/serve.js @@ -235,10 +235,14 @@ Serve.prototype.publishPollPosition = function (cb) { branch: this.data.branches || [], reason: this.data.poll_reason || undefined, details: { - type: this.data.poll_type, - choice: Number(this.data.poll_choice) + type: this.data.poll_type } } + if (this.data.poll_choice != null) { + content.details.choice = Number(this.data.poll_choice) + } else { + content.details.choices = u.toArray(this.data.poll_choices).map(Number) + } if (this.data.recps) content.recps = this.data.recps.split(',') var json = JSON.stringify(content, 0, 2) var q = qs.stringify({text: json, action: 'preview'}) |