2019-11-02 00:06:25 +01:00
|
|
|
const user_search = function (opts) {
|
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.
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const self = {};
|
2018-04-19 17:47:41 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const $widget = $('#user_search_section').expectOne();
|
|
|
|
const $input = $('.user-list-filter').expectOne();
|
2018-04-19 17:47:41 +02:00
|
|
|
|
|
|
|
self.input_field = function () {
|
|
|
|
return $input;
|
|
|
|
};
|
|
|
|
|
|
|
|
self.text = function () {
|
|
|
|
return $input.val().trim();
|
|
|
|
};
|
|
|
|
|
|
|
|
self.searching = function () {
|
|
|
|
return $input.is(':focus');
|
|
|
|
};
|
|
|
|
|
|
|
|
self.empty = function () {
|
|
|
|
return self.text() === '';
|
|
|
|
};
|
|
|
|
|
|
|
|
self.clear_search = function () {
|
|
|
|
if (self.empty()) {
|
|
|
|
self.close_widget();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$input.val('');
|
|
|
|
$input.blur();
|
2018-04-21 14:59:03 +02:00
|
|
|
opts.reset_items();
|
2018-04-19 17:47:41 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
self.escape_search = function () {
|
|
|
|
if (self.empty()) {
|
|
|
|
self.close_widget();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$input.val('');
|
|
|
|
opts.update_list();
|
|
|
|
};
|
|
|
|
|
|
|
|
self.hide_widget = function () {
|
|
|
|
$widget.addClass('notdisplayed');
|
2020-05-27 21:43:47 +02:00
|
|
|
resize.resize_sidebars();
|
2018-04-19 17:47:41 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
self.show_widget = function () {
|
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();
|
2018-04-19 17:47:41 +02:00
|
|
|
$widget.removeClass('notdisplayed');
|
2020-05-27 21:43:47 +02:00
|
|
|
resize.resize_sidebars();
|
2018-04-19 17:47:41 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
self.widget_shown = function () {
|
|
|
|
return $widget.hasClass('notdisplayed');
|
|
|
|
};
|
|
|
|
|
|
|
|
self.clear_and_hide_search = function () {
|
|
|
|
if (!self.empty()) {
|
|
|
|
$input.val('');
|
|
|
|
opts.update_list();
|
|
|
|
}
|
|
|
|
self.close_widget();
|
|
|
|
};
|
|
|
|
|
|
|
|
self.close_widget = function () {
|
|
|
|
$input.blur();
|
|
|
|
self.hide_widget();
|
|
|
|
opts.reset_items();
|
|
|
|
};
|
|
|
|
|
|
|
|
self.expand_column = function () {
|
2019-11-02 00:06:25 +01:00
|
|
|
const column = $input.closest(".app-main [class^='column-']");
|
2018-04-19 17:47:41 +02:00
|
|
|
if (!column.hasClass("expanded")) {
|
|
|
|
popovers.hide_all();
|
|
|
|
if (column.hasClass('column-left')) {
|
|
|
|
stream_popover.show_streamlist_sidebar();
|
|
|
|
} else if (column.hasClass('column-right')) {
|
|
|
|
popovers.show_userlist_sidebar();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
self.initiate_search = function () {
|
|
|
|
self.expand_column();
|
|
|
|
self.show_widget();
|
|
|
|
$input.focus();
|
|
|
|
};
|
|
|
|
|
|
|
|
self.toggle_filter_displayed = function () {
|
|
|
|
if (self.widget_shown()) {
|
|
|
|
self.initiate_search();
|
|
|
|
} else {
|
|
|
|
self.clear_and_hide_search();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function on_focus(e) {
|
2018-04-21 14:59:03 +02:00
|
|
|
opts.on_focus();
|
2018-04-19 17:47:41 +02:00
|
|
|
e.stopPropagation();
|
|
|
|
}
|
|
|
|
|
|
|
|
$('#clear_search_people_button').on('click', self.clear_search);
|
|
|
|
$('#userlist-header').on('click', self.toggle_filter_displayed);
|
|
|
|
|
|
|
|
$input.on('input', opts.update_list);
|
2018-04-21 14:59:03 +02:00
|
|
|
$input.on('focus', on_focus);
|
2018-04-19 17:47:41 +02:00
|
|
|
|
|
|
|
return self;
|
|
|
|
};
|
|
|
|
|
2019-10-25 09:45:13 +02:00
|
|
|
module.exports = user_search;
|
2018-05-28 08:04:36 +02:00
|
|
|
window.user_search = user_search;
|