You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

75 lines
2.7 KiB

{% extends 'partials/base.html' %}
{% block content %}
<h1>Специализации</h1>
{% load mptt_tags %}
{# {% for spec in object_list %}#}
{# <h4>{{ spec }}</h4>#}
{# {% endfor %}#}
{##}
{% load mptt_tags %}
{#<ul>#}
{# {% recursetree object_list %}#}
{# <li>#}
{# {{ node.name }}#}
{# {% if not node.is_leaf_node %}#}
{# <ul class="children">#}
{# {{ children }}#}
{# </ul>#}
{# {% endif %}#}
{# </li>#}
{# {% endrecursetree %}#}
{#</ul>#}
{% for ch in children %}
<p class="spec_list" data-id="{{ ch.id }}"> {{ ch }} </p>
{% for ch1 in ch.get_children %}
{# {{ ch1 }}#}
{% endfor %}
{% endfor %}
<div id="children" style="border:2px solid #000;">
</div>
{% block js_block %}
<script type="text/javascript">
$(function () {
function getCookie(name) {
var cookieValue = null;
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = jQuery.trim(cookies[i]);
if (cookie.substring(0, name.length + 1) == (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
$('body').on('click','p', function (e) {
e.preventDefault();
var csrftoken = getCookie('csrftoken');
var spec_id = $(this).attr('data-id')
$.ajax({
url:'/api/specializations?parent=' + spec_id,
type:'GET',
data:{ csrfmiddlewaretoken : csrftoken, spec_id: spec_id},
dataType:'json',
success:function(json){
console.log(json.results);
var out = ''
$.each(json.results, function(i,v){
out += '<p data-id="' + v.id + '">' + v.name + '</p>';
});
$('#children').html(out);
}
});
});
});
</script>
{% endblock %}
{% endblock %}