Add ui_report shim.

This commit is contained in:
Steve Howell 2017-03-18 13:17:41 -07:00 committed by Tim Abbott
parent c67aebf633
commit b98cd55ddb
12 changed files with 80 additions and 74 deletions

View File

@ -26,6 +26,7 @@
"server_events": false,
"ui": false,
"ui_state": false,
"ui_report": false,
"lightbox": false,
"stream_color": false,
"people": false,

View File

@ -268,9 +268,9 @@ form control in `static/js/admin.js`. :
success: function (data) {
# ...
if (data.invite_by_admins_only) {
ui.report_success("New users must be invited by an admin!", invite_by_admins_only_status);
ui_report.success("New users must be invited by an admin!", invite_by_admins_only_status);
} else {
ui.report_success("Any user may now invite new users!", invite_by_admins_only_status);
ui_report.success("Any user may now invite new users!", invite_by_admins_only_status);
}
# ...
}

View File

@ -308,7 +308,7 @@ channel.patch({
data: data,
success: function (response_data) {
if (response_data.name !== undefined) {
ui.report_success(i18n.t("Name changed!"), name_status);
ui_report.success(i18n.t("Name changed!"), name_status);
}
...
```

View File

@ -93,11 +93,11 @@ exports.update_user_data = function (user_id, new_data) {
function failed_listing_users(xhr) {
loading.destroy_indicator($('#subs_page_loading_indicator'));
ui.report_error(i18n.t("Error listing users or bots"), xhr, $("#administration-status"));
ui_report.error(i18n.t("Error listing users or bots"), xhr, $("#administration-status"));
}
function failed_listing_streams(xhr) {
ui.report_error(i18n.t("Error listing streams"), xhr, $("#administration-status"));
ui_report.error(i18n.t("Error listing streams"), xhr, $("#administration-status"));
}
function populate_users(realm_people_data) {
@ -513,7 +513,7 @@ function _setup_page() {
if ($("#deactivation_user_modal .email").html() !== email) {
blueslip.error("User deactivation canceled due to non-matching fields.");
ui.report_message("Deactivation encountered an error. Please reload and try again.",
ui_report.message("Deactivation encountered an error. Please reload and try again.",
$("#home-error"), 'alert-error');
}
$("#deactivation_user_modal").modal("hide");
@ -693,60 +693,60 @@ function _setup_page() {
data: data,
success: function (response_data) {
if (response_data.name !== undefined) {
ui.report_success(i18n.t("Name changed!"), name_status);
ui_report.success(i18n.t("Name changed!"), name_status);
}
if (response_data.restricted_to_domain !== undefined) {
if (response_data.restricted_to_domain) {
ui.report_success(i18n.t("New user e-mails now restricted to certain domains!"), restricted_to_domain_status);
ui_report.success(i18n.t("New user e-mails now restricted to certain domains!"), restricted_to_domain_status);
} else {
ui.report_success(i18n.t("New users may have arbitrary e-mails!"), restricted_to_domain_status);
ui_report.success(i18n.t("New users may have arbitrary e-mails!"), restricted_to_domain_status);
}
}
if (response_data.invite_required !== undefined) {
if (response_data.invite_required) {
ui.report_success(i18n.t("New users must be invited by e-mail!"), invite_required_status);
ui_report.success(i18n.t("New users must be invited by e-mail!"), invite_required_status);
} else {
ui.report_success(i18n.t("New users may sign up online!"), invite_required_status);
ui_report.success(i18n.t("New users may sign up online!"), invite_required_status);
}
}
if (response_data.invite_by_admins_only !== undefined) {
if (response_data.invite_by_admins_only) {
ui.report_success(i18n.t("New users must be invited by an admin!"), invite_by_admins_only_status);
ui_report.success(i18n.t("New users must be invited by an admin!"), invite_by_admins_only_status);
} else {
ui.report_success(i18n.t("Any user may now invite new users!"), invite_by_admins_only_status);
ui_report.success(i18n.t("Any user may now invite new users!"), invite_by_admins_only_status);
}
}
if (response_data.create_stream_by_admins_only !== undefined) {
if (response_data.create_stream_by_admins_only) {
ui.report_success(i18n.t("Only administrators may now create new streams!"), create_stream_by_admins_only_status);
ui_report.success(i18n.t("Only administrators may now create new streams!"), create_stream_by_admins_only_status);
} else {
ui.report_success(i18n.t("Any user may now create new streams!"), create_stream_by_admins_only_status);
ui_report.success(i18n.t("Any user may now create new streams!"), create_stream_by_admins_only_status);
}
}
if (response_data.name_changes_disabled !== undefined) {
if (response_data.name_changes_disabled) {
ui.report_success(i18n.t("Users cannot change their name!"), name_changes_disabled_status);
ui_report.success(i18n.t("Users cannot change their name!"), name_changes_disabled_status);
} else {
ui.report_success(i18n.t("Users may now change their name!"), name_changes_disabled_status);
ui_report.success(i18n.t("Users may now change their name!"), name_changes_disabled_status);
}
}
if (response_data.email_changes_disabled !== undefined) {
if (response_data.email_changes_disabled) {
ui.report_success(i18n.t("Users cannot change their email!"), email_changes_disabled_status);
ui_report.success(i18n.t("Users cannot change their email!"), email_changes_disabled_status);
} else {
ui.report_success(i18n.t("Users may now change their email!"), email_changes_disabled_status);
ui_report.success(i18n.t("Users may now change their email!"), email_changes_disabled_status);
}
}
if (response_data.add_emoji_by_admins_only !== undefined) {
if (response_data.add_emoji_by_admins_only) {
ui.report_success(i18n.t("Only administrators may now add new emoji!"), add_emoji_by_admins_only_status);
ui_report.success(i18n.t("Only administrators may now add new emoji!"), add_emoji_by_admins_only_status);
} else {
ui.report_success(i18n.t("Any user may now add new emoji!"), add_emoji_by_admins_only_status);
ui_report.success(i18n.t("Any user may now add new emoji!"), add_emoji_by_admins_only_status);
}
}
if (response_data.authentication_methods !== undefined) {
if (response_data.authentication_methods) {
ui.report_success(i18n.t("Authentication methods saved!"), authentication_methods_status);
ui_report.success(i18n.t("Authentication methods saved!"), authentication_methods_status);
}
}
if (response_data.allow_message_editing !== undefined) {
@ -756,16 +756,16 @@ function _setup_page() {
Math.ceil(response_data.message_content_edit_limit_seconds / 60);
if (response_data.allow_message_editing) {
if (response_data.message_content_edit_limit_seconds > 0) {
ui.report_success(i18n.t("Users can now edit topics for all their messages,"
ui_report.success(i18n.t("Users can now edit topics for all their messages,"
+" and the content of messages which are less than __num_minutes__ minutes old.",
{num_minutes :
data_message_content_edit_limit_minutes}),
message_editing_status);
} else {
ui.report_success(i18n.t("Users can now edit the content and topics of all their past messages!"), message_editing_status);
ui_report.success(i18n.t("Users can now edit the content and topics of all their past messages!"), message_editing_status);
}
} else {
ui.report_success(i18n.t("Users can no longer edit their past messages!"), message_editing_status);
ui_report.success(i18n.t("Users can no longer edit their past messages!"), message_editing_status);
}
// message_content_edit_limit_seconds could have been changed earlier
// in this function, so update the field just in case
@ -773,12 +773,12 @@ function _setup_page() {
}
if (response_data.default_language !== undefined) {
if (response_data.default_language) {
ui.report_success(i18n.t("Default language changed!"), default_language_status);
ui_report.success(i18n.t("Default language changed!"), default_language_status);
}
}
if (response_data.waiting_period_threshold !== undefined) {
if (response_data.waiting_period_threshold > 0) {
ui.report_success(i18n.t("Waiting period threshold changed!"), waiting_period_threshold_status);
ui_report.success(i18n.t("Waiting period threshold changed!"), waiting_period_threshold_status);
}
}
// Check if no changes made
@ -789,15 +789,15 @@ function _setup_page() {
}
}
if (no_changes_made) {
ui.report_success(i18n.t("No changes to save!"), name_status);
ui_report.success(i18n.t("No changes to save!"), name_status);
}
},
error: function (xhr) {
var reason = $.parseJSON(xhr.responseText).reason;
if (reason === "no authentication") {
ui.report_error(i18n.t("Failed!"), xhr, authentication_methods_status);
ui_report.error(i18n.t("Failed!"), xhr, authentication_methods_status);
} else {
ui.report_error(i18n.t("Failed!"), xhr, name_status);
ui_report.error(i18n.t("Failed!"), xhr, name_status);
}
},
});
@ -829,7 +829,7 @@ function _setup_page() {
},
error: function (xhr) {
var status = row.find(".admin-user-status");
ui.report_error(i18n.t("Failed!"), xhr, status);
ui_report.error(i18n.t("Failed!"), xhr, status);
},
});
});
@ -860,7 +860,7 @@ function _setup_page() {
},
error: function (xhr) {
var status = row.find(".admin-user-status");
ui.report_error(i18n.t("Failed!"), xhr, status);
ui_report.error(i18n.t("Failed!"), xhr, status);
},
});
});
@ -916,10 +916,10 @@ function _setup_page() {
url: url,
data: data,
success: function () {
ui.report_success(i18n.t('Updated successfully!'), admin_status);
ui_report.success(i18n.t('Updated successfully!'), admin_status);
},
error: function () {
ui.report_error(i18n.t('Update failed!'), admin_status);
ui_report.error(i18n.t('Update failed!'), admin_status);
},
});
});
@ -928,7 +928,7 @@ function _setup_page() {
$("#do_deactivate_stream_button").click(function () {
if ($("#deactivation_stream_modal .stream_name").text() !== $(".active_stream_row").find('.stream_name').text()) {
blueslip.error("Stream deactivation canceled due to non-matching fields.");
ui.report_message("Deactivation encountered an error. Please reload and try again.",
ui_report.message("Deactivation encountered an error. Please reload and try again.",
$("#home-error"), 'alert-error');
}
$("#deactivation_stream_modal").modal("hide");
@ -990,14 +990,14 @@ function _setup_page() {
data: $(this).serialize(),
success: function () {
$('#admin-emoji-status').hide();
ui.report_success(i18n.t("Custom emoji added!"), emoji_status);
ui_report.success(i18n.t("Custom emoji added!"), emoji_status);
$("form.admin-emoji-form input[type='text']").val("");
},
error: function (xhr) {
$('#admin-emoji-status').hide();
var errors = JSON.parse(xhr.responseText).msg;
xhr.responseText = JSON.stringify({msg: errors});
ui.report_error(i18n.t("Failed!"), xhr, emoji_status);
ui_report.error(i18n.t("Failed!"), xhr, emoji_status);
},
});
});
@ -1044,21 +1044,21 @@ function _setup_page() {
data: $(this).serialize(),
success: function (data) {
filter.id = data.id;
ui.report_success(i18n.t("Custom filter added!"), filter_status);
ui_report.success(i18n.t("Custom filter added!"), filter_status);
},
error: function (xhr) {
var errors = $.parseJSON(xhr.responseText).errors;
if (errors.pattern !== undefined) {
xhr.responseText = JSON.stringify({msg: errors.pattern});
ui.report_error(i18n.t("Failed"), xhr, pattern_status);
ui_report.error(i18n.t("Failed"), xhr, pattern_status);
}
if (errors.url_format_string !== undefined) {
xhr.responseText = JSON.stringify({msg: errors.url_format_string});
ui.report_error(i18n.t("Failed"), xhr, format_status);
ui_report.error(i18n.t("Failed"), xhr, format_status);
}
if (errors.__all__ !== undefined) {
xhr.responseText = JSON.stringify({msg: errors.__all__});
ui.report_error(i18n.t("Failed"), xhr, filter_status);
ui_report.error(i18n.t("Failed"), xhr, filter_status);
}
},
});

View File

@ -152,7 +152,7 @@ function report_error(msg, stack, opts) {
// invoked). In any case, it will pretty clear that
// something is wrong with the page and the user will
// probably try to reload anyway.
ui.report_message("Oops. It seems something has gone wrong. " +
ui_report.message("Oops. It seems something has gone wrong. " +
"The error has been reported to the fine " +
"folks at Zulip, but, in the mean time, " +
"please try reloading the page.",
@ -161,7 +161,7 @@ function report_error(msg, stack, opts) {
},
error: function () {
if (opts.show_ui_msg && ui !== undefined) {
ui.report_message("Oops. It seems something has gone wrong. " +
ui_report.message("Oops. It seems something has gone wrong. " +
"Please try reloading the page.",
$("#home-error"), "alert-error");
}

View File

@ -21,11 +21,11 @@ var exports = {};
// Display the canonical stream capitalization.
var my_email = people.my_current_email();
var true_stream_name = data.already_subscribed[my_email][0];
ui.report_success(i18n.t("Already subscribed to __stream__", {stream: true_stream_name}),
ui_report.success(i18n.t("Already subscribed to __stream__", {stream: true_stream_name}),
$status_message);
}
}, function (xhr) {
ui.report_error(i18n.t("Error adding subscription"), xhr, $status_message);
ui_report.error(i18n.t("Error adding subscription"), xhr, $status_message);
}
);
}
@ -40,7 +40,7 @@ var exports = {};
function () {
$status_message.hide();
}, function (xhr) {
ui.report_error(i18n.t("Error removing subscription"), xhr, $status_message);
ui_report.error(i18n.t("Error removing subscription"), xhr, $status_message);
}
);
}

View File

@ -419,7 +419,7 @@ exports.show_history = function (message) {
}));
},
error: function (xhr) {
ui.report_error(i18n.t("Error fetching message edit history"), xhr,
ui_report.error(i18n.t("Error fetching message edit history"), xhr,
$("#message-history-error"));
},
});

View File

@ -184,7 +184,7 @@ function do_reload_app(send_after_reload, save_pointer, save_narrow, save_compos
}
// TODO: We need a better API for showing messages.
ui.report_message(message, $("#reloading-application"));
ui_report.message(message, $("#reloading-application"));
blueslip.log('Starting server requested page reload');
reload_in_progress = true;

View File

@ -316,14 +316,14 @@ function _setup_page() {
// Scroll to the top so the error message is visible.
// We would scroll anyway if we end up submitting the form.
message_viewport.scrollTop(0);
ui.report_error(message, xhr, $('#account-settings-status').expectOne());
ui_report.error(message, xhr, $('#account-settings-status').expectOne());
}
function settings_change_success(message) {
// Scroll to the top so the error message is visible.
// We would scroll anyway if we end up submitting the form.
message_viewport.scrollTop(0);
ui.report_success(message, $('#account-settings-status').expectOne());
ui_report.success(message, $('#account-settings-status').expectOne());
}
$("form.your-account-settings").ajaxForm({
@ -410,11 +410,11 @@ function _setup_page() {
page_params.enable_digest_emails = result.enable_digest_emails;
}
ui.report_success(i18n.t("Updated notification settings!"), notify_settings_status);
ui_report.success(i18n.t("Updated notification settings!"), notify_settings_status);
}
function update_notification_settings_error(xhr) {
ui.report_error(i18n.t("Error changing settings"), xhr, $('#notify-settings-status').expectOne());
ui_report.error(i18n.t("Error changing settings"), xhr, $('#notify-settings-status').expectOne());
}
function post_notify_settings_changes(notification_changes, success_func,
@ -507,11 +507,11 @@ function _setup_page() {
url: '/json/settings/display',
data: data,
success: function () {
ui.report_success(i18n.t("User list will appear on the __side__ hand side! You will need to reload the window for your changes to take effect.", context),
ui_report.success(i18n.t("User list will appear on the __side__ hand side! You will need to reload the window for your changes to take effect.", context),
$('#display-settings-status').expectOne());
},
error: function (xhr) {
ui.report_error(i18n.t("Error updating user list placement setting"), xhr, $('#display-settings-status').expectOne());
ui_report.error(i18n.t("Error updating user list placement setting"), xhr, $('#display-settings-status').expectOne());
},
});
});
@ -531,11 +531,11 @@ function _setup_page() {
url: '/json/settings/display',
data: data,
success: function () {
ui.report_success(i18n.t("Emoji reactions will appear as __text_or_images__!", context),
ui_report.success(i18n.t("Emoji reactions will appear as __text_or_images__!", context),
$('#display-settings-status').expectOne());
},
error: function (xhr) {
ui.report_error(i18n.t("Error updating emoji appearance setting"), xhr, $('#display-settings-status').expectOne());
ui_report.error(i18n.t("Error updating emoji appearance setting"), xhr, $('#display-settings-status').expectOne());
},
});
});
@ -555,11 +555,11 @@ function _setup_page() {
url: '/json/settings/display',
data: data,
success: function () {
ui.report_success(i18n.t("Time will now be displayed in the __format__-hour format!", context),
ui_report.success(i18n.t("Time will now be displayed in the __format__-hour format!", context),
$('#display-settings-status').expectOne());
},
error: function (xhr) {
ui.report_error(i18n.t("Error updating time format setting"), xhr, $('#display-settings-status').expectOne());
ui_report.error(i18n.t("Error updating time format setting"), xhr, $('#display-settings-status').expectOne());
},
});
});
@ -588,11 +588,11 @@ function _setup_page() {
url: '/json/settings/display',
data: data,
success: function () {
ui.report_success(i18n.t("__lang__ is now the default language! You will need to reload the window for your changes to take effect", context),
ui_report.success(i18n.t("__lang__ is now the default language! You will need to reload the window for your changes to take effect", context),
$('#display-settings-status').expectOne());
},
error: function (xhr) {
ui.report_error(i18n.t("Error updating default language setting"), xhr, $('#display-settings-status').expectOne());
ui_report.error(i18n.t("Error updating default language setting"), xhr, $('#display-settings-status').expectOne());
},
});
});
@ -649,7 +649,7 @@ function _setup_page() {
window.location.href = "/login";
},
error: function (xhr) {
ui.report_error(i18n.t("Error deactivating account"), xhr, $('#account-settings-status').expectOne());
ui_report.error(i18n.t("Error deactivating account"), xhr, $('#account-settings-status').expectOne());
},
});
});
@ -669,7 +669,7 @@ function _setup_page() {
settings_status.hide();
},
error: function (xhr) {
ui.report_error(i18n.t("Error getting API key"), xhr, $('#account-settings-status').expectOne());
ui_report.error(i18n.t("Error getting API key"), xhr, $('#account-settings-status').expectOne());
$("#show_api_key_box").hide();
$("#get_api_key_box").show();
},
@ -981,10 +981,10 @@ function _setup_page() {
resize.resize_page_components();
}
ui.report_success(message, ui_settings_status);
ui_report.success(message, ui_settings_status);
},
error: function (xhr) {
ui.report_error(i18n.t("Error changing settings"), xhr, $('#ui-settings-status').expectOne());
ui_report.error(i18n.t("Error changing settings"), xhr, $('#ui-settings-status').expectOne());
},
});
});

View File

@ -20,3 +20,8 @@ var compose_state = {};
compose_state.has_message_content = compose.has_message_content;
compose_state.recipient = compose.recipient;
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

@ -780,13 +780,13 @@ function ajaxSubscribe(stream) {
if (!$.isEmptyObject(res.already_subscribed)) {
// Display the canonical stream capitalization.
true_stream_name = res.already_subscribed[people.my_current_email()][0];
ui.report_success(i18n.t("Already subscribed to __stream__", {stream: true_stream_name}),
ui_report.success(i18n.t("Already subscribed to __stream__", {stream: true_stream_name}),
$("#subscriptions-status"), 'subscriptions-status');
}
// The rest of the work is done via the subscribe event we will get
},
error: function (xhr) {
ui.report_error(i18n.t("Error adding subscription"), xhr,
ui_report.error(i18n.t("Error adding subscription"), xhr,
$("#subscriptions-status"), 'subscriptions-status');
},
});
@ -802,7 +802,7 @@ function ajaxUnsubscribe(sub) {
// The rest of the work is done via the unsubscribe event we will get
},
error: function (xhr) {
ui.report_error(i18n.t("Error removing subscription"), xhr,
ui_report.error(i18n.t("Error removing subscription"), xhr,
$("#subscriptions-status"), 'subscriptions-status');
},
});
@ -824,7 +824,7 @@ function ajaxSubscribeForCreation(stream, description, principals, invite_only,
// The rest of the work is done via the subscribe event we will get
},
error: function (xhr) {
ui.report_error(i18n.t("Error creating stream"), xhr,
ui_report.error(i18n.t("Error creating stream"), xhr,
$("#subscriptions-status"), 'subscriptions-status');
},
});
@ -932,11 +932,11 @@ exports.change_stream_description = function (e) {
},
success: function () {
// The event from the server will update the rest of the UI
ui.report_success(i18n.t("The stream description has been updated!"),
ui_report.success(i18n.t("The stream description has been updated!"),
$("#subscriptions-status"), 'subscriptions-status');
},
error: function (xhr) {
ui.report_error(i18n.t("Error updating the stream description"), xhr,
ui_report.error(i18n.t("Error updating the stream description"), xhr,
$("#subscriptions-status"), 'subscriptions-status');
},
});
@ -957,11 +957,11 @@ exports.change_stream_name = function (e) {
data: {new_name: JSON.stringify(new_name)},
success: function () {
new_name_box.val('');
ui.report_success(i18n.t("The stream has been renamed!"), $("#subscriptions-status "),
ui_report.success(i18n.t("The stream has been renamed!"), $("#subscriptions-status "),
'subscriptions-status');
},
error: function (xhr) {
ui.report_error(i18n.t("Error renaming stream"), xhr,
ui_report.error(i18n.t("Error renaming stream"), xhr,
$("#subscriptions-status"), 'subscriptions-status');
},
});

View File

@ -124,11 +124,11 @@ exports.report_error = function (response, xhr, status_box, type) {
response += ": " + JSON.parse(xhr.responseText).msg;
}
ui.report_message(response, status_box, 'alert-error', type);
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);
ui_report.message(response, status_box, 'alert-success', type);
};
function update_message_in_all_views(message_id, callback) {