The IPA.current_facet() has been merged into IPA.entity.setup()
and replaced by IPA.entity.get_facet(). The setup() will read the
current facet's name from the <entity>-facet URL parameter and store
the facet object in the entity object. The get_facet() without any
parameter will return the current facet object.

--
Endi S. Dewata
From 26f5bfe16a43b04726c8a3a38a7dcbd978d0d71e Mon Sep 17 00:00:00 2001
From: Endi S. Dewata <edew...@redhat.com>
Date: Thu, 21 Jul 2011 21:29:55 -0500
Subject: [PATCH] Refactored IPA.current_facet().

The IPA.current_facet() has been merged into IPA.entity.setup()
and replaced by IPA.entity.get_facet(). The setup() will read the
current facet's name from the <entity>-facet URL parameter and store
the facet object in the entity object. The get_facet() without any
parameter will return the current facet object.
---
 install/ui/add.js         |    6 ++----
 install/ui/association.js |    6 ++----
 install/ui/details.js     |    6 ++----
 install/ui/entitle.js     |   12 ++++--------
 install/ui/entity.js      |   41 +++++++++++++++++++----------------------
 install/ui/navigation.js  |    3 +--
 install/ui/user.js        |    6 ++----
 7 files changed, 32 insertions(+), 48 deletions(-)

