mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
Fixed problem with combobox.
The entity select widget has been modified to handle timing issue in both dialog box and details page. Ticket #1736
This commit is contained in:
parent
fa48fceaaf
commit
6d90bf2824
@ -201,6 +201,7 @@ IPA.dialog = function(spec) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
that.create();
|
that.create();
|
||||||
|
that.reset();
|
||||||
|
|
||||||
that.container.dialog({
|
that.container.dialog({
|
||||||
title: that.title,
|
title: that.title,
|
||||||
|
@ -359,11 +359,11 @@ IPA.dnszone_select_widget = function(spec) {
|
|||||||
|
|
||||||
var that = IPA.entity_select_widget(spec);
|
var that = IPA.entity_select_widget(spec);
|
||||||
|
|
||||||
that.create_search_command = function() {
|
that.create_search_command = function(filter) {
|
||||||
return IPA.command({
|
return IPA.command({
|
||||||
entity: that.other_entity,
|
entity: that.other_entity,
|
||||||
method: 'find',
|
method: 'find',
|
||||||
args: [that.filter.val()],
|
args: [filter],
|
||||||
options: {
|
options: {
|
||||||
forward_only: true
|
forward_only: true
|
||||||
}
|
}
|
||||||
|
@ -1686,7 +1686,13 @@ IPA.combobox_widget = function(spec) {
|
|||||||
name: 'filter',
|
name: 'filter',
|
||||||
keypress: function(e) {
|
keypress: function(e) {
|
||||||
if (e.which == 13) { // Enter
|
if (e.which == 13) { // Enter
|
||||||
that.search();
|
var filter = that.filter.val();
|
||||||
|
that.search(
|
||||||
|
filter,
|
||||||
|
function(data, text_status, xhr) {
|
||||||
|
that.select(filter);
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).appendTo(div);
|
}).appendTo(div);
|
||||||
@ -1695,7 +1701,13 @@ IPA.combobox_widget = function(spec) {
|
|||||||
name: 'search',
|
name: 'search',
|
||||||
icon: 'search-icon',
|
icon: 'search-icon',
|
||||||
click: function() {
|
click: function() {
|
||||||
that.search();
|
var filter = that.filter.val();
|
||||||
|
that.search(
|
||||||
|
filter,
|
||||||
|
function(data, text_status, xhr) {
|
||||||
|
that.select(filter);
|
||||||
|
}
|
||||||
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}).appendTo(div);
|
}).appendTo(div);
|
||||||
@ -1707,12 +1719,14 @@ IPA.combobox_widget = function(spec) {
|
|||||||
name: 'list',
|
name: 'list',
|
||||||
size: that.list_size,
|
size: that.list_size,
|
||||||
style: 'width: 100%',
|
style: 'width: 100%',
|
||||||
|
click: function() {
|
||||||
|
that.close();
|
||||||
|
},
|
||||||
change: function() {
|
change: function() {
|
||||||
var value = $('option:selected', that.list).val();
|
var value = $('option:selected', that.list).val();
|
||||||
that.input.val(value);
|
that.input.val(value);
|
||||||
IPA.select_range(that.input, 0, 0);
|
IPA.select_range(that.input, 0, 0);
|
||||||
|
|
||||||
that.close();
|
|
||||||
that.validate();
|
that.validate();
|
||||||
that.set_dirty(that.test_dirty());
|
that.set_dirty(that.test_dirty());
|
||||||
}
|
}
|
||||||
@ -1729,8 +1743,6 @@ IPA.combobox_widget = function(spec) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
that.create_error_link(container);
|
that.create_error_link(container);
|
||||||
|
|
||||||
that.search();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
that.open = function() {
|
that.open = function() {
|
||||||
@ -1745,27 +1757,66 @@ IPA.combobox_widget = function(spec) {
|
|||||||
return that.list_container.css('visibility') == 'visible';
|
return that.list_container.css('visibility') == 'visible';
|
||||||
};
|
};
|
||||||
|
|
||||||
that.search = function() {
|
that.search = function(filter) {
|
||||||
};
|
};
|
||||||
|
|
||||||
that.update = function() {
|
that.update = function() {
|
||||||
that.close();
|
that.close();
|
||||||
|
|
||||||
if (that.writable) {
|
if (that.writable) {
|
||||||
that.text.css('display', 'none');
|
that.text.css('display', 'none');
|
||||||
that.input.css('display', 'inline');
|
that.input.css('display', 'inline');
|
||||||
that.input.val(that.values[0]);
|
|
||||||
that.open_button.css('display', 'inline');
|
that.open_button.css('display', 'inline');
|
||||||
} else {
|
} else {
|
||||||
that.text.css('display', 'inline');
|
that.text.css('display', 'inline');
|
||||||
that.text.html(that.values[0]);
|
|
||||||
that.input.css('display', 'none');
|
that.input.css('display', 'none');
|
||||||
that.open_button.css('display', 'none');
|
that.open_button.css('display', 'none');
|
||||||
that.input.val(that.values[0]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (that.searchable) {
|
if (that.searchable) {
|
||||||
that.filter.empty();
|
that.filter.empty();
|
||||||
that.search();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// In a details page the following code will get the stored value.
|
||||||
|
// In a dialog box the value will be null.
|
||||||
|
var value = that.values.length ? that.values[0] : null;
|
||||||
|
|
||||||
|
// In a details page the following code will show the stored
|
||||||
|
// value immediately without waiting to populate the list.
|
||||||
|
// In a dialog box it will show blank.
|
||||||
|
that.set_value(value || '');
|
||||||
|
|
||||||
|
// In a details page the following code will populate the list
|
||||||
|
// and select the stored value.
|
||||||
|
// In a dialog box it will populate the list and select the first
|
||||||
|
// available option.
|
||||||
|
that.search(
|
||||||
|
null,
|
||||||
|
function(data, text_status, xhr) {
|
||||||
|
that.select(value);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
that.set_value = function(value) {
|
||||||
|
that.text.html(value);
|
||||||
|
that.input.val(value);
|
||||||
|
};
|
||||||
|
|
||||||
|
that.select = function(value) {
|
||||||
|
|
||||||
|
var option;
|
||||||
|
|
||||||
|
if (value) {
|
||||||
|
option = $('option[value="'+value+'"]', that.list);
|
||||||
|
} else {
|
||||||
|
option = $('option', that.list).first();
|
||||||
|
}
|
||||||
|
|
||||||
|
option.attr('selected', 'selected');
|
||||||
|
|
||||||
|
that.set_value(option.val());
|
||||||
|
that.set_dirty(that.test_dirty());
|
||||||
};
|
};
|
||||||
|
|
||||||
that.save = function() {
|
that.save = function() {
|
||||||
@ -1797,49 +1848,40 @@ IPA.entity_select_widget = function(spec) {
|
|||||||
that.other_entity = spec.other_entity;
|
that.other_entity = spec.other_entity;
|
||||||
that.other_field = spec.other_field;
|
that.other_field = spec.other_field;
|
||||||
|
|
||||||
that.create_search_command = function() {
|
that.create_search_command = function(filter) {
|
||||||
return IPA.command({
|
return IPA.command({
|
||||||
entity: that.other_entity,
|
entity: that.other_entity,
|
||||||
method: 'find',
|
method: 'find',
|
||||||
args: [that.filter.val()]
|
args: [filter]
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
that.search = function() {
|
that.search = function(filter, on_success, on_error) {
|
||||||
|
|
||||||
var command = that.create_search_command();
|
var command = that.create_search_command(filter);
|
||||||
|
|
||||||
command.on_success = function(data, text_status, xhr) {
|
command.on_success = function(data, text_status, xhr) {
|
||||||
|
|
||||||
that.remove_options();
|
that.remove_options();
|
||||||
|
|
||||||
var selected_option = null;
|
|
||||||
|
|
||||||
if (that.empty_option) {
|
if (that.empty_option) {
|
||||||
selected_option = that.create_option();
|
that.create_option();
|
||||||
}
|
}
|
||||||
|
|
||||||
var filter = that.filter.val();
|
|
||||||
var entries = data.result.result;
|
var entries = data.result.result;
|
||||||
for (var i=0; i<data.result.count; i++) {
|
for (var i=0; i<data.result.count; i++) {
|
||||||
var entry = entries[i];
|
var entry = entries[i];
|
||||||
var values = entry[that.other_field];
|
var values = entry[that.other_field];
|
||||||
var value = values[0];
|
var value = values[0];
|
||||||
|
|
||||||
var option = that.create_option(value, value);
|
that.create_option(value, value);
|
||||||
|
|
||||||
if (!selected_option || filter === value) {
|
|
||||||
selected_option = option;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (selected_option) {
|
if (on_success) on_success.call(this, data, text_status, xhr);
|
||||||
selected_option.attr('selected', 'selected');
|
|
||||||
that.input.val(selected_option.val());
|
|
||||||
that.set_dirty(that.test_dirty());
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
command.on_error = on_error;
|
||||||
|
|
||||||
command.execute();
|
command.execute();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user