The IPA.entity_builder has been modified to take a 'factory' parameter
in custom facet's and custom dialog's spec. The IPA.dialog has been
modified to take an array of fields in the spec. The IPA.search_facet
has been modified to take an array of columns in the spec.

--
Endi S. Dewata
From 1fd43a7ee0e562a7e3ad0c3c64f554dd8bcdaa0d Mon Sep 17 00:00:00 2001
From: Endi S. Dewata <[email protected]>
Date: Thu, 7 Apr 2011 16:14:58 -0500
Subject: [PATCH] Refactored builder interface.

The IPA.entity_builder has been modified to take a 'factory' parameter
in custom facet's and custom dialog's spec. The IPA.dialog has been
modified to take an array of fields in the spec. The IPA.search_facet
has been modified to take an array of columns in the spec.

---
 install/ui/dialog.js  |   19 +++++++++++
 install/ui/dns.js     |    5 ++-
 install/ui/entity.js  |   87 +++++++++++++++++++++++++------------------------
 install/ui/group.js   |    6 ++--
 install/ui/hbac.js    |    5 ++-
 install/ui/host.js    |    5 ++-
 install/ui/search.js  |   10 ++++++
 install/ui/service.js |   29 ++++++++--------
 install/ui/sudo.js    |    5 ++-
 9 files changed, 103 insertions(+), 68 deletions(-)

diff --git a/install/ui/dialog.js b/install/ui/dialog.js
index 17e78af6da42f86b2436e7590067e61f872dff95..964d5f5fcdd4a6012954ac4bdc1098af7d5e7b52 100644
--- a/install/ui/dialog.js
+++ b/install/ui/dialog.js
@@ -265,6 +265,25 @@ IPA.dialog = function(spec) {
     that.dialog_setup = that.setup;
     that.dialog_open = that.open;
 
+    var fields = spec.fields || [];
+    for (var i=0; i<fields.length; i++) {
+        var field_spec = fields[i];
+        var field;
+
+        if (field_spec instanceof Object) {
+            if (field_spec.factory) {
+                field = field_spec.factory(field_spec);
+            } else {
+                field = IPA.text_widget(field_spec);
+            }
+        } else {
+            var field_name = field_spec;
+            field = IPA.text_widget({ name: field_name, undo: false });
+        }
+
+        that.add_field(field);
+    }
+
     return that;
 };
 
diff --git a/install/ui/dns.js b/install/ui/dns.js
index 36ee2d6ef9395ba290defe9b46a67ff195ffca3f..d7175a1408a79f2d214697ed3b042aa6dee8fdb5 100644
--- a/install/ui/dns.js
+++ b/install/ui/dns.js
@@ -48,10 +48,11 @@ IPA.entity_factories.dnszone = function() {
                 'dnsclass',
                 'idnsallowdynupdate',
                 'idnsupdatepolicy']}]}).
-        facet(IPA.records_facet({
+        facet({
+            factory: IPA.records_facet,
             'name': 'records',
             'label': IPA.metadata.objects.dnsrecord.label
-        })).
+        }).
         standard_association_facets().
         build();
 };
