1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-22 18:50:08 +03:00

Bug #645: Iterate on arrays with vanilla loops.

For...in loops on Arrays were changed in to for(i = 0, i<length, ++i) style loops. There where the former form caused problems or problems had been workaround-ed small improvements have been made.
This commit is contained in:
Hector Sanjuan 2011-05-16 14:01:07 +02:00 committed by Ruben S. Montero
parent 7965feb43b
commit f5ebc510f2
3 changed files with 69 additions and 54 deletions

View File

@ -289,15 +289,14 @@ var vm_actions = {
//update the tab and pop it up again
var log_lines = res.split("\n");
var colored_log = '';
for (line in log_lines){
for (var line = 0; line < log_lines.length;++line){
line = log_lines[line];
if (typeof line == "string") {
if (line.match(/\[E\]/)){
line = '<span class="vm_log_error">'+line+'</span>'
}
colored_log += line + "\n";
if (line.match(/\[E\]/)){
line = '<span class="vm_log_error">'+line+'</span>';
}
colored_log += line + "\n";
}
var log_tab = {
title: "VM log",
content: '<pre>'+colored_log+'</pre>'

View File

@ -381,7 +381,7 @@ function updateVNetworkInfo(request,vn){
<thead>\
<tr><th colspan="2">Leases information</th></tr>\
</thead>'+
prettyPrintJSON(vn_info.LEASES)+
prettyPrintJSON(vn_info.LEASES.LEASE)+
'</table>';
}

View File

@ -198,59 +198,75 @@ function notifyMessage(msg){
// It recursively explores objects
function prettyPrintJSON(template_json,padding,weight, border_bottom,padding_top_bottom){
var str = ""
if (!template_json){ return "Not defined";}
if (!padding) {padding=0};
if (!weight) {weight="bold";}
if (!border_bottom) {border_bottom = "1px solid #CCCCCC";}
if (!padding_top_bottom) {padding_top_bottom=6;}
var field = null;
for (field in template_json) {
if (typeof template_json[field] == 'object'){
//name of field row
str += '<tr>\
<td class="key_td" style=\
"padding-left:'+padding+'px;\
font-weight:'+weight+';\
border-bottom:'+border_bottom+';\
padding-top:'+padding_top_bottom+'px;\
padding-bottom:'+padding_top_bottom+'px;">'
+field+
'</td>\
<td class="value_td" style=\
"border-bottom:'+border_bottom+';\
padding-top:'+padding_top_bottom+'px;\
padding-bottom:'+padding_top_bottom+'px">\
</td>\
</tr>';
//attributes rows
//empty row - prettyprint - empty row
str += '<tr>\
<td class="key_td" style="border-bottom:0"></td>\
<td class="value_td" style="border-bottom:0"></td>\
</tr>' +
prettyPrintJSON(template_json[field],padding+25,"normal","0",1) +
'<tr>\
<td class="key_td"></td>\
<td class="value_td"></td>\
</tr>';
} else {
str += '<tr>\
<td class="key_td" style="\
padding-left:'+padding+'px;\
font-weight:'+weight+';\
border-bottom:'+border_bottom+';\
padding-top:'+padding_top_bottom+'px;\
padding-bottom:'+padding_top_bottom+'px">'+
field+
'</td>\
<td class="value_td" style="\
border-bottom:'+border_bottom+';\
padding-top:'+padding_top_bottom+'px;\
padding-bottom:'+padding_top_bottom+'px">'+
template_json[field]+
'</td>\
if (template_json.constructor == Array){
for (field = 0; field < template_json.length; ++field){
str += prettyPrintRowJSON(field,template_json[field],padding,weight, border_bottom,padding_top_bottom);
}
} else {
for (field in template_json) {
str += prettyPrintRowJSON(field,template_json[field],padding,weight, border_bottom,padding_top_bottom);
}
}
return str;
}
function prettyPrintRowJSON(field,value,padding,weight, border_bottom,padding_top_bottom){
var str="";
if (typeof value == 'object'){
//name of field row
str += '<tr>\
<td class="key_td" style=\
"padding-left:'+padding+'px;\
font-weight:'+weight+';\
border-bottom:'+border_bottom+';\
padding-top:'+padding_top_bottom+'px;\
padding-bottom:'+padding_top_bottom+'px;">'
+field+
'</td>\
<td class="value_td" style=\
"border-bottom:'+border_bottom+';\
padding-top:'+padding_top_bottom+'px;\
padding-bottom:'+padding_top_bottom+'px">\
</td>\
</tr>';
};
//attributes rows
//empty row - prettyprint - empty row
str += '<tr>\
<td class="key_td" style="border-bottom:0"></td>\
<td class="value_td" style="border-bottom:0"></td>\
</tr>' +
prettyPrintJSON(value,padding+25,"normal","0",1) +
'<tr>\
<td class="key_td"></td>\
<td class="value_td"></td>\
</tr>';
} else {
str += '<tr>\
<td class="key_td" style="\
padding-left:'+padding+'px;\
font-weight:'+weight+';\
border-bottom:'+border_bottom+';\
padding-top:'+padding_top_bottom+'px;\
padding-bottom:'+padding_top_bottom+'px">'+
field+
'</td>\
<td class="value_td" style="\
border-bottom:'+border_bottom+';\
padding-top:'+padding_top_bottom+'px;\
padding-bottom:'+padding_top_bottom+'px">'+
value+
'</td>\
</tr>';
};
return str;
}
@ -336,7 +352,7 @@ function onError(request,error_json) {
var value;
rows = ["method","action","object","id","reason"];
message = "";
for (i in rows){
for (i = 0; i<rows.length; ++i){
key = rows[i];
value = eval(key);
if (value)