|
1 | 1 | (function($, cloudStack, testData) { |
2 | 2 |
|
3 | | - var zoneObjs, hypervisorObjs, featuredTemplateObjs, communityTemplateObjs, myTemplateObjs, isoObjs, serviceOfferingObjs, diskOfferingObjs; |
4 | | - var selectedZoneObj, selectedTemplateObj, selectedHypervisor, selectedDiskOfferingObj; |
| 3 | + var zoneObjs, hypervisorObjs, featuredTemplateObjs, communityTemplateObjs, myTemplateObjs, isoObjs, serviceOfferingObjs, diskOfferingObjs, networkOfferingObjs; |
| 4 | + var selectedZoneObj, selectedTemplateObj, selectedHypervisor, selectedDiskOfferingObj; |
5 | 5 | var step5ContainerType = 'nothing-to-select'; //'nothing-to-select', 'select-network', 'select-security-group' |
6 | 6 |
|
7 | 7 | cloudStack.sections.instances = { |
|
130 | 130 | // Step 3: Service offering |
131 | 131 | function(args) { |
132 | 132 | if(args.currentData["select-template"] == "select-template") { |
133 | | - for(var i=0; i < featuredTemplateObjs.length; i++) { |
134 | | - if(featuredTemplateObjs[i].id == args.currentData.templateid) { |
135 | | - selectedTemplateObj = featuredTemplateObjs[i]; |
136 | | - break; |
| 133 | + if(featuredTemplateObjs != null && featuredTemplateObjs.length > 0) { |
| 134 | + for(var i=0; i < featuredTemplateObjs.length; i++) { |
| 135 | + if(featuredTemplateObjs[i].id == args.currentData.templateid) { |
| 136 | + selectedTemplateObj = featuredTemplateObjs[i]; |
| 137 | + break; |
| 138 | + } |
137 | 139 | } |
138 | 140 | } |
139 | 141 | if(selectedTemplateObj == null) { |
140 | | - for(var i=0; i < communityTemplateObjs.length; i++) { |
141 | | - if(communityTemplateObjs[i].id == args.currentData.templateid) { |
142 | | - selectedTemplateObj = communityTemplateObjs[i]; |
143 | | - break; |
| 142 | + if(communityTemplateObjs != null && communityTemplateObjs.length > 0) { |
| 143 | + for(var i=0; i < communityTemplateObjs.length; i++) { |
| 144 | + if(communityTemplateObjs[i].id == args.currentData.templateid) { |
| 145 | + selectedTemplateObj = communityTemplateObjs[i]; |
| 146 | + break; |
| 147 | + } |
144 | 148 | } |
145 | 149 | } |
146 | 150 | } |
147 | 151 | if(selectedTemplateObj == null) { |
148 | | - for(var i=0; i < myTemplateObjs.length; i++) { |
149 | | - if(myTemplateObjs[i].id == args.currentData.templateid) { |
150 | | - selectedTemplateObj = myTemplateObjs[i]; |
151 | | - break; |
| 152 | + if(myTemplateObjs != null && myTemplateObjs.length > 0) { |
| 153 | + for(var i=0; i < myTemplateObjs.length; i++) { |
| 154 | + if(myTemplateObjs[i].id == args.currentData.templateid) { |
| 155 | + selectedTemplateObj = myTemplateObjs[i]; |
| 156 | + break; |
| 157 | + } |
152 | 158 | } |
153 | 159 | } |
154 | 160 | } |
|
228 | 234 | } |
229 | 235 | }); |
230 | 236 |
|
231 | | - if(includingSecurityGroupService == false || selectedHypervisor == "VMware" || g_directAttachSecurityGroupsEnabled != "true") { //??? |
| 237 | + if(includingSecurityGroupService == false || selectedHypervisor == "VMware" || g_directAttachSecurityGroupsEnabled != "true") { |
232 | 238 | step5ContainerType = 'nothing-to-select'; |
233 | 239 | } |
234 | 240 | else { |
|
257 | 263 | var networks = json.listnetworksresponse.network; |
258 | 264 |
|
259 | 265 | //***** check if there is an isolated network with sourceNAT (begin) ***** |
| 266 | + /* |
260 | 267 | var isolatedSourcenatNetwork = null; |
261 | 268 | if(selectedZoneObj.securitygroupsenabled == false) { |
262 | 269 | if (networks != null && networks.length > 0) { |
|
302 | 309 | }); |
303 | 310 | } |
304 | 311 | } |
| 312 | + */ |
305 | 313 | //***** check if there is an isolated network with sourceNAT (end) ***** |
306 | 314 |
|
307 | 315 |
|
308 | 316 | //***** populate all networks (begin) ********************************** |
309 | 317 | //isolatedSourcenatNetwork is first radio button in default network section. Show isolatedSourcenatNetwork when its networkofferingavailability is 'Required' or'Optional' |
| 318 | + /* |
310 | 319 | if (isolatedSourcenatNetwork.networkofferingavailability == 'Required' || isolatedSourcenatNetwork.networkofferingavailability == 'Optional') { |
311 | 320 | defaultNetworkArray.push(isolatedSourcenatNetwork); |
312 | 321 | } |
| 322 | + */ |
313 | 323 |
|
314 | 324 | //default networks are in default network section |
315 | 325 | //non-default networks are in additional network section |
316 | 326 | if (networks != null && networks.length > 0) { |
317 | | - for (var i = 0; i < networks.length; i++) { |
318 | | - //if selectedZoneObj.securitygroupsenabled is true and users still choose to select network instead of security group (from dialog), then UI won't show networks whose securitygroupenabled is true. |
319 | | - //if(selectedZoneObj.securitygroupsenabled == true && networks[i].securitygroupenabled == true) { |
320 | | - // continue; |
321 | | - //} |
322 | | - |
323 | | - if (networks[i].isdefault) { |
324 | | - if (isolatedSourcenatNetwork.networkofferingavailability == 'Required') { |
325 | | - continue; //don't display 2nd~Nth radio buttons in default network section when isolatedSourcenatNetwork.networkofferingavailability == 'Required' |
326 | | - } |
327 | | - if(networks[i].id != isolatedSourcenatNetwork.id) { |
328 | | - defaultNetworkArray.push(networks[i]); |
329 | | - } |
| 327 | + for (var i = 0; i < networks.length; i++) { |
| 328 | + if (networks[i].isdefault) { |
| 329 | + defaultNetworkArray.push(networks[i]); |
330 | 330 | } |
331 | 331 | else { |
332 | 332 | optionalNetworkArray.push(networks[i]); |
|
335 | 335 | } |
336 | 336 | //***** populate all networks (end) ************************************ |
337 | 337 | } |
| 338 | + }); |
| 339 | + |
| 340 | + $.ajax({ |
| 341 | + url: createURL("listNetworkOfferings"), |
| 342 | + dataType: "json", |
| 343 | + async: false, |
| 344 | + success: function(json) { |
| 345 | + networkOfferingObjs = json.listnetworkofferingsresponse.networkoffering; |
| 346 | + } |
338 | 347 | }); |
| 348 | + |
| 349 | + |
339 | 350 | args.response.success({ |
340 | 351 | type: 'select-network', |
341 | 352 | data: { |
342 | 353 | myNetworks: defaultNetworkArray, |
343 | 354 | sharedNetworks: optionalNetworkArray, |
344 | | - securityGroups: [] |
| 355 | + securityGroups: [], |
| 356 | + networkOfferings: networkOfferingObjs |
345 | 357 | } |
346 | 358 | }); |
347 | 359 | } |
|
378 | 390 | data: { |
379 | 391 | defaultNetworks: [], |
380 | 392 | optionalNetworks: [], |
381 | | - securityGroups: [] |
| 393 | + securityGroups: [] |
382 | 394 | } |
383 | 395 | }); |
384 | 396 | } |
|
419 | 431 | array1.push("&size=" + args.data.size); |
420 | 432 | } |
421 | 433 |
|
422 | | - //step 5: select network |
423 | | - if (step5ContainerType == 'select-network') { |
424 | | - var array2 = []; |
425 | | - var defaultNetwork = args.data["default-network"]; |
| 434 | + //step 5: select network ??? |
| 435 | + if (step5ContainerType == 'select-network') { |
| 436 | + var array2 = []; |
| 437 | + var defaultNetwork = args.data.defaultNetwork; //args.data.defaultNetwork might be equal to "new-network" |
| 438 | + var checkedNetworks = args.data["my-networks"]; |
| 439 | + |
| 440 | + //create new network starts here |
| 441 | + if(args.data["new-network"] == "create-new-network") { |
| 442 | + var selectedNetworkOfferingId; |
| 443 | + if(networkOfferingObjs != null && networkOfferingObjs.length > 0) { |
| 444 | + for(var k=0; k < networkOfferingObjs.length; k++) { |
| 445 | + if(networkOfferingObjs[k].name == args.data["new-network-serviceofferingid"]) |
| 446 | + selectedNetworkOfferingId = networkOfferingObjs[k].id; |
| 447 | + } |
| 448 | + } |
| 449 | + |
| 450 | + var networkName = "new Network"; |
| 451 | + $.ajax({ |
| 452 | + url: createURL("createNetwork&networkOfferingId="+selectedNetworkOfferingId+"&name="+todb(networkName)+"&displayText="+todb(networkName)+"&zoneId="+selectedZoneObj.id), |
| 453 | + dataType: "json", |
| 454 | + async: false, |
| 455 | + success: function(json) { |
| 456 | + newNetwork = json.createnetworkresponse.network; |
| 457 | + checkedNetworks.push(newNetwork.id); |
| 458 | + if(defaultNetwork == "new-network") |
| 459 | + defaultNetwork = newNetwork.id; |
| 460 | + } |
| 461 | + }); |
| 462 | + } |
| 463 | + //create new network ends here |
| 464 | + |
| 465 | + //add default network first |
426 | 466 | if(defaultNetwork != null && defaultNetwork.length > 0) |
427 | 467 | array2.push(defaultNetwork); |
428 | | - |
429 | | - var optionalNetworks = args.data["optional-networks"]; |
430 | | - //optionalNetworks might be: (1) an array of string, e.g. ["203", "202"], |
431 | | - if(typeof(optionalNetworks) == "object" && optionalNetworks.length != null) { |
432 | | - if(optionalNetworks != null && optionalNetworks.length > 0) { |
433 | | - for(var i=0; i < optionalNetworks.length; i++) { |
434 | | - array2.push(optionalNetworks[i]); |
| 468 | + |
| 469 | + //then, add other checked networks |
| 470 | + if(typeof(checkedNetworks) == "object" && checkedNetworks.length != null) { //checkedNetworks might be: (1) an array of string, e.g. ["203", "202"], |
| 471 | + if(checkedNetworks != null && checkedNetworks.length > 0) { |
| 472 | + for(var i=0; i < checkedNetworks.length; i++) { |
| 473 | + if(checkedNetworks[i] != defaultNetwork) //exclude defaultNetwork that has been added to array2 |
| 474 | + array2.push(checkedNetworks[i]); |
435 | 475 | } |
436 | 476 | } |
| 477 | + } |
| 478 | + else if(typeof(checkedNetworks) == "string" && checkedNetworks.length > 0) { //checkedNetworks might be: (2) just an string, e.g. "202" |
| 479 | + if(checkedNetworks != defaultNetwork) //exclude defaultNetwork that has been added to array2 |
| 480 | + array2.push(checkedNetworks); |
437 | 481 | } |
438 | | - //optionalNetworks might be: (2) just an string, e.g. "202" |
439 | | - else if(typeof(optionalNetworks) == "string" && optionalNetworks.length > 0) { |
440 | | - array2.push(optionalNetworks); |
441 | | - } |
| 482 | + |
442 | 483 | array1.push("&networkIds=" + array2.join(",")); |
443 | 484 | } |
444 | 485 | else if (step5ContainerType == 'select-security-group') { |
|
0 commit comments