From 9f7c82e28316490ff479e31eb7b50db1e6ef1cd8 Mon Sep 17 00:00:00 2001 From: Jayaram Pai Date: Thu, 23 Jan 2014 23:03:03 +0530 Subject: added question edit. added question details change. added admin_user feature. --- static/website/css/main.css | 37 +++++++++- static/website/js/custom.js | 4 +- static/website/js/thread-user.js | 91 ++++++++++++++++++++++- static/website/templates/get-question.html | 111 ++++++++++++++++++++++++----- static/website/templates/index.html | 2 +- static/website/templates/new-question.html | 2 +- static/website/templates/search.html | 2 +- 7 files changed, 224 insertions(+), 25 deletions(-) (limited to 'static/website') diff --git a/static/website/css/main.css b/static/website/css/main.css index 2d629ac..ab5226f 100644 --- a/static/website/css/main.css +++ b/static/website/css/main.css @@ -9,6 +9,10 @@ .navbar-default { margin-bottom: 0; } +/* override nicEditor */ +#questionInstance { + background: #ffffff !important; +} /* main styles */ body { background: #fafafa; @@ -54,7 +58,7 @@ body { } #content .editable { padding: 15px 5px 15px 5px; - background: #F0F0F0; + background: #fafafa; } #content .question .title a{ padding: 0 0 7px 0; @@ -94,6 +98,12 @@ body { background: #f5f5f5; color: #424242; } +#question-details-edit { + position: relative; + top: 2px; + margin-top: 2px; + color: #43ac6a; +} #content .question .meta{ position: absolute; right: 0px; @@ -132,11 +142,34 @@ table .title a { .modify a.save { display: none; } - .vs { padding: 0px 5px !important; font-size: x-small; } +.hideme { + display: none; +} +.saving, .saved { + position: fixed; + z-index: 10; + left: 45%; + top: 45%; + padding: 5px 10px; + -webkit-border-radius: 5px; + -moz-border-radius: 5px; + -o-border-radius: 5px; + border-radius: 5px; + -webkit-box-shadow: 0px 0px 10px #cccccc; + -moz-box-shadow: 0px 0px 10px #cccccc; + -obox-shadow: 0px 0px 10px #cccccc; + box-shadow: 0px 0px 10px #cccccc; +} +.saving { + background: lightyellow; +} +.saved { + background: lightgreen; +} #content .reply { position: relative; border-bottom: 1px solid #f5f5f5; diff --git a/static/website/js/custom.js b/static/website/js/custom.js index da5839b..467ba9d 100644 --- a/static/website/js/custom.js +++ b/static/website/js/custom.js @@ -7,6 +7,8 @@ $(document).ready(function() { $category.change(function() { $("#similar-link").hide(); var category = $(this).val(); + /* see thread-user.js */ + $("#question-details-ok").show(); $.ajax({ url: "/ajax-tutorials/", type: "POST", @@ -59,7 +61,7 @@ $(document).ready(function() { $response = $(data); var similar_count= $response.find("#similar-count").text(); $("#similar-link").show().html(similar_count); - $(".modal-body").html(data); + $("#modal-body").html(data); } }); }); diff --git a/static/website/js/thread-user.js b/static/website/js/thread-user.js index 502f0ce..189d126 100644 --- a/static/website/js/thread-user.js +++ b/static/website/js/thread-user.js @@ -1,5 +1,4 @@ bkLib.onDomLoaded(function() { - var questionNicEditor = new nicEditor({ buttonList : ['fontSize','bold','italic','underline','strikeThrough','subscript','superscript','html','image', 'link'], iconsPath: "/static/website/js/nicEditorIcons.gif", @@ -13,12 +12,19 @@ $(document).ready(function() { * question edit section * set the jquery variables */ + $saving = $(".saving"); + $saved= $(".saved"); $question = $(".question"); $question_modify = $(".question .modify"); $question_edit = $(".question .modify .edit"); $question_save = $(".question .modify .save"); + $question_title = $(".title"); + $question_title_editable = $(".title-editable"); + $question_title_edit = $("#title-edit"); + $question_title_edit_input = $("#title-edit input"); $questionNicPanel = $("#questionNicPanel"); $questionInstance = $("#questionInstance"); + $question_details_edit = $("#question-details-edit"); /* make the question editable and show modify */ //$question.addClass("editable"); @@ -28,9 +34,20 @@ $(document).ready(function() { function modify(thisObj){ thisObj.hide(); thisObj.next().css("display", "block"); + + $question_title.hide(); + $question_title_edit_input.val($.trim($($question_title).text())); + $question_title_edit.show(); + $question_edit.hide(); + $question_save.show(); + $questionNicPanel.show(); $questionInstance.focus(); + $question_details_edit.show(); } + $question_title_editable.click(function(){ + modify($question_edit); + }); $question_edit.click(function () { modify($question_edit); }); @@ -38,30 +55,96 @@ $(document).ready(function() { modify($question_edit); }); $question_save.click(function () { + $saving.show(); $(this).hide(); + $question_title.text($question_title_edit_input.val()); + $question_title_edit.hide(); + $question_title.show(); $questionNicPanel.hide(); + $question_details_edit.hide(); $(this).prev().css("display", "block"); /* make the ajax call */ //var id_length = $question_save.attr("id").length; //var question_id = parseInt($question_save.attr("id").substr(id_length-1)); var question_id = parseInt($question_save.data("qid")); - console.log(question_id); + var question_title = $question_title.text(); var question_body = $questionInstance.html(); $.ajax({ url: "/ajax-question-update/", data:{ question_id: question_id, + question_title: question_title, question_body: question_body, }, type: "POST", dataType: "html", success: function(data){ console.log(data); + $saving.hide(); + $saved.show(); + $saved.fadeOut("slow"); } }); }); + + /* + * question details edit section + * handle everything in the popup + */ + $question_details_edit = $("#question-details-edit"); + $question_details_ok = $("#question-details-ok"); + $question_category = $('#id_category'); + $question_tutorial = $('#id_tutorial'); + $question_minute_range = $('#id_minute_range'); + $question_second_range = $('#id_second_range'); + + $question_details_ok.click(function() { + console.log($(this).data("qid")); + var category = $question_category.val(); + var tutorial = $question_tutorial.val(); + var minute_range = $question_minute_range.val(); + var second_range = $question_second_range.val(); + $.ajax({ + url: "/ajax-details-update/", + data: { + qid: $(this).data("qid"), + category: category, + tutorial: tutorial, + minute_range: minute_range, + second_range: second_range + }, + type: "POST", + success: function(data){ + if(category != 'None') { + $(".category small a").html(category); + $(".category").show() + } else { + $(".category").hide() + } + if(tutorial!= 'None') { + $(".tutorial small a").html(tutorial); + $(".tutorial").show() + } else { + $(".tutorial").hide() + } + if(minute_range!= 'None') { + $(".minute_range small a").html(minute_range); + $(".minute_range").show() + } else { + $(".minute_range").hide() + } + if(second_range != 'None') { + $(".second_range small a").html(second_range); + $(".second_range").show() + } else { + $(".second_range").hide() + } + console.log(data); + } + }); + }); /* * reply edit section * set the dom variables @@ -89,6 +172,7 @@ $(document).ready(function() { }); $reply_save.click(function() { + $saving.show(); var target = $(this).data("target"); replyNicEditor.removeInstance(target); $replyPanelWrapper.hide(); @@ -108,6 +192,9 @@ $(document).ready(function() { }, success: function(data) { console.log(data); + $saving.hide(); + $saved.show(); + $saved.fadeOut("slow"); } }); }); diff --git a/static/website/templates/get-question.html b/static/website/templates/get-question.html index 8c242d6..19c0283 100644 --- a/static/website/templates/get-question.html +++ b/static/website/templates/get-question.html @@ -1,14 +1,26 @@ {% extends 'website/templates/base.html' %} {% load static %} {% load widget_tweaks %} + +{% load permission_tags %} + {% block content %} -
-
- {{ question.title }} +saving . . . +saved + +
+
+ {{ question.title }} +
+ +
+
Title
+ +
Question
-
+
{{ question.body|safe }}

