-
Notifications
You must be signed in to change notification settings - Fork 14
/
libvirt.ui.js
165 lines (155 loc) · 4.87 KB
/
libvirt.ui.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
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
159
160
161
162
163
164
165
"use strict";
// App
$(document).ready(function() {
// UI Elements
$('.button-collapse').sideNav();
$('.tooltipped').tooltip({delay: 50});
$('.materialboxed').materialbox();
$('.dropdown-button').dropdown({
inDuration: 300,
outDuration: 225,
constrainWidth: false, // Does not change width of dropdown to that of the activator
hover: true, // Activate on hover
gutter: 0, // Spacing from edge
belowOrigin: false, // Displays dropdown below the button
alignment: 'left', // Displays dropdown with edge aligned to the left of button
stopPropagation: false // Stops event propagation
});
$('.modal').modal({
dismissible: true, // Modal can be dismissed by clicking outside of the modal
opacity: .5, // Opacity of modal background
inDuration: 300, // Transition in duration
outDuration: 200, // Transition out duration
startingTop: '4%', // Starting top style attribute
endingTop: '10%', // Ending top style attribute
ready: function(modal, trigger) { // Callback for Modal open. Modal and trigger parameters available.
console.group('Modal');
console.info('Modal open.', modal, trigger);
console.groupEnd();
},
complete: function(modal) { // Callback for Modal close
console.group('Modal');
console.info('Modal close.', modal);
// Code for hypervisor connection
if (modal[0].id === 'modal-connect') {
var $user = $('#connect-user'),
$host = $('#connect-host');
if ($user.hasClass('valid') && $host.hasClass('valid')) {
console.log('do remote connection!', $user, $host);
}
else {
console.log('do local connection.');
}
}
console.groupEnd();
}
});
// User events bindings
$('a[href="#!"]').on('click', function(event) {
event.preventDefault();
});
$('.display-expand').on('click', function(event) {
event.preventDefault();
$('#variable-container').toggleClass('container');
});
$('#uploadForm').on('submit', function(event) {
event.preventDefault();
});
$('#connectForm').on('submit', function(event) {
event.preventDefault();
});
$('input[name="connect-mode"]').on('change', function(event) {
var $connector = $('#connect-ssh');
if (event.target.id === 'connect-mode-ssh') {
console.log('Connect mode "ssh" selected.', event, $connector);
if (event.target.checked === true) {
console.log('Show input field.');
$connector.show('slow');
}
}
else {
if ($connector && $connector.is(':visible') === true) {
console.log('Hide input field.');
$connector.hide('slow');
}
}
});
// Parse client query
if (window.location.search !== '') {
var params = new URLSearchParams(window.location.search);
console.info('Parsed query:', params.toString());
for (var p of params) {
console.log(p);
}
}
// Init polling from modules
if (params) {
switch (params.get('module')) {
case 'dsh':
var elements = ['cpu', 'mem', 'node', 'preview'];
var delayedPolling = setTimeout(function() {
var shortPolling = setInterval(function() {
elements.forEach(function (value, index) {
if (value === 'preview') { return; }
console.info('Request data id:', index, '| type:', value);
getJSONData(value);
});
}, 1000);
clearTimeout(delayedPolling);
$(window).one('unload', function () {
clearInterval(shortPolling);
});
}, 100);
var delayedPolling2 = setTimeout(function() {
var shortPolling2 = setInterval(function() {
elements.forEach(function (value, index) {
if (value !== 'preview') { return; }
$('.live-preview').each(function() {
console.info('Request data id:', index, '| type:', value);
getJSONData(value, $(this).data('vm'));
});
});
}, 5000);
clearTimeout(delayedPolling2);
$(window).one('unload', function () {
clearInterval(shortPolling2);
});
}, 100);
break;
case 'vms':
var elements = ['preview'];
var delayedPolling = setTimeout(function() {
var longPolling = setInterval(function() {
elements.forEach(function (value, index) {
console.info('Request data id:', index, '| type:', value);
$('.live-preview').each(function() {
getJSONData(value, $(this).data('vm'));
});
});
}, 5000);
clearTimeout(delayedPolling);
$(window).one('unload', function () {
clearInterval(longPolling);
});
}, 100);
break;
case 'vmi':
var elements = ['vhostcpu', 'vcpu', 'vdsk', 'vmem', 'vnet', 'vhost'];
var delayedPolling = setTimeout(function() {
var shortPolling = setInterval(function() {
elements.forEach(function (value, index) {
console.info('Request data id:', index, '| type:', value);
getJSONData(value, params.get('name'));
});
}, 1000);
clearTimeout(delayedPolling);
$(window).one('unload', function () {
clearInterval(shortPolling);
});
}, 100);
break;
default:
break;
}
}
});