From 0dd964ec05401809a408ab55d5517d3b2fba3a85 Mon Sep 17 00:00:00 2001 From: Jayaram Pai Date: Mon, 9 Dec 2013 12:47:18 +0530 Subject: reply edit with no ajax --- static/website/css/main.css | 9 ++++ static/website/js/custom.js | 22 ++++++++ static/website/js/thread-user.js | 60 ++++++++++++++++++---- .../website/templates/ajax-similar-questions.html | 23 +++++++++ static/website/templates/base.html | 34 +++++++++--- static/website/templates/get-question.html | 22 ++++++-- static/website/templates/new-question.html | 33 ++++++++++-- website/urls.py | 1 + website/views.py | 16 ++++++ 9 files changed, 193 insertions(+), 27 deletions(-) create mode 100644 static/website/templates/ajax-similar-questions.html diff --git a/static/website/css/main.css b/static/website/css/main.css index 07d38a6..7a58a4c 100644 --- a/static/website/css/main.css +++ b/static/website/css/main.css @@ -67,6 +67,9 @@ padding: 2px 7px; background: #f5f5f5; } +#similar-link { + display: none; +} #questionNicPanel { display: none; } @@ -81,10 +84,16 @@ .modify a.save { display: none; } + +.vs { + padding: 0px 5px !important; + font-size: x-small; +} #content .reply { position: relative; border-bottom: 1px solid #f5f5f5; padding: 20px 0; + margin: 10px 0px; } #content .reply .body { } diff --git a/static/website/js/custom.js b/static/website/js/custom.js index ef0752e..da5839b 100644 --- a/static/website/js/custom.js +++ b/static/website/js/custom.js @@ -5,6 +5,7 @@ $(document).ready(function() { $second_range = $("#id_second_range"); $category.change(function() { + $("#similar-link").hide(); var category = $(this).val(); $.ajax({ url: "/ajax-tutorials/", @@ -41,6 +42,27 @@ $(document).ready(function() { } }); }); + + $second_range.change(function() { + $.ajax({ + url: "/ajax-similar-questions/", + type: "POST", + data: { + category: $category.val(), + tutorial: $tutorial.val(), + minute_range: $minute_range.val(), + second_range: $second_range.val() + }, + dataType: "html", + success: function(data) { + console.log(data); + $response = $(data); + var similar_count= $response.find("#similar-count").text(); + $("#similar-link").show().html(similar_count); + $(".modal-body").html(data); + } + }); + }); $(document).ajaxStart(function() { $("#ajax-loader").show(); diff --git a/static/website/js/thread-user.js b/static/website/js/thread-user.js index dbf9bdd..698a946 100644 --- a/static/website/js/thread-user.js +++ b/static/website/js/thread-user.js @@ -9,17 +9,20 @@ bkLib.onDomLoaded(function() { }); $(document).ready(function() { - /*set the jquery variables */ + /* + * question edit section + * set the jquery variables + */ $question = $(".question"); - $modify = $(".modify"); - $edit = $(".modify .edit"); - $save = $(".modify .save"); + $question_modify = $(".question .modify"); + $question_edit = $(".question .modify .edit"); + $question_save = $(".question .modify .save"); $questionNicPanel = $("#questionNicPanel"); $questionInstance = $("#questionInstance"); /* make the question editable and show modify */ $question.addClass("editable"); - $modify.show(); + $question_modify.show(); /* edit and save click events */ function modify(thisObj){ @@ -28,20 +31,20 @@ $(document).ready(function() { $questionNicPanel.show(); $questionInstance.focus(); } - $edit.click(function () { - modify($edit); + $question_edit.click(function () { + modify($question_edit); }); $questionInstance.click(function() { - modify($edit); + modify($question_edit); }); - $save.click(function () { + $question_save.click(function () { $(this).hide(); $questionNicPanel.hide(); $(this).prev().css("display", "block"); /* make the ajax call */ - var id_length = $save.attr("id").length; - var question_id = parseInt($save.attr("id").substr(id_length-1)); + var id_length = $question_save.attr("id").length; + var question_id = parseInt($question_save.attr("id").substr(id_length-1)); console.log(question_id); var question_body = $questionInstance.html(); $.ajax({ @@ -57,5 +60,40 @@ $(document).ready(function() { } }); }); + + /* + * reply edit section + * set the dom variables + */ + $reply_edit = $('.reply .edit'); + $reply_save = $(".reply .save"); + $replyPanelWrapper = $("#replyPanelWrapper"); + + var replyNicEditor = new nicEditor({ + buttonList : ['fontSize','bold','italic','underline','strikeThrough','subscript','superscript','html','image'], + iconsPath: "/static/website/js/nicEditorIcons.gif", + }); + replyNicEditor.panelInstance('replyNicPanel'); + + $reply_edit.click(function() { + var reply_body = $(this).data("target"); + console.log(reply_body); + replyNicEditor.addInstance(reply_body); + $(this).parents("div.reply").prepend($replyPanelWrapper); + $replyPanelWrapper.show(); + $('#replyPanelWrapper .nicEdit-panelContain').parent().width('100%'); + $('#replyPanelWrapper .nicEdit-panelContain').parent().next().width('100%'); + $(this).hide(); + $(this).next().show(); + }); + + $reply_save.click(function() { + var reply_body = $(this).data("target"); + replyNicEditor.removeInstance(reply_body); + $replyPanelWrapper.hide(); + $('#replyPanelWrapper .nicEdit-panelContain').parent().width('100%'); + $(this).hide(); + $(this).prev().show(); + }); }); diff --git a/static/website/templates/ajax-similar-questions.html b/static/website/templates/ajax-similar-questions.html new file mode 100644 index 0000000..64f194f --- /dev/null +++ b/static/website/templates/ajax-similar-questions.html @@ -0,0 +1,23 @@ +
+
+ {% if questions.count > 0 %} + {% if questions.count == 1 %} + 1 similar question + {% else %} + {{ questions.count }} similar questions + {% endif %} + {% endif %} +
+
+ +{% for question in questions %} + + + +{% endfor %} +
+ + {{ question.title }} + +
+
diff --git a/static/website/templates/base.html b/static/website/templates/base.html index f7e2ac5..5e397e8 100644 --- a/static/website/templates/base.html +++ b/static/website/templates/base.html @@ -18,23 +18,42 @@ - Spoken Tutorial Forums + + Spoken Tutorial Forums + @@ -62,7 +81,6 @@ - {% block javascript %} {% endblock %} diff --git a/static/website/templates/get-question.html b/static/website/templates/get-question.html index f6280cf..5e68aed 100644 --- a/static/website/templates/get-question.html +++ b/static/website/templates/get-question.html @@ -59,16 +59,29 @@

