Hi,

Please review the attached patch. Thanks!

The ipa_entity_set_association_definition() has been added to configure
the association between 2 entitites. By default the associator is
BulkAssociator and the method is add_member. The entities have been
updated to use the right configurations.

The ipa_cmd() has been modified to detect IPA errors and invoke the
error handler.

A bug in refresh_on_success() has been fixed as well.

--
Endi S. Dewata
>From 3eda875c494d7928602dced8b240338910d14090 Mon Sep 17 00:00:00 2001
From: Endi S. Dewata <edew...@redhat.com>
Date: Fri, 1 Oct 2010 16:33:57 -0500
Subject: [PATCH] Entity association configuration.

The ipa_entity_set_association_definition() has been added to configure
the association between 2 entitites. By default the associator is
BulkAssociator and the method is add_member. The entities have been
updated to use the right configurations.

The ipa_cmd() has been modified to detect IPA errors and invoke the
error handler.

A bug in refresh_on_success() has been fixed as well.
---
 install/static/associate.js |   52 +++++++++++++++++++++++-------------------
 install/static/entity.js    |   19 +++++++++++++++-
 install/static/group.js     |    6 +++++
 install/static/host.js      |    4 +++
 install/static/hostgroup.js |    1 -
 install/static/ipa.js       |    7 +++++
 install/static/rolegroup.js |    4 +++
 install/static/service.js   |    4 +++
 install/static/user.js      |    7 +++++
 9 files changed, 78 insertions(+), 26 deletions(-)

