|
60 | 60 |
|
61 | 61 | 'number':{ |
62 | 62 | label:'Rule Number', |
63 | | - edit:true |
| 63 | + edit:true, |
| 64 | + isEditable: true |
64 | 65 |
|
65 | 66 | }, |
66 | 67 |
|
67 | | - 'cidrlist': { edit: true, label: 'label.cidr' }, |
| 68 | + 'cidrlist': { edit: true, label: 'label.cidr', isEditable: true }, |
68 | 69 | action: { |
69 | 70 | label: 'Action', |
| 71 | + isEditable: true, |
70 | 72 | select: function(args) { |
71 | 73 | args.response.success({ |
72 | 74 | data: [ |
|
78 | 80 | }, |
79 | 81 | 'protocol': { |
80 | 82 | label: 'label.protocol', |
| 83 | + isEditable: true, |
81 | 84 | select: function(args) { |
| 85 | + var isEditDialog = args.type === 'createForm'; |
| 86 | + |
82 | 87 | 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'); |
107 | 105 |
|
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'); |
111 | 120 |
|
112 | | - return $.inArray(name,['protocolnumber']) > -1; |
113 | | - }); |
| 121 | + return $.inArray(name,['protocolnumber']) > -1; |
| 122 | + }); |
114 | 123 |
|
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(); |
136 | 131 | $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 | + } |
138 | 202 | } |
139 | 203 | }); |
140 | 204 |
|
|
153 | 217 | } |
154 | 218 | }, |
155 | 219 |
|
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 }, |
159 | 223 | 'networkid': { |
160 | 224 | label: 'Select Tier', |
161 | 225 | select: function(args) { |
|
192 | 256 | }); |
193 | 257 | } |
194 | 258 | }, |
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 }, |
197 | 261 | 'traffictype' : { |
198 | 262 | label: 'label.traffic.type', |
| 263 | + isEditable: true, |
199 | 264 | select: function(args) { |
200 | 265 | args.response.success({ |
201 | 266 | data: [ |
|
219 | 284 | var $multi = args.$multi; |
220 | 285 | //Support for Protocol Number between 0 to 255 |
221 | 286 | 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; |
224 | 289 | } |
225 | 290 | else |
226 | 291 | delete args.data.protocolnumber; |
227 | 292 |
|
228 | 293 |
|
229 | | - |
| 294 | + |
230 | 295 | 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')}); |
232 | 297 | $(window).trigger('cloudStack.fullRefresh'); |
233 | 298 | } |
234 | 299 | 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')}); |
236 | 301 | $(window).trigger('cloudStack.fullRefresh'); |
237 | 302 | } |
238 | 303 |
|
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'); |
252 | 317 |
|
253 | | - return data; |
| 318 | + return data; |
| 319 | + } |
| 320 | + }, |
| 321 | + notification: { |
| 322 | + label: 'label.add.ACL', |
| 323 | + poll: pollAsyncJobResult |
254 | 324 | } |
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 | + } |
267 | 332 | } |
268 | 333 | }, |
269 | 334 | 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 | + }, |
270 | 381 | destroy: { |
271 | 382 | label: 'label.remove.ACL', |
272 | 383 | action: function(args) { |
|
0 commit comments