From f5ebc510f2e5be2d1a16464f19ba6230bf7f4e5f Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Mon, 16 May 2011 14:01:07 +0200 Subject: [PATCH 1/4] Bug #645: Iterate on arrays with vanilla loops. For...in loops on Arrays were changed in to for(i = 0, i' - } - colored_log += line + "\n"; + if (line.match(/\[E\]/)){ + line = ''+line+''; } + colored_log += line + "\n"; } + var log_tab = { title: "VM log", content: '
'+colored_log+'
' diff --git a/src/sunstone/public/js/plugins/vnets-tab.js b/src/sunstone/public/js/plugins/vnets-tab.js index 927461c1e1..e5a66e37c6 100644 --- a/src/sunstone/public/js/plugins/vnets-tab.js +++ b/src/sunstone/public/js/plugins/vnets-tab.js @@ -381,7 +381,7 @@ function updateVNetworkInfo(request,vn){ \ Leases information\ '+ - prettyPrintJSON(vn_info.LEASES)+ + prettyPrintJSON(vn_info.LEASES.LEASE)+ ''; } diff --git a/src/sunstone/public/js/sunstone-util.js b/src/sunstone/public/js/sunstone-util.js index 5e2ba6d22b..44f51a0c99 100644 --- a/src/sunstone/public/js/sunstone-util.js +++ b/src/sunstone/public/js/sunstone-util.js @@ -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 += '\ - ' - +field+ - '\ - \ - \ - '; - //attributes rows - //empty row - prettyprint - empty row - str += '\ - \ - \ - ' + - prettyPrintJSON(template_json[field],padding+25,"normal","0",1) + - '\ - \ - \ - '; - } else { - str += '\ - '+ - field+ - '\ - '+ - template_json[field]+ - '\ + 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 += '\ + ' + +field+ + '\ + \ + \ '; - }; + //attributes rows + //empty row - prettyprint - empty row + str += '\ + \ + \ + ' + + prettyPrintJSON(value,padding+25,"normal","0",1) + + '\ + \ + \ + '; + } else { + str += '\ + '+ + field+ + '\ + '+ + value+ + '\ + '; }; + 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 Date: Mon, 16 May 2011 15:40:48 +0200 Subject: [PATCH 2/4] Feature #643: Added select with the VM disks for the saveas dialog. --- src/sunstone/public/js/plugins/vms-tab.js | 79 +++++++++++++++++------ 1 file changed, 60 insertions(+), 19 deletions(-) diff --git a/src/sunstone/public/js/plugins/vms-tab.js b/src/sunstone/public/js/plugins/vms-tab.js index c27822cf95..a4bb7a1d34 100644 --- a/src/sunstone/public/js/plugins/vms-tab.js +++ b/src/sunstone/public/js/plugins/vms-tab.js @@ -244,12 +244,20 @@ var vm_actions = { {data:obj, success: function (req) { Sunstone.runAction("VM.show", - req.request.data[0]); + req.request.data[0][0]); }, error: onError }); } }, - + + "VM.saveas_disks" : { + type: "single", + call: OpenNebula.VM.show, + callback: saveasDisksCallback, + error: onError, + notify: false + }, + "VM.shutdown" : { type: "multiple", call: OpenNebula.VM.shutdown, @@ -689,10 +697,10 @@ function setupSaveasDialog(){
\
\
\ -
\ - \ - \ -
\ +
\ + \ + \ +
\ \
'); @@ -711,7 +719,7 @@ function setupSaveasDialog(){ var id = $('#vm_id',this).text(); var disk_id = $('#vm_disk_id',this).val(); var image_name = $('#image_name',this).val(); - var type = $('#image_type',this).val(); + //var type = $('#image_type',this).val(); if (!id.length || !disk_id.length || !image_name.length) { notifyError("Skipping VM "+id+ @@ -721,8 +729,8 @@ function setupSaveasDialog(){ var obj = { vm_id: id, disk_id : disk_id, - image_name : image_name, - type: type + image_name : image_name + //type: type }; args.push(id); Sunstone.runAction("VM.saveas",obj); @@ -755,35 +763,68 @@ function popUpSaveasDialog(elems){
Saveas for VM with ID '+this+'
\
\
\ - \ - \ + \ + \
\
\ \ \
\ + \
\ '; $('#saveas_vm_dialog #saveas_tabs').append(tab); + Sunstone.runAction("VM.saveas_disks",this); }); $('#saveas_vm_dialog #saveas_tabs').tabs(); $('#saveas_vm_dialog button').button(); - $('#saveas_vm_dialog').dialog('open'); } +function saveasDisksCallback(req,response){ + var vm_info = response.VM; + var id=vm_info.ID; + var select=""; + + var gen_option = function(id, name, source){ + if (name){ + return ''; + } + else { + return ''; + } + } + + var disks = vm_info.TEMPLATE.DISK; + if (!disks) { select = '';} + else if (disks.constructor == Array) //several disks + { + for (var i=0;i Date: Mon, 16 May 2011 15:46:03 +0200 Subject: [PATCH 3/4] Bug #645: Small fixes in new loops. --- src/sunstone/public/js/plugins/vms-tab.js | 4 ++-- src/sunstone/public/js/sunstone-util.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/sunstone/public/js/plugins/vms-tab.js b/src/sunstone/public/js/plugins/vms-tab.js index a4bb7a1d34..5ffc5be8de 100644 --- a/src/sunstone/public/js/plugins/vms-tab.js +++ b/src/sunstone/public/js/plugins/vms-tab.js @@ -297,8 +297,8 @@ var vm_actions = { //update the tab and pop it up again var log_lines = res.split("\n"); var colored_log = ''; - for (var line = 0; line < log_lines.length;++line){ - line = log_lines[line]; + for (var i = 0; i < log_lines.length;i++){ + var line = log_lines[i]; if (line.match(/\[E\]/)){ line = ''+line+''; } diff --git a/src/sunstone/public/js/sunstone-util.js b/src/sunstone/public/js/sunstone-util.js index 44f51a0c99..ca9ca9eabc 100644 --- a/src/sunstone/public/js/sunstone-util.js +++ b/src/sunstone/public/js/sunstone-util.js @@ -352,7 +352,7 @@ function onError(request,error_json) { var value; rows = ["method","action","object","id","reason"]; message = ""; - for (i = 0; i Date: Mon, 16 May 2011 15:51:05 +0200 Subject: [PATCH 4/4] Feature #644: Show ip field when using predefined network. --- src/sunstone/public/js/plugins/templates-tab.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sunstone/public/js/plugins/templates-tab.js b/src/sunstone/public/js/plugins/templates-tab.js index 0c2ad5cbb8..c58dfc76eb 100644 --- a/src/sunstone/public/js/plugins/templates-tab.js +++ b/src/sunstone/public/js/plugins/templates-tab.js @@ -295,7 +295,7 @@ var create_template_tmpl = '
\ \
Name of the network to attach this device
\
\ -
\ +
\ \ \
Request an specific IP from the Network
\