2020-08-01 03:43:15 +02:00
|
|
|
"use strict";
|
|
|
|
|
2020-02-13 22:34:29 +01:00
|
|
|
const util = require("./util");
|
2020-07-24 06:02:07 +02:00
|
|
|
|
2018-03-06 15:07:55 +01:00
|
|
|
exports.initialize_pill = function () {
|
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;
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.initialize = function () {
|
2018-07-23 02:20:57 +02:00
|
|
|
exports.widget = exports.initialize_pill();
|
2018-03-06 15:07:55 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.clear = function () {
|
2018-07-23 02:20:57 +02:00
|
|
|
exports.widget.clear();
|
2018-03-06 15:07:55 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.set_from_typeahead = function (person) {
|
|
|
|
// We expect person to be an object returned from people.js.
|
|
|
|
user_pill.append_person({
|
2018-07-23 02:20:57 +02:00
|
|
|
pill_widget: exports.widget,
|
2020-07-20 22:18:43 +02:00
|
|
|
person,
|
2018-03-06 15:07:55 +01:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.set_from_emails = function (value) {
|
|
|
|
// value is something like "alice@example.com,bob@example.com"
|
|
|
|
exports.clear();
|
2018-07-23 02:20:57 +02:00
|
|
|
exports.widget.appendValue(value);
|
2018-03-06 15:07:55 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.get_user_ids = function () {
|
2018-07-23 02:20:57 +02:00
|
|
|
return user_pill.get_user_ids(exports.widget);
|
2018-03-06 15:07:55 +01:00
|
|
|
};
|
|
|
|
|
2018-09-18 01:40:27 +02:00
|
|
|
exports.has_unconverted_data = function () {
|
|
|
|
return user_pill.has_unconverted_data(exports.widget);
|
|
|
|
};
|
|
|
|
|
2018-08-25 17:06:59 +02:00
|
|
|
exports.get_user_ids_string = function () {
|
2019-11-02 00:06:25 +01:00
|
|
|
const user_ids = exports.get_user_ids();
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2018-03-06 15:07:55 +01:00
|
|
|
exports.get_emails = function () {
|
|
|
|
// return something like "alice@example.com,bob@example.com"
|
2019-11-02 00:06:25 +01:00
|
|
|
const user_ids = exports.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;
|
|
|
|
};
|
|
|
|
|
2020-01-08 15:58:32 +01:00
|
|
|
exports.filter_taken_users = function (persons) {
|
|
|
|
return user_pill.filter_taken_users(persons, exports.widget);
|
2018-03-06 15:07:55 +01:00
|
|
|
};
|
|
|
|
|
2019-10-25 09:45:13 +02:00
|
|
|
window.compose_pm_pill = exports;
|