67 |
67 |
|
68 |
68 |
}
|
69 |
69 |
|
70 |
|
// http://stackoverflow.com/questions/499126/jquery-set-cursor-position-in-text-area
|
71 |
|
$.fn.setCursorPosition = function(pos) {
|
72 |
|
if ($(this).get(0).setSelectionRange) {
|
73 |
|
$(this).get(0).setSelectionRange(pos, pos);
|
74 |
|
} else if ($(this).get(0).createTextRange) {
|
75 |
|
var range = $(this).get(0).createTextRange();
|
76 |
|
range.collapse(true);
|
77 |
|
range.moveEnd('character', pos);
|
78 |
|
range.moveStart('character', pos);
|
79 |
|
range.select();
|
80 |
|
}
|
81 |
|
}
|
82 |
|
|
83 |
|
// indexOf prototype for IE
|
84 |
|
if (!Array.prototype.indexOf) {
|
85 |
|
Array.prototype.indexOf = function(elt /*, from*/) {
|
86 |
|
var len = this.length;
|
87 |
|
var from = Number(arguments[1]) || 0;
|
88 |
|
from = (from < 0)
|
89 |
|
? Math.ceil(from)
|
90 |
|
: Math.floor(from);
|
91 |
|
if (from < 0)
|
92 |
|
from += len;
|
93 |
|
|
94 |
|
for (; from < len; from++) {
|
95 |
|
if (from in this &&
|
96 |
|
this[from] === elt)
|
97 |
|
return from;
|
98 |
|
}
|
99 |
|
return -1;
|
100 |
|
};
|
101 |
|
}
|
102 |
|
|
103 |
|
// trim prototype for IE
|
104 |
|
if(typeof String.prototype.trim !== 'function') {
|
105 |
|
String.prototype.trim = function() {
|
106 |
|
return this.replace(/^\s+|\s+$/g, '');
|
107 |
|
}
|
108 |
|
}
|
109 |
|
|
110 |
|
// simple string format helper (http://stackoverflow.com/questions/610406/javascript-equivalent-to-printf-string-format)
|
111 |
|
String.prototype.format = function() {
|
112 |
|
var formatted = this;
|
113 |
|
for (var i = 0; i < arguments.length; i++) {
|
114 |
|
var regexp = new RegExp('\\{'+i+'\\}', 'gi');
|
115 |
|
formatted = formatted.replace(regexp, arguments[i]);
|
116 |
|
}
|
117 |
|
return formatted;
|
118 |
|
};
|
119 |
|
|
120 |
|
|
121 |
|
// Show VNC console
|
122 |
|
function vnc_attachment(host, port, password) {
|
123 |
|
// FIXME: Must be made into parameters, in settings.py
|
124 |
|
//vnc = open("", "displayWindow",
|
125 |
|
// "status=yes,toolbar=yes,menubar=yes");
|
126 |
|
vd = document.open("application/x-vnc");
|
127 |
|
|
128 |
|
vd.writeln("[connection]");
|
129 |
|
vd.writeln("host=" + host);
|
130 |
|
vd.writeln("port=" + port);
|
131 |
|
vd.writeln("password=" + password);
|
132 |
|
|
133 |
|
vd.close();
|
134 |
|
}
|
135 |
|
|
136 |
|
// connect to machine action
|
137 |
|
function machine_connect(serverIDs){
|
138 |
|
return;
|
139 |
|
if (!serverIDs.length){
|
140 |
|
//ajax_success('DEFAULT');
|
141 |
|
return false;
|
142 |
|
}
|
143 |
|
|
144 |
|
// prefer metadata values for specific options (username, domain)
|
145 |
|
var username_meta_key = 'user';
|
146 |
|
var domain_meta_key = "domain";
|
147 |
|
|
148 |
|
var serverID = serverIDs.pop();
|
149 |
|
var machine = get_machine(serverID);
|
150 |
|
var serverName = machine.name;
|
151 |
|
|
152 |
|
try {
|
153 |
|
var serverIP = machine.addresses.values[0].values[0].addr;
|
154 |
|
} catch (err) { var serverIP = 'undefined'; }
|
155 |
|
|
156 |
|
try {
|
157 |
|
var os = os_icon(machine.metadata);
|
158 |
|
} catch (err) { var os = 'undefined'; }
|
159 |
|
|
160 |
|
var username = "";
|
161 |
|
try {
|
162 |
|
username = machine.metadata.values[username_meta_key];
|
163 |
|
} catch (err) { username = undefined }
|
164 |
|
|
165 |
|
var domain = "";
|
166 |
|
try {
|
167 |
|
domain = machine.metadata.values[domain_meta_key];
|
168 |
|
} catch (erro) { domain = undefined }
|
169 |
|
|
170 |
|
var params_url = '?ip_address=' + serverIP + '&os=' + os + "&host_os=" + $.client.os + "&srv=" + serverID;
|
171 |
|
|
172 |
|
if (username) {
|
173 |
|
params_url += "&username=" + username;
|
174 |
|
}
|
175 |
|
|
176 |
|
if (domain) {
|
177 |
|
params_url += "&domain=" + domain;
|
178 |
|
}
|
179 |
|
|
180 |
|
//if ($.client.os == "Windows" && os == "windows") {
|
181 |
|
//// request rdp file
|
182 |
|
//window.open('machines/connect' + params_url + "&rdp=1");
|
183 |
|
//return;
|
184 |
|
//}
|
185 |
|
|
186 |
|
// FIXME: I18n ???
|
187 |
|
var title = 'Connect to: ' +
|
188 |
|
'<span class="machine-title"><img src="static/icons/machines/small/' + os +
|
189 |
|
'-on.png" /> ' + serverName +
|
190 |
|
'</span>';
|
191 |
|
|
192 |
|
// open msg box and fill it with json data retrieved from connect machine view
|
193 |
|
try {
|
194 |
|
// open msg box
|
195 |
|
msg_box({
|
196 |
|
title:title,
|
197 |
|
fixed: true,
|
198 |
|
content:'loading...',
|
199 |
|
extra:'', 'ajax':'machines/connect' + params_url,
|
200 |
|
parse_data:function(data){
|
201 |
|
var box_content = "<a href='"+data.link.url+"'>"+data.link.title+"</a>";
|
202 |
|
if (!data.link.url) {
|
203 |
|
box_content = "<span class='cmd'>"+data.link.title+"</span>";
|
204 |
|
}
|
205 |
|
data.title = false;
|
206 |
|
data.content = data.info;
|
207 |
|
data.extra = box_content;
|
208 |
|
return data;
|
209 |
|
}
|
210 |
|
});
|
211 |
|
} catch (error) {
|
212 |
|
// if msg box fails fallback redirecting the user to the connect url
|
213 |
|
window.open('machines/connect' + params_url);
|
214 |
|
}
|
215 |
|
|
216 |
|
|
217 |
|
// Restore os icon in list view
|
218 |
|
osIcon = $('#'+serverID).parent().parent().find('.list-logo');
|
219 |
|
osIcon.attr('src',osIcon.attr('os'));
|
220 |
|
|
221 |
|
return false;
|
222 |
|
}
|
223 |
|
|
224 |
|
|
225 |
70 |
function msg_box(user_config) {
|
226 |
71 |
var defaults = {'title':'Info message', 'content': 'this is an info message', 'ajax': false, 'extra':false};
|
227 |
72 |
var config = $.extend(defaults, user_config);
|