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
158
|
function setLoggedInText(principal){
$("#loggedinas").html( "Logged in as " + principal);
}
function whoamiSuccess(response){
$.cookie("whoami", response.result.summary);
setLoggedInText(response.result.summary);
}
function unimplemented(facet){
showContent();
$('#content').append("<div>Not yet implemented.</div>");
}
function buildNavigation(){
params= getPageParams();
var tab = params["tab"];
if (!tab){
tab=$.cookie("lastpage");
}
if ( !tab ) {
tab="user";
}
var facet = params["facet"];
var siteMap = [{name:"IDENTITY",
tab:"user",
children : [
{name:"Users",tab:"user", setup: setupUser},
{name:"Groups",tab:"group",setup: setupGroup},
{name:"Hosts",tab:"host", setup: setupHost},
{name:"Hostgroups",
tab:"hostgroup",
setup: setupHostgroup},
{name:"Netgroups",tab:"netgroup", setup:setupNetgroup}
]},
{name:"POLICY", tab:"policy", setup: unimplemented},
{name:"CONFIG", tab:"config", setup: unimplemented }];
var separator = $("<span class='main-separator' />");
var currentMain = siteMap[0];
for (var i = 0 ; i < siteMap.length; i++){
current = siteMap[i];
if (i > 0){
$('#main-nav').append(separator.clone());
}
var tabClass = "main-nav-off";
if (tab == current.tab){
currentMain = current;
tabClass = "main-nav-on";
}
var span = $("<span/>", {
"class": tabClass,
id: "span-tab-"+current.tab,
});
$("<a/>",{
"id": "tab-"+current.tab,
href: "#?tab="+current.tab,
text: current.name,
click: setActiveTab
}).appendTo(span);
span.appendTo("#main-nav")
}
if (currentMain.children){
var selectedSub;
for (var i =0; i < currentMain.children.length; i++){
var currentSub = currentMain.children[i];
var tabClass = "sub-nav-off";
if (tab == currentSub.tab){
tabClass = "sub-nav-on";
selectedSub = currentSub;
}
var span = $("<span/>", {
"class": tabClass,
id: "span-subtab-"+currentSub.tab
});
$("<a/>",{
"id": "subtab-"+currentSub.tab,
href: "#?tab="+currentSub.tab,
text: currentSub.name,
click: setActiveSubtab,
}).appendTo(span);
span.appendTo("#sub-nav");
}
if (selectedSub && selectedSub.setup){
selectedSub.setup(facet);
}
}else if (currentMain && currentMain.setup){
currentMain.setup(facet);
}
sampleData = "sampledata/whoami.json";
var whoami = $.cookie("whoami");
if (whoami == null){
ipa_cmd( 'whoami', [], {}, whoamiSuccess);
}else{
setLoggedInText(whoami);
}
}
function setActiveTab(){
var setupFunctions = {
user: setupUser,
policy: unimplemented,
config: unimplemented};
var tabName = this.id.substring("tab-".length);
$(".main-nav-on").removeClass('main-nav-on').addClass("main-nav-off")
var activeTab = "#span-tab-"+tabName;
$(activeTab).removeClass('main-nav-off').addClass("main-nav-on")
setupFunctions[tabName]();
}
function setActiveSubtab(){
var setupFunctions = {
user: setupUser,
group: setupGroup,
host: setupHost,
hostgroup:setupHostgroup,
netgroup:setupNetgroup,
};
var subtabName = this.id.substring("subtab-".length);
$(".sub-nav-on").removeClass('sub-nav-on').addClass("sub-nav-off")
var active = "#span-subtab-"+subtabName;
$(active).removeClass('sub-nav-off').addClass("sub-nav-on")
setupFunctions[subtabName]();
}
|