zerver/lib/events.py: Add FIELD_TYPE_CHOICES_DICT to page_params.

This commit add FIELD_TYPE_CHOICES_DICT to page_params and replace
FIELD_TYPE_CHOICES.

FIELD_TYPE_CHOICES_DICT includes all field types with keyword, id
and display name. Using this field-type-dict, we can access field
type information by it's keyword, and remove all static use of
field-type'a name or id in frontend.
This commit also modifies functions in js where this page_params
field-types is used.
This commit is contained in:
Yashashvi Dave
2018-08-15 15:05:18 +05:30
committed by Tim Abbott
parent 621a5cdc35
commit 6e65235a6d
6 changed files with 46 additions and 31 deletions

View File

@@ -76,20 +76,21 @@ exports.add_custom_profile_fields_to_settings = function () {
}
var all_custom_fields = page_params.custom_profile_fields;
var field_types = page_params.custom_profile_field_types;
all_custom_fields.forEach(function (field) {
var field_type = settings_profile_fields.field_type_id_to_string(field.type);
var field_type = field.type;
var type;
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 is_date_field = field_type === "Date";
var is_long_text = field_type === field_types.LONG_TEXT.id;
var is_choice_field = field_type === field_types.CHOICE.id;
var is_user_field = field_type === field_types.USER.id;
var is_date_field = field_type === field_types.DATE.id;
var field_choices = [];
if (field_type === "Long text" || field_type === "Short text") {
if (is_long_text || field_type === field_types.SHORT_TEXT.id) {
type = "text";
} else if (field_type === "Choice") {
} else if (is_choice_field) {
type = "choice";
var field_choice_dict = JSON.parse(field.field_data);
for (var choice in field_choice_dict) {
@@ -101,11 +102,11 @@ exports.add_custom_profile_fields_to_settings = function () {
};
}
}
} else if (field_type === "Date") {
} else if (is_date_field) {
type = "date";
} else if (field_type === "URL") {
} else if (field_type === field_types.URL.id) {
type = "url";
} else if (field_type === "User") {
} else if (is_user_field) {
if (value) {
value = JSON.parse(value);
}