diff --git a/forum/static/js/forum.js b/forum/static/js/forum.js index 319b41a..2d5515a 100644 --- a/forum/static/js/forum.js +++ b/forum/static/js/forum.js @@ -1,3 +1,8 @@ +/* +* +* Function to get a cookie stored on browser +* +*/ function getCookie(name) { var cookieValue = null; if (document.cookie && document.cookie !== '') { @@ -16,6 +21,31 @@ function getCookie(name) { /* * +* Defining action of the form to make a post in forum +* +*/ +$(document).ready(function (){ + var frm = $('#form_post'); + frm.submit(function () { + $.ajax({ + type: frm.attr('method'), + url: frm.attr('action'), + data: frm.serialize(), + success: function (data) { + $("#posts_list").append(data); + frm[0].reset(); + }, + error: function(data) { + console.log(frm.serialize()); + console.log('Error'); + } + }); + return false; + }); +}); + +/* +* * Function to load create forum's form and set the submit function * */ @@ -59,39 +89,9 @@ function createForum(url, topic) { /* * -* Function to load forum to modal +* Function to delete a forum * */ -function showForum(url, forum_id) { - $.ajax({ - url: url, - data: {'forum_id': forum_id}, - success: function(data) { - $(".forum_topics").html(data); - - var frm = $('#form_post'); - frm.submit(function () { - $.ajax({ - type: frm.attr('method'), - url: frm.attr('action'), - data: frm.serialize(), - success: function (data) { - $("#posts_list").append(data); - frm[0].reset(); - }, - error: function(data) { - console.log(frm.serialize()); - console.log('Error'); - } - }); - return false; - }); - } - }); - - $('#forumModal').modal(); -} - function delete_forum(url, forum, message) { alertify.confirm(message, function(){ var csrftoken = getCookie('csrftoken'); diff --git a/forum/templates/forum/forum_view.html b/forum/templates/forum/forum_view.html index 7f8b8d5..d41245f 100644 --- a/forum/templates/forum/forum_view.html +++ b/forum/templates/forum/forum_view.html @@ -59,7 +59,45 @@