(prerequisite) [PATCH] Multiple fields for one attribute:

Current implementation has a limitation to have one field per one attribute. This is fine for most cases. For cases where an attribute can have two editor widgets which can be swapped a need for two different types of field may occur.

This patch introduces 'param' option which supposes to contain attribute name. If 'param' is not specified it will contain field's name therefore backward compatibility is maintained. This extension allows to have two fields with different name and same param -> two fields get/supply value from/to the same attribute.

[PATCH] Added attrs to permission when target is group or filter:

Option to set attributes in permission was missing for target 'group' and 'filter'.

Attribute_table_widget with type=group is shown for target=group.

For target=filter a multivalued textbox is shown. This is because UI can't predict what type will the result of the filter be. In future it can be extended by interactive attribute selector to help user find what he wants to enter.

Mutlivalued widget was modified to show undo button for new entries even if show_undo is false. It is useful in adder dialog to indicate that user added something and to enable it reversal.

https://fedorahosted.org/freeipa/ticket/2372

--
Petr Vobornik
From 75c518879d0577d24ba1d486b113678aad2ae12d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Petr=20Voborn=C3=ADk?= <pvobo...@redhat.com>
Date: Wed, 22 Feb 2012 09:21:56 +0100
Subject: [PATCH] Multiple fields for one attribute

Current implementation has a limitation to have one field per one attribute. This is fine for most cases. For cases where an attribute can have two editor widgets which can be swapped a need for two different types of field may occur.

This patch introduces 'param' option which supposes to contain attribute name. If 'param' is not specified it will contain field's name therefore backward compatibility is maintained. This extension allows to have two fields with different name and same param -> two fields get/supply value from/to the same attribute.

Needed for:

https://fedorahosted.org/freeipa/ticket/2372
---
 install/ui/add.js     |    6 +++---
 install/ui/details.js |   16 +++++++++-------
 install/ui/field.js   |   11 ++++++-----
 install/ui/rule.js    |    4 ++--
 install/ui/service.js |    2 +-
 5 files changed, 21 insertions(+), 18 deletions(-)

diff --git a/install/ui/add.js b/install/ui/add.js
index c1031f8b37d50616b304fae4aa3210d2346ed572..9b473ccc28befceeb7d38ac675ec3019e724459c 100644
--- a/install/ui/add.js
+++ b/install/ui/add.js
@@ -122,17 +122,17 @@ IPA.entity_adder_dialog = function(spec) {
         for (var j=0; j<fields.length; j++) {
             var field = fields[j];
 
-            var values = record[field.name];
+            var values = record[field.param];
             if (!values) continue;
 
             // TODO: Handle multi-valued attributes like in detail facet's update()
             var value = values.join(',');
             if (!value) continue;
 
-            if (field.name == pkey_name) {
+            if (field.param === pkey_name) {
                 command.add_arg(value);
             } else {
-                command.set_option(field.name, value);
+                command.set_option(field.param, value);
             }
         }
 
diff --git a/install/ui/details.js b/install/ui/details.js
index acd498aa062f1bb52df2a4c4d6ad155a41a060b8..d68ebd07cb63e11efdc81e2017754431f945c90b 100644
--- a/install/ui/details.js
+++ b/install/ui/details.js
@@ -493,7 +493,7 @@ IPA.details_facet = function(spec) {
 
             if (only_dirty && !field.is_dirty()) continue;
 
-            var values = record[field.name];
+            var values = record[field.param];
             if (require_value && !values) continue;
 
             update_info.append_field(field, values);
@@ -838,23 +838,25 @@ IPA.command_builder = function() {
     that.add_field_option = function(command, field, values) {
         if (!field || !values) return;
 
+        var name = field.param;
+
         if (field.metadata) {
             if (field.metadata.primary_key) return;
             if (values.length === 1) {
-                command.set_option(field.name, values[0]);
+                command.set_option(name, values[0]);
             } else if (field.join) {
-                command.set_option(field.name, values.join(','));
+                command.set_option(name, values.join(','));
             } else {
-                command.set_option(field.name, values);
+                command.set_option(name, values);
             }
         } else {
             if (values.length) {
-                command.add_option('setattr', field.name+'='+values[0]);
+                command.add_option('setattr', name+'='+values[0]);
             } else {
-                command.add_option('setattr', field.name+'=');
+                command.add_option('setattr', name+'=');
             }
             for (var k=1; k<values.length; k++) {
-                command.add_option('addattr', field.name+'='+values[k]);
+                command.add_option('addattr', name+'='+values[k]);
             }
         }
     };
diff --git a/install/ui/field.js b/install/ui/field.js
index 46802be6cf9089a9eb75c338512fc7a775dea4b1..fc8f7fea736b7c3e3de794ce31915b66de8e9c34 100644
--- a/install/ui/field.js
+++ b/install/ui/field.js
@@ -32,6 +32,7 @@ IPA.field = function(spec) {
     that.entity = IPA.get_entity(spec.entity);
     that.container = null;
     that.name = spec.name;
+    that.param = spec.param || spec.name;
     that.label = spec.label;
     that.tooltip = spec.tooltip;
     that.formatter = spec.formatter;
@@ -66,7 +67,7 @@ IPA.field = function(spec) {
 
     var init = function() {
         if (!that.metadata && that.entity) {
-            that.metadata = IPA.get_entity_param(that.entity.name, that.name);
+            that.metadata = IPA.get_entity_param(that.entity.name, that.param);
         }
         if (that.metadata) {
             if (that.label === undefined) {
@@ -148,7 +149,7 @@ IPA.field = function(spec) {
     that.load = function(record) {
         that.record = record;
 
-        that.values = that.get_value(record, that.name);
+        that.values = that.get_value(record, that.param);
 
         that.load_writable(record);
 
@@ -185,7 +186,7 @@ IPA.field = function(spec) {
         }
 
         if (record.attributelevelrights) {
-            var rights = record.attributelevelrights[that.name];
+            var rights = record.attributelevelrights[that.param];
             if (!rights || rights.indexOf('w') < 0) {
                 that.writable = false;
             }
@@ -249,7 +250,7 @@ IPA.field = function(spec) {
         }
 
         if(record) {
-            record[that.name] = values;
+            record[that.param] = values;
         }
 
         return values;
@@ -589,7 +590,7 @@ IPA.sshkeys_field = function(spec) {
 
     that.load = function(record) {
 
-        var keys = that.get_value(record, that.name);
+        var keys = that.get_value(record, that.param);
         var fingerprints = that.get_value(record, that.sshfp_attr);
 
         var values = [];
diff --git a/install/ui/rule.js b/install/ui/rule.js
index f2d7c6dd10c6d1d8bf793cecfd8c45c140927f05..2a164832129f87b68fc45cd5cdbcb3e3935d767d 100644
--- a/install/ui/rule.js
+++ b/install/ui/rule.js
@@ -170,7 +170,7 @@ IPA.rule_association_table_field = function(spec) {
 
             if (typeof record !== 'object') {
                 record = {};
-                record[that.name] = values[i];
+                record[that.param] = values[i];
             }
 
             record[that.external] = external;
@@ -180,7 +180,7 @@ IPA.rule_association_table_field = function(spec) {
     };
 
     that.load = function(result) {
-        that.values = result[that.name] || [];
+        that.values = result[that.param] || [];
 
         if (that.external) {
             that.set_values_external(that.values, '');
diff --git a/install/ui/service.js b/install/ui/service.js
index f60d455508b748754a7396c639723dfef5968b3e..c86a6d05daa1d44dbff379bb85241182371464cb 100644
--- a/install/ui/service.js
+++ b/install/ui/service.js
@@ -347,7 +347,7 @@ IPA.service_provisioning_status_field = function (spec) {
     that.load = function(record) {
 
         that.values = {
-            value: record[that.name],
+            value: record[that.param],
             pkey: record['krbprincipalname'][0]
         };
 
-- 
1.7.7.6

From ddf71a04c8937eec1e4ff12cc75707e84547f46d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Petr=20Voborn=C3=ADk?= <pvobo...@redhat.com>
Date: Wed, 22 Feb 2012 12:53:00 +0100
Subject: [PATCH] Added attrs to permission when target is group or filter

Option to set attributes in permission was missing for target 'group' and 'filter'.

Attribute_table_widget with type=group is shown for target=group.

For target=filter a multivalued textbox is shown. This is because UI can't predict what type will the result of the filter be. In future it can be extended by interactive attribute selector to help user find what he wants to enter.

Mutlivalued widget was modified to show undo button for new entries even if show_undo is false. It is useful in adder dialog to indicate that user added something and to enable it reversal.

https://fedorahosted.org/freeipa/ticket/2372
---
 install/ui/aci.js            |  141 ++++++++++++++++++++++++++++++++----------
 install/ui/test/aci_tests.js |   17 ++++-
 install/ui/widget.js         |    2 +-
 3 files changed, 123 insertions(+), 37 deletions(-)

diff --git a/install/ui/aci.js b/install/ui/aci.js
index 02e03f309f279d62f411e3b9ffd8bae9fe09dc06..ec3c8065b8d13e7feede2947188504ec6919230e 100644
--- a/install/ui/aci.js
+++ b/install/ui/aci.js
@@ -52,7 +52,8 @@ IPA.aci.permission_entity = function(spec) {
                 {
                     type: 'select',
                     name: 'target',
-                    widget: 'target.target'
+                    widget: 'target.target',
+                    enabled: false
                 },
                 {
                     name: 'filter',
@@ -62,7 +63,8 @@ IPA.aci.permission_entity = function(spec) {
                 {
                     type: 'entity_select',
                     name: 'memberof',
-                    widget: 'target.memberof'
+                    widget: 'target.memberof',
+                    enabled: false
                 },
                 {
                     name: 'subtree',
@@ -85,6 +87,13 @@ IPA.aci.permission_entity = function(spec) {
                     name: 'attrs',
                     widget: 'target.attrs',
                     enabled: false
+                },
+                {
+                    name: 'attrs_multi',
+                    param: 'attrs',
+                    type: 'multivalued',
+                    widget: 'target.attrs_multi',
+                    enabled: false
                 }
             ],
             widgets: [
@@ -139,7 +148,8 @@ IPA.aci.permission_entity = function(spec) {
                 {
                     type: 'select',
                     name: 'target',
-                    widget: 'target.target'
+                    widget: 'target.target',
+                    enabled: false
                 },
                 {
                     name: 'filter',
@@ -149,7 +159,8 @@ IPA.aci.permission_entity = function(spec) {
                 {
                     type: 'entity_select',
                     name: 'memberof',
-                    widget: 'target.memberof'
+                    widget: 'target.memberof',
+                    enabled: false
                 },
                 {
                     name: 'subtree',
@@ -172,6 +183,13 @@ IPA.aci.permission_entity = function(spec) {
                     name: 'attrs',
                     widget: 'target.attrs',
                     enabled: false
+                },
+                {
+                    name: 'attrs_multi',
+                    type: 'multivalued',
+                    param: 'attrs',
+                    widget: 'target.attrs_multi',
+                    enabled: false
                 }
             ],
             widgets: [
@@ -702,6 +720,14 @@ IPA.permission_target_widget = function(spec) {
         });
 
         that.widgets.add_widget(that.attribute_table);
+
+        that.attribute_multivalued = IPA.multivalued_widget({
+            entity: that.entity,
+            name: 'attrs_multi',
+            hidden: true
+        });
+
+        that.widgets.add_widget(that.attribute_multivalued);
     };
 
     init();
@@ -725,34 +751,41 @@ IPA.permission_target_policy = function (widget_name) {
         });
 
         var type_select = widgets.get_widget('type');
-        var attribute_table = widgets.get_widget('attrs');
-        var attribute_field = that.container.fields.get_field('attrs');
+
         type_select.value_changed.attach(function() {
             var type = type_select.save()[0];
-            attribute_table.object_type = type;
-            attribute_field.reset();
+            that.set_attrs_type(type);
         });
     };
 
+    that.set_attrs_type = function(type) {
+        var attribute_field = that.container.fields.get_field('attrs');
+        var attribute_table = that.permission_target.widgets.get_widget('attrs');
+        attribute_table.object_type = type;
+        attribute_field.reset();
+    };
+
     that.post_create = function() {
         that.select_target(that.permission_target.targets[0]);
     };
 
     that.post_load = function(data) {
 
-        var targets = that.permission_target.targets;
+        var displayed_target;
 
-        that.set_target_visible_core('memberof', false);
+        for (var target in that.target_mapping) {
 
-        for (var i=0; i<targets.length; i++) {
-            var target = targets[i];
-
-            if(data.result.result[target]) {
-                that.select_target(target);
+            if (data.result.result[target]) {
+                displayed_target = target;
             } else {
                 that.set_target_visible(target, false);
             }
         }
+
+        if (displayed_target) {
+            that.permission_target.target = displayed_target;
+            that.set_target_visible(displayed_target, true);
+        }
     };
 
     that.select_target = function(target) {
@@ -763,27 +796,71 @@ IPA.permission_target_policy = function (widget_name) {
 
     that.set_target_visible = function(target, visible) {
 
-        that.set_target_visible_core(target, visible);
-
-        if (target === 'type') {
-            that.set_target_visible_core('attrs', visible);
-        } else {
-            var field = that.container.fields.get_field(target);
-            field.set_required(visible);
-        }
-
-        if (visible) {
-            var member_of_visible = target === 'type' || target === 'subtree';
-            that.set_target_visible_core('memberof', member_of_visible);
-        }
+        var target_info = that.target_mapping[target];
+        that.set_target_visible_core(target_info, visible);
     };
 
-    that.set_target_visible_core = function(target, visible) {
-        var widget = that.permission_target.widgets.get_widget(target);
-        var field = that.container.fields.get_field(target);
-        that.permission_target.set_row_visible(target, visible);
+    that.set_target_visible_core = function(target_info, visible) {
+        var widget = that.permission_target.widgets.get_widget(target_info.name);
+        var field = that.container.fields.get_field(target_info.name);
+        that.permission_target.set_row_visible(target_info.name, visible);
         field.enabled = visible;
+        field.set_required(visible && target_info.required);
         widget.hidden = !visible;
+
+        if (target_info.additional) {
+            for (var i=0; i<target_info.additional.length; i++) {
+                var nested_info = target_info.additional[i];
+                that.set_target_visible_core(nested_info, visible);
+            }
+        }
+
+        if (target_info.action) target_info.action();
+    };
+
+
+    that.target_mapping = {
+        filter: {
+            name: 'filter',
+            required: true,
+            additional: [
+                {
+                    name: 'attrs_multi'
+                }
+            ]
+        },
+        subtree: {
+            name: 'subtree',
+            required: true,
+            additional: [
+                {
+                    name: 'memberof'
+                }
+            ]
+        },
+        targetgroup: {
+            name: 'targetgroup',
+            required: true,
+            additional: [
+                {
+                    name: 'attrs'
+                }
+            ],
+            action: function() {
+                that.set_attrs_type('group');
+            }
+        },
+        type: {
+            name: 'type',
+            additional: [
+                {
+                    name: 'memberof'
+                },
+                {
+                    name: 'attrs'
+                }
+            ]
+        }
     };
 
 
diff --git a/install/ui/test/aci_tests.js b/install/ui/test/aci_tests.js
index 03e891c002397c2d3f536a57063ebf921b584375..c51107da45c04bee4de6b29bd452bce93a9b7d93 100644
--- a/install/ui/test/aci_tests.js
+++ b/install/ui/test/aci_tests.js
@@ -41,7 +41,8 @@ module('aci', {
                     {
                         type: 'select',
                         name: 'target',
-                        widget: 'target.target'
+                        widget: 'target.target',
+                        enabled: false
                     },
                     {
                         name: 'filter',
@@ -51,7 +52,8 @@ module('aci', {
                     {
                         type: 'entity_select',
                         name: 'memberof',
-                        widget: 'target.memberof'
+                        widget: 'target.memberof',
+                        enabled: false
                     },
                     {
                         name: 'subtree',
@@ -74,6 +76,13 @@ module('aci', {
                         name: 'attrs',
                         widget: 'target.attrs',
                         enabled: false
+                    },
+                    {
+                        name: 'attrs_multi',
+                        param: 'attrs',
+                        type: 'multivalued',
+                        widget: 'target.attrs_multi',
+                        enabled: false
                     }
                 ],
                 widgets: [
@@ -203,7 +212,7 @@ test("Testing aci grouptarget.", function() {
     same(target_widget.target, 'targetgroup' , 'group control selected');
 
 
-    same(get_visible_rows(target_widget), ['targetgroup'],
+    same(get_visible_rows(target_widget), ['targetgroup', 'attrs'],
         'group select row visible');
 
     ok ($('option', target_widget.group_select.container).length > 2,
@@ -252,7 +261,7 @@ test("Testing filter target.", function() {
 
     same(target_widget.target, 'filter', 'filter selected');
 
-    same(get_visible_rows(target_widget), ['filter'], 'filter row visible');
+    same(get_visible_rows(target_widget), ['filter', 'attrs_multi'], 'filter row visible');
 
     ok(record.filter[0], data.result.result.filter, 'filter set correctly');
 });
diff --git a/install/ui/widget.js b/install/ui/widget.js
index 3201dad7a4e78bf2afd38112d80b70602661a9f4..7ce7af90142eaf098273d4a6a1eedcf0a3ddec33 100644
--- a/install/ui/widget.js
+++ b/install/ui/widget.js
@@ -436,7 +436,7 @@ IPA.multivalued_widget = function(spec) {
 
         row.widget = that.widget_factory({
             name: that.name+'-'+row_index,
-            undo: that.undo,
+            undo: that.undo || row.is_new,
             read_only: that.read_only,
             writable: that.writable
         });
-- 
1.7.7.6

_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel

Reply via email to