Improve forms CSV export with polls

pull/1/head
yflory 3 years ago
parent a93a9f14d3
commit f5fc4f28bf

@ -1724,15 +1724,31 @@ define([
return h('div.cp-form-type-poll', lines); return h('div.cp-form-type-poll', lines);
}, },
exportCSV: function (answer) { exportCSV: function (answer, form) {
if (answer === false) { return; } var opts = form.opts || TYPES.poll.defaultOpts;
if (!answer || !answer.values) { return ['']; } var q = form.q || Messages.form_default;
if (answer === false) {
var cols = opts.values.map(function (key) {
return q + ' | ' + key;
});
cols.unshift(q);
return cols;
}
if (!answer || !answer.values) {
var empty = opts.values.map(function () { return ''; });
empty.unshift('');
return empty;
}
var str = ''; var str = '';
Object.keys(answer.values).sort().forEach(function (k, i) { Object.keys(answer.values).sort().forEach(function (k, i) {
if (i !== 0) { str += ';'; } if (i !== 0) { str += ';'; }
str += k.replace(';', '').replace(':', '') + ':' + answer.values[k]; str += k.replace(';', '').replace(':', '') + ':' + answer.values[k];
}); });
return [str]; var res = opts.values.map(function (key) {
return answer.values[key] || '';
});
res.unshift(str);
return res;
}, },
icon: h('i.cptools.cptools-form-poll') icon: h('i.cptools.cptools-form-poll')
}, },

Loading…
Cancel
Save