|
|
@ -82,6 +82,14 @@ define([
|
|
|
|
var MAX_OPTIONS = 15;
|
|
|
|
var MAX_OPTIONS = 15;
|
|
|
|
var MAX_ITEMS = 10;
|
|
|
|
var MAX_ITEMS = 10;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var extractValues = function (values) {
|
|
|
|
|
|
|
|
if (!Array.isArray(values)) { return []; }
|
|
|
|
|
|
|
|
return values.map(function (obj) {
|
|
|
|
|
|
|
|
if (typeof(obj) === "string") { return obj; }
|
|
|
|
|
|
|
|
return obj.v;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var saveAndCancelOptions = function (getRes, cb) {
|
|
|
|
var saveAndCancelOptions = function (getRes, cb) {
|
|
|
|
// Cancel changes
|
|
|
|
// Cancel changes
|
|
|
|
var cancelBlock = h('button.btn.btn-secondary', Messages.cancel);
|
|
|
|
var cancelBlock = h('button.btn.btn-secondary', Messages.cancel);
|
|
|
@ -313,7 +321,8 @@ define([
|
|
|
|
});
|
|
|
|
});
|
|
|
|
return el;
|
|
|
|
return el;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
var inputs = v.values.map(function (val) { return getOption(val, false); });
|
|
|
|
// TODO uid
|
|
|
|
|
|
|
|
var inputs = extractValues(v.values).map(function (val) { return getOption(val, false); });
|
|
|
|
inputs.push(add);
|
|
|
|
inputs.push(add);
|
|
|
|
|
|
|
|
|
|
|
|
var container = h('div.cp-form-edit-block', inputs);
|
|
|
|
var container = h('div.cp-form-edit-block', inputs);
|
|
|
@ -346,7 +355,7 @@ define([
|
|
|
|
if (v.type) {
|
|
|
|
if (v.type) {
|
|
|
|
var calendarInput = h('input');
|
|
|
|
var calendarInput = h('input');
|
|
|
|
calendarView = h('div', calendarInput);
|
|
|
|
calendarView = h('div', calendarInput);
|
|
|
|
var calendarDefault = v.type === "day" ? v.values.map(function (time) {
|
|
|
|
var calendarDefault = v.type === "day" ? extractValues(v.values).map(function (time) {
|
|
|
|
if (!time) { return; }
|
|
|
|
if (!time) { return; }
|
|
|
|
var d = new Date(time);
|
|
|
|
var d = new Date(time);
|
|
|
|
if (!isNaN(d)) { return d; }
|
|
|
|
if (!isNaN(d)) { return d; }
|
|
|
@ -597,13 +606,13 @@ define([
|
|
|
|
var makePollTable = function (answers, opts, resultsPageObj) {
|
|
|
|
var makePollTable = function (answers, opts, resultsPageObj) {
|
|
|
|
// Sort date values
|
|
|
|
// Sort date values
|
|
|
|
if (opts.type !== "text") {
|
|
|
|
if (opts.type !== "text") {
|
|
|
|
opts.values.sort(function (a, b) {
|
|
|
|
extractValues(opts.values).sort(function (a, b) { // TODO uid
|
|
|
|
return +new Date(a) - +new Date(b);
|
|
|
|
return +new Date(a) - +new Date(b);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Create first line with options
|
|
|
|
// Create first line with options
|
|
|
|
var allDays = getWeekDays(true);
|
|
|
|
var allDays = getWeekDays(true);
|
|
|
|
var els = opts.values.map(function (data) {
|
|
|
|
var els = extractValues(opts.values).map(function (data) { // TODO uid
|
|
|
|
var _date;
|
|
|
|
var _date;
|
|
|
|
if (opts.type === "day") {
|
|
|
|
if (opts.type === "day") {
|
|
|
|
_date = new Date(data);
|
|
|
|
_date = new Date(data);
|
|
|
@ -634,7 +643,7 @@ define([
|
|
|
|
if (opts.type === "time") {
|
|
|
|
if (opts.type === "time") {
|
|
|
|
var days = [h('div.cp-poll-cell')];
|
|
|
|
var days = [h('div.cp-poll-cell')];
|
|
|
|
var _days = {};
|
|
|
|
var _days = {};
|
|
|
|
opts.values.forEach(function (d) {
|
|
|
|
extractValues(opts.values).forEach(function (d) {
|
|
|
|
var date = new Date(d);
|
|
|
|
var date = new Date(d);
|
|
|
|
var day = date.toLocaleDateString();
|
|
|
|
var day = date.toLocaleDateString();
|
|
|
|
_days[day] = {
|
|
|
|
_days[day] = {
|
|
|
@ -665,7 +674,7 @@ define([
|
|
|
|
var avatar = h('span.cp-avatar');
|
|
|
|
var avatar = h('span.cp-avatar');
|
|
|
|
APP.common.displayAvatar($(avatar), Util.find(answerObj, ['user', 'avatar']), name);
|
|
|
|
APP.common.displayAvatar($(avatar), Util.find(answerObj, ['user', 'avatar']), name);
|
|
|
|
var values = answer.values || {};
|
|
|
|
var values = answer.values || {};
|
|
|
|
var els = opts.values.map(function (data) {
|
|
|
|
var els = extractValues(opts.values).map(function (data) {
|
|
|
|
var res = values[data] || 0;
|
|
|
|
var res = values[data] || 0;
|
|
|
|
var v = (Number(res) === 1) ? h('i.fa.fa-check.cp-yes') : undefined;
|
|
|
|
var v = (Number(res) === 1) ? h('i.fa.fa-check.cp-yes') : undefined;
|
|
|
|
var cell = h('div.cp-poll-cell.cp-form-poll-answer', {
|
|
|
|
var cell = h('div.cp-poll-cell.cp-form-poll-answer', {
|
|
|
@ -703,7 +712,7 @@ define([
|
|
|
|
var myTotals = {};
|
|
|
|
var myTotals = {};
|
|
|
|
var updateMyTotals = function () {
|
|
|
|
var updateMyTotals = function () {
|
|
|
|
if (!myLine) { return; }
|
|
|
|
if (!myLine) { return; }
|
|
|
|
opts.values.forEach(function (data) {
|
|
|
|
extractValues(opts.values).forEach(function (data) {
|
|
|
|
myLine.some(function (el) {
|
|
|
|
myLine.some(function (el) {
|
|
|
|
if ($(el).data('option') !== data) { return; }
|
|
|
|
if ($(el).data('option') !== data) { return; }
|
|
|
|
var res = Number($(el).attr('data-value')) || 0;
|
|
|
|
var res = Number($(el).attr('data-value')) || 0;
|
|
|
@ -726,7 +735,7 @@ define([
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
var totalEls = opts.values.map(function (data) {
|
|
|
|
var totalEls = extractValues(opts.values).map(function (data) {
|
|
|
|
var y = 0; // Yes
|
|
|
|
var y = 0; // Yes
|
|
|
|
var m = 0; // Maybe
|
|
|
|
var m = 0; // Maybe
|
|
|
|
answers.forEach(function (answerObj) {
|
|
|
|
answers.forEach(function (answerObj) {
|
|
|
@ -1122,7 +1131,7 @@ define([
|
|
|
|
if (!opts) { opts = TYPES.radio.defaultOpts; }
|
|
|
|
if (!opts) { opts = TYPES.radio.defaultOpts; }
|
|
|
|
if (!Array.isArray(opts.values)) { return; }
|
|
|
|
if (!Array.isArray(opts.values)) { return; }
|
|
|
|
var name = Util.uid();
|
|
|
|
var name = Util.uid();
|
|
|
|
var els = opts.values.map(function (data, i) {
|
|
|
|
var els = extractValues(opts.values).map(function (data, i) {
|
|
|
|
var radio = UI.createRadio(name, 'cp-form-'+name+'-'+i,
|
|
|
|
var radio = UI.createRadio(name, 'cp-form-'+name+'-'+i,
|
|
|
|
data, false, { mark: { tabindex:1 } });
|
|
|
|
data, false, { mark: { tabindex:1 } });
|
|
|
|
$(radio).find('input').data('val', data);
|
|
|
|
$(radio).find('input').data('val', data);
|
|
|
@ -1201,7 +1210,7 @@ define([
|
|
|
|
var lines = opts.items.map(function (itemData) {
|
|
|
|
var lines = opts.items.map(function (itemData) {
|
|
|
|
var name = itemData.uid;
|
|
|
|
var name = itemData.uid;
|
|
|
|
var item = itemData.v;
|
|
|
|
var item = itemData.v;
|
|
|
|
var els = opts.values.map(function (data, i) {
|
|
|
|
var els = extractValues(opts.values).map(function (data, i) {
|
|
|
|
var radio = UI.createRadio(name, 'cp-form-'+name+'-'+i,
|
|
|
|
var radio = UI.createRadio(name, 'cp-form-'+name+'-'+i,
|
|
|
|
'', false, { mark: { tabindex:1 } });
|
|
|
|
'', false, { mark: { tabindex:1 } });
|
|
|
|
$(radio).find('input').data('uid', name);
|
|
|
|
$(radio).find('input').data('uid', name);
|
|
|
@ -1211,7 +1220,7 @@ define([
|
|
|
|
els.unshift(h('div.cp-form-multiradio-item', item));
|
|
|
|
els.unshift(h('div.cp-form-multiradio-item', item));
|
|
|
|
return h('div.radio-group', {'data-uid':name}, els);
|
|
|
|
return h('div.radio-group', {'data-uid':name}, els);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
var header = opts.values.map(function (v) { return h('span', v); });
|
|
|
|
var header = extractValues(opts.values).map(function (v) { return h('span', v); });
|
|
|
|
header.unshift(h('span'));
|
|
|
|
header.unshift(h('span'));
|
|
|
|
lines.unshift(h('div.cp-form-multiradio-header', header));
|
|
|
|
lines.unshift(h('div.cp-form-multiradio-header', header));
|
|
|
|
|
|
|
|
|
|
|
@ -1353,7 +1362,7 @@ define([
|
|
|
|
if (!opts) { opts = TYPES.checkbox.defaultOpts; }
|
|
|
|
if (!opts) { opts = TYPES.checkbox.defaultOpts; }
|
|
|
|
if (!Array.isArray(opts.values)) { return; }
|
|
|
|
if (!Array.isArray(opts.values)) { return; }
|
|
|
|
var name = Util.uid();
|
|
|
|
var name = Util.uid();
|
|
|
|
var els = opts.values.map(function (data, i) {
|
|
|
|
var els = extractValues(opts.values).map(function (data, i) {
|
|
|
|
var cbox = UI.createCheckbox('cp-form-'+name+'-'+i,
|
|
|
|
var cbox = UI.createCheckbox('cp-form-'+name+'-'+i,
|
|
|
|
data, false, { mark: { tabindex:1 } });
|
|
|
|
data, false, { mark: { tabindex:1 } });
|
|
|
|
$(cbox).find('input').data('val', data);
|
|
|
|
$(cbox).find('input').data('val', data);
|
|
|
@ -1444,7 +1453,7 @@ define([
|
|
|
|
var lines = opts.items.map(function (itemData) {
|
|
|
|
var lines = opts.items.map(function (itemData) {
|
|
|
|
var name = itemData.uid;
|
|
|
|
var name = itemData.uid;
|
|
|
|
var item = itemData.v;
|
|
|
|
var item = itemData.v;
|
|
|
|
var els = opts.values.map(function (data, i) {
|
|
|
|
var els = extractValues(opts.values).map(function (data, i) {
|
|
|
|
var cbox = UI.createCheckbox('cp-form-'+name+'-'+i,
|
|
|
|
var cbox = UI.createCheckbox('cp-form-'+name+'-'+i,
|
|
|
|
'', false, { mark: { tabindex:1 } });
|
|
|
|
'', false, { mark: { tabindex:1 } });
|
|
|
|
$(cbox).find('input').data('uid', name);
|
|
|
|
$(cbox).find('input').data('uid', name);
|
|
|
@ -1467,7 +1476,7 @@ define([
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
var header = opts.values.map(function (v) { return h('span', v); });
|
|
|
|
var header = extractValues(opts.values).map(function (v) { return h('span', v); });
|
|
|
|
header.unshift(h('span'));
|
|
|
|
header.unshift(h('span'));
|
|
|
|
lines.unshift(h('div.cp-form-multiradio-header', header));
|
|
|
|
lines.unshift(h('div.cp-form-multiradio-header', header));
|
|
|
|
|
|
|
|
|
|
|
@ -1616,7 +1625,7 @@ define([
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
Util.shuffleArray(opts.values);
|
|
|
|
Util.shuffleArray(opts.values);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var els = opts.values.map(function (data) {
|
|
|
|
var els = extractValues(opts.values).map(function (data) {
|
|
|
|
var uid = Util.uid();
|
|
|
|
var uid = Util.uid();
|
|
|
|
map[uid] = data;
|
|
|
|
map[uid] = data;
|
|
|
|
invMap[data] = uid;
|
|
|
|
invMap[data] = uid;
|
|
|
@ -1670,7 +1679,7 @@ define([
|
|
|
|
},
|
|
|
|
},
|
|
|
|
reset: function () {
|
|
|
|
reset: function () {
|
|
|
|
Util.shuffleArray(opts.values);
|
|
|
|
Util.shuffleArray(opts.values);
|
|
|
|
var toSort = (opts.values).map(function (val) {
|
|
|
|
var toSort = extractValues(opts.values).map(function (val) {
|
|
|
|
return invMap[val];
|
|
|
|
return invMap[val];
|
|
|
|
});
|
|
|
|
});
|
|
|
|
sortable.sort(toSort);
|
|
|
|
sortable.sort(toSort);
|
|
|
@ -1728,7 +1737,7 @@ define([
|
|
|
|
var lines = makePollTable(answers, opts, false);
|
|
|
|
var lines = makePollTable(answers, opts, false);
|
|
|
|
|
|
|
|
|
|
|
|
// Add form
|
|
|
|
// Add form
|
|
|
|
var addLine = opts.values.map(function (data) {
|
|
|
|
var addLine = extractValues(opts.values).map(function (data) {
|
|
|
|
var cell = h('div.cp-poll-cell.cp-form-poll-choice', [
|
|
|
|
var cell = h('div.cp-poll-cell.cp-form-poll-choice', [
|
|
|
|
h('i.fa.fa-times.cp-no'),
|
|
|
|
h('i.fa.fa-times.cp-no'),
|
|
|
|
h('i.fa.fa-check.cp-yes'),
|
|
|
|
h('i.fa.fa-check.cp-yes'),
|
|
|
@ -1829,7 +1838,7 @@ define([
|
|
|
|
var opts = form.opts || TYPES.poll.defaultOpts;
|
|
|
|
var opts = form.opts || TYPES.poll.defaultOpts;
|
|
|
|
var q = form.q || Messages.form_default;
|
|
|
|
var q = form.q || Messages.form_default;
|
|
|
|
if (answer === false) {
|
|
|
|
if (answer === false) {
|
|
|
|
var cols = opts.values.map(function (key) {
|
|
|
|
var cols = extractValues(opts.values).map(function (key) {
|
|
|
|
return q + ' | ' + key;
|
|
|
|
return q + ' | ' + key;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
cols.unshift(q);
|
|
|
|
cols.unshift(q);
|
|
|
@ -1845,7 +1854,7 @@ define([
|
|
|
|
if (i !== 0) { str += ';'; }
|
|
|
|
if (i !== 0) { str += ';'; }
|
|
|
|
str += k.replace(';', '').replace(':', '') + ':' + answer.values[k];
|
|
|
|
str += k.replace(';', '').replace(':', '') + ':' + answer.values[k];
|
|
|
|
});
|
|
|
|
});
|
|
|
|
var res = opts.values.map(function (key) {
|
|
|
|
var res = extractValues(opts.values).map(function (key) {
|
|
|
|
return answer.values[key] || '';
|
|
|
|
return answer.values[key] || '';
|
|
|
|
});
|
|
|
|
});
|
|
|
|
res.unshift(str);
|
|
|
|
res.unshift(str);
|
|
|
|