forked from cockpit-project/cockpit
-
Notifications
You must be signed in to change notification settings - Fork 1
/
devices.js
91 lines (81 loc) · 2.95 KB
/
devices.js
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
/*
* This file is part of Cockpit.
*
* Copyright (C) 2015 Red Hat, Inc.
*
* Cockpit is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* Cockpit 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Cockpit; If not, see <http://www.gnu.org/licenses/>.
*/
define([
"jquery",
"base1/cockpit",
"storage/client",
"storage/jobs",
"storage/overview",
"storage/details",
"translated!base1/po",
], function($, cockpit, client, jobs, overview, details, po) {
cockpit.locale(po);
var _ = cockpit.gettext;
var C_ = cockpit.gettext;
/* INITIALIZATION AND NAVIGATION
*/
function init() {
var jobs_manager;
var overview_page;
var details_page;
$('body').on('click', '[data-goto-block]', function () {
cockpit.location.go([ $(this).attr('data-goto-block') ]);
});
$('body').on('click', '[data-goto-mdraid]', function () {
cockpit.location.go([ 'mdraid', $(this).attr('data-goto-mdraid') ]);
});
$('body').on('click', '[data-goto-vgroup]', function () {
cockpit.location.go([ 'vg', $(this).attr('data-goto-vgroup') ]);
});
function navigate() {
var path = cockpit.location.path;
if (path.length === 0) {
details_page.hide();
overview_page.show();
} else if (path.length == 1) {
overview_page.hide();
details_page.show('block', path[0]);
} else if (path.length == 2 && path[0] == 'mdraid') {
overview_page.hide();
details_page.show('mdraid', path[1]);
} else if (path.length == 2 && path[0] == 'vg') {
overview_page.hide();
details_page.show('vgroup', path[1]);
} else { /* redirect */
console.warn("not a init location: " + path);
cockpit.location = '';
}
$("body").show();
}
client.init(function () {
cockpit.translate();
if (client.features === false) {
$('#unsupported').show();
$("body").show();
} else {
jobs_manager = jobs.init(client);
overview_page = overview.init(client, jobs_manager);
details_page = details.init(client, jobs_manager);
$(cockpit).on("locationchanged", navigate);
navigate();
}
});
}
return init;
});