This patch demonstrates how to use the plugin framework with the existing entities. The plugin framework provides a name space for the classes, functions and variables specific for the plugin. Any code executed inside the init() method will be 'safe' because at that point the metadata and i18n messages have been loaded.

--
Endi S. Dewata
From 4a57d06d2caf658ba9dc7ec38b11acfaf0dc0a4c Mon Sep 17 00:00:00 2001
From: Endi S. Dewata <edew...@redhat.com>
Date: Fri, 18 Feb 2011 17:25:05 -0600
Subject: [PATCH] Applied plugin framework on user and group.

This patch demonstrates how to use the plugin framework with the
existing entities. The plugin framework provides a name space for
the classes, functions and variables specific for the plugin. Any
code executed inside the init() method will be 'safe' because at
that point the metadata and i18n messages have been loaded.
---
 install/ui/entity.js |    2 ++
 install/ui/group.js  |   19 +++++++++++--------
 install/ui/ipa.js    |    5 ++---
 install/ui/user.js   |   22 ++++++++++++----------
 4 files changed, 27 insertions(+), 21 deletions(-)

diff --git a/install/ui/entity.js b/install/ui/entity.js
index 01ad47eb71c63228b10e6387ccb7bbd4050bc1ad..44bb836f71b57e03dc22a0b3bc6dc765e216baae 100644
--- a/install/ui/entity.js
+++ b/install/ui/entity.js
@@ -238,6 +238,8 @@ IPA.entity = function (spec) {
 
     that.entity_init = that.init;
 
+    IPA.add_entity(that);
+
     return that;
 };
 
diff --git a/install/ui/group.js b/install/ui/group.js
index d2e35e258461361dd6d4dbda3e832ceab1ffd990..1ea9e794173b43796dcaa00bfc5b3a595687269b 100644
--- a/install/ui/group.js
+++ b/install/ui/group.js
@@ -24,9 +24,13 @@
 
 /* REQUIRES: ipa.js, details.js, search.js, add.js, entity.js */
 
-IPA.entity_factories.group =  function () {
+IPA.group = IPA.plugin({
+    name: 'group'
+});
 
-    return IPA.entity({
+IPA.group.init = function() {
+
+    IPA.entity({
         'name': 'group'
     }).
         facet(
@@ -58,7 +62,7 @@ IPA.entity_factories.group =  function () {
                         input({name: 'description'}).
                         input({name: 'gidnumber' }))).
         facet(
-            IPA.group_member_user_facet({
+            IPA.group.member_user_facet({
                 'name': 'member_user'
             })).
         facet(
@@ -76,11 +80,11 @@ IPA.entity_factories.group =  function () {
                 name: 'memberof_role',
                 associator: IPA.serial_associator
             })).
-        standard_associations();
+        standard_associations().
+        init();
 };
 
-
-IPA.group_member_user_facet = function (spec) {
+IPA.group.member_user_facet = function(spec) {
 
     spec = spec || {};
 
@@ -136,5 +140,4 @@ IPA.group_member_user_facet = function (spec) {
     };
 
     return that;
-
-};
\ No newline at end of file
+};
diff --git a/install/ui/ipa.js b/install/ui/ipa.js
index fbebb228364b22785e60ae595ae16435354e71a3..51f427a813ca9dbffac0712c434e18725a1c2351 100644
--- a/install/ui/ipa.js
+++ b/install/ui/ipa.js
@@ -124,10 +124,10 @@ var IPA = ( function () {
         return that.entities_by_name[name];
     };
 
-    function add_entity(entity) {
+    that.add_entity = function(entity) {
         that.entities.push(entity);
         that.entities_by_name[entity.name] = entity;
-    }
+    };
 
     that.start_entities = function(){
         var factory;
@@ -135,7 +135,6 @@ var IPA = ( function () {
         for (name in that.entity_factories){
             factory = that.entity_factories[name];
             var entity = factory();
-            add_entity(entity);
             entity.init();
         }
     };
diff --git a/install/ui/user.js b/install/ui/user.js
index 66a1b8d15650b11062289bc06f773e2066446fda..81534320994788400550e10503f32428c286657d 100644
--- a/install/ui/user.js
+++ b/install/ui/user.js
@@ -23,9 +23,13 @@
 
 /* REQUIRES: ipa.js, details.js, search.js, add.js, entity.js */
 
-IPA.entity_factories.user = function() {
+IPA.user = IPA.plugin({
+    name: 'user'
+});
 
-    return IPA.entity({
+IPA.user.init = function() {
+
+    IPA.entity({
         name: 'user'
     }).
         facet(
@@ -55,9 +59,9 @@ IPA.entity_factories.user = function() {
                     input({name:'initials'})).
             section(
                 IPA.stanza({name: 'account', label: IPA.messages.objects.user.account}).
-                    custom_input(IPA.user_status_widget({name:'nsaccountlock'})).
+                    custom_input(IPA.user.status_widget({name:'nsaccountlock'})).
                     input({name:'uid'}).
-                    custom_input(IPA.user_password_widget({name:'userpassword'})).
+                    custom_input(IPA.user.password_widget({name:'userpassword'})).
                     input({name:'uidnumber'}).
                     input({name:'gidnumber'}).
                     input({name:'loginshell'}).
@@ -97,13 +101,11 @@ IPA.entity_factories.user = function() {
                 name: 'memberof_role',
                 associator: IPA.serial_associator
             })).
-        standard_associations();
+        standard_associations().
+        init();
 };
 
-/* ATTRIBUTE CALLBACKS */
-
-
-IPA.user_status_widget = function(spec) {
+IPA.user.status_widget = function(spec) {
 
     spec = spec || {};
 
@@ -164,7 +166,7 @@ IPA.user_status_widget = function(spec) {
     return that;
 };
 
-IPA.user_password_widget = function(spec) {
+IPA.user.password_widget = function(spec) {
 
     spec = spec || {};
 
-- 
1.6.6.1

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

Reply via email to