From 6e5beaaa4a47b8471078e02ebc9591a9f80ceb57 Mon Sep 17 00:00:00 2001 From: Jessica Wang Date: Tue, 24 Jan 2012 14:36:01 -0800 Subject: [PATCH] cloudstack 3.0 new UI - network page - show load balancer tab if the network includes Lb service including ElasticLb capability. --- ui/scripts/network.js | 146 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 131 insertions(+), 15 deletions(-) diff --git a/ui/scripts/network.js b/ui/scripts/network.js index ababa55e30b..71b93d4aac4 100644 --- a/ui/scripts/network.js +++ b/ui/scripts/network.js @@ -429,9 +429,22 @@ } }, - tabFilter: function(args) { - var hiddenTabs = []; - if(args.context.networks[0].type == "Isolated") + tabFilter: function(args) { + var showLbTab = false; + $(args.context.networks[0].service).each(function(){ + if(this.name == "Lb") { + $(this.capability).each(function() { + if(this.name == "ElasticLb") { + showLbTab = true; + return false; //break $.each loop + } + }); + return false; //break $.each loop + } + }); + + var hiddenTabs = []; + if(showLbTab == false) hiddenTabs.push("loadBalancing"); return hiddenTabs; }, @@ -564,7 +577,7 @@ } } - /* + , //Brian, please duplicate loadBalancing from another place to here loadBalancing: { @@ -575,7 +588,7 @@ }); } } - */ + } } @@ -1437,7 +1450,118 @@ label: 'Sticky Policy', custom: { buttonLabel: 'Configure', - action: cloudStack.lbStickyPolicy() + action: function(args) { + var success = args.response.success; + var fields = { + methodname: { + label: 'Stickiness method', + select: function(args) { + var $select = args.$select; + var $form = $select.closest('form'); + + args.response.success({ + data: [ + { + id: 'none', + description: 'None' + }, + { + id: 'LbCookie', + description: 'LB-based' + }, + { + id: 'AppCookie', + description: 'Cookie-based' + }, + { + id: 'SourceBased', + description: 'Source-based' + } + ] + }, 500); + + $select.change(function() { + var value = $select.val(); + var showFields = []; + + switch (value) { + case 'none': + showFields = []; + break; + case 'LbCookie': + showFields = ['name', 'mode', 'nocache', 'indirect', 'postonly', 'domain']; + break; + case 'AppCookie': + showFields = ['name', 'length', 'holdtime', 'request-learn', 'prefix', 'mode']; + break; + case 'SourceBased': + showFields = ['tablesize', 'expire']; + break; + } + + $select.closest('.form-item').siblings('.form-item').each(function() { + var $field = $(this); + var id = $field.attr('rel'); + + if ($.inArray(id, showFields) > -1) { + $field.css('display', 'inline-block'); + } else { + $field.hide(); + } + }); + + $select.closest(':ui-dialog').dialog('option', 'position', 'center'); + }); + } + }, + name: { label: 'Name', validation: { required: true }, isHidden: true }, + mode: { label: 'Mode', isHidden: true }, + length: { label: 'Length', validation: { required: true }, isHidden: true }, + holdtime: { label: 'Hold Time', validation: { required: true }, isHidden: true }, + tablesize: { label: 'Table size', isHidden: true }, + expire: { label: 'Expire', isHidden: true }, + requestlearn: { label: 'Request-Learn', isBoolean: true, isHidden: true }, + prefix: { label: 'Prefix', isBoolean: true, isHidden: true }, + nocache: { label: 'No cache', isBoolean: true, isHidden: true }, + indirect: { label: 'Indirect', isBoolean: true, isHidden: true }, + postonly: { label: 'Is post-only', isBoolean: true, isHidden: true }, + domain: { label: 'Domain', isBoolean: true, isHidden: true } + }; + + if (args.data) { + var populatedFields = $.map(fields, function(field, id) { + return id; + }); + + $(populatedFields).each(function() { + var id = this; + var field = fields[id]; + var dataItem = args.data[id]; + + if (field.isBoolean) { + field.isChecked = dataItem ? true : false; + } else { + field.defaultValue = dataItem; + } + }); + } + + cloudStack.dialog.createForm({ + form: { + title: 'Configure Sticky Policy', + desc: 'Please complete the following fields', + fields: fields + }, + after: function(args) { + var data = cloudStack.serializeForm(args.$form); + success({ + data: $.extend(data, { + _buttonLabel: data.methodname.toUpperCase() + }) + }); + } + }); + } } }, 'add-vm': { @@ -1486,8 +1610,6 @@ dataType: 'json', async: true, success: function(data) { - var lbCreationComplete = false; - args.response.success({ fullRefresh: true, _custom: { @@ -1501,13 +1623,7 @@ pollAsyncJobResult({ _custom: args._custom, - complete: function(args) { - if (lbCreationComplete) { - return; - } - - lbCreationComplete = true; - + complete: function(args) { // Create stickiness policy if (stickyData && stickyData.methodname &&