summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--askbot/media/js/post.js19
-rw-r--r--askbot/media/js/utils.js13
2 files changed, 24 insertions, 8 deletions
diff --git a/askbot/media/js/post.js b/askbot/media/js/post.js
index fb6f6ef0..05e49387 100644
--- a/askbot/media/js/post.js
+++ b/askbot/media/js/post.js
@@ -1444,7 +1444,7 @@ EditCommentForm.prototype.attachTo = function(comment, mode){
this._submit_btn.html(gettext('save comment'));
}
this.getElement().show();
- this.enableButtons();
+ this.enableForm();
this.focus();
putCursorAtEnd(this._textarea);
};
@@ -1571,12 +1571,16 @@ EditCommentForm.prototype.createDom = function(){
this._textarea.val(this._text);
};
-EditCommentForm.prototype.enableButtons = function(){
+EditCommentForm.prototype.isEnabled = function() {
+ return (this._submit_btn.attr('disabled') !== 'disabled');//confusing! setters use boolean
+};
+
+EditCommentForm.prototype.enableForm = function() {
this._submit_btn.attr('disabled', false);
this._cancel_btn.attr('disabled', false);
};
-EditCommentForm.prototype.disableButtons = function(){
+EditCommentForm.prototype.disableForm = function() {
this._submit_btn.attr('disabled', true);
this._cancel_btn.attr('disabled', true);
};
@@ -1585,7 +1589,7 @@ EditCommentForm.prototype.reset = function(){
this._comment = null;
this._text = '';
this._textarea.val('');
- this.enableButtons();
+ this.enableForm();
};
EditCommentForm.prototype.confirmAbandon = function(){
@@ -1607,6 +1611,9 @@ EditCommentForm.prototype.getSaveHandler = function(){
var me = this;
return function(){
+ if (me.isEnabled() === false) {//prevent double submits
+ return false;
+ }
var text = me._textarea.val();
if (text.length < 10){
me.focus();
@@ -1627,7 +1634,7 @@ EditCommentForm.prototype.getSaveHandler = function(){
post_url = askbot['urls']['postComments'];
}
- me.disableButtons();
+ me.disableForm();
$.ajax({
type: "POST",
@@ -1650,7 +1657,7 @@ EditCommentForm.prototype.getSaveHandler = function(){
me._comment.getElement().show();
showMessage(me._comment.getElement(), xhr.responseText, 'after');
me.detach();
- me.enableButtons();
+ me.enableForm();
}
});
return false;
diff --git a/askbot/media/js/utils.js b/askbot/media/js/utils.js
index 2ae1510c..3c2a478b 100644
--- a/askbot/media/js/utils.js
+++ b/askbot/media/js/utils.js
@@ -384,6 +384,16 @@ OneShotForm.prototype.setSubmitButton = function(button) {
this._submitBtn = button;
};
+OneShotForm.prototype.enable = function() {
+ this._element.data('submitted', false);
+ this._submitBtn.removeClass('disabled');
+};
+
+OneShotForm.prototype.disable = function() {
+ this._element.data('submitted', true);
+ this._submitBtn.addClass('disabled');
+};
+
OneShotForm.prototype.decorate = function(element) {
this._element = element;
var me = this;
@@ -392,8 +402,7 @@ OneShotForm.prototype.decorate = function(element) {
if (element.data('submitted') === true) {
evt.preventDefault();
} else {
- element.data('submitted', true);
- button.addClass('disabled');
+ me.disable();
return true;
}
};