Updated Branches: refs/heads/autoscale dcae4e810 -> 0970f9333
cloudstack 3.0 UI - autoscale - implement enableAutoScaleVmGroup API, disableAutoScaleVmGroup API. Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/0970f933 Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/0970f933 Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/0970f933 Branch: refs/heads/autoscale Commit: 0970f933326984ddfbebf13a692b769c69982fa7 Parents: dcae4e8 Author: Jessica Wang <[email protected]> Authored: Tue Aug 7 16:33:04 2012 -0700 Committer: Jessica Wang <[email protected]> Committed: Wed Aug 8 10:42:02 2012 -0700 ---------------------------------------------------------------------- ui/scripts/autoscaler.js | 113 +++++++++++++++++-------------- ui/scripts/ui-custom/autoscaler.js | 3 + 2 files changed, 65 insertions(+), 51 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/0970f933/ui/scripts/autoscaler.js ---------------------------------------------------------------------- diff --git a/ui/scripts/autoscaler.js b/ui/scripts/autoscaler.js index db708e4..1dc90b9 100644 --- a/ui/scripts/autoscaler.js +++ b/ui/scripts/autoscaler.js @@ -25,63 +25,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 http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/0970f933/ui/scripts/ui-custom/autoscaler.js ---------------------------------------------------------------------- diff --git a/ui/scripts/ui-custom/autoscaler.js b/ui/scripts/ui-custom/autoscaler.js index ceec5a7..8e9c5c2 100644 --- a/ui/scripts/ui-custom/autoscaler.js +++ b/ui/scripts/ui-custom/autoscaler.js @@ -115,6 +115,9 @@ }; action.action({ + context: { + originalAutoscaleData: args.data, + }, response: { success: function(args) { var notification = $.extend(args.notification, {
