2010-09-16 09:28:07 -05:00
|
|
|
/* Authors:
|
|
|
|
* Pavel Zuna <pzuna@redhat.com>
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Red Hat
|
|
|
|
* see file 'COPYING' for use and warranty information
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; version 2 only
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
2010-09-30 15:37:33 -05:00
|
|
|
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);
|
|
|
|
}
|
2010-09-28 18:20:02 -05:00
|
|
|
|
2010-09-16 09:28:07 -05:00
|
|
|
function nav_create(nls, container, tabclass)
|
|
|
|
{
|
|
|
|
if (!container)
|
|
|
|
container = $('#navigation');
|
|
|
|
if (!tabclass)
|
|
|
|
tabclass = 'tabs';
|
|
|
|
|
2010-09-30 15:37:33 -05:00
|
|
|
nav_tabs_lists = nls;
|
|
|
|
nav_container = container;
|
|
|
|
|
2010-09-16 14:13:48 -05:00
|
|
|
nav_generate_tabs(nls, container, tabclass, 1);
|
2010-09-16 09:28:07 -05:00
|
|
|
|
|
|
|
var tabs = $('.' + tabclass);
|
2010-09-27 23:35:09 -05:00
|
|
|
tabs.tabs({
|
|
|
|
select: function(event, ui) {
|
|
|
|
var state = {};
|
|
|
|
var id = $(ui.panel).parent().attr('id');
|
|
|
|
state[id] = ui.index;
|
2010-09-30 15:37:33 -05:00
|
|
|
nav_push_state(state);
|
2010-09-27 23:35:09 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
2010-09-29 00:52:56 -05:00
|
|
|
|
2010-09-30 15:37:33 -05:00
|
|
|
nav_update_tabs();
|
2010-08-06 09:01:44 -05:00
|
|
|
}
|
|
|
|
|
2010-09-16 14:13:48 -05:00
|
|
|
function nav_generate_tabs(nls, container, tabclass, depth)
|
2010-09-16 09:28:07 -05:00
|
|
|
{
|
|
|
|
container.addClass(tabclass);
|
2010-09-16 14:13:48 -05:00
|
|
|
container.addClass('tabs'+depth);
|
2010-08-06 09:01:44 -05:00
|
|
|
|
2010-09-27 23:35:09 -05:00
|
|
|
var ul = $('<ul/>');
|
|
|
|
container.append(ul);
|
|
|
|
|
2010-09-16 09:28:07 -05:00
|
|
|
for (var i = 0; i < nls.length; ++i) {
|
2010-10-27 22:32:30 -05:00
|
|
|
var tab = nls[i];
|
2010-08-23 21:32:23 -05:00
|
|
|
|
2010-10-27 22:32:30 -05:00
|
|
|
var label = tab.name;
|
|
|
|
if ((IPA.metadata[tab.name]) && (IPA.metadata[tab.name].label)){
|
|
|
|
label = IPA.metadata[tab.name].label;
|
2010-09-24 19:48:23 -05:00
|
|
|
}
|
|
|
|
|
2010-10-27 22:32:30 -05:00
|
|
|
var li = nav_create_tab_li(tab.name, label);
|
2010-09-27 23:35:09 -05:00
|
|
|
ul.append(li);
|
2010-09-24 19:48:23 -05:00
|
|
|
|
2010-10-27 22:32:30 -05:00
|
|
|
var div = nav_create_tab_div(tab.name);
|
2010-09-27 23:35:09 -05:00
|
|
|
container.append(div);
|
2010-08-06 09:01:44 -05:00
|
|
|
|
2010-10-27 22:32:30 -05:00
|
|
|
if (tab.children) {
|
|
|
|
nav_generate_tabs(tab.children, div, tabclass, depth +1 );
|
|
|
|
} else {
|
|
|
|
var entity = ipa_get_entity(tab.name);
|
|
|
|
entity.label = tab.label;
|
|
|
|
entity.setup = tab.setup;
|
2010-08-23 21:32:23 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-08-06 09:01:44 -05:00
|
|
|
|
2010-09-27 23:35:09 -05:00
|
|
|
function nav_create_tab_li(id, name)
|
2010-09-16 09:28:07 -05:00
|
|
|
{
|
2010-09-27 23:35:09 -05:00
|
|
|
return $('<li/>').append($('<a/>', {
|
|
|
|
href: '#'+id,
|
|
|
|
title: id,
|
|
|
|
html: name
|
|
|
|
}));
|
2010-08-19 19:48:21 -05:00
|
|
|
}
|
|
|
|
|
2010-09-27 23:35:09 -05:00
|
|
|
function nav_create_tab_div(id)
|
2010-09-16 09:28:07 -05:00
|
|
|
{
|
2010-09-27 23:35:09 -05:00
|
|
|
return $('<div/>', {
|
|
|
|
id: id
|
|
|
|
});
|
2010-09-07 09:08:19 -05:00
|
|
|
}
|
|
|
|
|
2010-09-30 15:37:33 -05:00
|
|
|
function nav_update_tabs()
|
2010-09-16 09:28:07 -05:00
|
|
|
{
|
2010-09-30 15:37:33 -05:00
|
|
|
_nav_update_tabs(nav_tabs_lists, nav_container);
|
2010-09-27 23:35:09 -05:00
|
|
|
}
|
2010-09-29 00:52:56 -05:00
|
|
|
|
2010-09-30 15:37:33 -05:00
|
|
|
function _nav_update_tabs(nls, container)
|
2010-09-29 00:52:56 -05:00
|
|
|
{
|
2010-09-30 15:37:33 -05:00
|
|
|
var id = container.attr('id');
|
|
|
|
var index = nav_get_state(id);
|
|
|
|
if (!index || index >= nls.length) index = 0;
|
2010-09-29 00:52:56 -05:00
|
|
|
|
2010-09-30 15:37:33 -05:00
|
|
|
container.tabs('select', index);
|
2010-09-29 00:52:56 -05:00
|
|
|
|
2010-09-30 15:37:33 -05:00
|
|
|
var tab = nls[index];
|
|
|
|
var container2 = $('#' + tab.name);
|
2010-09-29 00:52:56 -05:00
|
|
|
|
2010-09-30 15:37:33 -05:00
|
|
|
if (tab.children) {
|
|
|
|
_nav_update_tabs(tab.children, container2);
|
2010-09-29 00:52:56 -05:00
|
|
|
|
2010-09-30 15:37:33 -05:00
|
|
|
} else if (tab.setup) {
|
2010-10-27 22:32:30 -05:00
|
|
|
var entity = IPA.get_entity(tab.name);
|
|
|
|
entity.setup(container2);
|
2010-09-29 00:52:56 -05:00
|
|
|
}
|
|
|
|
}
|