Skip to content

Commit 4f45c97

Browse files
committed
CLOUDSTACK-6438: Filter out existing IPs in dropdown
1 parent 9885cf4 commit 4f45c97

2 files changed

Lines changed: 28 additions & 9 deletions

File tree

‎ui/scripts/network.js‎

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -179,19 +179,26 @@
179179
var primaryIp = nic.ipaddress;
180180
var secondaryIps = nic.secondaryip ? nic.secondaryip : [];
181181
var ipSelection = [];
182+
var existingIps = $(args.context.subItemData).map(
183+
function(index, item) { return item.itemIp; }
184+
);
182185

183186
// Add primary IP as default
184-
ipSelection.push({
185-
id: primaryIp,
186-
description: primaryIp + ' (Primary)'
187-
});
187+
if ($.inArray(primaryIp, existingIps) == -1) {
188+
ipSelection.push({
189+
id: primaryIp,
190+
description: primaryIp + ' (Primary)'
191+
});
192+
}
188193

189194
// Add secondary IPs
190195
$(secondaryIps).map(function(index, secondaryIp) {
191-
ipSelection.push({
192-
id: secondaryIp.ipaddress,
193-
description: secondaryIp.ipaddress
194-
});
196+
if ($.inArray(secondaryIp.ipaddress, existingIps) == -1) {
197+
ipSelection.push({
198+
id: secondaryIp.ipaddress,
199+
description: secondaryIp.ipaddress
200+
});
201+
}
195202
});
196203

197204
args.response.success({

‎ui/scripts/ui/widgets/multiEdit.js‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,21 @@
196196
} else if (field.addButton && !options.noSelect) {
197197
if (options.multipleAdd) {
198198
$addButton.click(function() {
199+
var context = $.extend(true, {}, options.context);
200+
199201
if ($td.hasClass('disabled')) return false;
200202

203+
var $subItems = $td.closest('.data-item').find('.expandable-listing tr');
204+
205+
if ($subItems.size()) {
206+
context.subItemData = $subItems.map(function() {
207+
return $(this).data('json-obj');
208+
});
209+
}
210+
201211
_medit.vmList($multi,
202212
options.listView,
203-
options.context,
213+
context,
204214
options.multipleAdd, _l('label.add.vms'),
205215
addItemAction, {
206216
multiRule: multiRule
@@ -820,6 +830,8 @@
820830
var field = this;
821831
var $tr = _medit.multiItem.itemRow(field, itemActions, multiRule, $tbody).appendTo($tbody);
822832

833+
$tr.data('json-obj', field);
834+
823835
cloudStack.evenOdd($tbody, 'tr', {
824836
even: function($elem) {
825837
$elem.addClass('even');

0 commit comments

Comments
 (0)