diff options
Diffstat (limited to 'install/ui/widget.js')
-rw-r--r-- | install/ui/widget.js | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/install/ui/widget.js b/install/ui/widget.js index 4a77dda83..b5c02ee33 100644 --- a/install/ui/widget.js +++ b/install/ui/widget.js @@ -1,6 +1,7 @@ /*jsl:import ipa.js */ /* Authors: * Endi Sukma Dewata <edewata@redhat.com> + * Adam Young <ayoung@redhat.com> * * Copyright (C) 2010 Red Hat * see file 'COPYING' for use and warranty information @@ -1061,3 +1062,93 @@ IPA.table_widget = function (spec) { return that; }; +IPA.entity_select_widget = function(spec){ + + var that = IPA.widget(spec); + var entity = spec.entity || 'group'; + + function populate_select(value){ + function find_success(result){ + $('option', that.entity_select).remove(); + var entities = result.result.result; + for (var i =0; i < result.result.count; i +=1){ + var option = + $('<option/>',{ + text:entities[i].cn[0], + value:entities[i].cn[0] + }). + appendTo(that.entity_select); + if (value === entities[i].cn[0]){ + option.attr('selected','selected'); + } + } + } + function find_error(err){ + } + IPA.command({ + method: entity+'_find', + args:[that.entity_filter.val()], + options:{}, + on_success:find_success, + on_error:find_error + }).execute(); + } + + that.create = function(container){ + var dd = $('<dd/>').appendTo(container); + + that.entity_select = $('<select/>', { + id: that.name + '-entity-select', + change: function(){ + + } + }).appendTo(dd); + + + that.entity_filter = $('<input/>',{ + size:10, + type: 'text', + id: 'entity_filter', + style: 'display: none;', + keypress: function(){ + populate_select(); + } + }).appendTo(dd); + + $('<a />',{ + href:"", + text: 'add ' +entity + ' filter: ', + click:function(){ + that.entity_filter.css('display','inline'); + $(this).css('display','none'); + return false; + } + }).appendTo(dd); + populate_select(); + }; + that.reset = function(){ + that.entity_filter.val(that.values[0]); + populate_select(that.values[0]); + + }; + + that.is_dirty = function(){ + return (that.save()[0] !== that.values[0]); + }; + + that.load = function(record){ + var value = record[that.name]; + if (value instanceof Array) { + that.values = value; + } else { + that.values = value ? [value] : ['']; + } + that.reset(); + }; + + that.save = function(){ + return [$('option:selected', that.entity_select).val()]; + }; + + return that; +};
\ No newline at end of file |