zulip/static/js/stream_ui_updates.js

64 lines
1.9 KiB
JavaScript

var stream_ui_updates = (function () {
var exports = {};
exports.update_check_button_for_sub = function (sub) {
var button = subs.check_button_for_sub(sub);
if (sub.subscribed) {
button.addClass("checked");
} else {
button.removeClass("checked");
}
};
exports.update_settings_button_for_sub = function (sub) {
var settings_button = subs.settings_button_for_sub(sub);
if (sub.subscribed) {
settings_button.text(i18n.t("Unsubscribe")).removeClass("unsubscribed");
} else {
settings_button.text(i18n.t("Subscribe")).addClass("unsubscribed");
}
if (sub.should_display_subscription_button) {
settings_button.show();
} else {
settings_button.hide();
}
};
exports.update_regular_sub_settings = function (sub) {
if (!stream_edit.is_sub_settings_active(sub)) {
return;
}
var $settings = $(".subscription_settings[data-stream-id='" + sub.stream_id + "']");
if (sub.subscribed) {
if ($settings.find(".email-address").val().length === 0) {
// Rerender stream email address, if not.
$settings.find(".email-address").text(sub.email_address);
$settings.find(".stream-email-box").show();
}
$settings.find(".regular_subscription_settings").addClass('in');
} else {
$settings.find(".regular_subscription_settings").removeClass('in');
// Clear email address widget
$settings.find(".email-address").html("");
}
};
exports.update_change_stream_privacy_settings = function (sub) {
var stream_privacy_btn = $(".change-stream-privacy");
if (sub.can_change_stream_permissions) {
stream_privacy_btn.show();
} else {
stream_privacy_btn.hide();
}
};
return exports;
}());
if (typeof module !== 'undefined') {
module.exports = stream_ui_updates;
}
window.stream_ui_updates = stream_ui_updates;