diff options
author | Petr Vobornik <pvoborni@redhat.com> | 2014-07-09 13:39:14 +0200 |
---|---|---|
committer | Petr Vobornik <pvoborni@redhat.com> | 2014-07-21 10:47:06 +0200 |
commit | 4aefc0d6fe7a4879a9b8024eb7424b4dfa5fa7ca (patch) | |
tree | 8b1adc123868da871491d03a5953dfaaa6c0d4c9 /install/ui/src/freeipa/aci.js | |
parent | 9fa447cb6e5f1476072cf167eec8502cfc3e38e3 (diff) | |
download | freeipa-4aefc0d6fe7a4879a9b8024eb7424b4dfa5fa7ca.tar.gz freeipa-4aefc0d6fe7a4879a9b8024eb7424b4dfa5fa7ca.tar.xz freeipa-4aefc0d6fe7a4879a9b8024eb7424b4dfa5fa7ca.zip |
webui: custom attr in attributes widget
Web UI doesn't always know what are the possible attributes
for target object. This will allow to add custom attributes
if necessary.
https://fedorahosted.org/freeipa/ticket/4253
Reviewed-By: Endi Sukma Dewata <edewata@redhat.com>
Diffstat (limited to 'install/ui/src/freeipa/aci.js')
-rw-r--r-- | install/ui/src/freeipa/aci.js | 76 |
1 files changed, 65 insertions, 11 deletions
diff --git a/install/ui/src/freeipa/aci.js b/install/ui/src/freeipa/aci.js index 929ec92a4..4cf93c9b1 100644 --- a/install/ui/src/freeipa/aci.js +++ b/install/ui/src/freeipa/aci.js @@ -548,6 +548,12 @@ aci.attributes_widget = function(spec) { var that = IPA.checkboxes_widget(spec); + /** + * Additional options which are not defined in metadata + * @property {string[]} + */ + that.custom_options = spec.custom_options || []; + that.object_type = spec.object_type; that.skip_unmatched = spec.skip_unmatched === undefined ? false : spec.skip_unmatched; @@ -555,15 +561,20 @@ aci.attributes_widget = function(spec) { that.create = function(container) { that.container = container; - that.widget_create(container); - that.create_search_filter(container); - that.owb_create(container); + that.controls = $('<div/>', { + 'class': 'form-inline controls' + }); + that.controls.appendTo(container); + that.create_search_filter(that.controls); + that.create_add_control(that.controls); if (that.undo) { - that.create_undo(container); + that.create_undo(that.controls); } + that.owb_create(container); + that.create_error_link(container); }; @@ -595,6 +606,39 @@ aci.attributes_widget = function(spec) { filter_container.appendTo(container); }; + that.create_add_control = function(container) { + + that.add_button = IPA.button({ + label: '@i18n:buttons.add', + click: that.show_add_dialog + }); + container.append(' '); + that.add_button.appendTo(container); + }; + + that.show_add_dialog = function() { + + var dialog = IPA.form_dialog({ + name: "add_option", + title: "@i18n:objects.permission.add_custom_attr", + fields: [ + { + name: 'attr', + label: '@i18n:objects.permission.attribute', + required: true + } + ] + }); + dialog.on_confirm = function() { + if (!dialog.validate()) return; + var attr = dialog.get_field('attr'); + var value = attr.get_value()[0]; + that.add_custom_option(value, false, true, true); + dialog.close(); + }; + dialog.open(); + }; + that.filter_options = function() { $("li", that.$node).each(function() { var item = $(this); @@ -641,21 +685,31 @@ aci.attributes_widget = function(spec) { that.append = function() { - if (!that.values) return; - var unmatched = []; - for (var i=0; i<that.values.length; i++) { - if (!that.has_option(that.values[i])) { - unmatched.push(that.values[i]); + function add_unmatched(source) { + for (var i=0, l=source.length; i<l; i++) { + if (!that.has_option(source[i])) { + that.add_option(source[i], true /* suppress update */); + } } } - if (unmatched.length > 0 && !that.skip_unmatched) { - that.options.push.apply(that.options, that.prepare_options(unmatched)); + add_unmatched(that.custom_options); + + if (that.values && !that.skip_unmatched) { + add_unmatched(that.values); } }; + that.add_custom_option = function(name, to_custom, check, update) { + + var value = (name || '').toLowerCase(); + if (to_custom) that.custom_options.push(value); + if (check) that.values.push(value); + if (update) that.update(that.values); + }; + that.has_option = function(value) { var o = that.options; for (var i=0, l=o.length; i<l; i++) { |