From 38ed284054a0d2e436f8a2717faceabec7e996ab Mon Sep 17 00:00:00 2001 From: "Endi S. Dewata" Date: Thu, 21 Jul 2011 17:33:43 -0500 Subject: 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 file changed, 30 insertions(+), 8 deletions(-) (limited to 'install/ui/navigation.js') diff --git a/install/ui/navigation.js b/install/ui/navigation.js index 92949735..2f39d8b3 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 = $('
', { - 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