Add updated front end, updated CaseStudy model and profiles app
This commit is contained in:
@ -31,4 +31,95 @@
|
||||
// See GeometryField source (static/leaflet/leaflet.forms.js) to override more stuff...
|
||||
});
|
||||
</script>
|
||||
|
||||
<!-- Conditional logic for hiding and un-hiding fields. -->
|
||||
<script type="text/javascript">
|
||||
// Here we define the fields we need to conditionally toggle.
|
||||
// TODO: Move this knowledge out of the template
|
||||
var conditionalFields = [{
|
||||
"field": "#id_land_ownership",
|
||||
"showHide": ["#div_id_land_ownership_details"],
|
||||
"condition": "OTH"
|
||||
},
|
||||
{
|
||||
"field": "#id_power_technology",
|
||||
"showHide": ["#div_id_power_technology_other"],
|
||||
"condition": "OT"
|
||||
},
|
||||
{
|
||||
"field": "#id_sector_of_economy",
|
||||
"showHide": ["#div_id_generation_technology",
|
||||
"#div_id_biomass_detail",
|
||||
"#div_id_generation_technology_other",
|
||||
"#div_id_total_generation_capacity",
|
||||
"#div_id_total_investment",
|
||||
"#div_id_technical_or_economic_details"],
|
||||
"condition": ["WND","SOL","HYD"]
|
||||
}];
|
||||
|
||||
|
||||
|
||||
|
||||
// Here we define the checkboxes that we need to use to
|
||||
// conditionally toggle fields - they use slightly different
|
||||
// logic as they rely on the 'checked' attribute rather than value.
|
||||
var conditionalCheckboxes = [{
|
||||
"checkbox": "#id_affects_indigenous",
|
||||
"showHide": "#div_id_affects_indigenous_detail"
|
||||
}];
|
||||
|
||||
// Define a function that hides the field and then creates a listener to toggle the field.
|
||||
// Takes a single conditionalField dictionary with (field, showHide and condition).
|
||||
function addConditionalField(item) {
|
||||
hideAll(item.showHide);
|
||||
$(item.field).change(function(){
|
||||
// Get the value of the option
|
||||
var value = $(this).val();
|
||||
|
||||
// Check the value matches any of the conditions.
|
||||
if (isInArray(value, item.condition)){
|
||||
showAll(item.showHide);
|
||||
} else {
|
||||
hideAll(item.showHide);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// This function does the same as addConditionalField except it checks the status of
|
||||
// checkboxes instead of fields.
|
||||
function addConditionalCheckbox(item) {
|
||||
$(item.showHide).hide();
|
||||
$(item.checkbox).change(function(){
|
||||
if ($(this).is(":checked")) {
|
||||
$(item.showHide).show();
|
||||
} else {
|
||||
$(item.showHide).hide();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Helper functions
|
||||
function show(tag) {
|
||||
$(tag).show();
|
||||
}
|
||||
|
||||
function hide(tag) {
|
||||
$(tag).hide();
|
||||
}
|
||||
|
||||
function showAll(tags) {
|
||||
tags.forEach(show);
|
||||
}
|
||||
|
||||
function hideAll(tags) {
|
||||
tags.forEach(hide);
|
||||
}
|
||||
|
||||
function isInArray(value, array) {
|
||||
return array.indexOf(value) > -1;
|
||||
}
|
||||
|
||||
conditionalFields.forEach(addConditionalField);
|
||||
conditionalCheckboxes.forEach(addConditionalCheckbox);
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
||||
Reference in New Issue
Block a user