@@ -29,34 +41,38 @@ - + {{ question.minute_range }} min - - + + {{ question.second_range }} sec - + + + + + - {% ifequal question.uid|stringformat:'s' user.id|stringformat:'s' %} + {% if user|can_edit:question %} Edit Save - {% endifequal %} + {% endif %} - - {{ question.date_created|date:"y-d-m" }}, {{ question.date_created|time }} - + + {{ question.date_created|date:"y-d-m" }}, {{ question.date_created|time }} + @@ -72,7 +88,7 @@
{% for reply in replies %} -
+
{{ reply.body|safe }} @@ -82,12 +98,12 @@ {{ reply.user }} - {% ifequal reply.uid|stringformat:'s' user.id|stringformat:'s' %} + {% if user|can_edit:reply %} Edit Save - {% endifequal %} + {% endif %}
{% endfor %} @@ -104,7 +120,7 @@
{% endwith %} - + {% else %}

@@ -112,6 +128,66 @@

{% endif %} + + + + {% endblock %} diff --git a/static/website/templates/index.html b/static/website/templates/index.html index 1823f4e..47ca53c 100644 --- a/static/website/templates/index.html +++ b/static/website/templates/index.html @@ -2,7 +2,7 @@ {% block content %} {% load count_tags %}

Recent Questions

- +
diff --git a/static/website/templates/new-question.html b/static/website/templates/new-question.html index 60efa9b..63ae19a 100644 --- a/static/website/templates/new-question.html +++ b/static/website/templates/new-question.html @@ -62,7 +62,7 @@ - diff --git a/static/website/templates/search.html b/static/website/templates/search.html index 8c96acb..3ffc871 100644 --- a/static/website/templates/search.html +++ b/static/website/templates/search.html @@ -5,7 +5,7 @@ -- cgit
FOSS Tutorial Min