From 0aa01fa47b5c1c2678f2b211a4d91f0e9ebfb49f Mon Sep 17 00:00:00 2001 From: Jailson Dias Date: Tue, 8 Nov 2016 19:34:04 -0300 Subject: [PATCH] ajustando para quando criar uma enquete não precisar atualizar a página para ela aparecer #261 --- courses/templates/subject/poll_item_actions_teacher.html | 10 ++++++++++ poll/models.py | 2 +- poll/static/js/modal_poll.js | 61 +++++++++++++++++++++++++++++++++++++++++++++++++------------ poll/templates/poll/create.html | 9 +-------- poll/templates/poll/poll_edit.html | 4 ++++ poll/templates/poll/poll_view.html | 1 + poll/templates/poll/remove.html | 6 +++--- poll/templates/poll/update.html | 2 +- poll/urls.py | 2 ++ poll/views.py | 32 +++++++++++++++++++++++++++----- 10 files changed, 99 insertions(+), 30 deletions(-) create mode 100644 courses/templates/subject/poll_item_actions_teacher.html create mode 100644 poll/templates/poll/poll_edit.html create mode 100644 poll/templates/poll/poll_view.html diff --git a/courses/templates/subject/poll_item_actions_teacher.html b/courses/templates/subject/poll_item_actions_teacher.html new file mode 100644 index 0000000..4c3caf0 --- /dev/null +++ b/courses/templates/subject/poll_item_actions_teacher.html @@ -0,0 +1,10 @@ +{% load static i18n permission_tags professor_access %} + +
+ {% for poll in polls %} +
+
  • +
  • {{poll}}
  • +
    + {% endfor %} +
    diff --git a/poll/models.py b/poll/models.py index 68eac05..13bf8bc 100644 --- a/poll/models.py +++ b/poll/models.py @@ -12,7 +12,7 @@ class Poll(Activity): verbose_name_plural = _('Polls') def __str__(self): - return str(self.name) + str("/") + str(self.topic) + return str(self.name) class Answer(models.Model): answer = models.CharField(_("Answer"), max_length = 200) diff --git a/poll/static/js/modal_poll.js b/poll/static/js/modal_poll.js index 21d953f..87de7f5 100644 --- a/poll/static/js/modal_poll.js +++ b/poll/static/js/modal_poll.js @@ -1,9 +1,11 @@ -//controles do modal -$(window).ready(function() { // utilizado para abrir o modal quando tiver tido algum erro no preenchimento do formulario - if($('.not_submited').length){ - $('#poll').modal('show'); - } -}); +// +// //controles do modal +// $(window).ready(function() { // utilizado para abrir o modal quando tiver tido algum erro no preenchimento do formulario +// if($('.not_submited').length){ +// $('#poll').modal('show'); +// } +// }); + var Answer = { init: function(url) { // utilizado para adicionar um novo campo de resposta $.get(url, function(data){ @@ -17,24 +19,59 @@ var Answer = { }; var Submite = { - post: function(url,dados){ + create: function(url,dados, slug){ + $('#poll').modal('hide'); + var poll = null; + $.post(url,dados, function(data){ + $.ajax({ + method: "get", + url: data["view"], + success: function(view){ + $('#list-topic-'+ slug +'-poll').append(view); + } + }); + $.ajax({ + method: "get", + url: data["edit"], + success: function(edit){ + $('#list-topic-'+ slug +'-poll-edit').append(edit); + } + }); + $("#requisicoes_ajax").empty(); + alertify.alert('Link successfully created!'); + }).fail(function(data){ + $("div.modal-backdrop.fade.in").remove(); + $("#requisicoes_ajax").empty(); + $("#requisicoes_ajax").append(data.responseText); + $('#poll').modal('show'); + }); + }, + update: function(url,dados, slug_poll, slug_topic){ $('#poll').modal('hide'); $.post(url,dados, function(data){ + $('#list-topic-'+ slug_topic +'-poll #'+slug_poll).remove(); + $('#list-topic-'+ slug_topic +'-poll #'+slug_poll).remove(); + $('#list-topic-'+ slug_topic +'-poll').append(data); + $('#list-topic-'+ slug_topic +'-poll-edit').append(data); + $("#requisicoes_ajax").empty(); + alertify.alert('Link successfully updated!') }).fail(function(data){ $("div.modal-backdrop.fade.in").remove(); - $("#modal_poll").empty(); - $("#modal_poll").append(data.responseText); + $("#requisicoes_ajax").empty(); + $("#requisicoes_ajax").append(data.responseText); + $('#poll').modal('show'); }); }, remove: function(url,dados, id_li_link){ $('#poll').modal('hide'); $.post(url,dados, function(data){ $(id_li_link).remove(); - $("#modal_poll").empty(); + $(id_li_link+"_div").remove(); + $("#requisicoes_ajax").empty(); $("div.modal-backdrop.fade.in").remove(); }).fail(function(){ - $("#modal_poll").empty(); - $("#modal_poll").append(data); + $("#requisicoes_ajax").empty(); + $("#requisicoes_ajax").append(data); $('#poll').modal('show'); }); } diff --git a/poll/templates/poll/create.html b/poll/templates/poll/create.html index ee216fd..fd05942 100644 --- a/poll/templates/poll/create.html +++ b/poll/templates/poll/create.html @@ -2,13 +2,6 @@ {% load i18n widget_tweaks dict_access static%} -{# {% block style %} #} - - - -{# {% endblock %} #} - -{# {% block content %} #}