mirror of
https://github.com/zulip/zulip.git
synced 2025-11-02 13:03:29 +00:00
This commit was originally automatically generated using `tools/lint --only=eslint --fix`. It was then modified by tabbott to contain only changes to a set of files that are unlikely to result in significant merge conflicts with any open pull request, excluding about 20 files. His plan is to merge the remaining changes with more precise care, potentially involving merging parts of conflicting pull requests before running the `eslint --fix` operation. Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
81 lines
2.5 KiB
JavaScript
81 lines
2.5 KiB
JavaScript
exports.build_bot_create_widget = function () {
|
|
|
|
// We have to do strange gyrations with the file input to clear it,
|
|
// where we replace it wholesale, so we generalize the file input with
|
|
// a callback function.
|
|
const get_file_input = function () {
|
|
return $('#bot_avatar_file_input');
|
|
};
|
|
|
|
const file_name_field = $('#bot_avatar_file');
|
|
const input_error = $('#bot_avatar_file_input_error');
|
|
const clear_button = $('#bot_avatar_clear_button');
|
|
const upload_button = $('#bot_avatar_upload_button');
|
|
|
|
return upload_widget.build_widget(
|
|
get_file_input,
|
|
file_name_field,
|
|
input_error,
|
|
clear_button,
|
|
upload_button
|
|
);
|
|
};
|
|
|
|
exports.build_bot_edit_widget = function (target) {
|
|
const get_file_input = function () {
|
|
return target.find('.edit_bot_avatar_file_input');
|
|
};
|
|
|
|
const file_name_field = target.find('.edit_bot_avatar_file');
|
|
const input_error = target.find('.edit_bot_avatar_error');
|
|
const clear_button = target.find('.edit_bot_avatar_clear_button');
|
|
const upload_button = target.find('.edit_bot_avatar_upload_button');
|
|
|
|
return upload_widget.build_widget(
|
|
get_file_input,
|
|
file_name_field,
|
|
input_error,
|
|
clear_button,
|
|
upload_button
|
|
);
|
|
};
|
|
|
|
exports.build_user_avatar_widget = function (upload_function) {
|
|
const get_file_input = function () {
|
|
return $('#user_avatar_file_input').expectOne();
|
|
};
|
|
|
|
if (page_params.avatar_source === 'G') {
|
|
$("#user_avatar_delete_button").hide();
|
|
$("#user-avatar-source").show();
|
|
} else {
|
|
$("#user-avatar-source").hide();
|
|
}
|
|
|
|
$("#user_avatar_delete_button").on('click keydown', function (e) {
|
|
e.preventDefault();
|
|
e.stopPropagation();
|
|
channel.del({
|
|
url: '/json/users/me/avatar',
|
|
success: function () {
|
|
$("#user_avatar_delete_button").hide();
|
|
$("#user-avatar-source").show();
|
|
// Need to clear input because of a small edge case
|
|
// where you try to upload the same image you just deleted.
|
|
get_file_input().val('');
|
|
// Rest of the work is done via the user_events -> avatar_url event we will get
|
|
},
|
|
});
|
|
});
|
|
|
|
return upload_widget.build_direct_upload_widget(
|
|
get_file_input,
|
|
$("#user_avatar_file_input_error").expectOne(),
|
|
$("#user_avatar_upload_button").expectOne(),
|
|
upload_function,
|
|
page_params.max_avatar_file_size
|
|
);
|
|
};
|
|
|
|
window.avatar = exports;
|