diff --git a/ui/scripts/ui-custom/vpc.js b/ui/scripts/ui-custom/vpc.js
index 11ec4f7fcde..9ad6189109c 100644
--- a/ui/scripts/ui-custom/vpc.js
+++ b/ui/scripts/ui-custom/vpc.js
@@ -7,7 +7,7 @@
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
-// limitations under the License.
+// limitations under the License.
(function($, cloudStack) {
var elems = {
router: function() {
@@ -106,11 +106,13 @@
if ($action.hasClass('disabled')) {
return false;
}
-
+
tierAction({
action: action,
+ actionPreFilter: actionPreFilter,
context: context,
- $tier: $tier
+ $tier: $tier,
+ $actions: $actions
});
return true;
@@ -152,7 +154,7 @@
if ($(this).find('.loading-overlay').size()) {
return false;
}
-
+
addTierDialog({
$tiers: $tiers,
context: context,
@@ -204,7 +206,7 @@
disabledActions = actionPreFilter ? actionPreFilter({
context: context
- }) : [];
+ }) : [];
// Visual appearance for disabled actions
$actions.find('.action').map(function(index, action) {
@@ -223,12 +225,14 @@
var tierAction = function(args) {
var $tier = args.$tier;
var $loading = $('
').addClass('loading-overlay');
+ var $actions = args.$actions;
var actionArgs = args.action.action;
var action = actionArgs.action;
var actionID = args.action.id;
var notification = actionArgs.notification;
var label = actionArgs.label;
var context = args.context;
+ var actionPreFilter = args.actionPreFilter;
var success = function(args) {
var remove = args ? args.remove : false;
@@ -244,6 +248,13 @@
// Success
function(args) {
+ var newData = args.data ? args.data : {};
+ var newTier = $.extend(true, {}, context.tiers[0], newData);
+ var newContext = $.extend(true, {}, context);
+
+ // Update data
+ newContext.tiers = [newTier];
+
if (remove) {
$tier.remove();
} else {
@@ -258,6 +269,12 @@
$total.html(newTotal);
}
+
+ filterActions({
+ $actions: $actions,
+ actionPreFilter: actionPreFilter,
+ context: newContext
+ });
},
{},
@@ -361,7 +378,7 @@
response: {
success: function(args) {
var tier = args.data;
-
+
cloudStack.ui.notifications.add(
// Notification
{
diff --git a/ui/scripts/vpc.js b/ui/scripts/vpc.js
index 7e04c7005ac..307314bdea3 100644
--- a/ui/scripts/vpc.js
+++ b/ui/scripts/vpc.js
@@ -370,7 +370,10 @@
},
tiers: {
actionPreFilter: function(args) {
- return ['start'];
+ var tier = args.context.tiers[0];
+ var state = tier.state;
+
+ return state == 'Running' ? ['start'] : ['stop'];
},
actions: {
// Add new tier
@@ -407,7 +410,7 @@
args.response.success();
},
notification: {
- poll: function(args) { args.complete(); }
+ poll: function(args) { args.complete({ data: { state: 'Running' } }); }
}
},
stop: {
@@ -417,7 +420,7 @@
args.response.success();
},
notification: {
- poll: function(args) { args.complete(); }
+ poll: function(args) { args.complete({ data: { state: 'Stopped' } }); }
}
},
addVM: {
@@ -453,6 +456,7 @@
id: 1,
name: 'web',
cidr: '192.168.0.0/24',
+ state: 'Running',
virtualMachines: [
{ name: 'i-2-VM' },
{ name: 'i-3-VM' }
@@ -461,6 +465,7 @@
{
id: 2,
name: 'app',
+ state: 'Stopped',
cidr: '10.0.0.0/24',
virtualMachines: []
}