diff --git a/install/ui/add.js b/install/ui/add.js
index b6b797c4502f28eda6f2a8f6e26cd69940dbc634..614a209056070cfa973c3cffa6cec935443ceb6e 100644
--- a/install/ui/add.js
+++ b/install/ui/add.js
@@ -50,8 +50,7 @@ IPA.add_dialog = function (spec) {
             that.add(
                 record,
                 function(data, text_status, xhr) {
-                    var facet_name =   IPA.current_facet(IPA.current_entity);
-                    var facet = IPA.current_entity.get_facet(facet_name);
+                    var facet = IPA.current_entity.get_facet();
                     var table = facet.table;
                     table.refresh();
                     that.close();
@@ -66,8 +65,7 @@ IPA.add_dialog = function (spec) {
             that.add(
                 record,
                 function(data, text_status, xhr) {
-                    var facet_name =   IPA.current_facet(IPA.current_entity);
-                    var facet = IPA.current_entity.get_facet(facet_name);
+                    var facet = IPA.current_entity.get_facet();
                     var table = facet.table;
                     table.refresh();
                     that.reset();
diff --git a/install/ui/association.js b/install/ui/association.js
index 32b4c36977b764b7846b8b4daf39ed6c72ff40a9..5354117d0206a5de0643c3ee93fedfef3b130ba0 100644
--- a/install/ui/association.js
+++ b/install/ui/association.js
@@ -382,8 +382,7 @@ IPA.association_table_widget = function (spec) {
         }
 
         var entity = IPA.get_entity(that.entity_name);
-        var facet_name = IPA.current_facet(entity);
-        var facet = entity.get_facet(facet_name);
+        var facet = entity.get_facet();
 
         if (facet.is_dirty()) {
             var dialog = IPA.dirty_dialog({
@@ -408,8 +407,7 @@ IPA.association_table_widget = function (spec) {
         }
 
         var entity = IPA.get_entity(that.entity_name);
-        var facet_name = IPA.current_facet(entity);
-        var facet = entity.get_facet(facet_name);
+        var facet = entity.get_facet();
 
         if (facet.is_dirty()) {
             var dialog = IPA.dirty_dialog({
diff --git a/install/ui/details.js b/install/ui/details.js
index 45ffa6f16cdec64ff76032e2fa65eafef03baa63..50fccce4946b207999ef3f902b666a567b2b3e21 100644
--- a/install/ui/details.js
+++ b/install/ui/details.js
@@ -484,12 +484,10 @@ IPA.details_facet = function(spec) {
         }
     };
 
-    function new_key(){
+    that.needs_update = function() {
         var pkey = IPA.nav.get_state(that.entity_name+'-pkey');
         return pkey != that.pkey;
-    }
-    that.new_key = new_key;
-
+    };
 
     that.is_dirty = function() {
         var sections = that.sections.values;
diff --git a/install/ui/entitle.js b/install/ui/entitle.js
index bbcf2395c5e5901c3311678e0fd66e18b4cb10da..d0af1ab84183397c7b1c374d39196cd70ad6aeda 100644
--- a/install/ui/entitle.js
+++ b/install/ui/entitle.js
@@ -588,8 +588,7 @@ IPA.entitle.register_online_dialog = function(spec) {
             record.password,
             record.ipaentitlementid,
             function() {
-                var facet_name = IPA.current_facet(that.entity);
-                var facet = that.entity.get_facet(facet_name);
+                var facet = that.entity.get_facet();
                 facet.refresh();
                 that.close();
             }
@@ -613,8 +612,7 @@ IPA.entitle.register_offline_dialog = function(spec) {
         that.entity.register_offline(
             that.get_certificate(),
             function() {
-                var facet_name = IPA.current_facet(that.entity);
-                var facet = that.entity.get_facet(facet_name);
+                var facet = that.entity.get_facet();
                 facet.refresh();
                 that.close();
             }
@@ -646,8 +644,7 @@ IPA.entitle.consume_dialog = function(spec) {
         that.entity.consume(
             record.quantity,
             function() {
-                var facet_name = IPA.current_facet(that.entity);
-                var facet = that.entity.get_facet(facet_name);
+                var facet = that.entity.get_facet();
                 facet.refresh();
                 that.close();
             }
@@ -671,8 +668,7 @@ IPA.entitle.import_dialog = function(spec) {
         that.entity.import_certificate(
             that.get_certificate(),
             function() {
-                var facet_name = IPA.current_facet(that.entity);
-                var facet = that.entity.get_facet(facet_name);
+                var facet = that.entity.get_facet();
                 facet.refresh();
                 that.close();
             }
diff --git a/install/ui/entity.js b/install/ui/entity.js
index 0940c7d17e5bf8c523d575b0c4533e99012bb58f..83687fe7eff52784e862886a724e5d89b2c79a19 100644
--- a/install/ui/entity.js
+++ b/install/ui/entity.js
@@ -127,6 +127,10 @@ IPA.facet = function (spec) {
         that.header.load(data);
     };
 
+    that.needs_update = function() {
+        return true;
+    };
+
     that.is_dirty = function() {
         return false;
     };
@@ -459,7 +463,7 @@ IPA.entity = function (spec) {
     that.facet_groups = $.ordered_map();
 
     // current facet
-    that.facet_name = null;
+    that.facet = null;
 
     that.redirect_facet = spec.redirect_facet;
     that.containing_entity = null;
@@ -490,7 +494,14 @@ IPA.entity = function (spec) {
     };
 
     that.get_facet = function(name) {
-        if (name === 'default') {
+        if (name === undefined) {
+            // return the current facet
+            if (that.facet) return that.facet;
+
+            // return the main facet
+            return that.facets.values[0];
+
+        } else if (name === 'default') {
             // return the first facet in the first facet group
             var facet_groups = that.facet_groups.values;
             for (var i=0; i<facet_groups.length; i++) {
@@ -541,22 +552,17 @@ IPA.entity = function (spec) {
 
     that.setup = function(container) {
 
-        var prev_facet = that.facet;
+        var prev_entity = IPA.current_entity;
+        var prev_facet = prev_entity ? prev_entity.facet : null;
 
         IPA.current_entity = that;
-        var facet_name = IPA.current_facet(that);
 
+        var facet_name = IPA.nav.get_state(that.name+'-facet');
         that.facet = that.get_facet(facet_name);
-        if (!that.facet) return;
 
-        if (IPA.entity_name == that.name) {
-            if (that.facet_name == that.facet.name) {
-                if (that.facet.new_key && (!that.facet.new_key())) return;
-            } else {
-                that.facet_name = that.facet.name;
-            }
-        } else {
-            IPA.entity_name = that.name;
+        // same entity, same facet, and doesn't need updating => return
+        if (that == prev_entity && that.facet == prev_facet && !that.facet.needs_update()) {
+            return;
         }
 
         if (prev_facet) {
@@ -613,15 +619,6 @@ IPA.entity = function (spec) {
     return that;
 };
 
-IPA.current_facet = function(entity) {
-    var facet_name = IPA.nav.get_state(entity.name+'-facet');
-    var facets = entity.facets.values;
-    if (!facet_name  && facets.length) {
-        facet_name = facets[0].name;
-    }
-    return facet_name;
-};
-
 IPA.nested_tab_labels = {};
 
 IPA.get_nested_tab_label = function(entity_name){
diff --git a/install/ui/navigation.js b/install/ui/navigation.js
index be2936dca1a0e86e81658e23cbdb0fc3aca7a4de..92949735e35fb304a66e4bd6ca692b4538dfb1a5 100644
--- a/install/ui/navigation.js
+++ b/install/ui/navigation.js
@@ -87,8 +87,7 @@ IPA.navigation = function(spec) {
     that.push_state = function(params) {
 
         if (IPA.current_entity) {
-            var facet_name = IPA.current_facet(IPA.current_entity);
-            var facet = IPA.current_entity.get_facet(facet_name);
+            var facet = IPA.current_entity.get_facet();
 
             if (facet.is_dirty()) {
                 var dialog = IPA.dirty_dialog({
diff --git a/install/ui/user.js b/install/ui/user.js
index 5d104bfc6575e182d547990f4b7075fe1277cefe..fbcc728522e7f05cc50fe62593486280c0585f64 100644
--- a/install/ui/user.js
+++ b/install/ui/user.js
@@ -173,8 +173,7 @@ IPA.user_status_widget = function(spec) {
             click: function() {
 
                 var entity = IPA.get_entity(that.entity_name);
-                var facet_name = IPA.current_facet(entity);
-                var facet = entity.get_facet(facet_name);
+                var facet = entity.get_facet();
 
                 if (facet.is_dirty()) {
                     var dialog = IPA.dirty_dialog({
@@ -257,8 +256,7 @@ IPA.user_status_widget = function(spec) {
                 action == 'activate',
                 function(data, textStatus, xhr) {
                     var entity = IPA.get_entity(that.entity_name);
-                    var facet_name = IPA.current_facet(entity);
-                    var facet = entity.get_facet(facet_name);
+                    var facet = entity.get_facet();
                     facet.refresh();
                     dialog.close();
                 }
-- 
1.7.5.1

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

Reply via email to