custom fields: Add UI for user type of custom fields.

This commit is contained in:
Yashashvi Dave 2018-05-09 17:28:29 +05:30 committed by Tim Abbott
parent e82c879b85
commit b5cf73ae0c
2 changed files with 43 additions and 13 deletions

View File

@ -69,6 +69,7 @@ exports.add_custom_profile_fields_to_settings = function () {
var value = people.my_custom_profile_data(field.id);
var is_long_text = field_type === "Long text";
var is_choice_field = field_type === "Choice";
var is_user_field = field_type === "User";
var field_choices = [];
if (field_type === "Long text" || field_type === "Short text") {
@ -105,9 +106,36 @@ exports.add_custom_profile_fields_to_settings = function () {
field_value: value,
is_long_text_field: is_long_text,
is_choice_field: is_choice_field,
is_user_field: is_user_field,
field_choices: field_choices,
});
$("#account-settings .custom-profile-fields-form").append(html);
if (is_user_field) {
var pill_container = $('.custom_user_field[data-field-id="' + field.id + '"] .pill-container').expectOne();
var pills = user_pill.create_pills(pill_container);
function update_custom_user_field() {
var fields = [];
var user_id = user_pill.get_user_ids(pills);
if (user_id.length !== 1) {
ui_report.message(i18n.t("Only one user allowed"), $("#custom-field-status"), 'alert-error');
return;
}
fields.push({id: field.id, value: user_id[0]});
update_user_custom_profile_fields(fields);
}
if (value) {
var user = people.get_person_from_user_id(value);
user_pill.append_user(user, pills);
}
var input = pill_container.children('.input');
user_pill.set_up_typeahead_on_pills(input, pills, update_custom_user_field);
pills.onPillRemove(function () {
update_custom_user_field();
});
}
});
};

View File

@ -1,20 +1,22 @@
<div class="user-name-section custom_user_field" name="{{ field.name }}" data-field-id="{{ field.id }}">
<label for="{{ field.name }}" class="title">{{ field.name }}</label>
{{#if is_long_text_field}}
<textarea maxlength="500" class="custom_user_field_value">{{ field_value }}</textarea>
<textarea maxlength="500" class="custom_user_field_value">{{ field_value }}</textarea>
{{else if is_choice_field}}
<select class="custom_user_field_value">
{{#unless field_value}}
<option></option>
{{/unless}}
{{#each field_choices}}
<option value="{{ this.value }}" {{#if this.selected}}selected{{/if}}>{{ this.text }}</option>
{{/each}}
</select>
{{else if is_user_field }}
<div class="pill-container">
<div class="input" contenteditable="true"></div>
</div>
{{else}}
{{#if is_choice_field }}
<select class="custom_user_field_value">
{{#unless field_value}}
<option></option>
{{/unless}}
{{#each field_choices}}
<option value="{{ this.value }}" {{#if this.selected}}selected{{/if}}>{{ this.text }}</option>
{{/each}}
</select>
{{else}}
<input class="custom_user_field_value" type="{{ field_type }}" value="{{ field_value }}" maxlength="50" />
{{/if}}
<input class="custom_user_field_value" type="{{ field_type }}" value="{{ field_value }}" maxlength="50" />
{{/if}}
<div class="field_hint">{{ field.hint }}</div>
</div>