summaryrefslogtreecommitdiffstats
path: root/install/static/navigation.js
diff options
context:
space:
mode:
authorEndi S. Dewata <edewata@redhat.com>2010-09-30 15:37:33 -0500
committerAdam Young <ayoung@redhat.com>2010-10-01 09:06:47 -0400
commitc53831037cbe388d961420e87b036b1caf6cf723 (patch)
tree1d43f011ffaabad7307e5181b715659c41676815 /install/static/navigation.js
parent4f2d2fda93b1a118869579efa70d800a28b97a8b (diff)
downloadfreeipa.git-c53831037cbe388d961420e87b036b1caf6cf723.tar.gz
freeipa.git-c53831037cbe388d961420e87b036b1caf6cf723.tar.xz
freeipa.git-c53831037cbe388d961420e87b036b1caf6cf723.zip
Refactoring navigation.js.
The navigation.js has been modified to make it more abstract, i.e. unaware of entity facets. The nav_update_tabs() has been modified such that it activates and updates the tabs based on the current state stored in the URL. The facets are now handled in entity.js. The ipa_entity_setup() has been modified to update the facets based on the current state and cached state. The navigation.js also has been modified to be more class-like. The nav_create() has been modified to store the tab configuration and the tab container in internal variables nav_tabs_lists and nav_container. The nav_update_tabs() now can be called without any parameters. Functions nav_push_state(), nav_get_state(), and nav_remove_state() have been added to wrap BBQ API. This is to allow unit tests to replace them with mockup functions to remove dependency on BBQ.
Diffstat (limited to 'install/static/navigation.js')
-rw-r--r--install/static/navigation.js102
1 files changed, 35 insertions, 67 deletions
diff --git a/install/static/navigation.js b/install/static/navigation.js
index 3aa49fe2..4135cb44 100644
--- a/install/static/navigation.js
+++ b/install/static/navigation.js
@@ -18,8 +18,23 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-/* use this to track individual changes between two hashchange events */
-var window_hash_cache = {};
+var nav_tabs_lists;
+var nav_container;
+
+function nav_push_state(params)
+{
+ $.bbq.pushState(params);
+}
+
+function nav_get_state(key)
+{
+ return $.bbq.getState(key, true);
+}
+
+function nav_remove_state(key)
+{
+ $.bbq.removeState(key);
+}
function nav_create(nls, container, tabclass)
{
@@ -28,6 +43,9 @@ function nav_create(nls, container, tabclass)
if (!tabclass)
tabclass = 'tabs';
+ nav_tabs_lists = nls;
+ nav_container = container;
+
nav_generate_tabs(nls, container, tabclass, 1);
var tabs = $('.' + tabclass);
@@ -36,12 +54,12 @@ function nav_create(nls, container, tabclass)
var state = {};
var id = $(ui.panel).parent().attr('id');
state[id] = ui.index;
- $.bbq.pushState(state);
+ nav_push_state(state);
return true;
}
});
- nav_update_tabs(nls, container);
+ nav_update_tabs();
}
function nav_generate_tabs(nls, container, tabclass, depth)
@@ -88,76 +106,26 @@ function nav_create_tab_div(id)
});
}
-function nav_select_tabs(nls, container)
+function nav_update_tabs()
{
- var id = container.attr('id');
- var selectedTab = $.bbq.getState(id, true) || 0;
- if (selectedTab >= nls.length) selectedTab = 0;
- container.tabs('select', selectedTab);
-
- for (var i = 0; i < nls.length; ++i) {
- var n = nls[i];
-
- var div = $('#'+n.name);
-
- if ( (!n.setup) && n.children) {
- nav_select_tabs(n.children, div);
- }
- }
+ _nav_update_tabs(nav_tabs_lists, nav_container);
}
-function nav_update_tabs(nls, container)
+function _nav_update_tabs(nls, container)
{
- nav_select_tabs(nls, container);
-
- var index1 = container.tabs('option', 'selected');
- if (index1 >= nls.length) return;
-
- var tab1 = nls[index1];
- if (!tab1.children) return;
-
- var div1 = $('#' + tab1.name);
- var index2 = div1.tabs('option', 'selected');
- if (index2 >= tab1.children.length) return;
-
- var tab2 = tab1.children[index2];
- var obj_name = tab2.name;
- var entity_setup = tab2.setup;
- var div2 = $('#' + tab2.name);
-
- var state = obj_name + '-facet';
- var facet = $.bbq.getState(state, true) || 'search';
- var last_facet = window_hash_cache[state];
-
- if (facet != last_facet) {
- entity_setup(div2);
- window_hash_cache[state] = facet;
-
- } else if (facet == 'search') {
- state = obj_name + '-filter';
- var filter = $.bbq.getState(state, true);
- var last_filter = window_hash_cache[state];
- if (filter == last_filter) return;
-
- entity_setup(div2);
- window_hash_cache[state] = filter;
+ var id = container.attr('id');
+ var index = nav_get_state(id);
+ if (!index || index >= nls.length) index = 0;
- } else if (facet == 'details') {
- state = obj_name + '-pkey';
- var pkey = $.bbq.getState(state, true);
- var last_pkey = window_hash_cache[state];
- if (pkey == last_pkey) return;
+ container.tabs('select', index);
- entity_setup(div2);
- window_hash_cache[state] = pkey;
+ var tab = nls[index];
+ var container2 = $('#' + tab.name);
- } else if (facet == 'associate') {
- state = obj_name + '-enroll';
- var enroll = $.bbq.getState(state, true);
- var last_enroll = window_hash_cache[state];
- if (enroll == last_enroll) return;
+ if (tab.children) {
+ _nav_update_tabs(tab.children, container2);
- entity_setup(div2);
- window_hash_cache[state] = enroll;
+ } else if (tab.setup) {
+ tab.setup(container2);
}
}