mirror of https://github.com/zulip/zulip.git
realm_logo: Refactor `build_realm_logo_widget` function.
As a follow up of commit (bf1c9420df
), this
commit removes the `build_realm_day_mode_logo_widget` and
`build_realm_night_mode_logo_widget` function , and changes
`build_realm_logo_widget` to take single argument `is_night` and depending
on this argument, corresponding `day mode` or `night_mode` widget is
handled.
This commit is contained in:
parent
32853a565f
commit
2ccf5655da
|
@ -56,8 +56,7 @@ const _ui_report = {
|
||||||
};
|
};
|
||||||
|
|
||||||
const _realm_logo = {
|
const _realm_logo = {
|
||||||
build_realm_day_mode_logo_widget: noop,
|
build_realm_logo_widget: noop,
|
||||||
build_realm_night_mode_logo_widget: noop,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
set_global('channel', _channel);
|
set_global('channel', _channel);
|
||||||
|
|
|
@ -2,19 +2,29 @@
|
||||||
var realm_logo = (function () {
|
var realm_logo = (function () {
|
||||||
var exports = {};
|
var exports = {};
|
||||||
|
|
||||||
function build_realm_logo_widget(args) {
|
exports.build_realm_logo_widget = function (upload_function, is_night) {
|
||||||
|
var selector_prefix = '#realm_';
|
||||||
|
if (is_night) {
|
||||||
|
selector_prefix = '#realm_night_';
|
||||||
|
}
|
||||||
|
|
||||||
|
var delete_button_elem = $(selector_prefix + "logo_delete_button");
|
||||||
|
var file_input_elem = $(selector_prefix + "logo_file_input");
|
||||||
|
var file_input_error_elem = $(selector_prefix + "logo_file_input_error");
|
||||||
|
var upload_button_elem = $(selector_prefix + "logo_upload_button");
|
||||||
|
|
||||||
var get_file_input = function () {
|
var get_file_input = function () {
|
||||||
return args.file_input_elem.expectOne();
|
return file_input_elem.expectOne();
|
||||||
};
|
};
|
||||||
|
|
||||||
if (page_params.realm_logo_source === 'D') {
|
if (page_params.realm_logo_source === 'D') {
|
||||||
args.delete_button_elem.hide();
|
delete_button_elem.hide();
|
||||||
} else {
|
} else {
|
||||||
args.delete_button_elem.show();
|
delete_button_elem.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
var data = {night: JSON.stringify(args.is_night_mode)};
|
var data = {night: JSON.stringify(is_night)};
|
||||||
args.delete_button_elem.on('click', function (e) {
|
delete_button_elem.on('click', function (e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
channel.del({
|
channel.del({
|
||||||
|
@ -25,35 +35,11 @@ var realm_logo = (function () {
|
||||||
|
|
||||||
return upload_widget.build_direct_upload_widget(
|
return upload_widget.build_direct_upload_widget(
|
||||||
get_file_input,
|
get_file_input,
|
||||||
args.file_input_error_elem.expectOne(),
|
file_input_error_elem.expectOne(),
|
||||||
args.upload_button_elem.expectOne(),
|
upload_button_elem.expectOne(),
|
||||||
args.upload_function,
|
upload_function,
|
||||||
page_params.max_logo_file_size
|
page_params.max_logo_file_size
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
|
||||||
exports.build_realm_day_mode_logo_widget = function (upload_function) {
|
|
||||||
var args = {
|
|
||||||
delete_button_elem: $("#realm_logo_delete_button"),
|
|
||||||
file_input_elem: $('#realm_logo_file_input'),
|
|
||||||
file_input_error_elem: $("#realm_logo_file_input_error"),
|
|
||||||
is_night_mode: false,
|
|
||||||
upload_button_elem: $("#realm_logo_upload_button"),
|
|
||||||
upload_function: upload_function,
|
|
||||||
};
|
|
||||||
return build_realm_logo_widget(args);
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.build_realm_night_mode_logo_widget = function (upload_function) {
|
|
||||||
var args = {
|
|
||||||
delete_button_elem: $("#realm_night_logo_delete_button"),
|
|
||||||
file_input_elem: $('#realm_night_logo_file_input'),
|
|
||||||
file_input_error_elem: $("#realm_night_logo_file_input_error"),
|
|
||||||
is_night_mode: true,
|
|
||||||
upload_button_elem: $("#realm_night_logo_upload_button"),
|
|
||||||
upload_function: upload_function,
|
|
||||||
};
|
|
||||||
return build_realm_logo_widget(args);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.rerender = function () {
|
exports.rerender = function () {
|
||||||
|
|
|
@ -1087,8 +1087,9 @@ exports.build_page = function () {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
realm_logo.build_realm_day_mode_logo_widget(upload_realm_logo);
|
realm_logo.build_realm_logo_widget(upload_realm_logo, false);
|
||||||
realm_logo.build_realm_night_mode_logo_widget(upload_realm_logo);
|
realm_logo.build_realm_logo_widget(upload_realm_logo, true);
|
||||||
|
|
||||||
|
|
||||||
$('#deactivate_realm_button').on('click', function (e) {
|
$('#deactivate_realm_button').on('click', function (e) {
|
||||||
if (!overlays.is_modal_open()) {
|
if (!overlays.is_modal_open()) {
|
||||||
|
|
Loading…
Reference in New Issue