diff --git a/src/sunstone/public/js/sunstone-util.js b/src/sunstone/public/js/sunstone-util.js index fcab5f77c7..1523b6f4e9 100644 --- a/src/sunstone/public/js/sunstone-util.js +++ b/src/sunstone/public/js/sunstone-util.js @@ -1232,8 +1232,10 @@ function loadAccounting(resource, id, graphs, options){ }; } + function insert_extended_template_table(template_json,resource_type,resource_id) { + console.log(template_json); var str = '\ \ \ @@ -1321,7 +1323,7 @@ function insert_extended_template_table(template_json,resource_type,resource_id) // Convert from hash to string var template_str = "\n"; for(var key in template_json) - template_str=template_str+key+"="+ template_json[key]+"\n"; + template_str=template_str+key+"=\""+ template_json[key]+"\"\n"; // Let OpenNebula know Sunstone.runAction(resource_type+".update_template",resource_id,template_str); @@ -1331,45 +1333,112 @@ function insert_extended_template_table(template_json,resource_type,resource_id) } // Returns an HTML string with the json keys and values -function fromJSONtoHTMLTable(template_json,resource_type,resource_id){ +function fromJSONtoHTMLTable(template_json,resource_type,resource_id,vectorial){ var str = "" if (!template_json){ return "Not defined";} var field = null; - if (template_json.constructor == Array){ - for (field = 0; field < template_json.length; ++field){ - str += fromJSONtoHTMLRow(field, - template_json[field], - template_json, - resource_type, - resource_id); - } - } else { - for (field in template_json) { - str += fromJSONtoHTMLRow(field, - template_json[field], - template_json, - resource_type, - resource_id); - } + // Iterate for each value in the JSON object + for (field in template_json) + { + str += fromJSONtoHTMLRow(field, + template_json[field], + resource_type, + resource_id, + vectorial); } + return str; } + // Helper for fromJSONtoHTMLTable function -function fromJSONtoHTMLRow(field,value,template_json,resource_type,resource_id){ - var str = '\ - \ - \ - \ - \ - '; +function fromJSONtoHTMLRow(field,value,resource_type,resource_id, vectorial){ + var str = ""; + + // value can be an array + if (value.constructor == Array) + { + var it=null; + + for (it = 0; it < value.length; ++it) + { + var current_value = value[it]; + + // if value is object, we are dealing with a vectorial value + if (typeof current_value == 'object') + { + if (it==0) + { + // if it is the first occurrence, print the header + str += '\ + \ + \ + \ + ' + } + + str += fromJSONtoHTMLTable(current_value, + resource_type, + resource_id, + true); + } + else + { + str += fromJSONtoHTMLRow(field, + current_value, + resource_type, + resource_id, + false); + } + } + } + else // or value can be a string + { + var align_str = ""; + var key_class_str = ""; + var value_class_str = ""; + + if(vectorial) + { + align_str="text-align:center"; + key_class_str=" key_vectorial_td"; + value_class_str=" value_vectorial_td"; + } + + str += '\ + \ + '; + + if (vectorial) + { + str += '' + } + else + { + str += '\ + \ + '; + } + + } + return str; }
'+tr(field)+''+value+'
\ - e\ -
\ -
\ - x\ -
\ -
'+tr(field)+'\ +
\ + e\ +
\ +
\ +
\ + x\ +
\ +
'+tr(field)+''+value+'
\ +
\ + e\ +
\ +
\ +
\ + x\ +
\ +