js: Convert static/js/user_status_ui.js to ES6 module.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2021-02-10 08:03:40 -08:00 committed by Tim Abbott
parent 583febeffd
commit 4c37748712
8 changed files with 39 additions and 44 deletions

View File

@ -291,7 +291,6 @@
"user_events": false,
"user_groups": false,
"user_pill": false,
"user_status_ui": false,
"poll_widget": false,
"vdom": false,
"widgetize": false,

View File

@ -119,7 +119,6 @@ zrequire("sent_messages");
zrequire("typing");
zrequire("top_left_corner");
zrequire("starred_messages");
zrequire("user_status_ui");
const ui_init = rewiremock.proxy(() => zrequire("ui_init"), {
"../../static/js/emojisets": {

View File

@ -112,7 +112,6 @@ import "../message_fetch";
import "../server_events";
import "../zulip";
import "../presence";
import "../user_status_ui";
import "../buddy_data";
import "../padded_widget";
import "../buddy_list";

View File

@ -10,6 +10,7 @@ const render_buddy_list_tooltip_content = require("../templates/buddy_list_toolt
const message_edit_history = require("./message_edit_history");
const settings_panel_menu = require("./settings_panel_menu");
const user_status_ui = require("./user_status_ui");
const util = require("./util");
function convert_enter_to_click(e) {

View File

@ -156,5 +156,4 @@ declare let upload_widget: any;
declare let user_events: any;
declare let user_groups: any;
declare let user_pill: any;
declare let user_status_ui: any;
declare let widgetize: any;

View File

@ -22,6 +22,7 @@ const people = require("./people");
const settings_config = require("./settings_config");
const settings_data = require("./settings_data");
const user_status = require("./user_status");
const user_status_ui = require("./user_status_ui");
const util = require("./util");
let current_actions_popover_elem;

View File

@ -18,6 +18,7 @@ const people = require("./people");
const pm_conversations = require("./pm_conversations");
const topic_zoom = require("./topic_zoom");
const user_status = require("./user_status");
const user_status_ui = require("./user_status_ui");
// This is where most of our initialization takes place.
// TODO: Organize it a lot better. In particular, move bigger

View File

@ -1,17 +1,15 @@
"use strict";
import * as people from "./people";
import * as user_status from "./user_status";
const people = require("./people");
const user_status = require("./user_status");
exports.input_field = function () {
export function input_field() {
return $(".user_status_overlay input.user_status");
};
}
exports.submit_button = function () {
export function submit_button() {
return $(".user_status_overlay .set_user_status");
};
}
exports.open_overlay = function () {
export function open_overlay() {
const overlay = $(".user_status_overlay");
overlays.open_overlay({
name: "user_status_overlay",
@ -21,89 +19,87 @@ exports.open_overlay = function () {
const user_id = people.my_current_user_id();
const old_status_text = user_status.get_status_text(user_id);
const field = exports.input_field();
const field = input_field();
field.val(old_status_text);
field.trigger("select");
field.trigger("focus");
exports.toggle_clear_message_button();
toggle_clear_message_button();
const button = exports.submit_button();
const button = submit_button();
button.prop("disabled", true);
};
}
exports.close_overlay = function () {
export function close_overlay() {
overlays.close_overlay("user_status_overlay");
};
}
exports.submit_new_status = function () {
export function submit_new_status() {
const user_id = people.my_current_user_id();
let old_status_text = user_status.get_status_text(user_id) || "";
old_status_text = old_status_text.trim();
const new_status_text = exports.input_field().val().trim();
const new_status_text = input_field().val().trim();
if (old_status_text === new_status_text) {
exports.close_overlay();
close_overlay();
return;
}
user_status.server_update({
status_text: new_status_text,
success() {
exports.close_overlay();
close_overlay();
},
});
};
}
exports.update_button = function () {
export function update_button() {
const user_id = people.my_current_user_id();
let old_status_text = user_status.get_status_text(user_id) || "";
old_status_text = old_status_text.trim();
const new_status_text = exports.input_field().val().trim();
const button = exports.submit_button();
const new_status_text = input_field().val().trim();
const button = submit_button();
if (old_status_text === new_status_text) {
button.prop("disabled", true);
} else {
button.prop("disabled", false);
}
};
}
exports.toggle_clear_message_button = function () {
if (exports.input_field().val() !== "") {
export function toggle_clear_message_button() {
if (input_field().val() !== "") {
$("#clear_status_message_button").prop("disabled", false);
} else {
$("#clear_status_message_button").prop("disabled", true);
}
};
}
exports.clear_message = function () {
const field = exports.input_field();
export function clear_message() {
const field = input_field();
field.val("");
$("#clear_status_message_button").prop("disabled", true);
};
}
exports.initialize = function () {
export function initialize() {
$("body").on("click", ".user_status_overlay .set_user_status", () => {
exports.submit_new_status();
submit_new_status();
});
$("body").on("keypress", ".user_status_overlay .user_status", (event) => {
if (event.key === "Enter") {
event.preventDefault();
exports.submit_new_status();
submit_new_status();
}
});
$("body").on("keyup", ".user_status_overlay input.user_status", () => {
exports.update_button();
exports.toggle_clear_message_button();
update_button();
toggle_clear_message_button();
});
$("#clear_status_message_button").on("click", () => {
exports.clear_message();
exports.update_button();
clear_message();
update_button();
});
};
window.user_status_ui = exports;
}