From 4aefc0d6fe7a4879a9b8024eb7424b4dfa5fa7ca Mon Sep 17 00:00:00 2001 From: Petr Vobornik Date: Wed, 9 Jul 2014 13:39:14 +0200 Subject: 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 --- install/ui/src/freeipa/aci.js | 76 ++++++++++++++++++++++++++++++++------ install/ui/src/freeipa/dialog.js | 15 +++++++- install/ui/test/data/ipa_init.json | 2 + ipalib/plugins/internal.py | 2 + 4 files changed, 82 insertions(+), 13 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 = $('
', { + '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 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