diff --git a/src/sunstone/public/app/tabs/oneflow-services-tab/panels/roles.js b/src/sunstone/public/app/tabs/oneflow-services-tab/panels/roles.js
index 1708110ca0..5e9df52d21 100644
--- a/src/sunstone/public/app/tabs/oneflow-services-tab/panels/roles.js
+++ b/src/sunstone/public/app/tabs/oneflow-services-tab/panels/roles.js
@@ -24,14 +24,12 @@ define(function(require) {
var OpenNebulaRole = require('opennebula/role');
var roles_buttons = require('./roles/roles-buttons');
var roles_vm_buttons = require('./roles/roles-vm-buttons');
+ var StateRolesButtons = require('./roles/state-roles-buttons');
var Sunstone = require('sunstone');
var DomDataTable = require('utils/dom-datatable');
- var VMsTableUtils = require('tabs/vms-tab/utils/datatable-common');
- var SunstoneConfig = require('sunstone-config');
var Vnc = require('utils/vnc');
var Spice = require('utils/spice');
var Notifier = require('utils/notifier');
- var OpenNebulaAction = require("opennebula/action");
var OpenNebulaVM = require("opennebula/vm");
var VMS_TAB_ID = require('tabs/vms-tab/tabId');
@@ -62,8 +60,6 @@ define(function(require) {
this.element = info[XML_ROOT];
- this.selected_row_role_id = undefined;
-
// Controls visibility of buttons only available to OneFlow services. This
// panel is also used by the OneFlow templates
this.servicePanel = true;
@@ -142,11 +138,11 @@ define(function(require) {
function _setState(state, context) {
var that = this;
- if (this.servicerolesDataTable && state["selectedRole"]){
- $('.check_item[id="'+state["selectedRole"]+'"]', this.servicerolesDataTable.dataTable).closest('tr').click();
+ if (that.servicerolesDataTable && state["selectedRole"]){
+ $('.check_item[id="'+state["selectedRole"]+'"]', that.servicerolesDataTable.dataTable).closest('tr').click();
}
- if (this.serviceroleVMsDataTable && state["selectedVMs"]){
+ if (that.serviceroleVMsDataTable && state["selectedVMs"]){
$.each(state["selectedVMs"], function(){
$('.check_item[id="'+this+'"]', that.serviceroleVMsDataTable.dataTable).closest('tr').click();
});
@@ -158,11 +154,11 @@ define(function(require) {
Tips.setup(context);
- that.last_selected_row_role = undefined;
+ var lastRoleIndexSelected = undefined
+ var roles = that.element.TEMPLATE.BODY.roles;
- var roles = this.element.TEMPLATE.BODY.roles;
if (roles && roles.length) {
- this.servicerolesDataTable = new DomDataTable(
+ that.servicerolesDataTable = new DomDataTable(
'datatable_roles_'+this.panelId,
{
actions: true,
@@ -170,15 +166,25 @@ define(function(require) {
oneSelection: true,
customTabContext: $('#role_actions', context),
customTrListener: function(tableObj, tr){
- var aData = tableObj.dataTable.fnGetData(tr);
- var role_name = $(aData[0]).val();
+ var rowData = tableObj.dataTable.fnGetData(tr);
+ var roleName = $(rowData[0]).data().name
+
+ var roleIndexSelected = roles.findIndex(function(role) {
+ return role.name === roleName
+ })
- var role_index = tableObj.dataTable.fnGetPosition(tr);
+ if (lastRoleIndexSelected !== roleIndexSelected) {
+ lastRoleIndexSelected = roleIndexSelected
- $("#roles_extended_info", context).fadeOut('slow', function() {
- $(this).html(that.roleHTML(context, role_index))
- that.roleSetup($(this), role_index)
- }).fadeIn('slow');
+ var roleSelected = roles[roleIndexSelected];
+
+ StateRolesButtons.enableStateActions(roleSelected.state);
+
+ $("#roles_extended_info", context).fadeOut('slow', function() {
+ $(this).html(that.roleHTML(context, roleSelected))
+ that.roleSetup($(this), roleSelected)
+ }).fadeIn('slow');
+ }
// The info listener is triggered instead of
// the row selection. So we click the check input to select
@@ -197,9 +203,8 @@ define(function(require) {
}
- function _roleHTML(context, role_index) {
+ function _roleHTML(context, role) {
var that = this;
- var role = this.element.TEMPLATE.BODY.roles[role_index];
var ready_status_gate = that.element.TEMPLATE.BODY.ready_status_gate;
var promises = [];
var roleVms = [];
@@ -260,8 +265,8 @@ define(function(require) {
return TemplateRoleInfo({
'role': role,
- 'servicePanel': this.servicePanel,
- 'panelId': this.panelId,
+ 'servicePanel': that.servicePanel,
+ 'panelId': that.panelId,
'vmsTableColumns': [
Locale.tr("ID"),
Locale.tr("Name"),
@@ -297,12 +302,12 @@ define(function(require) {
})
}
- function _roleSetup(context, role_index) {
- if(this.servicePanel) {
- var role = this.element.TEMPLATE.BODY.roles[role_index];
+ function _roleSetup(context, role) {
+ var that = this
- this.serviceroleVMsDataTable = new DomDataTable(
- 'datatable_vms_'+this.panelId+'_'+role.name,
+ if(that.servicePanel) {
+ that.serviceroleVMsDataTable = new DomDataTable(
+ 'datatable_vms_' + that.panelId + '_' + role.name,
{
actions: true,
info: false,
@@ -317,7 +322,7 @@ define(function(require) {
}
});
- this.serviceroleVMsDataTable.initialize();
+ that.serviceroleVMsDataTable.initialize();
Sunstone.insertButtonsInTab(
TAB_ID,
"service_roles_tab",
diff --git a/src/sunstone/public/app/tabs/oneflow-services-tab/panels/roles/roles-buttons.js b/src/sunstone/public/app/tabs/oneflow-services-tab/panels/roles/roles-buttons.js
index 0ad32c16cf..020a71278b 100644
--- a/src/sunstone/public/app/tabs/oneflow-services-tab/panels/roles/roles-buttons.js
+++ b/src/sunstone/public/app/tabs/oneflow-services-tab/panels/roles/roles-buttons.js
@@ -21,72 +21,86 @@ define(function(require) {
"Role.scale_dialog" : {
type: "action",
text: Locale.tr("Scale"),
- layout: "create"
+ layout: "create",
+ custom_classes : "role-state-dependent"
},
"Role.hold" : {
type: "action",
text: Locale.tr("Hold"),
- layout: "vmsplanification_buttons"
+ layout: "vmsplanification_buttons",
+ custom_classes : "role-state-dependent"
},
"Role.release" : {
type: "action",
text: Locale.tr("Release"),
- layout: "vmsplanification_buttons"
+ layout: "vmsplanification_buttons",
+ custom_classes : "role-state-dependent"
},
"Role.suspend" : {
type: "action",
text: Locale.tr("Suspend"),
- layout: "vmspause_buttons"
+ layout: "vmspause_buttons",
+ custom_classes : "role-state-dependent"
},
"Role.resume" : {
type: "action",
text: '',
- layout: "vmsplay_buttons"
+ layout: "vmsplay_buttons",
+ custom_classes : "role-state-dependent"
},
"Role.stop" : {
type: "action",
text: Locale.tr("Stop"),
- layout: "vmsstop_buttons"
+ layout: "vmsstop_buttons",
+ custom_classes : "role-state-dependent"
},
"Role.reboot" : {
type: "action",
text: Locale.tr("Reboot"),
- layout: "vmsrepeat_buttons"
+ layout: "vmsrepeat_buttons",
+ custom_classes : "role-state-dependent"
},
"Role.reboot_hard" : {
type: "action",
text: Locale.tr("Reboot") + ' hard',
- layout: "vmsrepeat_buttons"
+ layout: "vmsrepeat_buttons",
+ custom_classes : "role-state-dependent"
},
"Role.poweroff" : {
type: "action",
text: Locale.tr("Power Off"),
- layout: "vmspause_buttons"
+ layout: "vmspause_buttons",
+ custom_classes : "role-state-dependent"
},
"Role.poweroff_hard" : {
type: "action",
text: Locale.tr("Power Off") + ' hard',
- layout: "vmspause_buttons"
+ layout: "vmspause_buttons",
+ custom_classes : "role-state-dependent"
},
"Role.undeploy" : {
type: "action",
text: Locale.tr("Undeploy"),
- layout: "vmsstop_buttons"
+ layout: "vmsstop_buttons",
+ custom_classes : "role-state-dependent"
},
"Role.undeploy_hard" : {
type: "action",
text: Locale.tr("Undeploy") + ' hard',
- layout: "vmsstop_buttons"
+ layout: "vmsstop_buttons",
+ custom_classes : "role-state-dependent"
},
"Role.terminate" : {
type: "action",
text: Locale.tr("Terminate"),
- layout: "vmsdelete_buttons"
+ layout: "vmsdelete_buttons",
+ custom_classes : "role-state-dependent"
},
"Role.terminate_hard" : {
type: "action",
text: Locale.tr("Terminate") + ' hard',
- layout: "vmsdelete_buttons"
+ layout: "vmsdelete_buttons",
+ custom_classes : "role-state-dependent"
}
};
diff --git a/src/sunstone/public/app/tabs/oneflow-services-tab/panels/roles/state-roles-buttons.js b/src/sunstone/public/app/tabs/oneflow-services-tab/panels/roles/state-roles-buttons.js
new file mode 100644
index 0000000000..148edc9c8a
--- /dev/null
+++ b/src/sunstone/public/app/tabs/oneflow-services-tab/panels/roles/state-roles-buttons.js
@@ -0,0 +1,92 @@
+/* -------------------------------------------------------------------------- */
+/* Copyright 2002-2020, OpenNebula Project, OpenNebula Systems */
+/* */
+/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
+/* not use this file except in compliance with the License. You may obtain */
+/* a copy of the License at */
+/* */
+/* http://www.apache.org/licenses/LICENSE-2.0 */
+/* */
+/* Unless required by applicable law or agreed to in writing, software */
+/* 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. */
+/* -------------------------------------------------------------------------- */
+
+define(function(require) {
+ var OpenNebulaFlow = require('opennebula/service');
+ var Buttons = require('./roles-buttons');
+
+ var ALL_ACTION_BUTTONS = $.map(Buttons, function(_, action) {
+ return [action]
+ })
+
+ var STATE_ACTIONS = {};
+
+ STATE_ACTIONS[OpenNebulaFlow.STATES.PENDING] =
+ ['Role.scale_dialog','Role.terminate', 'Role.terminate_hard'];
+
+ STATE_ACTIONS[OpenNebulaFlow.STATES.DEPLOYING] =
+ ['Role.scale_dialog','Role.terminate', 'Role.terminate_hard'];
+
+ STATE_ACTIONS[OpenNebulaFlow.STATES.RUNNING] =
+ [ALL_ACTION_BUTTONS];
+
+ STATE_ACTIONS[OpenNebulaFlow.STATES.UNDEPLOYING] =
+ ['Role.scale_dialog','Role.terminate', 'Role.terminate_hard'];
+
+ STATE_ACTIONS[OpenNebulaFlow.STATES.WARNING] =
+ ['Role.scale_dialog','Role.terminate', 'Role.terminate_hard'];
+
+ STATE_ACTIONS[OpenNebulaFlow.STATES.DONE] =
+ ['Role.scale_dialog','Role.terminate', 'Role.terminate_hard'];
+
+ STATE_ACTIONS[OpenNebulaFlow.STATES.FAILED_UNDEPLOYING] =
+ ['Role.scale_dialog','Role.terminate', 'Role.terminate_hard'];
+
+ STATE_ACTIONS[OpenNebulaFlow.STATES.FAILED_DEPLOYING] =
+ ['Role.scale_dialog','Role.terminate', 'Role.terminate_hard'];
+
+ STATE_ACTIONS[OpenNebulaFlow.STATES.SCALING] =
+ ['Role.scale_dialog','Role.terminate', 'Role.terminate_hard'];
+
+ STATE_ACTIONS[OpenNebulaFlow.STATES.FAILED_SCALING] =
+ ['Role.scale_dialog','Role.terminate', 'Role.terminate_hard'];
+
+ STATE_ACTIONS[OpenNebulaFlow.STATES.COOLDOWN] =
+ ['Role.scale_dialog','Role.terminate', 'Role.terminate_hard'];
+
+ return {
+ 'disableStateButton': disableStateButton,
+ 'enableStateButton': enableStateButton,
+ 'enableStateActions': enableStateActions
+ };
+
+ function disableStateButton(action) {
+ $(".role-state-dependent[href='" + action + "']")
+ .prop("disabled", true)
+ .removeClass("action-enabled")
+ .addClass("action-disabled")
+ .on("click.stateaction", function() { return false; });
+ }
+
+ function enableStateButton(action) {
+ $(".role-state-dependent[href='" + action + "']")
+ .removeAttr("disabled")
+ .addClass("action-enabled")
+ .removeClass("action-disabled")
+ .off("click.stateaction")
+ }
+
+ function enableStateActions(state) {
+ var state = parseInt(state);
+ var actionsAvailable = STATE_ACTIONS[state]
+
+ $.each(ALL_ACTION_BUTTONS, function(_, action) {
+ const isDisabled = actionsAvailable.indexOf(action) !== -1
+
+ isDisabled ? disableStateButton(action) : enableStateButton(action)
+ });
+ }
+});