User:Bosco/Unsigned helper.js: Difference between revisions

From Test Wiki
Content deleted Content added
doAddUnsignedTemplate: extract function from unsignedHelperAddUnsignedTemplate; unsignedHelperAddUnsignedTemplate: rename parameter to "event" for clarity
formatErrorSpan: extract function from doAddUnsignedTemplate
Line 33: Line 33:
editSummaryField.val(newText);
editSummaryField.val(newText);
}
}

function formatErrorSpan(errorMessage) {
return `<span style="color:red"><b>Error:</b> ${errorMessage}</span>`;
}

function doAddUnsignedTemplate() {
function doAddUnsignedTemplate() {
var f = document.getElementById('editform');
var f = document.getElementById('editform');
Line 81: Line 85:


if (!r.query || !r.query.pages) {
if (!r.query || !r.query.pages) {
dialog.html('<span style="color:red"><b>Error:</b> Bad response from API</span>');
dialog.html(formatErrorSpan('Bad response from API'));
if (window.console && typeof (window.console.error) == 'function')
if (window.console && typeof (window.console.error) == 'function')
window.console.error("Bad response", r);
window.console.error("Bad response", r);
Line 107: Line 111:
if (typeof (rr['*']) != 'undefined' && rr['*'].indexOf(txt) < 0) {
if (typeof (rr['*']) != 'undefined' && rr['*'].indexOf(txt) < 0) {
if (!user) {
if (!user) {
dialog.html('<span style="color:red"><b>Error:</b> Text was not found in the starting revision! Did you edit it?</span>');
dialog.html(formatErrorSpan('Text was not found in the starting revision! Did you edit it?'));
return;
return;
}
}
Line 166: Line 170:
return;
return;
}
}
dialog.html('<span style="color:red"><b>Error:</b> No revisions found in the page!</span>');
dialog.html(formatErrorSpan('No revisions found in the page!'));
},
},
error: function (xhr, textStatus, errorThrown) {
error: function (xhr, textStatus, errorThrown) {
if (!dialog.dialog('isOpen'))
if (!dialog.dialog('isOpen'))
return;
return;
dialog.html('<span style="color:red"><b>Error:</b> ' + textStatus + ' ' + errorThrown + '</span>');
dialog.html(formatErrorSpan(textStatus + ' ' + errorThrown));
}
}
};
};