From ab667912cf19d17e749d13b1d9f428ab6ae55b93 Mon Sep 17 00:00:00 2001 From: Petr Vobornik Date: Tue, 29 Nov 2011 13:36:07 +0100 Subject: Code cleanup of HBAC, Sudo rules https://fedorahosted.org/freeipa/ticket/1515 --- install/ui/rule.js | 199 ++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 151 insertions(+), 48 deletions(-) (limited to 'install/ui/rule.js') diff --git a/install/ui/rule.js b/install/ui/rule.js index 9f8e23187..003785bcd 100644 --- a/install/ui/rule.js +++ b/install/ui/rule.js @@ -22,84 +22,187 @@ /* REQUIRES: ipa.js, details.js, search.js, add.js, facet.js, entity.js */ -IPA.rule_details_section = function(spec) { +IPA.rule_details_widget = function(spec) { spec = spec || {}; - var that = IPA.details_section(spec); + var that = IPA.composite_widget(spec); - that.field_name = spec.field_name; + that.radio_name = spec.radio_name; that.options = spec.options || []; that.tables = spec.tables || []; that.columns = spec.columns; - that.create = function(container) { + that.init = function() { - that.container = container; + that.enable_radio = IPA.radio_widget({ + name: that.radio_name, + options: that.options + }); + + that.widgets.add_widget(that.enable_radio); + that.enable_radio.value_changed.attach(that.on_enable_radio_changed); + }; + + that.on_enable_radio_changed = function(value) { + if(value.length > 0) { + var enabled = ('' === value[0]); + for (var i=0; i', { - name: that.field_name, - title: metadata.doc, + //enable radios + var param_info = IPA.get_entity_param(that.entity.name, that.radio_name); + var title = param_info ? param_info.doc : that.radio_name; + var enable_radio_container = $('
', { + name: that.radio_name, + title: title, 'class': 'field' }).appendTo(container); + enable_radio_container.append(title+': '); + that.enable_radio.create(enable_radio_container); + //tables + for (var j=0; j', { + name: table.name, + title: metadata ? metadata.doc : table.name, + 'class': 'field' + }).appendTo(container); + + var widget = that.widgets.get_widget(table.name); + widget.create(table_container); } + }; + + that.init(); + + return that; +}; + + +IPA.rule_association_table_widget = function(spec) { + + spec = spec || {}; + + var that = IPA.association_table_widget(spec); + + that.external = spec.external; + + that.enabled = spec.enabled !== undefined ? spec.enabled : true; - if (that.options.length) { - var category = that.fields.get_field(that.field_name); - category.options=that.options; - category.reset = function() { - category.widget_reset(); - var values = category.save(); - if (values.length === 0){ - return; - } - var value = values[0]; - update_tables(value); - }; - category.create(span); - - var inputs = $('input[name='+that.field_name+']', container); - inputs.change(function() { - var input = $(this); - var value = input.val(); - update_tables(value); - }); + that.create_add_dialog = function() { + + var entity_label = that.entity.metadata.label_singular; + var pkey = IPA.nav.get_state(that.entity.name+'-pkey'); + var other_entity_label = IPA.metadata.objects[that.other_entity].label; + + var title = that.add_title; + title = title.replace('${entity}', entity_label); + title = title.replace('${primary_key}', pkey); + title = title.replace('${other_entity}', other_entity_label); + + return IPA.rule_association_adder_dialog({ + title: title, + pkey: pkey, + other_entity: that.other_entity, + attribute_member: that.attribute_member, + entity: that.entity, + external: that.external, + exclude: that.values + }); + }; + + return that; +}; + +IPA.rule_association_table_field = function(spec) { + + spec = spec || {}; + + var that = IPA.field(spec); + + that.load = function(result) { + that.values = result[that.name] || []; + if (that.external) { + var external_values = result[that.external] || []; + $.merge(that.values, external_values); } + that.widget.update(that.values); + that.widget.unselect_all(); + }; + that.get_update_info = function() { - for (var j=0; j', { - name: table.field_name, - title: metadata ? metadata.doc : table.field_name, - 'class': 'field' - }).appendTo(span); + if (!that.widget.enabled) { + var values = that.save(); - field = that.fields.get_field(table.field_name); - field.create(table_span); + if (values.length > 0) { //no need to delete if has no values + + var command = IPA.command({ + entity: that.entity.name, + method: that.widget.remove_method, + args: that.entity.get_primary_key(), + options: {all: true, rights: true} + }); + + command.set_option(that.widget.other_entity, values.join(',')); + update_info.append_command(command, that.priority); + } } + return update_info; + }; + + return that; +}; + +IPA.widget_factories['rule_association_table'] = IPA.rule_association_table_widget; +IPA.field_factories['rule_association_table'] = IPA.rule_association_table_field; +IPA.rule_association_adder_dialog = function(spec) { + + spec = spec || {}; + + var that = IPA.association_adder_dialog(spec); + + that.external = spec.external; + + that.add = function() { + var rows = that.available_table.remove_selected_rows(); + that.selected_table.add_rows(rows); + + if (that.external) { + var pkey_name = IPA.metadata.objects[that.other_entity].primary_key; + var value = that.external_field.val(); + if (!value) return; + + var record = {}; + record[pkey_name] = value; + that.selected_table.add_record(record); + that.external_field.val(''); + } }; return that; -- cgit