From c6b867f93fd958d21b8107e7f0e276abd8111b9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Benqu=C3=A9?= Date: Wed, 9 Jun 2021 14:58:52 +0100 Subject: [PATCH] Change order of question types --- www/form/inner.js | 188 +++++++++++++++++++++++----------------------- 1 file changed, 94 insertions(+), 94 deletions(-) diff --git a/www/form/inner.js b/www/form/inner.js index cb7f5de3e..5d1ee5763 100644 --- a/www/form/inner.js +++ b/www/form/inner.js @@ -1465,100 +1465,6 @@ define([ }, icon: h('i.cptools.cptools-form-grid-check') }, - poll: { - defaultOpts: { - type: 'text', // Text or Days or Time - values: [1, 2, 3].map(function (i) { - return Messages._getKey('form_defaultOption', [i]); - }) - }, - get: function (opts, answers, username, evOnChange) { - if (!opts) { opts = TYPES.poll.defaultOpts; } - if (!Array.isArray(opts.values)) { return; } - - var lines = makePollTable(answers, opts); - - // Add form - var addLine = opts.values.map(function (data) { - var cell = h('div.cp-poll-cell.cp-form-poll-choice', [ - h('i.fa.fa-times.cp-no'), - h('i.fa.fa-check.cp-yes'), - h('i.fa.fa-question.cp-maybe'), - ]); - var $c = $(cell); - $c.data('option', data); - var val = 0; - $c.attr('data-value', val); - $c.click(function () { - val = (val+1)%3; - $c.attr('data-value', val); - evOnChange.fire(); - }); - cell._setValue = function (v) { - val = v; - $c.attr('data-value', val); - }; - return cell; - }); - // Name input - //var nameInput = h('input', { value: username || Messages.anonymous }); - var nameInput = h('span.cp-poll-your-answers', Messages.form_pollYourAnswers) - addLine.unshift(h('div.cp-poll-cell', nameInput)); - lines.push(h('div', addLine)); - - var total = makePollTotal(answers, opts); - if (total) { lines.push(h('div', total)); } - - var tag = h('div.cp-form-type-poll-container', h('div.cp-form-type-poll', lines)); - var $tag = $(tag); - - var cursorGetter; - var setCursorGetter = function (f) { cursorGetter = f; }; - return { - tag: tag, - getValue: function () { - var res = {}; - $tag.find('.cp-form-poll-choice').each(function (i, el) { - var $el = $(el); - res[$el.data('option')] = $el.attr('data-value'); - }); - return { - values: res - }; - }, - reset: function () { - $tag.find('.cp-form-poll-choice').attr('data-value', 0); - }, - edit: function (cb, tmp) { - var v = Util.clone(opts); - return editOptions(v, setCursorGetter, cb, tmp); - }, - getCursor: function () { return cursorGetter(); }, - setValue: function (res) { - this.reset(); - if (!res || !res.values) { return; } - var val = res.values; - $tag.find('.cp-form-poll-choice').each(function (i, el) { - if (!el._setValue) { return; } - var $el = $(el); - el._setValue(val[$el.data('option')] || 0); - }); - } - }; - - }, - printResults: function (answers, uid, form) { - var opts = form[uid].opts || TYPES.poll.defaultOpts; - var _answers = getBlockAnswers(answers, uid); - var lines = makePollTable(_answers, opts); - - var total = makePollTotal(_answers, opts); - if (total) { lines.push(h('div', total)); } - - return h('div.cp-form-type-poll', lines); - }, - icon: h('i.cptools.cptools-form-poll') - }, sort: { defaultOpts: { values: [1,2].map(function (i) { @@ -1669,6 +1575,100 @@ define([ }, icon: h('i.cptools.cptools-form-list-ordered') }, + poll: { + defaultOpts: { + type: 'text', // Text or Days or Time + values: [1, 2, 3].map(function (i) { + return Messages._getKey('form_defaultOption', [i]); + }) + }, + get: function (opts, answers, username, evOnChange) { + if (!opts) { opts = TYPES.poll.defaultOpts; } + if (!Array.isArray(opts.values)) { return; } + + var lines = makePollTable(answers, opts); + + // Add form + var addLine = opts.values.map(function (data) { + var cell = h('div.cp-poll-cell.cp-form-poll-choice', [ + h('i.fa.fa-times.cp-no'), + h('i.fa.fa-check.cp-yes'), + h('i.fa.fa-question.cp-maybe'), + ]); + var $c = $(cell); + $c.data('option', data); + var val = 0; + $c.attr('data-value', val); + $c.click(function () { + val = (val+1)%3; + $c.attr('data-value', val); + evOnChange.fire(); + }); + cell._setValue = function (v) { + val = v; + $c.attr('data-value', val); + }; + return cell; + }); + // Name input + //var nameInput = h('input', { value: username || Messages.anonymous }); + var nameInput = h('span.cp-poll-your-answers', Messages.form_pollYourAnswers) + addLine.unshift(h('div.cp-poll-cell', nameInput)); + lines.push(h('div', addLine)); + + var total = makePollTotal(answers, opts); + if (total) { lines.push(h('div', total)); } + + var tag = h('div.cp-form-type-poll-container', h('div.cp-form-type-poll', lines)); + var $tag = $(tag); + + var cursorGetter; + var setCursorGetter = function (f) { cursorGetter = f; }; + return { + tag: tag, + getValue: function () { + var res = {}; + $tag.find('.cp-form-poll-choice').each(function (i, el) { + var $el = $(el); + res[$el.data('option')] = $el.attr('data-value'); + }); + return { + values: res + }; + }, + reset: function () { + $tag.find('.cp-form-poll-choice').attr('data-value', 0); + }, + edit: function (cb, tmp) { + var v = Util.clone(opts); + return editOptions(v, setCursorGetter, cb, tmp); + }, + getCursor: function () { return cursorGetter(); }, + setValue: function (res) { + this.reset(); + if (!res || !res.values) { return; } + var val = res.values; + $tag.find('.cp-form-poll-choice').each(function (i, el) { + if (!el._setValue) { return; } + var $el = $(el); + el._setValue(val[$el.data('option')] || 0); + }); + } + }; + + }, + printResults: function (answers, uid, form) { + var opts = form[uid].opts || TYPES.poll.defaultOpts; + var _answers = getBlockAnswers(answers, uid); + var lines = makePollTable(_answers, opts); + + var total = makePollTotal(_answers, opts); + if (total) { lines.push(h('div', total)); } + + return h('div.cp-form-type-poll', lines); + }, + icon: h('i.cptools.cptools-form-poll') + }, }; var renderResults = function (content, answers) {