mirror of
https://github.com/zulip/zulip.git
synced 2025-11-12 09:58:06 +00:00
custom profile field: Add logic for delete-btn of choices.
This commit add following logic in delete-btn of choices, so user can not delete all choices of custom field. Show `delete-btn` in all choices, but if there exist only choice hide `delete-btn` of that choice.
This commit is contained in:
committed by
Tim Abbott
parent
3c9a2a6d53
commit
ec6a94ac34
@@ -37,6 +37,20 @@ function read_field_data_from_form(selector) {
|
|||||||
return field_data;
|
return field_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function update_choice_delete_btn(container, display_flag) {
|
||||||
|
var no_of_choice_row = container.find(".choice-row").length;
|
||||||
|
|
||||||
|
// Disable delete button if there only one choice row
|
||||||
|
// Enable choice delete button more one than once choice
|
||||||
|
if (no_of_choice_row === 1) {
|
||||||
|
if (display_flag === true) {
|
||||||
|
container.find(".choice-row .delete-choice").show();
|
||||||
|
} else {
|
||||||
|
container.find(".choice-row .delete-choice").hide();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function create_choice_row(container) {
|
function create_choice_row(container) {
|
||||||
var context = {};
|
var context = {};
|
||||||
var row = templates.render("profile-field-choice", context);
|
var row = templates.render("profile-field-choice", context);
|
||||||
@@ -51,6 +65,7 @@ function clear_form_data() {
|
|||||||
// Clear data from choice field form
|
// Clear data from choice field form
|
||||||
$("#profile_field_choices").html("");
|
$("#profile_field_choices").html("");
|
||||||
create_choice_row($("#profile_field_choices"));
|
create_choice_row($("#profile_field_choices"));
|
||||||
|
update_choice_delete_btn($("#profile_field_choices"), false);
|
||||||
$("#profile_field_choices_row").hide();
|
$("#profile_field_choices_row").hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,13 +96,16 @@ function create_profile_field(e) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function add_choice_row(e) {
|
function add_choice_row(e) {
|
||||||
|
update_choice_delete_btn($(e.delegateTarget).parent(), true);
|
||||||
var choices_div = e.delegateTarget;
|
var choices_div = e.delegateTarget;
|
||||||
create_choice_row(choices_div);
|
create_choice_row(choices_div);
|
||||||
}
|
}
|
||||||
|
|
||||||
function delete_choice_row(e) {
|
function delete_choice_row(e) {
|
||||||
var row = $(e.currentTarget).parent();
|
var row = $(e.currentTarget).parent();
|
||||||
|
var container = row.parent();
|
||||||
row.remove();
|
row.remove();
|
||||||
|
update_choice_delete_btn(container, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_profile_field_info(id) {
|
function get_profile_field_info(id) {
|
||||||
@@ -153,6 +171,7 @@ function open_edit_form(e) {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
update_choice_delete_btn(choice_list, false);
|
||||||
Sortable.create(choice_list[0], {
|
Sortable.create(choice_list[0], {
|
||||||
onUpdate: function () {},
|
onUpdate: function () {},
|
||||||
});
|
});
|
||||||
@@ -255,6 +274,7 @@ exports.do_populate_profile_fields = function (profile_fields_data) {
|
|||||||
|
|
||||||
function set_up_choices_field() {
|
function set_up_choices_field() {
|
||||||
create_choice_row('#profile_field_choices');
|
create_choice_row('#profile_field_choices');
|
||||||
|
update_choice_delete_btn($("#profile_field_choices"), false);
|
||||||
|
|
||||||
var choice_list = $("#profile_field_choices")[0];
|
var choice_list = $("#profile_field_choices")[0];
|
||||||
Sortable.create(choice_list, {
|
Sortable.create(choice_list, {
|
||||||
|
|||||||
Reference in New Issue
Block a user