durfdoen-2.0/layouts/quiz.erb
2020-03-19 22:24:54 +01:00

74 lines
1.9 KiB
Text

<div style="display: flex">
<div style="width: 70vw;">
<% @items.find_all("/quiz/*").each_with_index do |quest, i| %>
<div id="question_<%=i%>" class="question">
<%= render '/partials/question.*', question: quest %>
</div>
<% end %>
</div>
<div style="width: 28vw;" style="display: flex; flex-direction: column;">
<% all_groups().each do |group| %>
<div id="d_<%= group[:id] %>" style="display: none;">
<%= render '/partials/group_small.*', group: group %>
</div>
<% end %>
</div>
</div>
<script>
const _groups = {};
<% all_groups().each do |group| %>
_groups["d_<%= group[:id] %>"] = document.getElementById("d_<%= group[:id] %>");
<% end %>
const _save_answers = {};
console.log(_groups);
function save_answers(vers) {
for (let ver of vers) {
if (_save_answers[ver]) {
_save_answers[ver] += 1;
} else {
_save_answers[ver] = 1;
}
}
}
function del_answers(vers) {
for (let ver of vers) {
_save_answers[ver] -= 1;
}
}
function finish_answers() {
for (let ver in _save_answers) {
console.log(ver);
if (_save_answers[ver] == 0) {
_groups["d_"+ver].style.display = "none";
} else {
_groups["d_"+ver].style.display = "block";
_groups["d_"+ver].style.order = -1 * _save_answers[ver];
}
}
console.log(_save_answers);
}
function getSelectValues(select) {
var result = [];
var options = select && select.options;
var opt;
for (var i=0, iLen=options.length; i<iLen; i++) {
opt = options[i];
if (opt.selected) {
result.push(opt.value || opt.text);
}
}
return result;
}
</script>
<%= yield %>