The service type field in the service adder dialog has been modified to use an editable combobox.
Ticket #1633. -- Endi S. Dewata
From 0e3929baaaa1b0db342771429eba64e789e65a79 Mon Sep 17 00:00:00 2001 From: Endi S. Dewata <edew...@redhat.com> Date: Fri, 16 Sep 2011 12:02:12 -0500 Subject: [PATCH] Use editable combobox for service type. The service type field in the service adder dialog has been modified to use an editable combobox. Ticket #1633. --- install/ui/service.js | 42 +++++++++++++++--------------------------- install/ui/widget.js | 34 +++++++++++++++++++++++++++++----- 2 files changed, 44 insertions(+), 32 deletions(-) diff --git a/install/ui/service.js b/install/ui/service.js index 7ff1ba711b40db90d3407859a4a1049e345bd343..44c5326442607aa8401b06136b64adad6a421ee6 100644 --- a/install/ui/service.js +++ b/install/ui/service.js @@ -78,31 +78,6 @@ IPA.entity_factories.service = function() { }; -IPA.service_select_widget = function(spec) { - - var that = IPA.text_widget(spec); - var known_services = ["", "cifs", "DNS", "ftp", "HTTP","imap", "ldap", - "libvirt","nfs","qpidd","smtp"]; - - that.parent_create = that.create; - - that.create = function(container) { - - var select_widget = $('<select/>'); - for (var i = 0; i < known_services.length; i += 1){ - select_widget.append($('<option/>',{ - text: known_services[i], - click: function(){ - that.input.val(this.value); - } - })); - } - container.append(select_widget); - that.parent_create(container); - }; - return that; -}; - IPA.service_add_dialog = function(spec) { spec = spec || {}; @@ -114,10 +89,23 @@ IPA.service_add_dialog = function(spec) { entity: spec.entity, hidden: true })). - field(IPA.service_select_widget({ + field(IPA.combobox_widget({ name: 'service', label: IPA.messages.objects.service.service, - size: 20, + options: [ + 'cifs', + 'DNS', + 'ftp', + 'HTTP', + 'imap', + 'ldap', + 'libvirt', + 'nfs', + 'smtp', + 'qpidd' + ], + editable: true, + size: 10, entity: spec.entity, param_info: { required: true }, undo: false diff --git a/install/ui/widget.js b/install/ui/widget.js index 4a02cb7d8c55834da047e2677053f80d1c4eafb3..2f607194985323fda93a97b5282f8b2fa6717eb5 100644 --- a/install/ui/widget.js +++ b/install/ui/widget.js @@ -1600,8 +1600,9 @@ IPA.combobox_widget = function(spec) { that.editable = spec.editable; that.searchable = spec.searchable; - that.list_size = spec.list_size || 5; + that.size = spec.size || 5; that.empty_option = spec.empty_option === undefined ? true : spec.empty_option; + that.options = spec.options || []; that.create = function(container) { that.widget_create(container); @@ -1700,7 +1701,7 @@ IPA.combobox_widget = function(spec) { that.list = $('<select/>', { name: 'list', - size: that.list_size, + size: that.size, style: 'width: 100%', change: function() { var value = $('option:selected', that.list).val(); @@ -1732,7 +1733,30 @@ IPA.combobox_widget = function(spec) { return that.list_container.css('visibility') == 'visible'; }; - that.search = function(filter) { + that.search = function(filter, on_success, on_error) { + + that.remove_options(); + + if (that.empty_option) { + that.create_option(); + } + + for (var i=0; i<that.options.length; i++) { + var option = that.options[i]; + + var label, value; + if (option instanceof Object) { + label = option.label; + value = option.value; + } else { + label = option; + value = option; + } + + that.create_option(label, value); + } + + if (on_success) on_success.call(this); }; that.update = function() { @@ -1799,9 +1823,9 @@ IPA.combobox_widget = function(spec) { return value === '' ? [] : [value]; }; - that.create_option = function(text, value) { + that.create_option = function(label, value) { return $('<option/>', { - text: text, + text: label, value: value }).appendTo(that.list); }; -- 1.7.5.1
_______________________________________________ Freeipa-devel mailing list Freeipa-devel@redhat.com https://www.redhat.com/mailman/listinfo/freeipa-devel