Extract ui_report.js.

This moves the implementations of error/report/message from
ui.js to ui_report.js.  They had been shimmed before, so calling
modules still use the same names to call the functions, but we
no longer need the shims.
This commit is contained in:
Steve Howell 2017-04-03 07:13:25 -07:00
parent d8fad9587c
commit 2d52463b61
5 changed files with 53 additions and 46 deletions

View File

@ -18,7 +18,3 @@ compose_state.has_message_content = compose.has_message_content;
compose_state.recipient = compose.recipient; compose_state.recipient = compose.recipient;
compose_state.composing = compose.composing; compose_state.composing = compose.composing;
var ui_report = {};
ui_report.success = ui.report_success;
ui_report.error = ui.report_error;
ui_report.message= ui.report_message;

View File

@ -18,47 +18,6 @@ exports.replace_emoji_with_text = function (element) {
}); });
}; };
/* Arguments used in the report_* functions are,
response- response that we want to display
status_box- element being used to display the response
cls- class that we want to add/remove to/from the status_box
type- used to define more complex logic for special cases (currently being
used only for subscriptions-status) */
exports.report_message = function (response, status_box, cls, type) {
if (cls === undefined) {
cls = 'alert';
}
if (type === undefined) {
type = ' ';
}
if (type === 'subscriptions-status') {
status_box.removeClass(status_classes).addClass(cls).children('#response')
.text(response).stop(true).fadeTo(0, 1);
} else {
status_box.removeClass(status_classes).addClass(cls)
.text(response).stop(true).fadeTo(0, 1);
}
status_box.show();
};
exports.report_error = function (response, xhr, status_box, type) {
if (xhr && xhr.status.toString().charAt(0) === "4") {
// Only display the error response for 4XX, where we've crafted
// a nice response.
response += ": " + JSON.parse(xhr.responseText).msg;
}
ui_report.message(response, status_box, 'alert-error', type);
};
exports.report_success = function (response, status_box, type) {
ui_report.message(response, status_box, 'alert-success', type);
};
function update_message_in_all_views(message_id, callback) { function update_message_in_all_views(message_id, callback) {
_.each([message_list.all, home_msg_list, message_list.narrowed], function (list) { _.each([message_list.all, home_msg_list, message_list.narrowed], function (list) {
if (list === undefined) { if (list === undefined) {

51
static/js/ui_report.js Normal file
View File

@ -0,0 +1,51 @@
var ui_report = (function () {
var exports = {};
/* Arguments used in the report_* functions are,
response- response that we want to display
status_box- element being used to display the response
cls- class that we want to add/remove to/from the status_box
type- used to define more complex logic for special cases (currently being
used only for subscriptions-status) */
exports.message = function (response, status_box, cls, type) {
if (cls === undefined) {
cls = 'alert';
}
if (type === undefined) {
type = ' ';
}
if (type === 'subscriptions-status') {
status_box.removeClass(status_classes).addClass(cls).children('#response')
.text(response).stop(true).fadeTo(0, 1);
} else {
status_box.removeClass(status_classes).addClass(cls)
.text(response).stop(true).fadeTo(0, 1);
}
status_box.show();
};
exports.error = function (response, xhr, status_box, type) {
if (xhr && xhr.status.toString().charAt(0) === "4") {
// Only display the error response for 4XX, where we've crafted
// a nice response.
response += ": " + JSON.parse(xhr.responseText).msg;
}
exports.message(response, status_box, 'alert-error', type);
};
exports.success = function (response, status_box, type) {
exports.message(response, status_box, 'alert-success', type);
};
return exports;
}());
if (typeof module !== 'undefined') {
module.exports = ui_report;
}

View File

@ -88,7 +88,7 @@ def find(fns):
continue continue
elif fn == 'signup.js' and 'class_to_add' in line: elif fn == 'signup.js' and 'class_to_add' in line:
html_classes = ['error', 'success'] html_classes = ['error', 'success']
elif fn == 'ui.js' and 'status_classes' in line: elif fn == 'ui_report.js' and 'status_classes' in line:
html_classes = ['alert'] html_classes = ['alert']
if not html_classes: if not html_classes:

View File

@ -859,6 +859,7 @@ JS_SPECS = {
'js/floating_recipient_bar.js', 'js/floating_recipient_bar.js',
'js/lightbox.js', 'js/lightbox.js',
'js/ui_state.js', 'js/ui_state.js',
'js/ui_report.js',
'js/ui.js', 'js/ui.js',
'js/ui_util.js', 'js/ui_util.js',
'js/pointer.js', 'js/pointer.js',