summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEvgeny Fadeev <evgeny.fadeev@gmail.com>2010-11-15 00:02:26 -0500
committerEvgeny Fadeev <evgeny.fadeev@gmail.com>2010-11-15 00:02:26 -0500
commita4fa9484589747b1e142e69f43ba087d6b1797ae (patch)
treedee9d668851e4cab7fc3eab2dc9c4ab006fec0a3
parentbeee0be8e95fc6be5bc65749572ae4fbc25e682d (diff)
downloadaskbot-a4fa9484589747b1e142e69f43ba087d6b1797ae.tar.gz
askbot-a4fa9484589747b1e142e69f43ba087d6b1797ae.tar.bz2
askbot-a4fa9484589747b1e142e69f43ba087d6b1797ae.zip
some more progress with comments
-rw-r--r--askbot/skins/default/media/js/i18n.js1
-rw-r--r--askbot/skins/default/media/js/post.js236
-rwxr-xr-xaskbot/skins/default/media/style/style.css53
-rw-r--r--askbot/skins/default/templates/answer_edit.html2
-rw-r--r--askbot/skins/default/templates/ask.html2
-rw-r--r--askbot/skins/default/templates/base.html7
-rw-r--r--askbot/skins/default/templates/macros.html77
-rw-r--r--askbot/skins/default/templates/question.html3
-rw-r--r--askbot/skins/default/templates/question_edit.html2
-rw-r--r--askbot/urls.py10
-rw-r--r--askbot/views/writers.py14
11 files changed, 252 insertions, 155 deletions
diff --git a/askbot/skins/default/media/js/i18n.js b/askbot/skins/default/media/js/i18n.js
index 22edd5bd..d326bdd7 100644
--- a/askbot/skins/default/media/js/i18n.js
+++ b/askbot/skins/default/media/js/i18n.js
@@ -135,6 +135,7 @@ var i18nEn = {
'cannot flag message as offensive twice':'cannot flag message as offensive twice ',
'edit':'edit',
'click to edit this comment':'click to edit this comment',
+ 'confirm abandon comment':'Are you sure you do not want to post this comment?'
};
var i18nFi = {
diff --git a/askbot/skins/default/media/js/post.js b/askbot/skins/default/media/js/post.js
index 90680c01..71c525a9 100644
--- a/askbot/skins/default/media/js/post.js
+++ b/askbot/skins/default/media/js/post.js
@@ -41,21 +41,21 @@ function removeLoader() {
$("img.ajax-loader").remove();
}
-function setSubmitButtonDisabled(formSelector, isDisabled) {
- $(formSelector).find("input[type='submit']").attr("disabled", isDisabled ? "true" : "");
+function setSubmitButtonDisabled(form, isDisabled) {
+ form.find("input[type='submit']").attr("disabled", isDisabled ? "true" : "");
}
-function enableSubmitButton(formSelector) {
- setSubmitButtonDisabled(formSelector, false);
+function enableSubmitButton(form) {
+ setSubmitButtonDisabled(form, false);
}
-function disableSubmitButton(formSelector) {
- setSubmitButtonDisabled(formSelector, true);
+function disableSubmitButton(form) {
+ setSubmitButtonDisabled(form, true);
}
-function setupFormValidation(formSelector, validationRules, validationMessages, onSubmitCallback) {
- enableSubmitButton(formSelector);
- $(formSelector).validate({
+function setupFormValidation(form, validationRules, validationMessages, onSubmitCallback) {
+ enableSubmitButton(form);
+ form.validate({
debug: true,
rules: (validationRules ? validationRules : {}),
messages: (validationMessages ? validationMessages : {}),
@@ -74,7 +74,7 @@ function setupFormValidation(formSelector, validationRules, validationMessages,
span.replaceWith(error);
},
submitHandler: function(form) {
- disableSubmitButton(formSelector);
+ disableSubmitButton(form);
if (onSubmitCallback){
onSubmitCallback();
@@ -888,22 +888,33 @@ DeleteIcon.prototype.createDom = function(){
var EditCommentForm = function(){
WrappedElement.call(this);
this._comment = null;
- this._text = '';
+ this._comment_widget = null;
this._element = null;
+ this._text = '';
};
inherits(EditCommentForm, WrappedElement);
EditCommentForm.prototype.setComment = function(comment, text){
- self._comment = comment;
- self._text = text || '';
+};
+
+EditCommentForm.prototype.attachTo = function(comment){
+ var form = editCommentForm.setComment(comment);
+ this._comment = comment;
+ this._comment_widget = comment.getContainerWidget();
+ this._text = comment.getText();
+ comment.getElement().after(this.getElement());
+ comment.getElement().hide();
+ this._comment_widget.hideButton();
+ this.getElement().show();
+ this._textarea.focus();
};
EditCommentForm.prototype.makeCounterUpdater = function(){
//returns event handler
var counter = this._text_counter;
var handler = function(){
- var text_area = $(this);
- var length = text_area.val() ? textarea.val().length : 0;
+ var textarea = $(this);
+ var length = textarea.val() ? textarea.val().length : 0;
var length1 = maxCommentLength - 100;
if (length1 < 0){
length1 = Math.round(0.7*maxCommentLength);
@@ -949,9 +960,8 @@ EditCommentForm.prototype.createDom = function(){
.focus(update_counter)
.keyup(update_counter)
- this.setId(post_id);
setupFormValidation(
- "#" + this.getId(),
+ this._element,
{ comment: { required: true, minlength: 10} },
'',
this.save
@@ -959,7 +969,7 @@ EditCommentForm.prototype.createDom = function(){
};
EditCommentForm.prototype.activate = function(){
- this._text_area.focus();
+ this._textarea.focus();
};
EditCommentForm.prototype.enableButtons = function(){
@@ -980,14 +990,32 @@ EditCommentForm.prototype.set_text = function(text){
this._textarea.html(text);
};
-EditCommentForm.prototype.userConfirmAbandon = function(){
- return confirm('want to abandon this comment?');
+EditCommentForm.prototype.reset = function(){
+ this._comment = null;
+ this._textarea.val('');
+};
+
+EditCommentForm.prototype.isFree = function(){
+ if (this._comment){
+ if (this._comment.isBlank()){
+ this._comment.dispose();
+ return true;
+ }
+ this._textarea.focus();
+ if (confirm($.i18n._('confirm abandon comment'))){
+ this._comment.getElement().show();
+ this.reset();
+ return true;
+ }
+ return false;
+ }
+ else {
+ return true;
+ }
};
-EditCommentForm.prototype.setId = function(post_id){
- this._parent_post_id = post_id;
- var id = 'form-comments-' + this._post_type + '-' + post_id;
- this._element.attr('id', id);
+EditCommentForm.prototype.userConfirmAbandon = function(){
+ return confirm('want to abandon this comment?');
};
EditCommentForm.prototype.getCBoxElement = function(){
@@ -1043,10 +1071,12 @@ EditCommentForm.prototype.save = function(){
//a single instance to reuse
var editCommentForm = new EditCommentForm();
-var Comment = function(data){
+var Comment = function(widget, data){
WrappedElement.call(this);
+ this._container_widget = widget;
this._data = data;
- this._blank = true;
+ this._blank = true;//set to false by setContent
+ this._element = null;
this._delete_prompt = $.i18n._('delete this comment');
if (data && data['is_deletable']){
this._deletable = data['is_deletable'];
@@ -1060,11 +1090,11 @@ var Comment = function(data){
inherits(Comment, WrappedElement);
Comment.prototype.decorate = function(element){
- this._element = element;
- var parent_type = element.parent().attr('id').split('-')[2];
- var comment_id = element.attr('id').replace('comment-','');
+ this._element = $(element);
+ var parent_type = this._element.parent().parent().attr('id').split('-')[2];
+ var comment_id = this._element.attr('id').replace('comment-','');
this._data = {id: comment_id};
- var delete_img = element.find('img.delete-icon');
+ var delete_img = this._element.find('img.delete-icon');
if (delete_img.length > 0){
this._deletable = true;
this._editable = true;
@@ -1079,22 +1109,30 @@ Comment.prototype.decorate = function(element){
}
};
+Comment.prototype.isBlank = function(){
+ return this._blank;
+};
+
+Comment.prototype.getContainerWidget = function(){
+ return this._container_widget;
+};
+
Comment.prototype.setContent = function(data){
this._data = data;
this._element.html('');
- this._element.attr('class', 'comment').css('display:none');
+ this._element.attr('class', 'comment');
this._element.attr('id', 'comment-' + this._data['id']);
this._element.append(data['text']);
this._element.append(' - ');
- this._user_link = $('<a></a>').attr('class', 'comment-user');
+ this._user_link = $('<a></a>').attr('class', 'author');
this._user_link.attr('href', this._data['user_url']);
this._user_link.html(this._data['user_display_name']);
this._element.append(this._user_link);
this._element.append(' (');
- this._comment_age = $('<span></span>');
+ this._comment_age = $('<span class="age"></span>');
this._comment_age.html(this._data['comment_age']);
this._element.append(this._comment_age);
this._element.append(')');
@@ -1106,15 +1144,20 @@ Comment.prototype.setContent = function(data){
if (this._editable){
this._edit_link = new EditLink(this.getEditHandler());
this._element.append(this._edit_link.getElement());
- this._element.mouseover(function(){this._edit_link.getElement().show()});
- this._element.mouseout(function(){this._edit_link.getElement().hide()});
+ var edit_link = this._edit_link;
+ this._element.mouseover(function(){edit_link.getElement().show()});
+ this._element.mouseout(function(){edit_link.getElement().hide()});
}
this._blank = false;
};
Comment.prototype.dispose = function(){
- this._user_link.remove();
- this._comment_age.remove();
+ if (this._user_link){
+ this._user_link.remove();
+ }
+ if (this._comment_age){
+ this._comment_age.remove();
+ }
if (this._delete_icon){
this._delete_icon.dispose();
}
@@ -1145,21 +1188,24 @@ Comment.prototype.loadText = function(on_load_handler){
});
};
+Comment.prototype.getText = function(){
+ if (!this.isBlank()){
+ if ('text' in this._data){
+ return this._data['text'];
+ }
+ }
+ return '';
+}
+
Comment.prototype.getEditHandler = function(){
var comment_id = this._data['id'];
var parent_post_id = this._data['post_id'];
var comment = this;
return function(){
comment.loadText(
- function(text){
+ function(){
if (editCommentForm.isFree()){
- editCommentForm.setComment(comment, text);
- comment.getElement().after(editCommentForm.getElement());
- comment.getElement().hide();
- editCommentForm.activate();
- }
- else {
- editCommentForm.getElement().focus();
+ editCommentForm.attachTo(comment);
}
}
);
@@ -1194,50 +1240,81 @@ var PostCommentsWidget = function(){
};
inherits(PostCommentsWidget, WrappedElement);
-var PostCommentsWidget.prototype.decorate = function(element){
- var can_post_input = element.find('[id^="can-post-comments"]') + objectType + '-' + id);
- this._user_can_post = (can_post_input.val().toLowerCase() == 'true');
- this._activate_button = element.find('a[id^="comments-link"]');
+PostCommentsWidget.prototype.decorate = function(element){
+ var element = $(element);
+ this._element = element;
- if (this.user_can_post == false){
- setupButtonEventHandlers(this._activate_button, this.getDenyHandler());
+ var widget_id = element.attr('id');
+ var id_bits = widget_id.split('-');
+ this._post_id = id_bits[3];
+ this._post_type = id_bits[2];
+ this._is_truncated = askbot['data'][widget_id]['truncated'];
+ this._user_can_post = askbot['data'][widget_id]['can_post'];
+
+ //see if user can comment here
+ var controls = element.find('.controls');
+ this._activate_button = controls.find('.button');
+
+ if (this._user_can_post == false){
+ setupButtonEventHandlers(
+ this._activate_button,
+ this.getDenyHandler()
+ );
+ }
+ else {
+ setupButtonEventHandlers(
+ this._activate_button,
+ this.getActivateHandler()
+ );
}
- this._element = element;
- var id = element.attr('id');
- this._post_type = id.split('-')[2];
- setupButtonEventHandlers(this._activate_button, this.getActivateHandler());
-
- this._cbox = element.find('[id^="comments-container"]');
+ this._cbox = element.find('.content');
var comments = new Array();
- this._cbox.each(function(index, element)){
- var comment = new Comment();
+ var me = this;
+ this._cbox.children().each(function(index, element){
+ var comment = new Comment(me);
comments.push(comment)
comment.decorate(element);
});
this._comments = comments;
};
-var PostCommentsWidget.prototype.getActivateHandler = function(){
+PostCommentsWidget.prototype.hideButton = function(){
+ this._activate_button.hide();
+};
+
+PostCommentsWidget.prototype.showButton = function(){
+ this._activate_button.show();
+}
+
+PostCommentsWidget.prototype.startNewComment = function(){
+ var comment = new Comment(this);
+ this._cbox.append(comment.getElement());
+ editCommentForm.attachTo(comment);
+};
+
+PostCommentsWidget.prototype.needToReload = function(){
+ return this._is_truncated;
+};
+
+PostCommentsWidget.prototype.getActivateHandler = function(){
var me = this;
return function() {
if (editCommentForm.isFree()){
- me.reloadAllComments(function(json){
- me.reRenderComments(json);
- var comment = new Comment();
- var form = editCommentForm.setComment(comment);
- me._cbox.append(form.getElement());
- me._activate_button.hide();
- editCommentForm.getElement().focus();
- });
- }
- else {
- editCommentForm.getElement().focus();
+ if (me.needToReload()){
+ me.reloadAllComments(function(json){
+ me.reRenderComments(json);
+ me.startNewComment();
+ });
+ }
+ else {
+ me.startNewComment();
+ }
}
};
};
-var PostCommentsWidget.prototype.getDenyHandler = function(){
+PostCommentsWidget.prototype.getDenyHandler = function(){
var me = this;
return function(){
if (me._denied == false){
@@ -1247,14 +1324,14 @@ var PostCommentsWidget.prototype.getDenyHandler = function(){
'<a href="' + scriptUrl + $.i18n._('faq/') + '" class="comment-user">' +
$.i18n._('please see') + 'faq</a></span>'
);
- me._cbox.append(denial);
+ me._controls.append(denial);
}
me._denied = true;
};
};
-var PostCommentsWidget.prototype.reloadAllComments = function(callback){
+PostCommentsWidget.prototype.reloadAllComments = function(callback){
var post_data = {post_id: this._post_id, post_type: this._post_type};
$.ajax({
type: "GET",
@@ -1265,15 +1342,16 @@ var PostCommentsWidget.prototype.reloadAllComments = function(callback){
});
};
-var PostCommentsWidget.prototype.reRenderComments = function(json){
+PostCommentsWidget.prototype.reRenderComments = function(json){
$.each(this._comments, function(i, item){
item.dispose();
});
this._comments = new Array();
+ var me = this;
$.each(json, function(i, item){
- var comment = new Comment(item);
- this._comments.push(comment);
- this._element.prepend(comment.getElement());
+ var comment = new Comment(me, item);
+ me._cbox.append(comment.getElement());
+ me._comments.push(comment);
});
};
@@ -1321,7 +1399,7 @@ var socialSharing = function(){
}();
$(document).ready(function() {
- $('id^=comments-container-').each(function(index, element){
+ $('[id^="comments-for-"]').each(function(index, element){
var comments = new PostCommentsWidget();
comments.decorate(element);
});
diff --git a/askbot/skins/default/media/style/style.css b/askbot/skins/default/media/style/style.css
index 812ec8fd..3a7dc684 100755
--- a/askbot/skins/default/media/style/style.css
+++ b/askbot/skins/default/media/style/style.css
@@ -1304,31 +1304,37 @@ a:hover.medal {
font-size: 90%;
}
-div.comments {
- line-height: 150%;
- padding: 10px 0;
-}
-
-div.post-comments {
+.comments div.controls {
clear: both;
background: url(../images/gray-up-arrow-h18px.png) no-repeat;
width: 100%;
padding-left: 12px;
- margin: 3px 0 10px 0;
+ margin: 3px 0 20px 0;
}
-form.post-comments textarea {
+.comments textarea {
height: 6em;
margin-bottom: 4px;
}
-form.post-comments input {
+.comments input {
margin-left: 10px;
margin-top: 1px;
vertical-align: top;
width: 100px;
}
+.comments .controls a {
+ color: #888888;
+ padding: 0 3px 2px;
+}
+
+.comments .controls a:hover {
+ background-color: #777777;
+ color: white;
+ text-decoration: none;
+}
+
span.text-counter {
margin-right: 20px;
font-size: 11px;
@@ -1344,16 +1350,11 @@ p.form-item {
margin: 0px;
}
-div.comments-container, div.comments-container-accepted, div.comments-container-owner, div.comments-container-deleted {
+div.comments {
padding: 0;
}
-.post-comments a {
- color: #888888;
- padding: 0 3px 2px;
-}
-
-a.comments-link, a.comments-link-accepted, a.comments-link-owner, a.comments-link-deleted {
+.comments .button {
color: black;
font-size: 11px;
background: #eeeeee;
@@ -1361,25 +1362,19 @@ a.comments-link, a.comments-link-accepted, a.comments-link-owner, a.comments-lin
cursor: pointer;
}
-.post-comments a:hover {
- background-color: #777777;
- color: white;
- text-decoration: none;
-}
-
.comment a {
background-color: inherit;
color: blue;
padding: 0;
}
-a.comment-user, a.comment-user:hover {
+.comment a.author, a.author:hover {
background-color: inherit;
color: blue;
padding: 0;
}
-a.comment-user:hover {
+.comment a.author:hover {
text-decoration: underline;
}
@@ -1408,11 +1403,11 @@ a.comment-user:hover {
border-bottom-color: #9BD59B;
}
-.accepted-answer .comments-link {
+.accepted-answer .comments .button {
background-color: #CCFFBF;
}
-.accepted-answer .comments-container {
+.accepted-answer .comments {
background-color: #CCFFBF;
}
@@ -1435,11 +1430,11 @@ a.comment-user:hover {
background: #E9E9FF;
}
-.answered-by-owner .comments-link {
+.answered-by-owner .comments .button {
background-color: #E6ECFF;
}
-.answered-by-owner .comments-container {
+.answered-by-owner .comments {
background-color: #E6ECFF;
}
@@ -2570,7 +2565,7 @@ ul.form-horizontal-rows li input {
margin: 4px 8px 0 0;
}
-.comments-container {
+.comments {
clear: both;
}
diff --git a/askbot/skins/default/templates/answer_edit.html b/askbot/skins/default/templates/answer_edit.html
index b263c03f..ab2f2aac 100644
--- a/askbot/skins/default/templates/answer_edit.html
+++ b/askbot/skins/default/templates/answer_edit.html
@@ -65,7 +65,7 @@
$('#pre-collapse').text(txt);
});
- setupFormValidation("#fmedit", CPValidator.getQuestionFormRules(), CPValidator.getQuestionFormMessages());
+ setupFormValidation($("#fmedit"), CPValidator.getQuestionFormRules(), CPValidator.getQuestionFormMessages());
$('#id_revision').unbind().change(function(){
$("#select_revision").click();
diff --git a/askbot/skins/default/templates/ask.html b/askbot/skins/default/templates/ask.html
index 52d130e5..0bdb5ed1 100644
--- a/askbot/skins/default/templates/ask.html
+++ b/askbot/skins/default/templates/ask.html
@@ -57,7 +57,7 @@
});
- setupFormValidation("#fmask", CPValidator.getQuestionFormRules(), CPValidator.getQuestionFormMessages());
+ setupFormValidation($("#fmask"), CPValidator.getQuestionFormRules(), CPValidator.getQuestionFormMessages());
lanai.highlightSyntax();
});
</script>
diff --git a/askbot/skins/default/templates/base.html b/askbot/skins/default/templates/base.html
index 24fbfdcd..4d23cc60 100644
--- a/askbot/skins/default/templates/base.html
+++ b/askbot/skins/default/templates/base.html
@@ -20,6 +20,11 @@
body { margin-top:2.4em; }
</style>
{% endif %}
+ <script type="text/javascript">
+ var askbot = {};
+ askbot['data'] = {};
+ askbot['urls'] = {};
+ </script>
{% block forejs %}
{% endblock %}
</head>
@@ -42,8 +47,6 @@
var scriptUrl = '/{{settings.ASKBOT_URL}}'
var askbotSkin = '{{settings.ASKBOT_DEFAULT_SKIN}}';
var enableMathJax = {% if settings.ENABLE_MATHJAX %}true{% else %}false{% endif %};
- var askbot = askbot || {};
- askbot['data'] = askbot['data'] || {};
{% if request.user.is_authenticated() %}
askbot['data']['userIsAuthenticated'] = true;
askbot['data']['userId'] = {{request.user.id}};
diff --git a/askbot/skins/default/templates/macros.html b/askbot/skins/default/templates/macros.html
index ac93d28a..0fa3dd4f 100644
--- a/askbot/skins/default/templates/macros.html
+++ b/askbot/skins/default/templates/macros.html
@@ -257,43 +257,54 @@ poor design of the data or methods on data objects #}
{%- macro post_comments_widget(post=None, user=None, max_comments=None) -%}
{% set comments = post.get_comments()[:max_comments] %}
{% spaceless %}
- <div class="comments-container" id="comments-container-{{post.post_type}}-{{post.id}}">
- {% for comment in comments %}
- <div class="comment" id="comment-{{comment.id}}">
- {{comment.html}}
- - <a class="comment-user" href="{{comment.user.get_profile_url()}}">{{comment.user.username}}</a>
- <span class="comment-age">&nbsp;({{comment.added_at|diff_date}})</span>
- {% if user|can_delete_comment(comment) %}
- <img class="delete-icon"
- src="{{"/images/close-small.png"|media}}"
- title="{% trans %}delete this comment{% endtrans %}"/>
+ {% set widget_id = 'comments-for-' + post.post_type + '-' + post.id %}
+ <div class="comments" id="{{widget_id}}">
+ <div class="content">
+ {% for comment in comments %}
+ <div class="comment" id="comment-{{comment.id}}">
+ {{comment.html}} -
+ <a
+ class="author"
+ href="{{comment.user.get_profile_url()}}"
+ >{{comment.user.username}}</a>
+ <span class="age">&nbsp;({{comment.added_at|diff_date}})</span>
+ {% if user|can_delete_comment(comment) %}
+ <img class="delete-icon"
+ src="{{"/images/close-small.png"|media}}"
+ title="{% trans %}delete this comment{% endtrans %}"
+ />
+ {% endif %}
+ </div>
+ {% endfor %}
+ </div>
+ <div class="controls">
+ {% set can_post = user|can_post_comment(post) %}
+ <script type="text/javascript">
+ askbot['data']['{{widget_id}}'] = {
+ can_post: {% if can_post %}true{% else %}false{% endif %},
+ truncated: {% if post.comment_count > max_comments %}true{% else %}false{% endif %}
+ };
+ </script>
+ <input type="hidden" value="{{ can_post }}" />
+ {% if can_post or post.comment_count > max_comments %}
+ <a class="button">
+ {% if can_post %}
+ {% trans %}add comment{% endtrans %}
+ {% endif %}
+ {% if post.comment_count > max_comments %}
+ {% set remaining_comments = post.comment_count - max_comments %}
+ {% if can_post %}/
+ {% trans counter=remaining_comments %}see <strong>{{counter}}</strong> more{% pluralize %}see <strong>{{counter}}</strong> more{% endtrans %}
+ {% else %}
+ {% trans counter=remaining_comments %}see <strong>{{counter}}</strong> more comment{% pluralize %}see <strong>{{counter}}</strong> more comments
+ {% endtrans %}
+ {% endif %}
+ {% endif %}
+ </a>
{% endif %}
</div>
- {% endfor %}
</div>
{% endspaceless %}
- <div class="post-comments" style="margin-bottom:20px">
- <input
- id="can-post-comments-{{post.post_type}}-{{post.id}}"
- type="hidden"
- value="{{ user|can_post_comment(post) }}"
- />
- {% if user|can_post_comment(post) or post.comment_count > max_comments %}
- <a id="comments-link-{{post.post_type}}-{{post.id}}" class="comments-link">
- {% if user|can_post_comment(post) %}
- {% trans %}add comment{% endtrans %}
- {% endif %}
- {% if post.comment_count > max_comments %}
- {% set remaining_comments = post.comment_count - max_comments %}
- {% if user|can_post_comment(question) %}/
- {% trans counter=remaining_comments %}see <strong>{{counter}}</strong> more{% pluralize %}see <strong>{{counter}}</strong> more{% endtrans %}
- {% else %}
- {% trans counter=remaining_comments %}see <strong>{{counter}}</strong> more comment{% pluralize %}see <strong>{{counter}}</strong> more comments
- {% endtrans %}
- {% endif %}
- {% endif %}</a>
- {% endif %}
- </div>
{%- endmacro -%}
{%- macro reversible_sort_button(button_sort_criterium=None, asc_tooltip=None, asc_label=None,
diff --git a/askbot/skins/default/templates/question.html b/askbot/skins/default/templates/question.html
index d5b188ed..2af509cd 100644
--- a/askbot/skins/default/templates/question.html
+++ b/askbot/skins/default/templates/question.html
@@ -413,6 +413,7 @@
var codeFriendlyMarkdown = false;
{% endif %}
var maxCommentLength = {{settings.MAX_COMMENT_LENGTH}};
+ askbot['urls']['post_comments'] = '{% url post_comments %}';
</script>
<script type='text/javascript' src='{{"/js/wmd/showdown.js"|media}}'></script>
<script type='text/javascript' src='{{"/js/wmd/wmd.js"|media}}'></script>
@@ -453,7 +454,7 @@
$('#previewer').toggle();
$('#pre-collapse').text(txt);
});
- setupFormValidation("#fmanswer", CPValidator.getQuestionFormRules(), CPValidator.getQuestionFormMessages());
+ setupFormValidation($("#fmanswer"), CPValidator.getQuestionFormRules(), CPValidator.getQuestionFormMessages());
}
</script>
{% include "editor_data.html" %}
diff --git a/askbot/skins/default/templates/question_edit.html b/askbot/skins/default/templates/question_edit.html
index 5729dc02..ef2ecb82 100644
--- a/askbot/skins/default/templates/question_edit.html
+++ b/askbot/skins/default/templates/question_edit.html
@@ -89,7 +89,7 @@
});
setupFormValidation(
- "#fmedit",
+ $("#fmedit"),
CPValidator.getQuestionFormRules(),
CPValidator.getQuestionFormMessages()
);
diff --git a/askbot/urls.py b/askbot/urls.py
index 3decdfdb..5502743a 100644
--- a/askbot/urls.py
+++ b/askbot/urls.py
@@ -116,11 +116,11 @@ urlpatterns = patterns('',
app.writers.delete_comment,
name='delete_comment'
),
- url(
- r'^comment/get_text/$',
- app.commands.get_comment_text,
- name='get_comment_text'
- ),
+ #url(
+ # r'^comment/get_text/$',
+ # app.commands.get_comment_text,
+ # name='get_comment_text'
+ #),
#place general question item in the end of other operations
url(
r'^%s(?P<id>\d+)/' % _('question/'),
diff --git a/askbot/views/writers.py b/askbot/views/writers.py
index 42ac4ca3..6d304e45 100644
--- a/askbot/views/writers.py
+++ b/askbot/views/writers.py
@@ -425,19 +425,27 @@ def __generate_comments_json(obj, user):#non-view generates json data for the po
return HttpResponse(data, mimetype="application/json")
def question_comments(request, id):#ajax handler for loading comments to question
- question = get_object_or_404(models.Question, id=id)
user = request.user
return __comments(request, question)
def answer_comments(request, id):#ajax handler for loading comments on answer
- answer = get_object_or_404(models.Answer, id=id)
user = request.user
return __comments(request, answer)
-def __comments(request, obj):#non-view generic ajax handler to load comments to an object
+def post_comments(request):#non-view generic ajax handler to load comments to an object
# only support get post comments by ajax now
user = request.user
if request.is_ajax():
+ post_type = request.REQUEST['post_type']
+ id = request.REQUEST['post_id']
+ if post_type == 'question':
+ post_model = models.Question
+ elif post_type == 'answer':
+ post_model = models.Answer
+ else:
+ raise Http404
+
+ obj = get_object_or_404(post_model, id=id)
if request.method == "GET":
response = __generate_comments_json(obj, user)
elif request.method == "POST":