From 2e6aeee9af905092a497ec9a6015b0df7b4154c6 Mon Sep 17 00:00:00 2001 From: Jessica Wang Date: Tue, 7 Aug 2012 16:33:04 -0700 Subject: [PATCH] cloudstack 3.0 UI - autoscale - implement enableAutoScaleVmGroup API, disableAutoScaleVmGroup API. --- ui/scripts/autoscaler.js | 113 ++++++++++++++++------------- ui/scripts/ui-custom/autoscaler.js | 3 + 2 files changed, 65 insertions(+), 51 deletions(-) diff --git a/ui/scripts/autoscaler.js b/ui/scripts/autoscaler.js index 17bf976f2c9..658a9b727d2 100644 --- a/ui/scripts/autoscaler.js +++ b/ui/scripts/autoscaler.js @@ -20,63 +20,74 @@ // UI actions to appear in dialog autoscaleActions: { enable: { - label: 'Enable Autoscaler', - action: function(args) { - args.response.success({ - _custom: { jobId: 12345 }, - notification: { - poll: function(args) { - args.complete({ - data: { state: 'Enabled' } - }); - } - } - }); + label: 'Enable Autoscale VM Group', + action: function(args) { + $.ajax({ + url: createURL('enableAutoScaleVmGroup'), + data: { + id: args.context.originalAutoscaleData.context.autoscaleVmGroup.id + }, + success: function(json) { + var jid = json.enableautoscalevmGroupresponse.jobid; + args.response.success({ + _custom: { + jobId: jid, + getUpdatedItem: function(json) { + return json.queryasyncjobresultresponse.jobresult.autoscalevmgroup; + }, + getActionFilter: function() { + return cloudStack.autoscaler.actionFilter; + } + }, + notification: { + poll: pollAsyncJobResult + } + }); + } + }); } }, disable: { - label: 'Disable Autoscaler', - action: function(args) { - args.response.success({ - _custom: { jobId: 12345 }, - notification: { - poll: function(args) { - args.complete({ - data: { state: 'Disabled' } - }); - } - } - }); - } - }, - restart: { - label: 'Restart Autoscaler', - action: function(args) { - args.response.success({ - _custom: { jobId: 12345 }, - notification: { - poll: function(args) { - args.complete({ - data: { state: 'Enabled' } - }); - } - } - }); + label: 'Disable Autoscale VM Group', + action: function(args) { + $.ajax({ + url: createURL('disableAutoScaleVmGroup'), + data: { + id: args.context.originalAutoscaleData.context.autoscaleVmGroup.id + }, + success: function(json) { + var jid = json.disableautoscalevmGroupresponse.jobid; + args.response.success({ + _custom: { + jobId: jid, + getUpdatedItem: function(json) { + return json.queryasyncjobresultresponse.jobresult.autoscalevmgroup; + }, + getActionFilter: function() { + return cloudStack.autoscaler.actionFilter; + } + }, + notification: { + poll: pollAsyncJobResult + } + }); + } + }); } } }, - actionFilter: function(args) { - var data = $.isArray(args.context.originalAutoscaleData) ? - args.context.originalAutoscaleData[0] : {}; - - if (data.state == 'Enabled') { - return ['disable', 'restart']; - } else if (data.state == 'Disabled') { - return ['enable']; - } - - // No existing data, so actions are not visible - return []; + actionFilter: function(args) { + var allowedActions = []; + if(args.context.originalAutoscaleData == null) { //new LB rule + //no actions for new LB rule + } + else { //existing LB rule + if(args.context.originalAutoscaleData[0].context.autoscaleVmGroup.state == 'disabled') + allowedActions.push('enable'); + else if(args.context.originalAutoscaleData[0].context.autoscaleVmGroup.state == 'enabled') + allowedActions.push('disable'); + } + return allowedActions; }, dataProvider: function(args) { // Reset data diff --git a/ui/scripts/ui-custom/autoscaler.js b/ui/scripts/ui-custom/autoscaler.js index b0ab5859ecd..f0cd4a81f4b 100644 --- a/ui/scripts/ui-custom/autoscaler.js +++ b/ui/scripts/ui-custom/autoscaler.js @@ -108,6 +108,9 @@ }; action.action({ + context: { + originalAutoscaleData: args.data, + }, response: { success: function(args) { var notification = $.extend(args.notification, {