diff --git a/install/ui/entity.js b/install/ui/entity.js
index 75ec32cfaea8069ebca8cfc7fb6bb311eef0c550..4db58465d29a36622e475db32426669bbc5e2b63 100644
--- a/install/ui/entity.js
+++ b/install/ui/entity.js
@@ -539,7 +539,7 @@ IPA.entity_builder = function(){
 
     var that = {};
     var entity = null;
-    var current_facet = null;
+    var facet = null;
 
     function section(spec){
         var current_section = null;
@@ -555,7 +555,7 @@ IPA.entity_builder = function(){
         }else{
             current_section = IPA.details_list_section(spec);
         }
-        current_facet.add_section(current_section);
+        facet.add_section(current_section);
         var fields = spec.fields;
         if (fields){
             var i;
@@ -581,8 +581,14 @@ IPA.entity_builder = function(){
         return that;
     };
 
-    that.dialog = function(value){
-        current_facet.dialog(value);
+    that.dialog = function(spec) {
+        var dialog;
+        if (spec.factory) {
+            dialog = spec.factory(spec);
+        } else {
+            dialog = IPA.dialog(spec);
+        }
+        facet.dialog(dialog);
         return that;
     };
 
@@ -590,8 +596,8 @@ IPA.entity_builder = function(){
         var sections = spec.sections;
         spec.sections = null;
         spec.entity_name = entity.name;
-        current_facet =IPA.details_facet(spec);
-        entity.facet(current_facet);
+        facet =IPA.details_facet(spec);
+        entity.facet(facet);
 
         var i;
         for ( i =0; i < sections.length; i += 1){
@@ -601,27 +607,19 @@ IPA.entity_builder = function(){
         return that;
     };
 
-    that.facet = function (facet){
-        current_facet = facet;
+    that.facet = function(spec) {
+        facet = spec.factory(spec);
         entity.facet(facet);
         return that;
     };
 
     that.search_facet = function (spec){
-        current_facet = IPA.search_facet({
-            entity_name:entity.name,
-            search_all: spec.search_all || false
+        facet = IPA.search_facet({
+            entity_name: entity.name,
+            search_all: spec.search_all || false,
+            columns: spec.columns
         });
 
-        var columns = spec.columns;
-        var i;
-        for (i = 0; i < columns.length; i +=1){
-            if(columns[i] instanceof Object){
-                current_facet.column(columns[i]);
-            }else{
-                current_facet.column({name:columns[i]});
-            }
-        }
         var current_dialog =
             IPA.add_dialog({
                 'name': 'add',
@@ -629,35 +627,38 @@ IPA.entity_builder = function(){
                 entity_name: entity.name
             });
 
-        current_facet.dialog(current_dialog);
+        facet.dialog(current_dialog);
 
         var add_fields = spec.add_fields;
-        for (i = 0; i < add_fields.length; i += 1){
-            var field = add_fields[i];
-            if (field instanceof Object){
-                /* This is a bit of a hack ,and is here to support ACI
-                   permissions.  The target section is a group of secveral
-                   widgets together.  It makes more sense to do them as a
-                   seciont than as a widgit. However, since they can  be mixed
-                   into the flow with the other widgets, the section needs to
-                   be definied here with the fields to get the order correct.*/
-                var factory;
-                if (field.section){
-                    factory = field.factory;
-                    field.factory = null;
-                    field.name = field.section;
-                    field.section = null;
-                    current_dialog.add_section(factory(field));
+        if (add_fields) {
+            for (var i = 0; i < add_fields.length; i += 1){
+                var field = add_fields[i];
+                if (field instanceof Object){
+                    /* This is a bit of a hack ,and is here to support ACI
+                       permissions.  The target section is a group of secveral
+                       widgets together.  It makes more sense to do them as a
+                       seciont than as a widgit. However, since they can  be mixed
+                       into the flow with the other widgets, the section needs to
+                       be definied here with the fields to get the order correct.*/
+                    var factory;
+                    if (field.section){
+                        factory = field.factory;
+                        field.factory = null;
+                        field.name = field.section;
+                        field.section = null;
+                        current_dialog.add_section(factory(field));
+                    }else{
+                        field.entity_name = entity.name;
+                        factory = field.factory || IPA.text_widget;
+                        current_dialog.field(factory(field));
+                    }
                 }else{
-                    field.entity_name = entity.name;
-                    factory = field.factory;
-                    current_dialog.field(factory(field));
+                    current_dialog.text(add_fields[i]);
                 }
-            }else{
-                current_dialog.text(add_fields[i]);
             }
         }
-        entity.facet(current_facet);
+
+        entity.facet(facet);
         return that;
     };
 
diff --git a/install/ui/group.js b/install/ui/group.js
index 7c7488f108a5a8b3379b35fea3e37e8d9e01a000..fb07a8cb3303e240267e80e5ddcbdf15e5933510 100644
--- a/install/ui/group.js
+++ b/install/ui/group.js
@@ -47,8 +47,8 @@ IPA.entity_factories.group =  function () {
                 name:'details',
                 fields:['cn','description','gidnumber']
             }]}).
-        facet( IPA.association_facet({
-            'name': 'member_user',
+        association_facet({
+            name: 'member_user',
             columns:[
                 {
                     name: 'uid',
@@ -72,7 +72,7 @@ IPA.entity_factories.group =  function () {
                 }
             ]
 
-        })).
+        }).
         association_facet({
                 name: 'memberof_group',
                 associator: IPA.serial_associator
diff --git a/install/ui/hbac.js b/install/ui/hbac.js
index a0c353af39738402e13b27b4e25de692d9c7519e..fa824ab8239ce213dbce4c66fdebb47df419ad3f 100644
--- a/install/ui/hbac.js
+++ b/install/ui/hbac.js
@@ -42,9 +42,10 @@ IPA.entity_factories.hbacrule = function () {
                         }],
                     'undo': false
                 }]}).
-        facet(IPA.hbacrule_details_facet({
+        facet({
+            factory: IPA.hbacrule_details_facet,
             'name': 'details'
-        })).
+        }).
         build();
 };
 
diff --git a/install/ui/host.js b/install/ui/host.js
index dc1c0ee15472cf6cfbeb9e17e5fa62f724e62981..c7424fbe5e235928424a0d02bca82c31fc6c73ca 100644
--- a/install/ui/host.js
+++ b/install/ui/host.js
@@ -70,9 +70,10 @@ IPA.entity_factories.host = function () {
                     }
                 ]
             }]}).
-        facet(IPA.host_managedby_host_facet({
+        facet({
+            factory: IPA.host_managedby_host_facet,
             name: 'managedby_host'
-        })).
+        }).
         association_facet({
             name: 'memberof_hostgroup',
             associator: IPA.serial_associator
diff --git a/install/ui/search.js b/install/ui/search.js
index bd2c0f16631f0b01cdedd1b82b213e34985be461..ad74b812a1babd4fd0d4055eae95dc7ccbef138c 100644
--- a/install/ui/search.js
+++ b/install/ui/search.js
@@ -410,6 +410,16 @@ IPA.search_facet = function(spec) {
     that.search_facet_create_content = that.create_content;
     that.search_facet_setup = that.setup;
 
+    var columns = spec.columns || [];
+    for (var i=0; i<columns.length; i++) {
+        var column = columns[i];
+        if (column instanceof Object) {
+            var factory = column.factory || IPA.column;
+            that.add_column(factory(column));
+        } else {
+            that.create_column({ name: column });
+        }
+    }
    
     return that;
 };
diff --git a/install/ui/service.js b/install/ui/service.js
index 3631525187d5fad0997ffd5546c998ab65cf90d4..dc89ec08e3fff6aba99da8aa48a8041a3310a99d 100644
--- a/install/ui/service.js
+++ b/install/ui/service.js
@@ -27,15 +27,15 @@ IPA.entity_factories.service = function() {
 
     return  IPA.entity_builder().
         entity('service').
-        facet(
-            IPA.search_facet().
-                column({name: 'krbprincipalname'}).
-                dialog(
-                    IPA.service_add_dialog({
-                        name: 'add',
-                        title: IPA.messages.objects.service.add,
-                        width: '450px'
-                    }))).
+        search_facet({
+            columns: [ 'krbprincipalname' ]
+        }).
+            dialog({
+                factory: IPA.service_add_dialog,
+                name: 'add',
+                title: IPA.messages.objects.service.add,
+                width: '450px'
+            }).
         details_facet({sections:[
             {
                 name: 'details',
@@ -69,11 +69,12 @@ IPA.entity_factories.service = function() {
                     label: IPA.messages.objects.service.status
                 }]
             }]}).
-        facet(IPA.service_managedby_host_facet({
-                name: 'managedby_host',
-                add_method: 'add_host',
-                remove_method: 'remove_host'
-        })).
+        facet({
+            factory: IPA.service_managedby_host_facet,
+            name: 'managedby_host',
+            add_method: 'add_host',
+            remove_method: 'remove_host'
+        }).
         standard_association_facets().
         build();
 };
diff --git a/install/ui/sudo.js b/install/ui/sudo.js
index 0f2e8491e59d04502ee728654cd61d981ec80584..d0fe7528c070ba0132a70a95937f1c56435ee90a 100644
--- a/install/ui/sudo.js
+++ b/install/ui/sudo.js
@@ -31,9 +31,10 @@ IPA.entity_factories.sudorule = function () {
             columns:['cn','description','cmdcategory'],
             add_fields:['cn']
         }).
-        facet(IPA.sudorule_details_facet({
+        facet({
+            factory: IPA.sudorule_details_facet,
             'name': 'details'
-        })).
+        }).
         build();
 };
 
-- 
1.7.4

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

Reply via email to