From 4f45c972c315d674e8a7fd669c5ea816057294b6 Mon Sep 17 00:00:00 2001 From: Brian Federle Date: Thu, 1 May 2014 15:38:26 -0700 Subject: [PATCH] CLOUDSTACK-6438: Filter out existing IPs in dropdown --- ui/scripts/network.js | 23 +++++++++++++++-------- ui/scripts/ui/widgets/multiEdit.js | 14 +++++++++++++- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/ui/scripts/network.js b/ui/scripts/network.js index abfaac322a7..7a495c18abf 100755 --- a/ui/scripts/network.js +++ b/ui/scripts/network.js @@ -179,19 +179,26 @@ var primaryIp = nic.ipaddress; var secondaryIps = nic.secondaryip ? nic.secondaryip : []; var ipSelection = []; + var existingIps = $(args.context.subItemData).map( + function(index, item) { return item.itemIp; } + ); // Add primary IP as default - ipSelection.push({ - id: primaryIp, - description: primaryIp + ' (Primary)' - }); + if ($.inArray(primaryIp, existingIps) == -1) { + ipSelection.push({ + id: primaryIp, + description: primaryIp + ' (Primary)' + }); + } // Add secondary IPs $(secondaryIps).map(function(index, secondaryIp) { - ipSelection.push({ - id: secondaryIp.ipaddress, - description: secondaryIp.ipaddress - }); + if ($.inArray(secondaryIp.ipaddress, existingIps) == -1) { + ipSelection.push({ + id: secondaryIp.ipaddress, + description: secondaryIp.ipaddress + }); + } }); args.response.success({ diff --git a/ui/scripts/ui/widgets/multiEdit.js b/ui/scripts/ui/widgets/multiEdit.js index 367cc27fd81..47e5f438182 100755 --- a/ui/scripts/ui/widgets/multiEdit.js +++ b/ui/scripts/ui/widgets/multiEdit.js @@ -196,11 +196,21 @@ } else if (field.addButton && !options.noSelect) { if (options.multipleAdd) { $addButton.click(function() { + var context = $.extend(true, {}, options.context); + if ($td.hasClass('disabled')) return false; + var $subItems = $td.closest('.data-item').find('.expandable-listing tr'); + + if ($subItems.size()) { + context.subItemData = $subItems.map(function() { + return $(this).data('json-obj'); + }); + } + _medit.vmList($multi, options.listView, - options.context, + context, options.multipleAdd, _l('label.add.vms'), addItemAction, { multiRule: multiRule @@ -820,6 +830,8 @@ var field = this; var $tr = _medit.multiItem.itemRow(field, itemActions, multiRule, $tbody).appendTo($tbody); + $tr.data('json-obj', field); + cloudStack.evenOdd($tbody, 'tr', { even: function($elem) { $elem.addClass('even');