2013-07-29 17:29:25 +02:00
|
|
|
var avatar = (function () {
|
|
|
|
|
|
|
|
var exports = {};
|
|
|
|
|
2013-08-01 15:43:48 +02:00
|
|
|
exports.build_bot_create_widget = function () {
|
2013-07-29 17:29:25 +02:00
|
|
|
|
2013-07-29 20:39:38 +02:00
|
|
|
// 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.
|
|
|
|
var get_file_input = function () {
|
|
|
|
return $('#bot_avatar_file_input');
|
|
|
|
};
|
|
|
|
|
2013-07-29 21:17:34 +02:00
|
|
|
var file_name_field = $('#bot_avatar_file');
|
|
|
|
var input_error = $('#bot_avatar_file_input_error');
|
|
|
|
var clear_button = $('#bot_avatar_clear_button');
|
|
|
|
var upload_button = $('#bot_avatar_upload_button');
|
|
|
|
|
2017-02-21 03:15:22 +01:00
|
|
|
return upload_widget.build_widget(
|
2013-07-29 21:31:21 +02:00
|
|
|
get_file_input,
|
|
|
|
file_name_field,
|
|
|
|
input_error,
|
|
|
|
clear_button,
|
|
|
|
upload_button
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2017-03-01 01:31:33 +01:00
|
|
|
exports.build_bot_edit_widget = function (target) {
|
2013-07-29 16:27:18 +02:00
|
|
|
var get_file_input = function () {
|
2017-03-01 01:31:33 +01:00
|
|
|
return target.find('.edit_bot_avatar_file_input');
|
2013-07-29 16:27:18 +02:00
|
|
|
};
|
|
|
|
|
2017-03-01 01:31:33 +01:00
|
|
|
var file_name_field = target.find('.edit_bot_avatar_file');
|
|
|
|
var input_error = target.find('.edit_bot_avatar_error');
|
|
|
|
var clear_button = target.find('.edit_bot_avatar_clear_button');
|
|
|
|
var upload_button = target.find('.edit_bot_avatar_upload_button');
|
2013-07-29 16:27:18 +02:00
|
|
|
|
2017-02-21 03:15:22 +01:00
|
|
|
return upload_widget.build_widget(
|
2013-07-29 16:27:18 +02:00
|
|
|
get_file_input,
|
|
|
|
file_name_field,
|
|
|
|
input_error,
|
|
|
|
clear_button,
|
|
|
|
upload_button
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2013-10-28 15:49:38 +01:00
|
|
|
exports.build_user_avatar_widget = function (upload_function) {
|
|
|
|
var get_file_input = function () {
|
|
|
|
return $('#user_avatar_file_input').expectOne();
|
|
|
|
};
|
|
|
|
|
2016-12-21 18:34:03 +01:00
|
|
|
if (page_params.avatar_source === 'G') {
|
|
|
|
$("#user_avatar_delete_button").hide();
|
2018-03-02 18:33:20 +01:00
|
|
|
$("#user-avatar-source").show();
|
|
|
|
} else {
|
|
|
|
$("#user-avatar-source").hide();
|
2016-12-21 18:34:03 +01:00
|
|
|
}
|
2018-03-02 18:33:20 +01:00
|
|
|
|
2019-07-06 05:39:11 +02:00
|
|
|
$("#user_avatar_delete_button").on('click keydown', function (e) {
|
2016-12-21 18:34:03 +01:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
channel.del({
|
|
|
|
url: '/json/users/me/avatar',
|
2018-10-18 10:04:43 +02:00
|
|
|
success: function () {
|
2018-05-06 21:43:17 +02:00
|
|
|
$("#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('');
|
2018-10-18 10:04:43 +02:00
|
|
|
// Rest of the work is done via the user_events -> avatar_url event we will get
|
2017-01-12 00:17:43 +01:00
|
|
|
},
|
2016-12-21 18:34:03 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-02-21 03:15:22 +01:00
|
|
|
return upload_widget.build_direct_upload_widget(
|
2018-05-06 21:43:17 +02:00
|
|
|
get_file_input,
|
|
|
|
$("#user_avatar_file_input_error").expectOne(),
|
|
|
|
$("#user_avatar_upload_button").expectOne(),
|
|
|
|
upload_function,
|
|
|
|
page_params.max_avatar_file_size
|
2013-10-28 15:49:38 +01:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2013-07-29 17:29:25 +02:00
|
|
|
return exports;
|
|
|
|
|
|
|
|
}());
|
2016-12-04 08:59:56 +01:00
|
|
|
|
|
|
|
if (typeof module !== 'undefined') {
|
|
|
|
module.exports = avatar;
|
|
|
|
}
|
2018-05-28 08:04:36 +02:00
|
|
|
window.avatar = avatar;
|