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 () {
|
2020-06-17 05:58:39 +02:00
|
|
|
return $('#realm-icon-upload-widget .image_file_input').expectOne();
|
2019-10-25 09:15:16 +02:00
|
|
|
};
|
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') {
|
2020-06-17 05:58:39 +02:00
|
|
|
$("#realm-icon-upload-widget .settings-page-delete-button").hide();
|
2019-10-25 09:15:16 +02:00
|
|
|
} else {
|
2020-06-17 05:58:39 +02:00
|
|
|
$("#realm-icon-upload-widget .settings-page-delete-button").show();
|
2019-10-25 09:15:16 +02:00
|
|
|
}
|
2020-06-17 05:58:39 +02:00
|
|
|
$("#realm-icon-upload-widget .settings-page-delete-button").on('click', function (e) {
|
2019-10-25 09:15:16 +02:00
|
|
|
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,
|
2020-06-17 05:58:39 +02:00
|
|
|
$("#realm-icon-upload-widget .image_file_input_error").expectOne(),
|
|
|
|
$("#realm-icon-upload-widget .image_upload_button").expectOne(),
|
2019-10-25 09:15:16 +02:00
|
|
|
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 () {
|
2020-06-17 05:58:39 +02:00
|
|
|
$("#realm-icon-upload-widget .image-block").attr("src", page_params.realm_icon_url);
|
2019-10-25 09:15:16 +02:00
|
|
|
if (page_params.realm_icon_source === 'U') {
|
2020-06-17 05:58:39 +02:00
|
|
|
$("#realm-icon-upload-widget .settings-page-delete-button").show();
|
2019-10-25 09:15:16 +02:00
|
|
|
} else {
|
2020-06-17 05:58:39 +02:00
|
|
|
$("#realm-icon-upload-widget .settings-page-delete-button").hide();
|
2019-10-25 09:15:16 +02:00
|
|
|
// Need to clear input because of a small edge case
|
|
|
|
// where you try to upload the same image you just deleted.
|
2020-06-17 05:58:39 +02:00
|
|
|
const file_input = $("#realm-icon-upload-widget .image_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;
|