Answers:

+ + + {% for reply in replies %} -
- +
+ +
{{ reply.body|safe }} - +
{{ reply.user }} -
+ + {% ifequal reply.uid|stringformat:'s' user.id|stringformat:'s' %} + + Edit + Save + + {% endifequal %} +
{% endfor %}
{% csrf_token %} @@ -102,6 +115,7 @@ {% ifequal question.user|stringformat:"s" user|stringformat:"s" %} {% else %} + {% endblock %} + +{% block javascript %} + +{% endblock %} diff --git a/website/urls.py b/website/urls.py index 774acb9..c385ea0 100644 --- a/website/urls.py +++ b/website/urls.py @@ -14,4 +14,5 @@ urlpatterns = patterns('', url(r'^ajax-tutorials/$', 'website.views.ajax_tutorials', name='ajax_tutorials'), url(r'^ajax-duration/$', 'website.views.ajax_duration', name='ajax_duration'), url(r'^ajax-question-update/$', 'website.views.ajax_question_update', name='ajax_question_update'), + url(r'^ajax-similar-questions/$', 'website.views.ajax_similar_questions', name='ajax_similar_questions'), ) diff --git a/website/views.py b/website/views.py index e18a000..538d90e 100644 --- a/website/views.py +++ b/website/views.py @@ -155,3 +155,19 @@ def ajax_question_update(request): question.body = body question.save() return HttpResponse("saved") + +@csrf_exempt +def ajax_similar_questions(request): + if request.method == 'POST': + category = request.POST['category'] + tutorial = request.POST['tutorial'] + minute_range = request.POST['minute_range'] + second_range = request.POST['second_range'] + + # add more filtering when the forum grows + questions = Question.objects.filter(category=category).filter(tutorial=tutorial) + context = { + 'questions': questions + } + return render(request, 'website/templates/ajax-similar-questions.html', context); + -- cgit