diff --git a/install/static/associate.js b/install/static/associate.js
index c3453e9..826641a 100644
--- a/install/static/associate.js
+++ b/install/static/associate.js
@@ -42,14 +42,14 @@ function SerialAssociator(form, manyObjPkeys, on_success)
             var args = [manyObjPkey];
 
             ipa_cmd( form.method,args, options ,
-                     function(response){
-                         if (response.error){
-                             alert("error adding member: "+response.error.message);
+                     function(data, text_status, xhr) {
+                         if (data.error){
+                             alert("error adding member: "+data.error.message);
                          }else{
                              associator.associateNext();
                          }
                      },
-                     function(response){
+                     function(xhr, text_status, error_thrown) {
                          alert("associateFailure");
                      },
                      form.manyObj );
@@ -85,14 +85,14 @@ function BulkAssociator(form, manyObjPkeys, on_success)
         var args = [form.pkey];
 
         ipa_cmd( form.method,args, options ,
-                 function(response){
-                     if (response.error){
-                         alert("error adding member: "+response.error.message);
+                 function(data, text_status, xhr) {
+                     if (data.error){
+                         alert("error adding member: "+data.error.message);
                      }else{
                          associator.on_success();
                      }
                  },
-                 function(response){
+                 function(xhr, text_status, error_thrown) {
                      alert("associateFailure");
                  },
                  form.oneObj );
@@ -124,7 +124,7 @@ function AssociationForm(oneObj, pkey, manyObj, on_success, associatorConstructo
     if (associatorConstructor)
         this.associatorConstructor = associatorConstructor;
     else
-        this.associatorConstructor = SerialAssociator;
+        this.associatorConstructor = BulkAssociator;
 
     this.setup = function() {
         var label = ipa_objs[form.manyObj].label;
@@ -212,7 +212,7 @@ function AssociationForm(oneObj, pkey, manyObj, on_success, associatorConstructo
 /**
     A modfied version of search. It shows the  associations for an object.
 */
-function AssociationList(obj, pkey, manyObj, associationColumns, jobj)
+function AssociationList(obj, pkey, manyObj, associationColumns, jobj, associationConstructor, method)
 {
     var form = this;
 
@@ -220,20 +220,22 @@ function AssociationList(obj, pkey, manyObj, associationColumns, jobj)
     this.pkey = pkey;
     this.associationColumns = associationColumns;
     this.manyObj = manyObj;
-    this.parentTab = jobj;
+    this.container = jobj;
+    this.associationConstructor = associationConstructor;
+    this.method = method;
 
     this.refresh = function() {
 
-        function refresh_on_success(userData) {
-           var tbody = this.parentTab.find('.search-table tbody');
-           tbody.empty();
-           var associationList = userData.result.result[this.associationColumns[0].column];
-           for (var j = 0; j < associationList.length; j++){
+        function refresh_on_success(data, text_status, xhr) {
+            var tbody = form.container.find('.search-table tbody');
+            tbody.empty();
+            var associationList = data.result.result[form.associationColumns[0].column];
+            for (var j = 0; j < associationList.length; j++){
                 var row  = $("<tr/>").appendTo(tbody);
                 for (var k = 0; k < associationColumns.length ;k++){
-                    var column = this.associationColumns[k].column;
+                    var column = form.associationColumns[k].column;
                     $("<td></td>",{
-                        html: userData.result.result[column][j]
+                        html: data.result.result[column][j]
                     }).appendTo(row);
                 }
             }
@@ -249,17 +251,17 @@ function AssociationList(obj, pkey, manyObj, associationColumns, jobj)
     }
 
     this.setup = function() {
-        association_list_create(this.obj, this.parentTab);
-        this.parentTab.find(".search-filter").css("display", "none");
-        this.parentTab.find(".search-buttons").html("");
+        association_list_create(this.obj, this.container);
+        this.container.find(".search-filter").css("display", "none");
+        this.container.find(".search-buttons").html("");
         $("<input/>", {
             type:  'button',
             value: 'enroll',
             click: function() {
                 form.show_enrollment_dialog();
             }
-        }).appendTo(this.parentTab.find(".search-buttons"));
-        var header = $("<tr></tr>").appendTo(this.parentTab.find('.search-table thead:last'));
+        }).appendTo(this.container.find(".search-buttons"));
+        var header = $("<tr></tr>").appendTo(this.container.find('.search-table thead:last'));
         for (var i =0 ; i != associationColumns.length ;i++){
             $("<th></th>",{
                 html: associationColumns[i].title
@@ -277,7 +279,9 @@ function AssociationList(obj, pkey, manyObj, associationColumns, jobj)
             function() {
                 form.refresh();
                 enrollment_dialog.close();
-            }
+            },
+            this.associationConstructor,
+            this.method
         );
         enrollment_dialog.setup();
     }
diff --git a/install/static/entity.js b/install/static/entity.js
index 5be67a3..820c567 100644
--- a/install/static/entity.js
+++ b/install/static/entity.js
@@ -1,5 +1,6 @@
 /*  Authors:
  *    Pavel Zuna <pz...@redhat.com>
+ *    Endi S. Dewata <edew...@redhat.com>
  *
  * Copyright (C) 2010 Red Hat
  * see file 'COPYING' for use and warranty information
@@ -23,6 +24,7 @@
 var ipa_entity_search_list = {};
 var ipa_entity_add_list = {};
 var ipa_entity_details_list = {};
+var ipa_entity_association_list = {};
 
 /* use this to track individual changes between two hashchange events */
 var window_hash_cache = {};
@@ -42,6 +44,11 @@ function ipa_entity_set_details_definition(obj_name, data)
     ipa_entity_details_list[obj_name] = data;
 }
 
+function ipa_entity_set_association_definition(obj_name, data)
+{
+    ipa_entity_association_list[obj_name] = data;
+}
+
 function ipa_entity_setup(container)
 {
     var id = container.attr('id');
@@ -151,7 +158,17 @@ function _ipa_entity_setup(jobj) {
                 column: attr + '_' + enroll_obj_name
             }
         ];
-        var frm = new AssociationList(obj_name, pkey, enroll_obj_name, columns, jobj);
+
+        var association = ipa_entity_association_list[obj_name];
+        var association_config = association ? association[enroll_obj_name] : null;
+        var associator = association_config ? association_config.associator : null;
+        var method = association_config ? association_config.method : null;
+
+        var frm = new AssociationList(
+                obj_name, pkey, enroll_obj_name, columns, jobj,
+                associator, method
+        );
+
         ipa_entity_generate_views(obj_name, jobj, switch_view);
         frm.setup();
     };
diff --git a/install/static/group.js b/install/static/group.js
index 4c2c5b0..591184d 100644
--- a/install/static/group.js
+++ b/install/static/group.js
@@ -44,6 +44,12 @@ ipa_entity_set_details_definition('group', [
     ]]
 ]);
 
+ipa_entity_set_association_definition('group', {
+    'netgroup': { associator: SerialAssociator },
+    'rolegroup': { associator: SerialAssociator },
+    'taskgroup': { associator: SerialAssociator }
+});
+
 function f_posix(dlg, mode)
 {
     function checkbox_on_click() {
diff --git a/install/static/host.js b/install/static/host.js
index 432f2f7..d19ac0d 100644
--- a/install/static/host.js
+++ b/install/static/host.js
@@ -42,3 +42,7 @@ ipa_entity_set_details_definition('host', [
     ]]
 ]);
 
+ipa_entity_set_association_definition('host', {
+    'hostgroup': { associator: SerialAssociator },
+    'rolegroup': { associator: SerialAssociator }
+});
diff --git a/install/static/hostgroup.js b/install/static/hostgroup.js
index e3863fe..fd062dc 100644
--- a/install/static/hostgroup.js
+++ b/install/static/hostgroup.js
@@ -39,4 +39,3 @@ ipa_entity_set_details_definition('hostgroup', [
         ['description', 'Description', null]
     ]]
 ]);
-
diff --git a/install/static/ipa.js b/install/static/ipa.js
index 9e84bb9..31c9120 100644
--- a/install/static/ipa.js
+++ b/install/static/ipa.js
@@ -83,6 +83,13 @@ function ipa_cmd(name, args, options, win_callback, fail_callback, objname)
             }
             ipa_error_handler(xhr, text_status, error_thrown);
 
+        } else if (data.error) {
+            var error_thrown = {
+                name: 'IPA Error '+data.error.code,
+                message: data.error.message
+            }
+            ipa_error_handler(xhr, text_status, error_thrown);
+
         } else if (win_callback) {
             win_callback(data, text_status, xhr);
         }
diff --git a/install/static/rolegroup.js b/install/static/rolegroup.js
index 0297554..64728ab 100644
--- a/install/static/rolegroup.js
+++ b/install/static/rolegroup.js
@@ -39,3 +39,7 @@ ipa_entity_set_details_definition('rolegroup', [
         ['description', 'Description', null],
     ]]
 ]);
+
+ipa_entity_set_association_definition('rolegroup', {
+    'taskgroup': { associator: SerialAssociator }
+});
diff --git a/install/static/service.js b/install/static/service.js
index c12e563..43ef968 100644
--- a/install/static/service.js
+++ b/install/static/service.js
@@ -47,3 +47,7 @@ function service_add_krbprincipalname(add_dialog, flag) {
     }
     return null;
 }
+
+ipa_entity_set_association_definition('service', {
+    'host': { method: 'add_host' }
+});
diff --git a/install/static/user.js b/install/static/user.js
index 2698c8b..d42d32d 100644
--- a/install/static/user.js
+++ b/install/static/user.js
@@ -74,6 +74,13 @@ ipa_entity_set_details_definition('user', [
     ]]
 ]);
 
+ipa_entity_set_association_definition('user', {
+    'group': { associator: SerialAssociator },
+    'netgroup': { associator: SerialAssociator },
+    'rolegroup': { associator: SerialAssociator },
+    'taskgroup': { associator: SerialAssociator }
+});
+
 /* Account status Toggle button */
 
 function toggle_on_click(obj)
-- 
1.6.6.1

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

Reply via email to