The select event handler in the navigation tab has been modified to
distinguish the source of the event. If the event is triggered by
URL hash change, it will use the state specified in the URL. If the
event is triggered by a mouse click, it will use the state stored
internally.

--
Endi S. Dewata
From 2a24649459ca9b2455f29a91eeb77b5024ad0122 Mon Sep 17 00:00:00 2001
From: Endi S. Dewata <edew...@redhat.com>
Date: Thu, 21 Jul 2011 17:33:43 -0500
Subject: [PATCH] Fixed problem with navigation state loading.

The select event handler in the navigation tab has been modified to
distinguish the source of the event. If the event is triggered by
URL hash change, it will use the state specified in the URL. If the
event is triggered by a mouse click, it will use the state stored
internally.
---
 install/ui/navigation.js |   38 ++++++++++++++++++++++++++++++--------
 1 files changed, 30 insertions(+), 8 deletions(-)

diff --git a/install/ui/navigation.js b/install/ui/navigation.js
index 92949735e35fb304a66e4bd6ca692b4538dfb1a5..2f39d8b3139cc4039b27132fa24434f0c8396d41 100644
--- a/install/ui/navigation.js
+++ b/install/ui/navigation.js
@@ -30,6 +30,8 @@ IPA.navigation = function(spec) {
     that.name = spec.name;
 
     that.container = spec.container;
+    that.root = that.container.attr('id');
+
     that.content = spec.content;
     that.tab_class = spec.tab_class || 'tabs';
     that.max_depth = spec.max_depth || 3;
@@ -63,6 +65,18 @@ IPA.navigation = function(spec) {
         return that.tabs_by_name[name];
     };
 
+    that.get_current_tab = function(state) {
+        var name = null;
+        var next = state[that.root];
+
+        while (next) {
+            name = next;
+            next = state[name];
+        }
+
+        return that.get_tab(name);
+    };
+
     that.get_path_state = function(name) {
 
         var path_state = {};
@@ -77,7 +91,7 @@ IPA.navigation = function(spec) {
             parent = tab.parent;
         }
 
-        path_state[that.container.attr('id')] = tab.name;
+        path_state[that.root] = tab.name;
 
         return path_state;
     };
@@ -99,7 +113,7 @@ IPA.navigation = function(spec) {
                 };
 
                 dialog.init();
-                dialog.open($('#navigation'));
+                dialog.open(that.container);
 
                 return false;
             }
@@ -110,7 +124,7 @@ IPA.navigation = function(spec) {
         }
 
         var url_state ={};
-        var key = 'navigation';
+        var key = that.root;
         while(state[key]){
             var value = state[key];
             url_state[key] = value;
@@ -168,7 +182,7 @@ IPA.navigation = function(spec) {
             state[entity_name + '-pkey'] = pkey;
         }
 
-        that.push_state(state);
+        return that.push_state(state);
     };
 
     /*like show page, but works for nested entities */
@@ -194,7 +208,7 @@ IPA.navigation = function(spec) {
     that.create = function() {
 
         var container = $('<div/>', {
-            name: 'navigation'
+            name: that.root
         }).appendTo(that.container);
 
         that._create(that.tabs, container, 1);
@@ -205,7 +219,15 @@ IPA.navigation = function(spec) {
                 var panel = $(ui.panel);
                 var name = panel.attr('name');
 
-                return that.show_page(name);
+                var state = $.bbq.getState();
+                var tab = that.get_current_tab(state);
+
+                if (tab && tab.name == name) { // hash change
+                    return that.push_state(state);
+
+                } else { // mouse click
+                    return that.show_page(name);
+                }
             }
         });
     };
@@ -220,7 +242,7 @@ IPA.navigation = function(spec) {
 
         for (var i=0; i<tabs.length; i++) {
             var tab = tabs[i];
-            var tab_id = 'navigation-'+tab.name;
+            var tab_id = that.root+'-'+tab.name;
 
             if (tab.entity) {
                 var entity = IPA.get_entity(tab.entity);
@@ -275,7 +297,7 @@ IPA.navigation = function(spec) {
         }
         $('.entity', that.content).css('display', 'none');
 
-        var container = $('div[name=navigation]', that.container);
+        var container = $('div[name='+that.root+']', that.container);
         that._update(that.tabs, container, 1);
     };
 
-- 
1.7.5.1

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

Reply via email to