2020-08-01 03:43:15 +02:00
|
|
|
"use strict";
|
|
|
|
|
2020-08-20 21:24:06 +02:00
|
|
|
const people = require("./people");
|
2021-02-10 17:03:21 +01:00
|
|
|
const user_status = require("./user_status");
|
2020-08-20 21:24:06 +02:00
|
|
|
|
2019-01-26 21:14:33 +01:00
|
|
|
exports.input_field = function () {
|
2020-07-15 01:29:15 +02:00
|
|
|
return $(".user_status_overlay input.user_status");
|
2019-01-26 21:14:33 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.submit_button = function () {
|
2020-07-15 01:29:15 +02:00
|
|
|
return $(".user_status_overlay .set_user_status");
|
2019-01-26 21:14:33 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.open_overlay = function () {
|
2019-11-02 00:06:25 +01:00
|
|
|
const overlay = $(".user_status_overlay");
|
2019-01-26 21:14:33 +01:00
|
|
|
overlays.open_overlay({
|
2020-07-15 01:29:15 +02:00
|
|
|
name: "user_status_overlay",
|
2020-07-20 22:18:43 +02:00
|
|
|
overlay,
|
|
|
|
on_close() {},
|
2019-01-26 21:14:33 +01:00
|
|
|
});
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const user_id = people.my_current_user_id();
|
|
|
|
const old_status_text = user_status.get_status_text(user_id);
|
|
|
|
const field = exports.input_field();
|
2019-01-26 21:14:33 +01:00
|
|
|
field.val(old_status_text);
|
2020-07-20 21:24:26 +02:00
|
|
|
field.trigger("select");
|
|
|
|
field.trigger("focus");
|
2019-04-28 22:32:38 +02:00
|
|
|
exports.toggle_clear_message_button();
|
2019-01-26 21:14:33 +01:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const button = exports.submit_button();
|
2020-07-22 02:59:06 +02:00
|
|
|
button.prop("disabled", true);
|
2019-01-26 21:14:33 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.close_overlay = function () {
|
2020-07-15 01:29:15 +02:00
|
|
|
overlays.close_overlay("user_status_overlay");
|
2019-01-26 21:14:33 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.submit_new_status = function () {
|
2019-11-02 00:06:25 +01:00
|
|
|
const user_id = people.my_current_user_id();
|
2020-07-15 01:29:15 +02:00
|
|
|
let old_status_text = user_status.get_status_text(user_id) || "";
|
2019-01-26 21:14:33 +01:00
|
|
|
old_status_text = old_status_text.trim();
|
2019-11-02 00:06:25 +01:00
|
|
|
const new_status_text = exports.input_field().val().trim();
|
2019-01-26 21:14:33 +01:00
|
|
|
|
|
|
|
if (old_status_text === new_status_text) {
|
|
|
|
exports.close_overlay();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
user_status.server_update({
|
|
|
|
status_text: new_status_text,
|
2020-07-20 22:18:43 +02:00
|
|
|
success() {
|
2019-01-26 21:14:33 +01:00
|
|
|
exports.close_overlay();
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.update_button = function () {
|
2019-11-02 00:06:25 +01:00
|
|
|
const user_id = people.my_current_user_id();
|
2020-07-15 01:29:15 +02:00
|
|
|
let old_status_text = user_status.get_status_text(user_id) || "";
|
2019-01-26 21:14:33 +01:00
|
|
|
old_status_text = old_status_text.trim();
|
2019-11-02 00:06:25 +01:00
|
|
|
const new_status_text = exports.input_field().val().trim();
|
|
|
|
const button = exports.submit_button();
|
2019-01-26 21:14:33 +01:00
|
|
|
|
|
|
|
if (old_status_text === new_status_text) {
|
2020-07-22 02:59:06 +02:00
|
|
|
button.prop("disabled", true);
|
2019-01-26 21:14:33 +01:00
|
|
|
} else {
|
2020-07-22 02:59:06 +02:00
|
|
|
button.prop("disabled", false);
|
2019-01-26 21:14:33 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-04-28 22:32:38 +02:00
|
|
|
exports.toggle_clear_message_button = function () {
|
2020-07-15 01:29:15 +02:00
|
|
|
if (exports.input_field().val() !== "") {
|
|
|
|
$("#clear_status_message_button").prop("disabled", false);
|
2019-04-28 22:32:38 +02:00
|
|
|
} else {
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#clear_status_message_button").prop("disabled", true);
|
2019-04-28 22:32:38 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.clear_message = function () {
|
2019-11-02 00:06:25 +01:00
|
|
|
const field = exports.input_field();
|
2020-07-15 01:29:15 +02:00
|
|
|
field.val("");
|
|
|
|
$("#clear_status_message_button").prop("disabled", true);
|
2019-04-28 22:32:38 +02:00
|
|
|
};
|
|
|
|
|
2019-01-26 21:14:33 +01:00
|
|
|
exports.initialize = function () {
|
2020-07-15 01:29:15 +02:00
|
|
|
$("body").on("click", ".user_status_overlay .set_user_status", () => {
|
2019-01-26 21:14:33 +01:00
|
|
|
exports.submit_new_status();
|
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("body").on("keypress", ".user_status_overlay .user_status", (event) => {
|
|
|
|
if (event.key === "Enter") {
|
2020-03-05 10:08:27 +01:00
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
exports.submit_new_status();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("body").on("keyup", ".user_status_overlay input.user_status", () => {
|
2019-01-26 21:14:33 +01:00
|
|
|
exports.update_button();
|
2019-04-28 22:32:38 +02:00
|
|
|
exports.toggle_clear_message_button();
|
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#clear_status_message_button").on("click", () => {
|
2019-04-28 22:32:38 +02:00
|
|
|
exports.clear_message();
|
|
|
|
exports.update_button();
|
2019-01-26 21:14:33 +01:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2019-10-25 09:45:13 +02:00
|
|
|
window.user_status_ui = exports;
|