88 lines
		
	
	
	
		
			2.5 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			88 lines
		
	
	
	
		
			2.5 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
| {% extends "base.html" %}
 | |
| 
 | |
| 
 | |
| {% block content %}
 | |
| 
 | |
| <h2><strong>Export lidí</strong></h2>
 | |
| 
 | |
| <select name="select-one" id="select-one">
 | |
|   <option value="0">---</option>
 | |
|   <option value="1">Řešitelé čísla</option>
 | |
|   <option value="2">Řešitelé ročníku</option>
 | |
|   <option value="3">Všichni řešitelé, kteří ještě neodmaturovali</option>
 | |
|   <option value="4">Organizátoři soustředění</option>
 | |
| </select>
 | |
| 
 | |
| <select name="select-two" id="select-two">
 | |
| <!-- will be filled with ajax -->
 | |
| </select>
 | |
| 
 | |
| <button id="download-button">Stáhnout</button>
 | |
| 
 | |
| <script defer>
 | |
|   const select_one = document.getElementById("select-one")
 | |
|   const select_two = document.getElementById("select-two")
 | |
|   const download_button = document.getElementById("download-button")
 | |
| 
 | |
|   download_button.style.display = 'none'
 | |
|   select_two.style.display = 'none'
 | |
| 
 | |
|   const fetch_dict_string = '{{ typy_exportu|safe }}'
 | |
|   const fetch_dict = JSON.parse(fetch_dict_string)
 | |
| 
 | |
| 
 | |
|   select_one.addEventListener('change', (e) => {
 | |
|     value = e.target.value
 | |
|     select_two.style.display = 'none'
 | |
|     select_two.innerHTML = ''
 | |
|     // puvodni stav
 | |
|     if (value == 0) {
 | |
|       download_button.style.display = 'none'
 | |
|       select_two.style.display = 'none'
 | |
|       return
 | |
|     }
 | |
|     // v tomto pripade muzeme rovnou stahnout
 | |
|     if (!(value in fetch_dict)) {
 | |
|       download_button.style.display = 'block'
 | |
|       select_two.style.display = 'none'
 | |
|       return
 | |
|     }
 | |
|     download_button.style.display = 'none'
 | |
|     fetch("/profil/exporty_lidi/get/" + value)
 | |
|       .then(response => response.json())
 | |
|       .then(data => {
 | |
|         const option = document.createElement('option')
 | |
|         option.value = 0
 | |
|         option.text = '---'
 | |
|         select_two.appendChild(option)
 | |
|         for (const [key, value] of Object.entries(data)) {
 | |
|           const option = document.createElement('option')
 | |
|           option.value = value["id"]
 | |
|           option.text = value["display"]
 | |
|           select_two.appendChild(option)
 | |
|         }
 | |
|         select_two.style.display = 'block'
 | |
|       })
 | |
| 
 | |
|   })
 | |
| 
 | |
|   select_two.addEventListener('change', (e) => {
 | |
|     value = e.target.value
 | |
|     if (value == 0) {
 | |
|       download_button.style.display = 'none'
 | |
|       return
 | |
|     }
 | |
|     download_button.style.display = 'block'
 | |
|   })
 | |
| 
 | |
|   download_button.addEventListener('click', (e) => {
 | |
|     if (select_two.innerHTML == '') {
 | |
|       window.location.href = "/profil/exporty_lidi/get_csv_only_one_step/" + select_one.value
 | |
|     } else {
 | |
|       window.location.href = "/profil/exporty_lidi/get_csv/" + select_one.value + "/" + select_two.value
 | |
|     }
 | |
|     
 | |
|   })
 | |
| </script>
 | |
| 
 | |
| {% endblock %}
 |