seminar | treenode editor | prepracovan system pridavani TreeNodu
Zatim jen rozepsano, nefunkcni.
This commit is contained in:
parent
e4818d28ea
commit
8bb6e770fe
7 changed files with 104 additions and 10 deletions
|
@ -27,3 +27,6 @@ div.node_type {
|
||||||
background-color: #d4d4d4;
|
background-color: #d4d4d4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.hidden-tn {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
18
seminar/static/seminar/treenode_editor.js
Normal file
18
seminar/static/seminar/treenode_editor.js
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
function showSelectedItemForm(sel,id){
|
||||||
|
var option;
|
||||||
|
var name;
|
||||||
|
var div;
|
||||||
|
Array.from(sel.options).forEach(function(option){
|
||||||
|
console.log(option);
|
||||||
|
name = 'pridat-'+option.value+'-'+id;
|
||||||
|
div = document.getElementById(name);
|
||||||
|
console.log(div);
|
||||||
|
div.style.display = 'none';
|
||||||
|
});
|
||||||
|
name = sel.options[sel.selectedIndex].value;
|
||||||
|
name = 'pridat-'+name+'-'+id;
|
||||||
|
div = document.getElementById(name);
|
||||||
|
console.log(div);
|
||||||
|
div.style.display = 'block';
|
||||||
|
|
||||||
|
}
|
|
@ -10,6 +10,7 @@ dfsdfs
|
||||||
|
|
||||||
{% block custom_css %}
|
{% block custom_css %}
|
||||||
<link rel="stylesheet" type="text/css" href="{% static 'css/mamweb-dev.css' %}" />
|
<link rel="stylesheet" type="text/css" href="{% static 'css/mamweb-dev.css' %}" />
|
||||||
|
<script src="/static/seminar/treenode_editor.js"></script>
|
||||||
{% endblock custom_css %}
|
{% endblock custom_css %}
|
||||||
|
|
||||||
{% load comments %}
|
{% load comments %}
|
||||||
|
|
|
@ -5,13 +5,23 @@
|
||||||
{% appendableChildren obj.parent as dostupne_typy %}
|
{% appendableChildren obj.parent as dostupne_typy %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{# ulohaZadani ulohaVzorak Reseni Cast Text #}
|
||||||
{% if dostupne_typy %}
|
{% if dostupne_typy %}
|
||||||
<div class="pink">Přidat {{kam}}
|
<div class="pink">Přidat {{kam}}
|
||||||
<select name="pridat-typ-{{obj.node.id}}-{{kam_slug}}">
|
<select name="pridat-typ-{{obj.node.id}}-{{kam_slug}}" onchange="showSelectedItemForm(this,'{{obj.node.id}}-{{kam_slug}}')">
|
||||||
{% for typ in dostupne_typy %}
|
{% for typ in dostupne_typy %}
|
||||||
<option value="{{typ.0}}">{{typ.1}}</option>
|
<option value="{{typ.0}}">{{typ.1}}</option>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</select>
|
</select>
|
||||||
<button action="submit" formaction="{%url 'treenode_pridat' obj.node.id kam_slug%}">Přidat</button>
|
<div class="hidden-tn" id="pridat-castNode-{{obj.node.id}}-{{kam_slug}}">
|
||||||
|
Nadpis: <input name="pridat-cast-{{obj.node.id}}-{{kam_slug}}" type="text">
|
||||||
|
<button action="submit" formaction="{%url 'treenode_pridat' obj.node.id kam_slug%}">Přidat</button>
|
||||||
|
</div>
|
||||||
|
<div class="hidden-tn" id="pridat-textNode-{{obj.node.id}}-{{kam_slug}}"> Vytvořit</div>
|
||||||
|
<div class="hidden-tn" id="pridat-reseniNode-{{obj.node.id}}-{{kam_slug}}">Vytvořit, Tady bude autocomplete na reseniNode</div>
|
||||||
|
<div class="hidden-tn" id="pridat-ulohaZadaniNode-{{obj.node.id}}-{{kam_slug}}">Vytvořit zadání</div>
|
||||||
|
<div class="hidden-tn" id="pridat-ulohaVzorakNode-{{obj.node.id}}-{{kam_slug}}">Vytvořit vzorák k: Tady bude autocomplete na problémy k aktuálnímu kontextu</div>
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
{% endif %}{# appendablebleChildren #}
|
{% endif %}{# appendablebleChildren #}
|
||||||
|
|
|
@ -185,7 +185,45 @@ def appendableChildren(value):
|
||||||
return appendableChildren(value.parent)
|
return appendableChildren(value.parent)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@register.simple_tag
|
||||||
|
def canAppendReseni(value):
|
||||||
|
if isTemaVCisle(value.node):
|
||||||
|
return True
|
||||||
|
if isCast(value.node):
|
||||||
|
return canAppendReseni(value.parent)
|
||||||
|
return False
|
||||||
|
|
||||||
|
@register.simple_tag
|
||||||
|
def canAppendUlohaZadani(value):
|
||||||
|
if isTemaVCisle(value.node):
|
||||||
|
return True
|
||||||
|
if isCast(value.node):
|
||||||
|
return canAppendUlohaZadani(value.parent)
|
||||||
|
return False
|
||||||
|
|
||||||
|
@register.simple_tag
|
||||||
|
def canAppendUlohaVzorak(value):
|
||||||
|
if isTemaVCisle(value.node):
|
||||||
|
return True
|
||||||
|
if isCast(value.node):
|
||||||
|
return canAppendUlohaVzorak(value.parent)
|
||||||
|
return False
|
||||||
|
|
||||||
|
@register.simple_tag
|
||||||
|
def canAppendCast(value):
|
||||||
|
if isTemaVCisle(value.node) or isOrgText(value.node) or isReseni(value.node) or isUlohaZadani(value.node) or isUlohaVzorak(value.node):
|
||||||
|
return True
|
||||||
|
if isCast(value.node):
|
||||||
|
return canAppendCast(value.parent)
|
||||||
|
return False
|
||||||
|
|
||||||
|
@register.simple_tag
|
||||||
|
def canAppendText(value):
|
||||||
|
if isTemaVCisle(value.node) or isOrgText(value.node) or isReseni(value.node) or isUlohaZadani(value.node) or isUlohaVzorak(value.node):
|
||||||
|
return True
|
||||||
|
if isCast(value.node):
|
||||||
|
return canAppendText(value.parent)
|
||||||
|
return False
|
||||||
|
|
||||||
#@register.filter
|
#@register.filter
|
||||||
#def is(value):
|
#def is(value):
|
||||||
|
|
|
@ -26,7 +26,7 @@ urlpatterns = [
|
||||||
path('cislo/<int:rocnik>.<int:cislo>/', views.CisloView.as_view(), name='seminar_cislo'), # odkomentované jenom kvůli testování archivu
|
path('cislo/<int:rocnik>.<int:cislo>/', views.CisloView.as_view(), name='seminar_cislo'), # odkomentované jenom kvůli testování archivu
|
||||||
path('problem/<int:pk>/', views.ProblemView.as_view(), name='seminar_problem'),
|
path('problem/<int:pk>/', views.ProblemView.as_view(), name='seminar_problem'),
|
||||||
path('treenode/<int:pk>/', views.TreeNodeView.as_view(), name='seminar_treenode'),
|
path('treenode/<int:pk>/', views.TreeNodeView.as_view(), name='seminar_treenode'),
|
||||||
path('treenode/editor/pridat/<int:pk>/<str:kam>/', views.TreeNodePridatView.as_view(), name='treenode_pridat'),
|
path('treenode/editor/pridat/<str:co>/<int:pk>/<str:kam>/', views.TreeNodePridatView.as_view(), name='treenode_pridat'),
|
||||||
path('treenode/editor/smazat/<int:pk>/', views.TreeNodeSmazatView.as_view(), name='treenode_smazat'),
|
path('treenode/editor/smazat/<int:pk>/', views.TreeNodeSmazatView.as_view(), name='treenode_smazat'),
|
||||||
path('treenode/editor/odvesitpryc/<int:pk>/', views.TreeNodeOdvesitPrycView.as_view(), name='treenode_odvesitpryc'),
|
path('treenode/editor/odvesitpryc/<int:pk>/', views.TreeNodeOdvesitPrycView.as_view(), name='treenode_odvesitpryc'),
|
||||||
path('treenode/editor/podvesit/<int:pk>/<str:kam>/', views.TreeNodePodvesitView.as_view(), name='treenode_podvesit'),
|
path('treenode/editor/podvesit/<int:pk>/<str:kam>/', views.TreeNodePodvesitView.as_view(), name='treenode_podvesit'),
|
||||||
|
|
|
@ -159,14 +159,40 @@ class TreeNodePridatView(generic.View):
|
||||||
}
|
}
|
||||||
|
|
||||||
def post(self, request, *args, **kwargs):
|
def post(self, request, *args, **kwargs):
|
||||||
|
######## FIXME: ROZEPSANE, NEFUNGUJE, DOPSAT !!!!!! ###########
|
||||||
node = s.TreeNode.objects.get(pk=self.kwargs['pk'])
|
node = s.TreeNode.objects.get(pk=self.kwargs['pk'])
|
||||||
kam = self.kwargs['kam']
|
kam = self.kwargs['kam']
|
||||||
|
co = self.kwargs['co']
|
||||||
|
typ = self.type_from_str[co]
|
||||||
|
|
||||||
|
raise NotImplementedError('Neni to dopsane, dopis to!')
|
||||||
|
|
||||||
|
if kam not in ('pred','syn','za'):
|
||||||
|
raise ValidationError('Přidat lze pouze před nebo za node nebo jako syna')
|
||||||
|
|
||||||
|
if co == m.TextNode:
|
||||||
|
new_obj = m.Text()
|
||||||
|
new_obj.save()
|
||||||
|
elif co == m.CastNode:
|
||||||
|
new_obj = m.CastNode()
|
||||||
|
new_obj.nadpis = request.POST.get('pridat-castNode-{}-{}'.format(node.id,kam))
|
||||||
|
new_obj.save()
|
||||||
|
elif co == m.ReseniNode:
|
||||||
|
new_obj = m.
|
||||||
|
pass
|
||||||
|
elif co == m.UlohaZadaniNode:
|
||||||
|
pass
|
||||||
|
elif co == m.UlohaReseniNode:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
new_obj = None
|
||||||
|
|
||||||
|
|
||||||
|
if kam == 'pred':
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
if kam not in ('syn','za'):
|
|
||||||
raise ValidationError('Přidat lze pouze před nebo za node')
|
|
||||||
if kam == 'syn':
|
if kam == 'syn':
|
||||||
strtyp = request.POST.get('pridat-typ-{}-syn'.format(node.id))
|
|
||||||
typ = self.type_from_str[strtyp]
|
|
||||||
if typ == m.TextNode:
|
if typ == m.TextNode:
|
||||||
text_obj = m.Text()
|
text_obj = m.Text()
|
||||||
text_obj.save()
|
text_obj.save()
|
||||||
|
@ -174,8 +200,6 @@ class TreeNodePridatView(generic.View):
|
||||||
else:
|
else:
|
||||||
node = treelib.create_child(node,typ)
|
node = treelib.create_child(node,typ)
|
||||||
if kam == 'za':
|
if kam == 'za':
|
||||||
strtyp = request.POST.get('pridat-typ-{}-za'.format(node.id))
|
|
||||||
typ = self.type_from_str[strtyp]
|
|
||||||
if typ == m.TextNode:
|
if typ == m.TextNode:
|
||||||
text_obj = m.Text()
|
text_obj = m.Text()
|
||||||
text_obj.save()
|
text_obj.save()
|
||||||
|
@ -226,7 +250,7 @@ class SirotcinecView(generic.ListView):
|
||||||
template_name = 'seminar/orphanage.html'
|
template_name = 'seminar/orphanage.html'
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
return s.TreeNode.objects.not_instance_of(s.RocnikNode).filter(root=None,succ=None,father_of_first=None)
|
return s.TreeNode.objects.not_instance_of(s.RocnikNode).filter(root=None,prev=None,succ=None,father_of_first=None)
|
||||||
|
|
||||||
class ProblemView(generic.DetailView):
|
class ProblemView(generic.DetailView):
|
||||||
model = s.Problem
|
model = s.Problem
|
||||||
|
|
Loading…
Reference in a new issue