diff --git a/amadeus/static/js/topics.js b/amadeus/static/js/topics.js new file mode 100644 index 0000000..9433204 --- /dev/null +++ b/amadeus/static/js/topics.js @@ -0,0 +1,37 @@ +// utilizado para fazer a re-organização dos tópicos +$("#topics-accordion").sortable({ + delay: 100, + distance: 5, + handler: 'i.fa-arrows', + update: function( event, ui ) { + var cont = 1; + var data = []; + + $("#topics-accordion").find('.order_inp').each(function () { + $(this).val(cont++); + + data.push({ + 'topic_id': $(this).parent().find('.id_inp').val(), + 'topic_order': $(this).val() + }); + }); + + data = JSON.stringify(data); + + sendUpdate(data); + }, +}); + +function sendUpdate(data) { + $.ajax({ + url: $('.url_order').val(), + dataType: 'json', + data: {'data': data}, + success: function(response) { + console.log(response); + }, + error: function(response) { + console.log(response); + } + }); +} \ No newline at end of file diff --git a/topics/templates/topics/list.html b/topics/templates/topics/list.html index ff55f77..6f7a543 100644 --- a/topics/templates/topics/list.html +++ b/topics/templates/topics/list.html @@ -4,6 +4,7 @@ {% subject_permissions request.user subject as has_subject_permissions %}
+ {% for topic in subject.topic_subject.all %} {% if not topic.repository and topic.visible or has_subject_permissions %}
@@ -22,8 +23,7 @@ @@ -41,41 +41,5 @@ {% endfor %}
- \ No newline at end of file + + \ No newline at end of file diff --git a/topics/templates/topics/update.html b/topics/templates/topics/update.html new file mode 100644 index 0000000..53607ae --- /dev/null +++ b/topics/templates/topics/update.html @@ -0,0 +1,20 @@ +{% extends 'subjects/view.html' %} + +{% load django_bootstrap_breadcrumbs %} + +{% block breadcrumbs %} + {{ block.super }} + {% breadcrumb 'Update Topic' 'topics:update' subject.slug topic.slug %} +{% endblock %} + +{% block content %} +
+
+
+ {% include 'topics/_form.html' %} +
+
+
+
+
+{% endblock %} diff --git a/topics/urls.py b/topics/urls.py index 01ca0e5..5d77fed 100644 --- a/topics/urls.py +++ b/topics/urls.py @@ -5,5 +5,6 @@ from . import views urlpatterns = [ url(r'^create/(?P[\w_-]+)/$', views.CreateView.as_view(), name = 'create'), + url(r'^update/(?P[\w_-]+)/(?P[\w_-]+)/$', views.UpdateView.as_view(), name = 'update'), url(r'^update_order/$', views.update_order, name = 'update_order'), ] diff --git a/topics/views.py b/topics/views.py index 5488e2e..914b5d8 100644 --- a/topics/views.py +++ b/topics/views.py @@ -70,6 +70,50 @@ class CreateView(LoginRequiredMixin, generic.edit.CreateView): return reverse_lazy('subjects:view', kwargs = {'slug': self.object.subject.slug}) +class UpdateView(LoginRequiredMixin, generic.UpdateView): + login_url = reverse_lazy("users:login") + redirect_field_name = 'next' + + template_name = 'topics/update.html' + form_class = TopicForm + model = Topic + context_object_name = 'topic' + + def dispatch(self, request, *args, **kwargs): + slug = self.kwargs.get('sub_slug', '') + subject = get_object_or_404(Subject, slug = slug) + + if not has_subject_permissions(request.user, subject): + return redirect(reverse_lazy('subjects:home')) + + return super(UpdateView, self).dispatch(request, *args, **kwargs) + + def get_initial(self): + initial = super(UpdateView, self).get_initial() + + slug = self.kwargs.get('sub_slug', '') + + initial['subject'] = get_object_or_404(Subject, slug = slug) + + return initial + + def get_context_data(self, **kwargs): + context = super(UpdateView, self).get_context_data(**kwargs) + + context['title'] = _('Update Topic') + + slug = self.kwargs.get('sub_slug', '') + subject = get_object_or_404(Subject, slug = slug) + + context['subject'] = subject + + return context + + def get_success_url(self): + messages.success(self.request, _('Topic "%s" was updated on virtual enviroment "%s" successfully!')%(self.object.name, self.object.subject.name)) + + return reverse_lazy('subjects:view', kwargs = {'slug': self.object.subject.slug}) + def update_order(request): data = request.GET.get('data', None) -- libgit2 0.21.2