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>
|
<!DOCTYPE html>
|
||||||
<html lang="nl">
|
<html lang="nl">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="utf-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||||
<title> Durf Doen! - <%= item[:naam] || abbreviation(item) %> </title>
|
<title> Durf Doen! - <%= item[:naam] || abbreviation(item) %> </title>
|
||||||
|
|
||||||
<link rel="stylesheet" href="/stylesheets/main.css">
|
<link rel="stylesheet" href="/stylesheets/main.css">
|
||||||
<link rel="shortcut icon" href="/assets/favicon.png">
|
<link rel="shortcut icon" href="/assets/favicon.png">
|
||||||
|
|
||||||
<%#= item[:head] %>
|
<%#= item[:head] %>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
<%= link_to group[:titel], group %>
|
<%= link_to group[:naam], group %>
|
||||||
|
|
|
@ -3,8 +3,7 @@
|
||||||
<p>
|
<p>
|
||||||
Geef je postcode in
|
Geef je postcode in
|
||||||
</p>
|
</p>
|
||||||
<input id="postcodeField" type=number value="9000">
|
<input id="postcodeField" type=number>
|
||||||
</input>
|
|
||||||
<%else%>
|
<%else%>
|
||||||
<select <% if question[:type] == "meerkeuze" %> multiple="multiple" <% end %>
|
<select <% if question[:type] == "meerkeuze" %> multiple="multiple" <% end %>
|
||||||
id="<%= (question[:tekst] || "") + (question[:vraag] || "") %>_option">
|
id="<%= (question[:tekst] || "") + (question[:vraag] || "") %>_option">
|
||||||
|
@ -15,38 +14,51 @@
|
||||||
</option>
|
</option>
|
||||||
<% end %>
|
<% end %>
|
||||||
</select>
|
</select>
|
||||||
<% end %>
|
<% for answer in question[:antwoorden]%>
|
||||||
<% for answer in question[:antwoorden]%>
|
<% if answer[:vraag] %>
|
||||||
<% if answer[:vraag] %>
|
<div id='<%= html_escape(answer[:tekst] + answer[:vraag]) %>' style="display:none;">
|
||||||
<div id='<%= html_escape(answer[:tekst] + answer[:vraag]) %>' style="display:none;">
|
<%= render '/partials/question.*', question: answer %>
|
||||||
<%= render '/partials/question.*', question: answer %>
|
</div>
|
||||||
</div>
|
<% end %>
|
||||||
<% end %>
|
<% 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
|
// Reference back to the last selected option
|
||||||
// This way we can 'deselect' the question results
|
// This way we can 'deselect' the question results
|
||||||
let last_answered = [];
|
let last_answered = [];
|
||||||
|
@ -88,6 +100,8 @@
|
||||||
|
|
||||||
const selected = getSelectValues(event.target);
|
const selected = getSelectValues(event.target);
|
||||||
|
|
||||||
|
console.log(event.target);
|
||||||
|
|
||||||
// Update results
|
// Update results
|
||||||
save_answers(selected.flatMap(e => question_results[e] || []));
|
save_answers(selected.flatMap(e => question_results[e] || []));
|
||||||
del_answers(last_answered.flatMap(e => question_results[e] || []));
|
del_answers(last_answered.flatMap(e => question_results[e] || []));
|
||||||
|
@ -101,4 +115,5 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
<%end%>
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -37,10 +37,19 @@ module VerenigingenHelper
|
||||||
"naam" => x[:naam],
|
"naam" => x[:naam],
|
||||||
"verkorte_naam" => x[:verkorte_naam],
|
"verkorte_naam" => x[:verkorte_naam],
|
||||||
"konvent" => x[:konvent],
|
"konvent" => x[:konvent],
|
||||||
"themas" => x[:themas]
|
"themas" => x[:themas],
|
||||||
|
"postcodes" => x[:postcodes].to_a,
|
||||||
} }.to_a
|
} }.to_a
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def postcodes_per_vereniging
|
||||||
|
@items.find_all("**/verenigingen/*").map { |x| {
|
||||||
|
"postcodes" => x[:postcodes],
|
||||||
|
"id" => x[:id]
|
||||||
|
} }.flatten.to_a
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
def abbreviation(item)
|
def abbreviation(item)
|
||||||
item.identifier.without_ext.split('/').last
|
item.identifier.without_ext.split('/').last
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue