Fix for ticket #2910: fix inconsistencies in notice posting response display that broke help command, could be generally wonky
Previous code was importing nodes from the XHR result into current document, then pulling text content of what might be the right element, then concat'ing that straight into HTML. Eww! Now pulling the text content straight from the XHR result -- same element that we check for existence of -- and using jQuery's own text() to do the getting and setting of text. Also note that some browsers might have been pulling HTML instead of text, or other funkiness.
This commit is contained in:
parent
f901c25012
commit
532178e3ee
53
js/util.js
53
js/util.js
|
@ -315,6 +315,29 @@ var SN = { // StatusNet
|
|||
FormNoticeXHR: function(form) {
|
||||
SN.C.I.NoticeDataGeo = {};
|
||||
form.append('<input type="hidden" name="ajax" value="1"/>');
|
||||
|
||||
/**
|
||||
* Show a response feedback bit under the new-notice dialog.
|
||||
*
|
||||
* @param {String} cls: CSS class name to use ('error' or 'success')
|
||||
* @param {String} text
|
||||
* @access private
|
||||
*/
|
||||
var showFeedback = function(cls, text) {
|
||||
form.append(
|
||||
$('<p class="form_response"></p>')
|
||||
.addClass(cls)
|
||||
.text(text)
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Hide the previous response feedback, if any.
|
||||
*/
|
||||
var removeFeedback = function() {
|
||||
form.find('.form_response').remove();
|
||||
};
|
||||
|
||||
form.ajaxForm({
|
||||
dataType: 'xml',
|
||||
timeout: '60000',
|
||||
|
@ -361,9 +384,10 @@ var SN = { // StatusNet
|
|||
.find('#'+SN.C.S.NoticeActionSubmit)
|
||||
.removeClass(SN.C.S.Disabled)
|
||||
.removeAttr(SN.C.S.Disabled, SN.C.S.Disabled);
|
||||
form.find('.form_response').remove();
|
||||
removeFeedback();
|
||||
if (textStatus == 'timeout') {
|
||||
form.append('<p class="form_response error">Sorry! We had trouble sending your notice. The servers are overloaded. Please try again, and contact the site administrator if this problem persists.</p>');
|
||||
// @fixme i18n
|
||||
showFeedback('error', 'Sorry! We had trouble sending your notice. The servers are overloaded. Please try again, and contact the site administrator if this problem persists.');
|
||||
}
|
||||
else {
|
||||
var response = SN.U.GetResponseXML(xhr);
|
||||
|
@ -378,28 +402,27 @@ var SN = { // StatusNet
|
|||
SN.U.FormNoticeEnhancements(form);
|
||||
}
|
||||
else {
|
||||
form.append('<p class="form_response error">(Sorry! We had trouble sending your notice ('+xhr.status+' '+xhr.statusText+'). Please report the problem to the site administrator if this happens again.</p>');
|
||||
// @fixme i18n
|
||||
showFeedback('error', '(Sorry! We had trouble sending your notice ('+xhr.status+' '+xhr.statusText+'). Please report the problem to the site administrator if this happens again.');
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
success: function(data, textStatus) {
|
||||
form.find('.form_response').remove();
|
||||
var result;
|
||||
if ($('#'+SN.C.S.Error, data).length > 0) {
|
||||
result = document._importNode($('p', data)[0], true);
|
||||
result = result.textContent || result.innerHTML;
|
||||
form.append('<p class="form_response error">'+result+'</p>');
|
||||
removeFeedback();
|
||||
var errorResult = $('#'+SN.C.S.Error, data);
|
||||
if (errorResult.length > 0) {
|
||||
showFeedback('error', errorResult.text());
|
||||
}
|
||||
else {
|
||||
if($('body')[0].id == 'bookmarklet') {
|
||||
// @fixme self is not referenced anywhere?
|
||||
self.close();
|
||||
}
|
||||
|
||||
if ($('#'+SN.C.S.CommandResult, data).length > 0) {
|
||||
result = document._importNode($('p', data)[0], true);
|
||||
result = result.textContent || result.innerHTML;
|
||||
form.append('<p class="form_response success">'+result+'</p>');
|
||||
var commandResult = $('#'+SN.C.S.CommandResult, data);
|
||||
if (commandResult.length > 0) {
|
||||
showFeedback('success', commandResult.text());
|
||||
}
|
||||
else {
|
||||
// New notice post was successful. If on our timeline, show it!
|
||||
|
@ -428,9 +451,7 @@ var SN = { // StatusNet
|
|||
else {
|
||||
// Not on a timeline that this belongs on?
|
||||
// Just show a success message.
|
||||
result = document._importNode($('title', data)[0], true);
|
||||
result_title = result.textContent || result.innerHTML;
|
||||
form.append('<p class="form_response success">'+result_title+'</p>');
|
||||
showFeedback('success', $('title', data).text());
|
||||
}
|
||||
}
|
||||
form.resetForm();
|
||||
|
|
2
js/util.min.js
vendored
2
js/util.min.js
vendored
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user