2021-02-28 00:38:58 +01:00
|
|
|
import * as people from "./people";
|
|
|
|
import * as user_pill from "./user_pill";
|
|
|
|
import * as util from "./util";
|
2020-08-01 03:43:15 +02:00
|
|
|
|
2021-02-28 00:38:58 +01:00
|
|
|
export let widget;
|
2020-07-24 06:02:07 +02:00
|
|
|
|
2021-02-28 00:38:58 +01:00
|
|
|
export function initialize_pill() {
|
2019-11-02 00:06:25 +01:00
|
|
|
const container = $("#private_message_recipient").parent();
|
2018-03-06 15:07:55 +01:00
|
|
|
|
2019-10-26 00:11:05 +02:00
|
|
|
const pill = input_pill.create({
|
2020-07-20 22:18:43 +02:00
|
|
|
container,
|
2018-03-06 15:07:55 +01:00
|
|
|
create_item_from_text: user_pill.create_item_from_email,
|
|
|
|
get_text_from_item: user_pill.get_email_from_item,
|
|
|
|
});
|
|
|
|
|
|
|
|
return pill;
|
2021-02-28 00:38:58 +01:00
|
|
|
}
|
2018-03-06 15:07:55 +01:00
|
|
|
|
2021-02-28 00:38:58 +01:00
|
|
|
export function initialize() {
|
|
|
|
widget = initialize_pill();
|
2020-07-29 17:32:39 +02:00
|
|
|
|
2021-02-28 00:38:58 +01:00
|
|
|
widget.onPillCreate(() => {
|
2020-07-29 17:32:39 +02:00
|
|
|
compose_actions.update_placeholder_text();
|
|
|
|
});
|
|
|
|
|
2021-02-28 00:38:58 +01:00
|
|
|
widget.onPillRemove(() => {
|
2020-07-29 17:32:39 +02:00
|
|
|
compose_actions.update_placeholder_text();
|
|
|
|
});
|
2021-02-28 00:38:58 +01:00
|
|
|
}
|
2018-03-06 15:07:55 +01:00
|
|
|
|
2021-02-28 00:38:58 +01:00
|
|
|
export function clear() {
|
|
|
|
widget.clear();
|
|
|
|
}
|
2018-03-06 15:07:55 +01:00
|
|
|
|
2021-02-28 00:38:58 +01:00
|
|
|
export function set_from_typeahead(person) {
|
2018-03-06 15:07:55 +01:00
|
|
|
// We expect person to be an object returned from people.js.
|
|
|
|
user_pill.append_person({
|
2021-02-28 00:38:58 +01:00
|
|
|
pill_widget: widget,
|
2020-07-20 22:18:43 +02:00
|
|
|
person,
|
2018-03-06 15:07:55 +01:00
|
|
|
});
|
2021-02-28 00:38:58 +01:00
|
|
|
}
|
2018-03-06 15:07:55 +01:00
|
|
|
|
2021-02-28 00:38:58 +01:00
|
|
|
export function set_from_emails(value) {
|
2018-03-06 15:07:55 +01:00
|
|
|
// value is something like "alice@example.com,bob@example.com"
|
2021-02-28 00:38:58 +01:00
|
|
|
clear();
|
|
|
|
widget.appendValue(value);
|
|
|
|
}
|
2018-03-06 15:07:55 +01:00
|
|
|
|
2021-02-28 00:38:58 +01:00
|
|
|
export function get_user_ids() {
|
|
|
|
return user_pill.get_user_ids(widget);
|
|
|
|
}
|
2018-03-06 15:07:55 +01:00
|
|
|
|
2021-02-28 00:38:58 +01:00
|
|
|
export function has_unconverted_data() {
|
|
|
|
return user_pill.has_unconverted_data(widget);
|
|
|
|
}
|
2018-09-18 01:40:27 +02:00
|
|
|
|
2021-02-28 00:38:58 +01:00
|
|
|
export function get_user_ids_string() {
|
|
|
|
const user_ids = get_user_ids();
|
2019-11-02 00:06:25 +01:00
|
|
|
const sorted_user_ids = util.sorted_ids(user_ids);
|
2020-07-15 01:29:15 +02:00
|
|
|
const user_ids_string = sorted_user_ids.join(",");
|
2018-08-25 17:06:59 +02:00
|
|
|
return user_ids_string;
|
2021-02-28 00:38:58 +01:00
|
|
|
}
|
2018-08-25 17:06:59 +02:00
|
|
|
|
2021-02-28 00:38:58 +01:00
|
|
|
export function get_emails() {
|
2018-03-06 15:07:55 +01:00
|
|
|
// return something like "alice@example.com,bob@example.com"
|
2021-02-28 00:38:58 +01:00
|
|
|
const user_ids = get_user_ids();
|
2020-07-02 01:45:54 +02:00
|
|
|
const emails = user_ids.map((id) => people.get_by_user_id(id).email).join(",");
|
2018-03-06 15:07:55 +01:00
|
|
|
return emails;
|
2021-02-28 00:38:58 +01:00
|
|
|
}
|
2018-03-06 15:07:55 +01:00
|
|
|
|
2021-02-28 00:38:58 +01:00
|
|
|
export function filter_taken_users(persons) {
|
|
|
|
return user_pill.filter_taken_users(persons, widget);
|
|
|
|
}
|