give quiz a nice post code handler
This commit is contained in:
parent
3c5bd9767a
commit
cc183c7775
4 changed files with 58 additions and 35 deletions
|
@ -1,14 +1,13 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="nl">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||
<title> Durf Doen! - <%= item[:naam] || abbreviation(item) %> </title>
|
||||
|
||||
<link rel="stylesheet" href="/stylesheets/main.css">
|
||||
<link rel="shortcut icon" href="/assets/favicon.png">
|
||||
|
||||
<%#= item[:head] %>
|
||||
</head>
|
||||
<body>
|
||||
|
|
|
@ -1 +1 @@
|
|||
<%= link_to group[:titel], group %>
|
||||
<%= link_to group[:naam], group %>
|
||||
|
|
|
@ -3,8 +3,7 @@
|
|||
<p>
|
||||
Geef je postcode in
|
||||
</p>
|
||||
<input id="postcodeField" type=number value="9000">
|
||||
</input>
|
||||
<input id="postcodeField" type=number>
|
||||
<%else%>
|
||||
<select <% if question[:type] == "meerkeuze" %> multiple="multiple" <% end %>
|
||||
id="<%= (question[:tekst] || "") + (question[:vraag] || "") %>_option">
|
||||
|
@ -15,38 +14,51 @@
|
|||
</option>
|
||||
<% end %>
|
||||
</select>
|
||||
<% end %>
|
||||
<% for answer in question[:antwoorden]%>
|
||||
<% if answer[:vraag] %>
|
||||
<div id='<%= html_escape(answer[:tekst] + answer[:vraag]) %>' style="display:none;">
|
||||
<%= render '/partials/question.*', question: answer %>
|
||||
</div>
|
||||
<% for answer in question[:antwoorden]%>
|
||||
<% if answer[:vraag] %>
|
||||
<div id='<%= html_escape(answer[:tekst] + answer[:vraag]) %>' style="display:none;">
|
||||
<%= render '/partials/question.*', question: answer %>
|
||||
</div>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<script>
|
||||
<script>
|
||||
<% if question[:type] == "specialCase1" %>
|
||||
(function setupPostCodeField() {
|
||||
const postcodes = (function genpostcodes() {
|
||||
const postcodes = {};
|
||||
|
||||
for(let ver of <%= postcodes_per_vereniging.to_json %> ) {
|
||||
for(let post of ver["postcodes"] || []) {
|
||||
if(!(post in postcodes)) postcodes[post+""] = [];
|
||||
|
||||
postcodes[post+""].push(ver["id"]);
|
||||
}
|
||||
}
|
||||
|
||||
return postcodes;
|
||||
})();
|
||||
|
||||
let last_answered = [];
|
||||
|
||||
const postcodeField = document.getElementById("postcodeField");
|
||||
|
||||
const handler = () => {
|
||||
const selected = postcodes[postcodeField.value] || [];
|
||||
|
||||
// Update results
|
||||
save_answers(selected);
|
||||
del_answers(last_answered);
|
||||
save_state();
|
||||
|
||||
last_answered = selected;
|
||||
};
|
||||
|
||||
postcodeField.addEventListener("past", handler, false);
|
||||
postcodeField.addEventListener("input", handler, false);
|
||||
})();
|
||||
<%else%>
|
||||
{
|
||||
(function setupPostCodeField() {
|
||||
const postCodes = (function genPostCodes() {
|
||||
|
||||
console.log("Running postcodes");
|
||||
const postCodes = {};
|
||||
|
||||
<% verenigingen().each do |ver| %>
|
||||
console.log("<%=ver[:naam]%>");
|
||||
|
||||
<% if ver[:postcodes] %>
|
||||
<% for postcode in ver[:postcodes] %>
|
||||
console.log("<%=postcode%>");
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
})();
|
||||
|
||||
console.log("Running");
|
||||
|
||||
// const postField =
|
||||
})();
|
||||
|
||||
// Reference back to the last selected option
|
||||
// This way we can 'deselect' the question results
|
||||
let last_answered = [];
|
||||
|
@ -88,6 +100,8 @@
|
|||
|
||||
const selected = getSelectValues(event.target);
|
||||
|
||||
console.log(event.target);
|
||||
|
||||
// Update results
|
||||
save_answers(selected.flatMap(e => question_results[e] || []));
|
||||
del_answers(last_answered.flatMap(e => question_results[e] || []));
|
||||
|
@ -101,4 +115,5 @@
|
|||
}
|
||||
});
|
||||
}
|
||||
<%end%>
|
||||
</script>
|
||||
|
|
|
@ -37,10 +37,19 @@ module VerenigingenHelper
|
|||
"naam" => x[:naam],
|
||||
"verkorte_naam" => x[:verkorte_naam],
|
||||
"konvent" => x[:konvent],
|
||||
"themas" => x[:themas]
|
||||
"themas" => x[:themas],
|
||||
"postcodes" => x[:postcodes].to_a,
|
||||
} }.to_a
|
||||
end
|
||||
|
||||
def postcodes_per_vereniging
|
||||
@items.find_all("**/verenigingen/*").map { |x| {
|
||||
"postcodes" => x[:postcodes],
|
||||
"id" => x[:id]
|
||||
} }.flatten.to_a
|
||||
end
|
||||
|
||||
|
||||
def abbreviation(item)
|
||||
item.identifier.without_ext.split('/').last
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue