The IPA.association_adder_dialog has been modified to use an exclusion
list to hide entries that are already enrolled.

The IPA.adder_dialog has been modified to store the columns directly
in the available & selected tables.

Ticket #1797

--
Endi S. Dewata
From f8339f3fb32840fc6f2aa5b4b98f587cabd80075 Mon Sep 17 00:00:00 2001
From: Endi S. Dewata <[email protected]>
Date: Mon, 19 Sep 2011 18:51:43 -0500
Subject: [PATCH] Fixed problem enrolling member with the same name.

The IPA.association_adder_dialog has been modified to use an exclusion
list to hide entries that are already enrolled.

The IPA.adder_dialog has been modified to store the columns directly
in the available & selected tables.

Ticket #1797
---
 install/ui/association.js |   67 +++++++++++++++++++++++---------------------
 install/ui/dialog.js      |   68 ++++++++++++++++++++-------------------------
 install/ui/sudo.js        |   23 +--------------
 3 files changed, 67 insertions(+), 91 deletions(-)

diff --git a/install/ui/association.js b/install/ui/association.js
index 2f08c73b92385497496d0afd2c54f91d4483ac23..3d75072ae3d14b0c3cfe46d020df6c9659c2a55d 100644
--- a/install/ui/association.js
+++ b/install/ui/association.js
@@ -144,17 +144,9 @@ IPA.bulk_associator = function(spec) {
 /**
  * This dialog is used for adding associations between two entities.
  */
-IPA.association_adder_dialog = function (spec) {
+IPA.association_adder_dialog = function(spec) {
 
     spec = spec || {};
-    /*
-      TODO: columns map in IPA.adder_dialog should be removed and add_column()
-      should be modified to add the column directly into the available_table
-      and selected_table. This way IPA.association_adder_dialog can call
-      create_column() from the initialization area, no need to modify the
-      parameters.
-    */
-    default_columns(spec);
 
     var that = IPA.adder_dialog(spec);
 
@@ -162,17 +154,35 @@ IPA.association_adder_dialog = function (spec) {
     that.pkey = spec.pkey;
     that.other_entity = spec.other_entity;
     that.attribute_member = spec.attribute_member;
+    that.exclude = spec.exclude || [];
+
+    var init = function() {
+        if (!that.get_columns().length) {
+            var pkey_name = IPA.metadata.objects[spec.other_entity].primary_key;
+            that.create_column({
+                entity: that.entity,
+                name: pkey_name,
+                label: IPA.metadata.objects[spec.other_entity].label,
+                primary_key: true,
+                width: '600px'
+            });
+        }
+    };
 
     that.search = function() {
         function on_success(data, text_status, xhr) {
-            var results = data.result;
+
             that.clear_available_values();
 
-            var pkey_attr = that.entity.metadata.primary_key;
+            var other_entity = IPA.get_entity(that.other_entity);
+            var pkey_attr = other_entity.metadata.primary_key;
 
-            for (var i=0; i<results.count; i++){
+            var results = data.result;
+            for (var i=0; i<results.count; i++) {
                 var result = results.result[i];
-                if (result[pkey_attr] != spec.pkey){
+                var pkey = result[pkey_attr][0];
+
+                if (that.exclude.indexOf(pkey) < 0) {
                     that.add_available_value(result);
                 }
             }
@@ -207,18 +217,7 @@ IPA.association_adder_dialog = function (spec) {
         }).execute();
     };
 
-    /*initialization*/
-    function default_columns(spec){
-        if (!spec.columns) {
-            var pkey_name = IPA.metadata.objects[spec.other_entity].primary_key;
-            spec.columns = [{
-                name: pkey_name,
-                label: IPA.metadata.objects[spec.other_entity].label,
-                primary_key: true,
-                width: '600px'
-            }];
-        }
-    }
+    init();
 
     return that;
 };
@@ -526,7 +525,8 @@ IPA.association_table_widget = function (spec) {
             pkey: pkey,
             other_entity: that.other_entity,
             attribute_member: that.attribute_member,
-            method: that.add_method
+            method: that.add_method,
+            exclude: that.values
         });
     };
 
@@ -963,12 +963,15 @@ IPA.association_facet = function (spec) {
         title = title.replace('${primary_key}', pkey);
         title = title.replace('${other_entity}', label);
 
+        var pkeys = that.data[that.get_attribute_name()];
+
         var dialog = IPA.association_adder_dialog({
-            'title': title,
-            'entity': that.entity,
-            'pkey': pkey,
-            'other_entity': that.other_entity,
-            'attribute_member': that.attribute_member
+            title: title,
+            entity: that.entity,
+            pkey: pkey,
+            other_entity: that.other_entity,
+            attribute_member: that.attribute_member,
+            exclude: pkeys
         });
 
         var adder_columns = that.adder_columns.values;
@@ -1165,7 +1168,7 @@ IPA.association_facet = function (spec) {
             if (that.remove_button) that.remove_button.css('display', 'none');
         }
 
-        var pkey = IPA.get_entity(that.entity.name).get_primary_key();
+        var pkey = that.entity.get_primary_key();
 
         var command = IPA.command({
             entity: that.entity.name,
diff --git a/install/ui/dialog.js b/install/ui/dialog.js
index a78ee93eddc1364842031b293f652be72ce15cf5..2bed0bbc0a63887424e50c0910fc055cb36de2d9 100644
--- a/install/ui/dialog.js
+++ b/install/ui/dialog.js
@@ -252,7 +252,7 @@ IPA.dialog = function(spec) {
  * This dialog provides an interface for searching and selecting
  * values from the available results.
  */
-IPA.adder_dialog = function (spec) {
+IPA.adder_dialog = function(spec) {
 
     spec = spec || {};
 
@@ -261,7 +261,7 @@ IPA.adder_dialog = function (spec) {
     that.width = spec.width || 600;
     that.height = spec.height || 360;
 
-    if (!that.entity){
+    if (!that.entity) {
         var except = {
             expected: false,
             message:'Adder dialog created without entity.'
@@ -269,15 +269,37 @@ IPA.adder_dialog = function (spec) {
         throw except;
     }
 
-    that.columns = $.ordered_map();
+    var init = function() {
+        that.available_table = IPA.table_widget({
+            entity: that.entity,
+            name: 'available',
+            scrollable: true
+        });
 
+        that.selected_table = IPA.table_widget({
+            entity: that.entity,
+            name: 'selected',
+            scrollable: true
+        });
+
+        if (spec.columns) {
+            for (var i=0; i<spec.columns.length; i++) {
+                that.create_column(spec.columns[i]);
+            }
+        }
+    };
 
     that.get_column = function(name) {
-        return that.columns.get(name);
+        return that.available_table.get_column(name);
+    };
+
+    that.get_columns = function() {
+        return that.available_table.get_columns();
     };
 
     that.add_column = function(column) {
-        that.columns.put(column.name, column);
+        that.available_table.add_column(column);
+        that.selected_table.add_column(column);
     };
 
     that.set_columns = function(columns) {
@@ -288,7 +310,8 @@ IPA.adder_dialog = function (spec) {
     };
 
     that.clear_columns = function() {
-        that.columns.empty();
+        that.available_table.clear_columns();
+        that.selected_table.clear_columns();
     };
 
     that.create_column = function(spec) {
@@ -298,32 +321,8 @@ IPA.adder_dialog = function (spec) {
         return column;
     };
 
-    function initialize_table(){
-        that.available_table = IPA.table_widget({
-            entity: that.entity,
-            name: 'available',
-            scrollable: true
-        });
-
-        var columns = that.columns.values;
-        that.available_table.set_columns(columns);
-
-        that.selected_table = IPA.table_widget({
-            entity: that.entity,
-            name: 'selected',
-            scrollable: true
-        });
-
-        that.selected_table.set_columns(columns);
-    }
     that.create = function() {
 
-        /*TODO:  move this earlier
-          The table initialization should be done earlier.  However,
-          the adder columns are not added until after initialization is over,
-          and thus we have to dleay the creation of the table.*/
-        initialize_table();
-
         // do not call that.dialog_create();
 
         var container = $('<div/>', {
@@ -473,7 +472,6 @@ IPA.adder_dialog = function (spec) {
         that.search();
     };
 
-
     that.open = function(container) {
 
         that.buttons[IPA.messages.buttons.enroll] = that.execute;
@@ -516,13 +514,7 @@ IPA.adder_dialog = function (spec) {
         return that.selected_table.save();
     };
 
-    /*dialog initialization */
-   if (spec.columns){
-        for (var i =0; i < spec.columns.length; i +=1){
-            that.create_column(spec.columns[i]);
-        }
-    }
-
+    init();
 
     that.adder_dialog_create = that.create;
 
diff --git a/install/ui/sudo.js b/install/ui/sudo.js
index 624b8c850b3ef17835dbb0fa2881f5ded8f659cf..d5d0ca552397cb10aa515c7871f786e070a501ac 100644
--- a/install/ui/sudo.js
+++ b/install/ui/sudo.js
@@ -1114,7 +1114,8 @@ IPA.sudorule_association_table_widget = function(spec) {
             other_entity: that.other_entity,
             attribute_member: that.attribute_member,
             entity: that.entity,
-            external: that.external
+            external: that.external,
+            exclude: that.values
         });
     };
 
@@ -1140,24 +1141,6 @@ IPA.sudo.rule_association_adder_dialog = function(spec) {
 
     that.external = spec.external;
 
-
-    function setup_table(){
-        if (!that.columns.length) {
-            var pkey_name = IPA.metadata.objects[that.other_entity].primary_key;
-            that.create_column({
-                entity: that.entity,
-                name: pkey_name,
-                label: IPA.metadata.objects[that.other_entity].label,
-                primary_key: true,
-                width: '200px'
-            });
-        }
-    }
-
-    that.create = function() {
-        that.adder_dialog_create();
-    };
-
     that.add = function() {
         var rows = that.available_table.remove_selected_rows();
         that.selected_table.add_rows(rows);
@@ -1174,7 +1157,5 @@ IPA.sudo.rule_association_adder_dialog = function(spec) {
         }
     };
 
-    setup_table();
-
     return that;
 };
-- 
1.7.5.1

_______________________________________________
Freeipa-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/freeipa-devel

Reply via email to