From 7512bf4f381ba3764fb6bbc4ccceff4244d8b465 Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Tue, 30 Aug 2011 19:11:47 +0200 Subject: [PATCH] Bug #785: Fix leases prints for VNETs --- src/sunstone/public/js/plugins/vnets-tab.js | 38 ++++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/src/sunstone/public/js/plugins/vnets-tab.js b/src/sunstone/public/js/plugins/vnets-tab.js index 7d6f6de516..2fe282396c 100644 --- a/src/sunstone/public/js/plugins/vnets-tab.js +++ b/src/sunstone/public/js/plugins/vnets-tab.js @@ -302,13 +302,6 @@ function vnShow(req){ //returns an array with the VNET information fetched from the JSON object function vNetworkElementArray(vn_json){ var network = vn_json.VNET; - var total_leases = "0"; - - if (network.TOTAL_LEASES){ - total_leases = network.TOTAL_LEASES; - } else if (network.LEASES && network.LEASES.LEASE){ - total_leases = network.LEASES.LEASE.length ? network.LEASES.LEASE.length : "1"; - } return [ '', @@ -319,7 +312,7 @@ function vNetworkElementArray(vn_json){ parseInt(network.TYPE) ? "FIXED" : "RANGED", network.BRIDGE, parseInt(network.PUBLIC) ? "yes" : "no", - total_leases ]; + network.TOTAL_LEASES ]; } @@ -411,18 +404,14 @@ function updateVNetworkInfo(request,vn){ Public\ '+(parseInt(vn_info.PUBLIC) ? "yes" : "no" )+'\ \ - '; - - //if it is a fixed VNET we can add leases information - if (vn_info.TEMPLATE.TYPE == "FIXED"){ - info_tab_content += - '\ +
\ + \ \ \ '+ - prettyPrintJSON(vn_info.TEMPLATE.LEASES)+ - '
Leases information
'; - } + printLeases(vn_info.LEASES)+ + '';; + var info_tab = { @@ -446,6 +435,21 @@ function updateVNetworkInfo(request,vn){ } +function printLeases(leases){ + if (!leases.LEASE) //empty + { + return ""; + }; + + if (leases.LEASE.constructor == Array) //>1 lease + { + return prettyPrintJSON(leases.LEASE); + } + else {//1 lease + return prettyPrintJSON([leases.LEASE]); + }; +} + //Prepares the vnet creation dialog function setupCreateVNetDialog() { dialogs_context.append('
');