Skip to content

Commit 7e96bf5

Browse files
committed
CLOUDSTACK-3170: Support editing ACL rule items
1 parent aeab881 commit 7e96bf5

3 files changed

Lines changed: 205 additions & 93 deletions

File tree

ui/scripts/ui/dialog.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@
236236
response: {
237237
success: function(args) {
238238
$(args.data).each(function() {
239-
var id = this.id;
239+
var id = this.id ? this.id : this.name;
240240
var description = this.description;
241241

242242
if (args.descriptionField)
@@ -272,7 +272,7 @@
272272
.appendTo($value);
273273

274274
// Pass form item to provider for additional manipulation
275-
$.extend(selectArgs, { $select: $input });
275+
$.extend(selectArgs, { $select: $input, $form: $form, type: 'createForm' });
276276

277277
if (dependsOn) {
278278
$dependsOn = $input.closest('form').find('input, select').filter(function() {

ui/scripts/ui/widgets/multiEdit.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,7 @@
336336
},
337337
error: function(args) {
338338
error(args);
339-
$loading.remove();
340-
$dataItem.show();
339+
$multi.trigger('refresh');
341340

342341
return cloudStack.dialog.error;
343342
}
@@ -402,6 +401,8 @@
402401
var editableFields = {};
403402

404403
$.each(fields, function(key, field) {
404+
field.isDisabled = false;
405+
405406
if (field && field.isEditable) editableFields[key] = $.extend(true, {}, field, {
406407
defaultValue: data[key]
407408
});

ui/scripts/vpc.js

Lines changed: 200 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,15 @@
6060

6161
'number':{
6262
label:'Rule Number',
63-
edit:true
63+
edit:true,
64+
isEditable: true
6465

6566
},
6667

67-
'cidrlist': { edit: true, label: 'label.cidr' },
68+
'cidrlist': { edit: true, label: 'label.cidr', isEditable: true },
6869
action: {
6970
label: 'Action',
71+
isEditable: true,
7072
select: function(args) {
7173
args.response.success({
7274
data: [
@@ -78,63 +80,125 @@
7880
},
7981
'protocol': {
8082
label: 'label.protocol',
83+
isEditable: true,
8184
select: function(args) {
85+
var isEditDialog = args.type === 'createForm';
86+
8287
args.$select.change(function() {
83-
var $inputs = args.$form.find('input');
84-
var $icmpFields = $inputs.filter(function() {
85-
var name = $(this).attr('name');
86-
87-
return $.inArray(name, [
88-
'icmptype',
89-
'icmpcode'
90-
]) > -1;
91-
});
92-
var $otherFields = $inputs.filter(function() {
93-
var name = $(this).attr('name');
94-
95-
return name != 'protocolnumber' &&
96-
name != 'icmptype' &&
97-
name != 'icmpcode' &&
98-
name != 'cidrlist';
99-
});
100-
var $portFields = $inputs.filter(function() {
101-
var name = $(this).attr('name');
102-
return $.inArray(name, [
103-
'startport',
104-
'endport'
105-
]) > -1;
106-
});
88+
var $inputs, $icmpFields, $otherFields, $portFields, $protocolFields, $protocolinput;
89+
90+
//
91+
// Editing existing rules in createForm dialog
92+
//
93+
if (isEditDialog) {
94+
$inputs = args.$form.find('.form-item');
95+
$icmpFields = $inputs.filter(function() {
96+
var name = $(this).attr('rel');
97+
98+
return $.inArray(name, [
99+
'icmptype',
100+
'icmpcode'
101+
]) > -1;
102+
});
103+
$otherFields = $inputs.filter(function() {
104+
var name = $(this).attr('rel');
107105

108-
var $protocolinput = args.$form.find('td input');
109-
var $protocolFields = $protocolinput.filter(function(){
110-
var name = $(this).attr('name');
106+
return name != 'protocolnumber' &&
107+
name != 'icmptype' &&
108+
name != 'icmpcode' &&
109+
name != 'cidrlist';
110+
});
111+
$portFields = $inputs.filter(function() {
112+
var name = $(this).attr('rel');
113+
return $.inArray(name, [
114+
'startport',
115+
'endport'
116+
]) > -1;
117+
});
118+
$protocolFields = $inputs.filter(function(){
119+
var name = $(this).attr('rel');
111120

112-
return $.inArray(name,['protocolnumber']) > -1;
113-
});
121+
return $.inArray(name,['protocolnumber']) > -1;
122+
});
114123

115-
if ($(this).val() == 'protocolnumber' ){
116-
$icmpFields.hide();
117-
$otherFields.hide();
118-
$protocolFields.show().addClass('required');
119-
} else if ($(this).val() == 'icmp') {
120-
$icmpFields.show();
121-
$icmpFields.attr('disabled', false);
122-
$protocolFields.hide().removeClass('required');
123-
$otherFields.attr('disabled', 'disabled');
124-
$otherFields.hide();
125-
$otherFields.parent().find('label.error').hide();
126-
} else {
127-
$otherFields.show();
128-
$otherFields.parent().find('label.error').hide();
129-
$otherFields.attr('disabled', false);
130-
$icmpFields.attr('disabled', 'disabled');
131-
$icmpFields.hide();
132-
$icmpFields.parent().find('label.error').hide();
133-
$protocolFields.hide().removeClass('required');
134-
if ($(this).val() == 'all'){
135-
$portFields.attr('disabled', 'disabled');
124+
if ($(this).val() == 'protocolnumber' ){
125+
$icmpFields.hide();
126+
$portFields.show();
127+
$protocolFields.show();
128+
} else if ($(this).val() == 'icmp') {
129+
$icmpFields.show();
130+
$protocolFields.hide();
136131
$portFields.hide();
137-
}
132+
} else {
133+
$otherFields.show();
134+
$icmpFields.hide();
135+
$protocolFields.hide();
136+
137+
if ($(this).val() == 'all') {
138+
$portFields.hide();
139+
}
140+
}
141+
} else {
142+
//
143+
// Add new form
144+
//
145+
$inputs = args.$form.find('input');
146+
$icmpFields = $inputs.filter(function() {
147+
var name = $(this).attr('name');
148+
149+
return $.inArray(name, [
150+
'icmptype',
151+
'icmpcode'
152+
]) > -1;
153+
});
154+
$otherFields = $inputs.filter(function() {
155+
var name = $(this).attr('name');
156+
157+
return name != 'protocolnumber' &&
158+
name != 'icmptype' &&
159+
name != 'icmpcode' &&
160+
name != 'cidrlist' &&
161+
name != 'number';
162+
});
163+
$portFields = $inputs.filter(function() {
164+
var name = $(this).attr('name');
165+
return $.inArray(name, [
166+
'startport',
167+
'endport'
168+
]) > -1;
169+
});
170+
171+
$protocolinput = args.$form.find('td input');
172+
$protocolFields = $protocolinput.filter(function(){
173+
var name = $(this).attr('name');
174+
175+
return $.inArray(name,['protocolnumber']) > -1;
176+
});
177+
178+
if ($(this).val() == 'protocolnumber' ){
179+
$icmpFields.hide();
180+
$otherFields.hide();
181+
$protocolFields.show().addClass('required');
182+
} else if ($(this).val() == 'icmp') {
183+
$icmpFields.show();
184+
$icmpFields.attr('disabled', false);
185+
$protocolFields.hide().removeClass('required');
186+
$otherFields.attr('disabled', 'disabled');
187+
$otherFields.hide();
188+
$otherFields.parent().find('label.error').hide();
189+
} else {
190+
$otherFields.show();
191+
$otherFields.parent().find('label.error').hide();
192+
$otherFields.attr('disabled', false);
193+
$icmpFields.attr('disabled', 'disabled');
194+
$icmpFields.hide();
195+
$icmpFields.parent().find('label.error').hide();
196+
$protocolFields.hide().removeClass('required');
197+
if ($(this).val() == 'all'){
198+
$portFields.attr('disabled', 'disabled');
199+
$portFields.hide();
200+
}
201+
}
138202
}
139203
});
140204

@@ -153,9 +217,9 @@
153217
}
154218
},
155219

156-
'protocolnumber': {label:'Protocol Number',edit:true},
157-
'startport': { edit: true, label: 'label.start.port', isOptional: true },
158-
'endport': { edit: true, label: 'label.end.port', isOptional: true },
220+
'protocolnumber': {label:'Protocol Number',edit:true, isEditable: true},
221+
'startport': { edit: true, label: 'label.start.port', isOptional: true, isEditable: true },
222+
'endport': { edit: true, label: 'label.end.port', isOptional: true, isEditable: true },
159223
'networkid': {
160224
label: 'Select Tier',
161225
select: function(args) {
@@ -192,10 +256,11 @@
192256
});
193257
}
194258
},
195-
'icmptype': { edit: true, label: 'ICMP.type', isDisabled: true, desc:'Please specify -1 if you want to allow all ICMP types', defaultValue:'-1' },
196-
'icmpcode': { edit: true, label: 'ICMP.code', isDisabled: true, desc:'Please specify -1 if you want to allow all ICMP codes', defaultValue:'-1' },
259+
'icmptype': { edit: true, label: 'ICMP.type', isDisabled: true, desc:'Please specify -1 if you want to allow all ICMP types', defaultValue:'-1', isEditable: true },
260+
'icmpcode': { edit: true, label: 'ICMP.code', isDisabled: true, desc:'Please specify -1 if you want to allow all ICMP codes', defaultValue:'-1', isEditable: true },
197261
'traffictype' : {
198262
label: 'label.traffic.type',
263+
isEditable: true,
199264
select: function(args) {
200265
args.response.success({
201266
data: [
@@ -219,54 +284,100 @@
219284
var $multi = args.$multi;
220285
//Support for Protocol Number between 0 to 255
221286
if(args.data.protocol == 'protocolnumber'){
222-
$.extend(args.data,{protocol:args.data.protocolnumber});
223-
delete args.data.protocolnumber;
287+
$.extend(args.data,{protocol:args.data.protocolnumber});
288+
delete args.data.protocolnumber;
224289
}
225290
else
226291
delete args.data.protocolnumber;
227292

228293

229-
294+
230295
if((args.data.protocol == 'tcp' || args.data.protocol == 'udp') && (args.data.startport=="" || args.data.startport == undefined)){
231-
cloudStack.dialog.notice({message:_l('Start Port or End Port value should not be blank')});
296+
cloudStack.dialog.notice({message:_l('Start Port or End Port value should not be blank')});
232297
$(window).trigger('cloudStack.fullRefresh');
233298
}
234299
else if((args.data.protocol == 'tcp' || args.data.protocol == 'udp') && (args.data.endport=="" || args.data.endport == undefined)){
235-
cloudStack.dialog.notice({message:_l('Start Port or End Port value should not be blank')});
300+
cloudStack.dialog.notice({message:_l('Start Port or End Port value should not be blank')});
236301
$(window).trigger('cloudStack.fullRefresh');
237302
}
238303

239-
else{
240-
$.ajax({
241-
url: createURL('createNetworkACL'),
242-
data: $.extend(args.data, {
243-
aclid: args.context.aclLists[0].id
244-
}),
245-
dataType: 'json',
246-
success: function(data) {
247-
args.response.success({
248-
_custom: {
249-
jobId: data.createnetworkaclresponse.jobid,
250-
getUpdatedItem: function(json) {
251-
$(window).trigger('cloudStack.fullRefresh');
304+
else{
305+
$.ajax({
306+
url: createURL('createNetworkACL'),
307+
data: $.extend(args.data, {
308+
aclid: args.context.aclLists[0].id
309+
}),
310+
dataType: 'json',
311+
success: function(data) {
312+
args.response.success({
313+
_custom: {
314+
jobId: data.createnetworkaclresponse.jobid,
315+
getUpdatedItem: function(json) {
316+
$(window).trigger('cloudStack.fullRefresh');
252317

253-
return data;
318+
return data;
319+
}
320+
},
321+
notification: {
322+
label: 'label.add.ACL',
323+
poll: pollAsyncJobResult
254324
}
255-
},
256-
notification: {
257-
label: 'label.add.ACL',
258-
poll: pollAsyncJobResult
259-
}
260-
});
261-
},
262-
error: function(data) {
263-
args.response.error(parseXMLHttpResponse(data));
264-
}
265-
});
266-
}
325+
});
326+
},
327+
error: function(data) {
328+
args.response.error(parseXMLHttpResponse(data));
329+
}
330+
});
331+
}
267332
}
268333
},
269334
actions: {
335+
edit: {
336+
label: 'label.edit',
337+
action: function(args) {
338+
var data = {
339+
id: args.context.multiRule[0].id,
340+
cidrlist: args.data.cidrlist,
341+
number: args.data.number,
342+
protocol: args.data.protocol,
343+
traffictype: args.data.traffictype,
344+
action: args.data.action
345+
};
346+
347+
if (data.protocol === 'tcp' || data.protocol === 'udp') {
348+
$.extend(data, {
349+
startport: args.data.startport,
350+
endport: args.data.endport
351+
});
352+
} else if (data.protocol === 'icmp') {
353+
$.extend(data, {
354+
icmptype: args.data.icmptype,
355+
icmpcode: args.data.icmpcode
356+
});
357+
} else if (data.protocol === 'protocolnumber') {
358+
$.extend(data, {
359+
protocolnumber: args.data.protocolnumber
360+
});
361+
}
362+
363+
$.ajax({
364+
url: createURL('updateNetworkACLItem'),
365+
data: data,
366+
success: function(json) {
367+
args.response.success({
368+
_custom: { jobId: json.createnetworkaclresponse.jobid }, // API response obj name needs to be fixed
369+
notification: {
370+
label: 'Edit ACL rule',
371+
poll: pollAsyncJobResult
372+
}
373+
});
374+
},
375+
error: function(error) {
376+
args.response.error(parseXMLHttpResponse(error));
377+
}
378+
});
379+
}
380+
},
270381
destroy: {
271382
label: 'label.remove.ACL',
272383
action: function(args) {

0 commit comments

Comments
 (0)