settings_profile_fields: Extract func set_up_choices_field_edit_form.

This commit is contained in:
Yashashvi Dave
2019-06-06 16:44:34 +05:30
committed by Tim Abbott
parent 1fef813914
commit ac0d60f577

View File

@@ -184,27 +184,12 @@ exports.parse_field_choices_from_field_data = function (field_data) {
return choices;
};
function open_edit_form(e) {
var field_id = $(e.currentTarget).attr("data-profile-field-id");
var profile_field = get_profile_field_info(field_id);
profile_field.row.hide();
profile_field.form.show();
var field = get_profile_field(parseInt(field_id, 10));
// Set initial value in edit form
profile_field.form.find('input[name=name]').val(field.name);
profile_field.form.find('input[name=hint]').val(field.hint);
if (parseInt(field.type, 10) === field_types.CHOICE.id) {
function set_up_choices_field_edit_form(profile_field, field_data) {
// Re-render field choices in edit form to load initial choice data
var choice_list = profile_field.form.find('.edit_profile_field_choices_container');
choice_list.off();
choice_list.html("");
var field_data = {};
if (field.field_data !== "") {
field_data = JSON.parse(field.field_data);
}
var choices_data = exports.parse_field_choices_from_field_data(field_data);
_.each(choices_data, function (choice) {
@@ -221,6 +206,25 @@ function open_edit_form(e) {
Sortable.create(choice_list[0], {
onUpdate: function () {},
});
}
function open_edit_form(e) {
var field_id = $(e.currentTarget).attr("data-profile-field-id");
var profile_field = get_profile_field_info(field_id);
profile_field.row.hide();
profile_field.form.show();
var field = get_profile_field(parseInt(field_id, 10));
// Set initial value in edit form
profile_field.form.find('input[name=name]').val(field.name);
profile_field.form.find('input[name=hint]').val(field.hint);
var field_data = {};
if (field.field_data) {
field_data = JSON.parse(field.field_data);
}
if (parseInt(field.type, 10) === field_types.CHOICE.id) {
set_up_choices_field_edit_form(profile_field, field_data);
}
profile_field.form.find('.reset').on("click", function () {