summaryrefslogtreecommitdiffstats
path: root/install/ui/navigation.js
blob: 4a3fe6916689cf20ae6f09b3e21c681ad7396b68 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*jsl:import ipa.js */

/*  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, either version 3 of the License, or
 * (at your option) any later version.
 *
 * 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, see <http://www.gnu.org/licenses/>.
*/

var nav_tabs_lists;
var nav_container;



function nav_push_state(params)
{
    if (!IPA.test_dirty()){
        return false;
    }
    $.bbq.pushState(params);
    return true;
}

function nav_get_state(key)
{
    return $.bbq.getState(key, true);
}

function nav_remove_state(key)
{
    $.bbq.removeState(key);
}

function nav_create(nls, container, tabclass)
{
    if (!container)
        container = $('#navigation');
    if (!tabclass)
        tabclass = 'tabs';

    nav_tabs_lists = nls;
    nav_container = container;

    nav_generate_tabs(nls, container, tabclass, 1);

    var tabs = $('.' + tabclass);
    tabs.tabs({
        select: function(event, ui) {
            var panel = $(ui.panel);
            var parent = panel.parent();
            var id = parent.attr('id');
            var state = {};
            state[id] = ui.index;
            return nav_push_state(state);
        }
    });

    nav_update_tabs();
}

function nav_generate_tabs(nls, container, tabclass, depth)
{
    container.addClass(tabclass);
    container.addClass('tabs'+depth);

    var ul = $('<ul/>');
    container.append(ul);

    for (var i = 0; i < nls.length; ++i) {
        var tab = nls[i];

        var label = tab.name;
        if (tab.entity) {
            var entity = IPA.get_entity(tab.entity);
            label = entity.label;
        }
        if (tab.label){
            label = tab.label;
        }

        var li = nav_create_tab_li(tab.name, label);
        ul.append(li);

        var div = nav_create_tab_div(tab.name);
        container.append(div);

        if (tab.entity) {
            div.addClass('entity-container');
        }

        if (tab.children && depth === 1) {
            nav_generate_tabs(tab.children, div, tabclass, depth +1 );
        }
    }
}

function nav_create_tab_li(id, name)
{
    return $('<li/>').append($('<a/>', {
        href: '#'+id,
        title: id,
        html: name
    }));
}

function nav_create_tab_div(id)
{
    return $('<div/>', {
        id: id
    });
}

function nav_update_tabs()
{
    _nav_update_tabs(nav_tabs_lists, nav_container,1);
}

function _nav_update_tabs(nls, container,depth)
{
    var id = container.attr('id');
    var index = nav_get_state(id);
    if (!index || index >= nls.length) index = 0;

    container.tabs('select', index);

    var tab = nls[index];
    var container2 = $('#' + tab.name);

    if (tab.children   && depth === 1 ) {
        _nav_update_tabs(tab.children, container2,depth+1);

    } else if (tab.entity) {
        var entity_name = tab.entity;

        var nested_entity = nav_get_state(entity_name+'-entity');

        if (nested_entity){
            entity_name = nested_entity;
        }

        var entity = IPA.get_entity(entity_name);
        entity.setup(container2);
    }
}