2019-10-25 09:15:16 +02:00
|
|
|
exports.build_realm_icon_widget = function (upload_function) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const get_file_input = function () {
|
2019-10-25 09:15:16 +02:00
|
|
|
return $('#realm_icon_file_input').expectOne();
|
|
|
|
};
|
2017-02-21 03:41:20 +01:00
|
|
|
|
2020-03-28 20:33:49 +01:00
|
|
|
if (!page_params.is_admin) {
|
|
|
|
return;
|
|
|
|
}
|
2019-10-25 09:15:16 +02:00
|
|
|
if (page_params.realm_icon_source === 'G') {
|
|
|
|
$("#realm_icon_delete_button").hide();
|
|
|
|
} else {
|
|
|
|
$("#realm_icon_delete_button").show();
|
|
|
|
}
|
|
|
|
$("#realm_icon_delete_button").on('click', function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
channel.del({
|
|
|
|
url: '/json/realm/icon',
|
2017-02-21 03:41:20 +01:00
|
|
|
});
|
2019-10-25 09:15:16 +02:00
|
|
|
});
|
2017-02-21 03:41:20 +01:00
|
|
|
|
2019-10-25 09:15:16 +02:00
|
|
|
return upload_widget.build_direct_upload_widget(
|
|
|
|
get_file_input,
|
|
|
|
$("#realm_icon_file_input_error").expectOne(),
|
|
|
|
$("#realm_icon_upload_button").expectOne(),
|
|
|
|
upload_function,
|
|
|
|
page_params.max_icon_file_size
|
|
|
|
);
|
|
|
|
};
|
2017-02-21 03:41:20 +01:00
|
|
|
|
2019-10-25 09:15:16 +02:00
|
|
|
exports.rerender = function () {
|
|
|
|
$("#realm-settings-icon").attr("src", page_params.realm_icon_url);
|
|
|
|
if (page_params.realm_icon_source === 'U') {
|
|
|
|
$("#realm_icon_delete_button").show();
|
|
|
|
} else {
|
|
|
|
$("#realm_icon_delete_button").hide();
|
|
|
|
// Need to clear input because of a small edge case
|
|
|
|
// where you try to upload the same image you just deleted.
|
2019-11-02 00:06:25 +01:00
|
|
|
const file_input = $("#realm_icon_file_input");
|
2019-10-25 09:15:16 +02:00
|
|
|
file_input.val('');
|
|
|
|
}
|
|
|
|
};
|
2017-02-26 20:35:23 +01:00
|
|
|
|
2019-10-25 09:45:13 +02:00
|
|
|
window.realm_icon = exports;
|