account settings: Replace logic with existing functions.

Replace settings api calls with existing function
`settings_ui.do_settings_change()`. This commit also
adds a ui element for save alert notificaiton.
This commit is contained in:
Yashashvi Dave 2019-07-10 22:47:26 +05:30 committed by Tim Abbott
parent e2e7d288a5
commit ff75c77f7a
3 changed files with 42 additions and 54 deletions

View File

@ -62,10 +62,6 @@ function settings_change_error(message, xhr) {
ui_report.error(message, xhr, $('#account-settings-status').expectOne());
}
function settings_change_success(message) {
ui_report.success(message, $('#account-settings-status').expectOne());
}
function update_user_custom_profile_fields(fields, method) {
if (method === undefined) {
blueslip.error("Undefined method in update_user_custom_profile_fields");
@ -331,7 +327,7 @@ exports.set_up = function () {
$('#change_password_button').on('click', function (e) {
e.preventDefault();
e.stopPropagation();
var change_password_info = $('#change_password_modal').find(".change_password_info").expectOne();
var change_password_error = $('#change_password_modal').find(".change_password_info").expectOne();
var data = {
old_password: $('#old_password').val(),
@ -355,19 +351,15 @@ exports.set_up = function () {
}
}
channel.patch({
url: "/json/settings",
data: data,
success: function () {
settings_change_success(i18n.t("Updated settings!"));
overlays.close_modal('change_password_modal');
clear_password_change();
var opts = {
success_continuation: function () {
overlays.close_modal("change_password_modal");
},
error: function (xhr) {
ui_report.error(i18n.t("Failed"), xhr, change_password_info);
error_msg_element: change_password_error,
};
settings_ui.do_settings_change(channel.patch, '/json/settings', data,
$('#account-settings-status').expectOne(), opts);
clear_password_change();
},
});
});
$('#new_password').on('input', function () {
@ -378,54 +370,40 @@ exports.set_up = function () {
$("#change_full_name_button").on('click', function (e) {
e.preventDefault();
e.stopPropagation();
var change_full_name_info = $('#change_full_name_modal').find(".change_full_name_info").expectOne();
var change_full_name_error = $('#change_full_name_modal').find(".change_full_name_info").expectOne();
var data = {};
data.full_name = $('.full_name_change_container').find("input[name='full_name']").val();
channel.patch({
url: '/json/settings',
data: data,
success: function (data) {
if ('full_name' in data) {
settings_change_success(i18n.t("Updated settings!"));
} else {
settings_change_success(i18n.t("No changes made."));
}
overlays.close_modal('change_full_name_modal');
var opts = {
success_continuation: function () {
overlays.close_modal("change_full_name_modal");
},
error: function (xhr) {
ui_report.error(i18n.t("Failed"), xhr, change_full_name_info);
},
});
error_msg_element: change_full_name_error,
};
settings_ui.do_settings_change(channel.patch, '/json/settings', data,
$('#account-settings-status').expectOne(), opts);
});
$('#change_email_button').on('click', function (e) {
e.preventDefault();
e.stopPropagation();
var change_email_info = $('#change_email_modal').find(".change_email_info").expectOne();
var change_email_error = $('#change_email_modal').find(".change_email_info").expectOne();
var data = {};
data.email = $('.email_change_container').find("input[name='email']").val();
channel.patch({
url: '/json/settings',
data: data,
success: function (data) {
if ('account_email' in data) {
settings_change_success(data.account_email);
var opts = {
success_continuation: function () {
if (page_params.development_environment) {
var email_msg = templates.render('settings/dev_env_email_access');
$("#account-settings-status").append(email_msg);
}
} else {
settings_change_success(i18n.t("No changes made."));
ui_report.success(email_msg, $("#dev-account-settings-status").expectOne(), 4000);
}
overlays.close_modal('change_email_modal');
},
error: function (xhr) {
ui_report.error(i18n.t("Failed"), xhr, change_email_info);
},
});
error_msg_element: change_email_error,
};
settings_ui.do_settings_change(channel.patch, '/json/settings', data,
$('#account-settings-status').expectOne(), opts);
});
$('#change_email').on('click', function (e) {

View File

@ -49,11 +49,20 @@ exports.do_settings_change = function (request_method, url, data, status_element
settings_ui.display_checkmark(spinner);
}, appear_after);
if (success_continuation !== undefined) {
if (opts !== undefined && opts.success_continuation_arg) {
success_continuation(opts.success_continuation_arg);
} else {
success_continuation(reponse_data);
}
}
},
error: function (xhr) {
if (opts !== undefined && opts.error_msg_element) {
loading.destroy_indicator(spinner);
ui_report.error(exports.strings.failure, xhr, opts.error_msg_element);
} else {
ui_report.error(exports.strings.failure, xhr, spinner);
}
if (error_continuation !== undefined) {
error_continuation(xhr);
}

View File

@ -1,9 +1,10 @@
<div id="account-settings" class="settings-section show" data-name="your-account">
<div class="alert" id="account-settings-status"></div>
<div class="alert" id="dev-account-settings-status"></div>
<div class="account-settings-form">
<div class="inline-block">
<form class="email-change-form grid">
<h3>{{t "User settings" }}</h3>
<h3 class="inline-block">{{t "User settings" }}</h3>
<div class="alert-notification" id="account-settings-status"></div>
<div class="input-group user-name-section">
<label class="inline-block title">{{t "Email" }}</label>
<a id="change_email" {{#if page_params.is_admin}}href="#change_email"{{else}}{{#unless page_params.realm_email_changes_disabled}}href="#change_email"{{/unless}}{{/if}}>