2020-07-23 04:10:24 +02:00
|
|
|
class UserSearch {
|
2018-04-19 17:47:41 +02:00
|
|
|
// This is mostly view code to manage the user search widget
|
|
|
|
// above the buddy list. We rely on other code to manage the
|
|
|
|
// details of populating the list when we change.
|
|
|
|
|
2020-07-23 04:10:24 +02:00
|
|
|
$widget = $("#user_search_section").expectOne();
|
|
|
|
$input = $(".user-list-filter").expectOne();
|
2018-04-19 17:47:41 +02:00
|
|
|
|
2020-07-23 04:10:24 +02:00
|
|
|
constructor(opts) {
|
|
|
|
this._reset_items = opts.reset_items;
|
|
|
|
this._update_list = opts.update_list;
|
|
|
|
this._on_focus = opts.on_focus;
|
2018-04-19 17:47:41 +02:00
|
|
|
|
2020-07-23 04:10:24 +02:00
|
|
|
$("#clear_search_people_button").on("click", () => this.clear_search());
|
|
|
|
$("#userlist-header").on("click", () => this.toggle_filter_displayed());
|
2018-04-19 17:47:41 +02:00
|
|
|
|
2020-07-23 04:10:24 +02:00
|
|
|
this.$input.on("input", opts.update_list);
|
|
|
|
this.$input.on("focus", (e) => this.on_focus(e));
|
|
|
|
}
|
|
|
|
|
|
|
|
input_field() {
|
|
|
|
return this.$input;
|
|
|
|
}
|
|
|
|
|
|
|
|
text() {
|
|
|
|
return this.$input.val().trim();
|
|
|
|
}
|
2018-04-19 17:47:41 +02:00
|
|
|
|
2020-07-23 04:10:24 +02:00
|
|
|
searching() {
|
|
|
|
return this.$input.is(":focus");
|
|
|
|
}
|
2018-04-19 17:47:41 +02:00
|
|
|
|
2020-07-23 04:10:24 +02:00
|
|
|
empty() {
|
|
|
|
return this.text() === "";
|
|
|
|
}
|
2018-04-19 17:47:41 +02:00
|
|
|
|
2020-07-23 04:10:24 +02:00
|
|
|
clear_search() {
|
|
|
|
if (this.empty()) {
|
|
|
|
this.close_widget();
|
2018-04-19 17:47:41 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-07-23 04:10:24 +02:00
|
|
|
this.$input.val("");
|
|
|
|
this.$input.trigger("blur");
|
|
|
|
this._reset_items();
|
|
|
|
}
|
2018-04-19 17:47:41 +02:00
|
|
|
|
2020-07-23 04:10:24 +02:00
|
|
|
escape_search() {
|
|
|
|
if (this.empty()) {
|
|
|
|
this.close_widget();
|
2018-04-19 17:47:41 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-07-23 04:10:24 +02:00
|
|
|
this.$input.val("");
|
|
|
|
this._update_list();
|
|
|
|
}
|
2018-04-19 17:47:41 +02:00
|
|
|
|
2020-07-23 04:10:24 +02:00
|
|
|
hide_widget() {
|
|
|
|
this.$widget.addClass("notdisplayed");
|
2020-05-27 21:43:47 +02:00
|
|
|
resize.resize_sidebars();
|
2020-07-23 04:10:24 +02:00
|
|
|
}
|
2018-04-19 17:47:41 +02:00
|
|
|
|
2020-07-23 04:10:24 +02:00
|
|
|
show_widget() {
|
2019-02-08 14:37:04 +01:00
|
|
|
// Hide all the popovers but not userlist sidebar
|
|
|
|
// when the user wants to search.
|
2019-07-10 08:03:41 +02:00
|
|
|
popovers.hide_all_except_sidebars();
|
2020-07-23 04:10:24 +02:00
|
|
|
this.$widget.removeClass("notdisplayed");
|
2020-05-27 21:43:47 +02:00
|
|
|
resize.resize_sidebars();
|
2020-07-23 04:10:24 +02:00
|
|
|
}
|
2018-04-19 17:47:41 +02:00
|
|
|
|
2020-07-23 04:10:24 +02:00
|
|
|
widget_shown() {
|
|
|
|
return this.$widget.hasClass("notdisplayed");
|
|
|
|
}
|
2018-04-19 17:47:41 +02:00
|
|
|
|
2020-07-23 04:10:24 +02:00
|
|
|
clear_and_hide_search() {
|
|
|
|
if (!this.empty()) {
|
|
|
|
this.$input.val("");
|
|
|
|
this._update_list();
|
2018-04-19 17:47:41 +02:00
|
|
|
}
|
2020-07-23 04:10:24 +02:00
|
|
|
this.close_widget();
|
|
|
|
}
|
2018-04-19 17:47:41 +02:00
|
|
|
|
2020-07-23 04:10:24 +02:00
|
|
|
close_widget() {
|
|
|
|
this.$input.trigger("blur");
|
|
|
|
this.hide_widget();
|
|
|
|
this._reset_items();
|
|
|
|
}
|
2018-04-19 17:47:41 +02:00
|
|
|
|
2020-07-23 04:10:24 +02:00
|
|
|
expand_column() {
|
|
|
|
const column = this.$input.closest(".app-main [class^='column-']");
|
2018-04-19 17:47:41 +02:00
|
|
|
if (!column.hasClass("expanded")) {
|
|
|
|
popovers.hide_all();
|
2020-07-15 01:29:15 +02:00
|
|
|
if (column.hasClass("column-left")) {
|
2018-04-19 17:47:41 +02:00
|
|
|
stream_popover.show_streamlist_sidebar();
|
2020-07-15 01:29:15 +02:00
|
|
|
} else if (column.hasClass("column-right")) {
|
2018-04-19 17:47:41 +02:00
|
|
|
popovers.show_userlist_sidebar();
|
|
|
|
}
|
|
|
|
}
|
2020-07-23 04:10:24 +02:00
|
|
|
}
|
2018-04-19 17:47:41 +02:00
|
|
|
|
2020-07-23 04:10:24 +02:00
|
|
|
initiate_search() {
|
|
|
|
this.expand_column();
|
|
|
|
this.show_widget();
|
|
|
|
this.$input.trigger("focus");
|
|
|
|
}
|
2018-04-19 17:47:41 +02:00
|
|
|
|
2020-07-23 04:10:24 +02:00
|
|
|
toggle_filter_displayed() {
|
|
|
|
if (this.widget_shown()) {
|
|
|
|
this.initiate_search();
|
2018-04-19 17:47:41 +02:00
|
|
|
} else {
|
2020-07-23 04:10:24 +02:00
|
|
|
this.clear_and_hide_search();
|
2018-04-19 17:47:41 +02:00
|
|
|
}
|
2020-07-23 04:10:24 +02:00
|
|
|
}
|
2018-04-19 17:47:41 +02:00
|
|
|
|
2020-07-23 04:10:24 +02:00
|
|
|
on_focus(e) {
|
|
|
|
this._on_focus();
|
2018-04-19 17:47:41 +02:00
|
|
|
e.stopPropagation();
|
|
|
|
}
|
2020-07-23 04:10:24 +02:00
|
|
|
}
|
2018-04-19 17:47:41 +02:00
|
|
|
|
2020-07-23 04:10:24 +02:00
|
|
|
module.exports = UserSearch;
|
|
|
|
window.UserSearch = UserSearch;
|