stream_edit: Extract generic pill functions to be reused in future.

This commit is contained in:
Aman Agrawal
2021-01-16 07:42:53 +00:00
committed by Tim Abbott
parent 96bfeeb9e6
commit 827aaa227e

View File

@@ -292,6 +292,22 @@ exports.sort_but_pin_current_user_on_top = function (users) {
}
};
exports.create_item_from_text = function (text, current_items) {
const item = stream_pill.create_item_from_stream_name(text, current_items);
if (item) {
return item;
}
return user_pill.create_item_from_email(text, current_items);
};
exports.get_text_from_item = function (item) {
const text = stream_pill.get_stream_name_from_item(item);
if (text) {
return text;
}
return user_pill.get_email_from_item(item);
};
function show_subscription_settings(sub) {
const stream_id = sub.stream_id;
const sub_settings = exports.settings_for_sub(sub);
@@ -307,25 +323,10 @@ function show_subscription_settings(sub) {
)}'] .pill-container`,
);
function create_item_from_text(text, current_items) {
const item = stream_pill.create_item_from_stream_name(text, current_items);
if (item) {
return item;
}
return user_pill.create_item_from_email(text, current_items);
}
function get_text_from_item(item) {
const text = stream_pill.get_stream_name_from_item(item);
if (text) {
return text;
}
return user_pill.get_email_from_item(item);
}
exports.pill_widget = input_pill.create({
container,
create_item_from_text,
get_text_from_item,
create_item_from_text: exports.create_item_from_text,
get_text_from_item: exports.get_text_from_item,
});
if (!sub.render_subscribers) {