toulouse-2022: add json cell to display maelis catalog (#73851)
This commit is contained in:
parent
1ece39a340
commit
54da8c0465
|
@ -183,6 +183,17 @@
|
|||
"url": "{{passerelle_url}}toulouse-maelis/{{ slug }}/validate-basket?{% if foyer_id %}family_id={{ foyer_id }}{% else %}NameID={{ user_nameid }}{% endif %}"
|
||||
}
|
||||
}
|
||||
},
|
||||
"toulouse-maelis-catalog": {
|
||||
"cache_duration": 0,
|
||||
"force_async": true,
|
||||
"name": "Toulouse - Maelis : Catalogue des activités",
|
||||
"url": "{{ passerelle_url }}toulouse-maelis/{{ slug }}/read-activity-list?ref_date={% now 'Y-m-d' %}",
|
||||
"form": [
|
||||
{"label": "Slug du connecteur", "varname": "slug", "required": true},
|
||||
{"label": "URL de la démarche d'inscription", "varname": "form_url", "required": true}
|
||||
],
|
||||
"varnames": ["q"]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,264 @@
|
|||
<h2>Catalogue des activité {{ json.meta.reference_year }}-{{ json.meta.reference_year|add:1 }}</h2>
|
||||
|
||||
<div class="search">
|
||||
<ul class="themes">
|
||||
{% for theme_id in json.meta.all_criterias_order %}
|
||||
{% with theme=json.meta.all_criterias|get:theme_id %}
|
||||
{% if theme.data %}
|
||||
<li class="theme-value {{ theme_id }}">
|
||||
<button>{{ theme.text }}</button>
|
||||
<ul class="criterias">
|
||||
{% for key in theme.order %}
|
||||
<li class="criteria-values {{ theme_id }}-{{ key }}">
|
||||
<button>{{ theme.data|get:key }}</button>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</li>
|
||||
{% endif %}
|
||||
{% endwith %}
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="results">
|
||||
<ul>
|
||||
{% for item in json.data %}
|
||||
<li class="
|
||||
{% for theme_key, criterias in item.criterias.items %}
|
||||
{% for key in criterias.order %}{{ theme_key }}-{{ key }} {% endfor %}
|
||||
{% endfor %}
|
||||
result-item">
|
||||
<h3>{{ item.text }}</h3>
|
||||
{{ item.place.text }} /
|
||||
du {{ item.unit.dateStart|date:"d/m/Y" }} au {{ item.unit.dateEnd|date:"d/m/Y" }} /
|
||||
{{ item.criterias.type.data|get:item.criterias.type.order.0 }} /
|
||||
{{ item.place.text }} ---
|
||||
<span class="result-toggling">🔍 Voir</span>
|
||||
<a href="{{ eservices_url }}{{ form_url }}tryauth?activity_id={{ activity.activity_id}}&unit_id={{ activity.uniœt_id }}&place_id={{ activity.place_id }}">📝 Inscription</a>
|
||||
<span class="result-detail">
|
||||
<p class'resutl-detail-title'>Description :</p>
|
||||
{% lorem %}
|
||||
<p class'resutl-detail-title'>Public :</p>
|
||||
{% for key in item.criterias.public.order %}
|
||||
{{ item.criterias.public.data|get:key }}
|
||||
{% if not forloop.last %}, {% endif %}
|
||||
{% endfor %}.
|
||||
</p>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.gru-content div.cell h2 + div {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.themes > li {
|
||||
display: flex;
|
||||
margin-bottom: 2px;
|
||||
}
|
||||
|
||||
.themes button {
|
||||
padding: 10px;
|
||||
margin-left: 2px;
|
||||
}
|
||||
|
||||
.themes li > button {
|
||||
border: 1px solid #FFA58A;
|
||||
background-color: white;
|
||||
color: #FFA58A;
|
||||
}
|
||||
|
||||
.themes li.unused > button {
|
||||
background-color: #FFA58A;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.criterias {
|
||||
list-style: none;
|
||||
display: flex;
|
||||
padding-left: 0;
|
||||
}
|
||||
|
||||
.criterias li button {
|
||||
border: 1px solid #D8522A;
|
||||
background-color: white;
|
||||
color: #D8522A;
|
||||
margin-right: 5px;;
|
||||
}
|
||||
|
||||
.criterias li.selected button {
|
||||
background-color: #D8522A;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.results li {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.results li.shown {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.results h3 {
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
.results a {
|
||||
font-weight: 900;
|
||||
}
|
||||
|
||||
.result-detail {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.result-detail.shown {
|
||||
border-top: 1px solid black;
|
||||
border-bottom: 1px solid black;
|
||||
padding: 1em 0;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.resutl-detail-title {
|
||||
margin-bottom: .5em;
|
||||
}
|
||||
</style>
|
||||
|
||||
<script>
|
||||
// criterias stored by themes
|
||||
const criterias = {
|
||||
{% for theme_key, criterias in json.meta.all_criterias.items %}
|
||||
'{{ theme_key }}': [{% for key in criterias.order %}'{{ key }}', {% endfor %}],
|
||||
{% endfor %}
|
||||
};
|
||||
|
||||
// ex: "http://.../?q=types-LOI_VAC,ages-0,ages-1,ages-3,ages-4,ages-5,places-A10053179604"
|
||||
const param_q = "{{ q }}";
|
||||
|
||||
// check if cell should be display, based on a uniq theme
|
||||
function is_cell_matching_theme(cell, theme) {
|
||||
|
||||
// accept cell as no criterias is selected for this theme
|
||||
if ($('.themes .' + theme).hasClass('unused')) {
|
||||
return true
|
||||
}
|
||||
|
||||
// accept cell is at least one criteria for this theme match (or)
|
||||
var found = false
|
||||
for (var i = 0; i < criterias[theme].length; i++) {
|
||||
var criteria = theme + '-' + criterias[theme][i];
|
||||
var criteria_class = '.criterias .' + criteria;
|
||||
if (cell.hasClass(criteria) && $(criteria_class).hasClass('selected')) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
// check if cell should be displayed, matching all themes (and)
|
||||
function is_cell_matching(cell) {
|
||||
var found = true;
|
||||
for (const theme in criterias) {
|
||||
if (is_cell_matching_theme(cell, theme) === false) {
|
||||
found = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
// show all matching results
|
||||
function show_results() {
|
||||
$('.result-item').each(function(idx, elem) {
|
||||
if (is_cell_matching($(this))) {
|
||||
$(this).addClass('shown');
|
||||
}
|
||||
else {
|
||||
$(this).removeClass('shown');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// check if no criteria is selected for a theme
|
||||
function is_theme_still_in_use(theme) {
|
||||
var found = false
|
||||
for (var i = 0; i < criterias[theme].length; i++) {
|
||||
val = criterias[theme][i]
|
||||
if ($('.criterias .' + theme + '-' + val).hasClass('selected')) {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
// trigger on criteria
|
||||
function select_criteria(theme, value) {
|
||||
var criteria = theme + '-' + value
|
||||
var criteria_class = '.' + criteria
|
||||
if (! $('.criterias ' + criteria_class).hasClass('selected')) {
|
||||
$('.criterias ' + criteria_class).addClass('selected');
|
||||
$('.themes .' + theme).removeClass('unused');
|
||||
}
|
||||
else {
|
||||
$('.criterias ' + criteria_class).removeClass('selected');
|
||||
if (! is_theme_still_in_use(theme)) {
|
||||
$('.themes .' + theme).addClass('unused');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// trigger on theme (first element of a row of criteria)
|
||||
function unuse_theme(theme) {
|
||||
if (! $('.themes .' + theme).hasClass('unused')) {
|
||||
$('.themes .' + theme + ' .criteria-values').removeClass('selected');
|
||||
$('.themes .' + theme).addClass('unused');
|
||||
}
|
||||
}
|
||||
|
||||
$('document').ready(function(){
|
||||
for (const theme in criterias) { // const needed
|
||||
|
||||
// register triggers to unuse themes
|
||||
$('.themes .'+ theme + ' > button').on('click', function() {
|
||||
unuse_theme(theme);
|
||||
show_results();
|
||||
});
|
||||
|
||||
// register triggers to select criterias
|
||||
var length = criterias[theme].length;
|
||||
for (var i = 0; i < length; i++) {
|
||||
const value = criterias[theme][i] // const needed
|
||||
$('.criterias .' + theme + '-' + value).on('click', function() {
|
||||
select_criteria(theme, value);
|
||||
show_results();
|
||||
});
|
||||
}
|
||||
|
||||
// initialize with all themes unused
|
||||
unuse_theme(theme);
|
||||
}
|
||||
|
||||
// modify selection from query-string
|
||||
var params = param_q.split(',');
|
||||
for (var i = 0; i < params.length; i++) {
|
||||
if (params[i].length > 0) {
|
||||
args = params[i].split('-');
|
||||
console.log(args.length)
|
||||
if (args.length == 2 && args[0].length > 0 && args[1].length > 0) {
|
||||
select_criteria(args[0], args[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
show_results();
|
||||
});
|
||||
|
||||
// toggle result detail
|
||||
$('.result-toggling').on('click', function() {
|
||||
$(this).siblings(".result-detail").toggleClass('shown')
|
||||
});
|
||||
</script>
|
Loading…
Reference in New Issue