mirror of https://github.com/zulip/zulip.git
pills: Add exportable function for creating non-editable pills.
This commit is contained in:
parent
9a6a82516d
commit
5c11ab857e
|
@ -367,6 +367,61 @@ exports.create = function (opts) {
|
|||
return prototype;
|
||||
};
|
||||
|
||||
// Following function is used for creating non-editable pills.
|
||||
exports.create_non_editable_pills = function (opts) {
|
||||
|
||||
if (!opts.container) {
|
||||
blueslip.error('Pill needs container.');
|
||||
return;
|
||||
}
|
||||
|
||||
var store = {
|
||||
pills: [],
|
||||
$parent: opts.container,
|
||||
};
|
||||
|
||||
var funcs = {
|
||||
// This is generally called by typeahead logic, where we have all
|
||||
// the data we need (as opposed to, say, just a user-typed email).
|
||||
appendValidatedData: function (item) {
|
||||
var id = exports.random_id();
|
||||
|
||||
if (!item.display_value) {
|
||||
blueslip.error('no display_value returned');
|
||||
return;
|
||||
}
|
||||
|
||||
var payload = {
|
||||
id: id,
|
||||
item: item,
|
||||
};
|
||||
|
||||
store.pills.push(payload);
|
||||
|
||||
var opts = {
|
||||
id: payload.id,
|
||||
display_value: item.display_value,
|
||||
cannot_edit: true,
|
||||
};
|
||||
|
||||
var pill_html = templates.render('input_pill', opts);
|
||||
payload.$element = $(pill_html);
|
||||
store.$parent.append(payload.$element);
|
||||
},
|
||||
|
||||
items: function () {
|
||||
return _.pluck(store.pills, 'item');
|
||||
},
|
||||
};
|
||||
|
||||
var prototype = {
|
||||
appendValidatedData: funcs.appendValidatedData.bind(funcs),
|
||||
items: funcs.items,
|
||||
};
|
||||
|
||||
return prototype;
|
||||
|
||||
};
|
||||
return exports;
|
||||
|
||||
}());
|
||||
|
|
|
@ -60,7 +60,9 @@ exports.append_person = function (opts) {
|
|||
user_id: person.user_id,
|
||||
email: person.email,
|
||||
});
|
||||
pill_widget.clear_text();
|
||||
if (pill_widget.clear_text !== undefined) {
|
||||
pill_widget.clear_text();
|
||||
}
|
||||
};
|
||||
|
||||
exports.get_user_ids = function (pill_widget) {
|
||||
|
|
Loading…
Reference in New Issue