From 4be136ddb44c6bf344c080c40f88d7ab7bb40ea4 Mon Sep 17 00:00:00 2001 From: Zambom Date: Wed, 12 Oct 2016 16:47:08 -0300 Subject: [PATCH] Fixing some forum bugs --- forum/static/js/forum.js | 117 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------ forum/templates/forum/forum_view.html | 2 +- forum/templates/post/post_list.html | 2 +- forum/templates/post/post_render.html | 2 +- forum/templates/post_answers/post_answer_list.html | 2 +- forum/templates/post_answers/post_answer_render.html | 2 +- forum/views.py | 5 ++++- 7 files changed, 78 insertions(+), 54 deletions(-) diff --git a/forum/static/js/forum.js b/forum/static/js/forum.js index c21ba63..61dc4e2 100644 --- a/forum/static/js/forum.js +++ b/forum/static/js/forum.js @@ -46,7 +46,7 @@ $(document).ready(function (){ /* * -* Function to load create forum's form and set the submit function +* Function to load create forum's form * */ function createForum(url, topic) { @@ -57,35 +57,45 @@ function createForum(url, topic) { $(".forum_form").html(data); $("#id_topic").val(topic); - $('.date-picker').datepicker({ - format: 'dd/mm/yyyy', - }); + setForumCreateFormSubmit(); + } + }); - var frm = $('#forum_create'); - frm.submit(function () { - $.ajax({ - type: frm.attr('method'), - url: frm.attr('action'), - data: frm.serialize(), - success: function (data) { - data = data.split('-'); + $("#createForum").modal(); +} - $('.foruns_list').append(""+data[2]+"
"); +/* +* +* Function to set the forum's create form submit function +* +*/ +function setForumCreateFormSubmit() { + $('.date-picker').datepicker({ + format: 'dd/mm/yyyy', + }); - $("#createForum").modal('hide'); + var frm = $('#forum_create'); + frm.submit(function () { + $.ajax({ + type: frm.attr('method'), + url: frm.attr('action'), + data: frm.serialize(), + success: function (data) { + data = data.split('-'); - showForum(data[0], data[1]); - }, - error: function(data) { - $(".forum_form").html(data.responseText); - } - }); - return false; - }); - } - }); + $('.foruns_list').append(""+data[2]+"
"); - $("#createForum").modal(); + $("#createForum").modal('hide'); + + showForum(data[0], data[1]); + }, + error: function(data) { + $(".forum_form").html(data.responseText); + setForumCreateFormSubmit(); + } + }); + return false; + }); } /* @@ -100,29 +110,7 @@ function editForum(url, forum, success_message) { success: function(data) { $(".forum_form").html(data); - $('.date-picker').datepicker({ - format: 'dd/mm/yyyy', - }); - - var frm = $('#forum_create'); - frm.submit(function () { - $.ajax({ - type: frm.attr('method'), - url: frm.attr('action'), - data: frm.serialize(), - success: function (data) { - $('.forum_view').html(data); - - alertify.success(success_message); - - $("#editForum").modal('hide'); - }, - error: function(data) { - $(".forum_form").html(data.responseText); - } - }); - return false; - }); + setForumUpdateFormSubmit(success_message); } }); @@ -131,6 +119,39 @@ function editForum(url, forum, success_message) { /* * +* Function to set the forum's update form submit function +* +*/ +function setForumUpdateFormSubmit(success_message) { + $('.date-picker').datepicker({ + format: 'dd/mm/yyyy', + }); + + var frm = $('#forum_create'); + frm.submit(function () { + $.ajax({ + type: frm.attr('method'), + url: frm.attr('action'), + data: frm.serialize(), + success: function (data) { + $('.forum_view').html(data); + + alertify.success(success_message); + + $("#editForum").modal('hide'); + }, + error: function(data) { + $(".forum_form").html(data.responseText); + + setForumUpdateFormSubmit(success_message); + } + }); + return false; + }); +} + +/* +* * Function to delete a forum * */ diff --git a/forum/templates/forum/forum_view.html b/forum/templates/forum/forum_view.html index 9ca54b3..18272fc 100644 --- a/forum/templates/forum/forum_view.html +++ b/forum/templates/forum/forum_view.html @@ -50,7 +50,7 @@ {% endblock %} {% block content %} -
+
diff --git a/forum/templates/post/post_list.html b/forum/templates/post/post_list.html index 020c576..9266c99 100644 --- a/forum/templates/post/post_list.html +++ b/forum/templates/post/post_list.html @@ -16,7 +16,7 @@ -