1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-22 18:50:08 +03:00

Bug #4134: Move vm state code from info panel to a hook

(cherry picked from commit d16104baedf8cbbb94b5fdcfed1394601c6123c7)
This commit is contained in:
Carlos Martín 2015-11-05 12:44:19 +01:00
parent b632349af3
commit 759f7aae30
4 changed files with 104 additions and 27 deletions

View File

@ -51,6 +51,11 @@ define(function(require) {
_addPanels(_tabId, panels)
}
var panelsHooks = tabObj.panelsHooks;
if (panelsHooks) {
_addPanelsHooks(_tabId, panelsHooks);
}
var dialogs = tabObj.dialogs;
if (dialogs) {
_addDialogs(dialogs)
@ -77,6 +82,11 @@ define(function(require) {
return false;
}
var _addPanelsHooks = function(tabId, hooks) {
SunstoneCfg["tabs"][tabId]['panelsHooks'] = hooks;
return false;
}
var _addPanels = function(tabId, panels) {
var indexedPanels = {}
$.each(panels, function(index, panel) {
@ -568,6 +578,14 @@ define(function(require) {
});
}
var hooks = SunstoneCfg['tabs'][tabName].panelsHooks;
if (hooks) {
$.each(hooks, function(i, hook){
hook.pre(info, contextTabId);
});
}
var panels = SunstoneCfg['tabs'][tabName].panels;
var active = false;
var templatePanelsParams = []
@ -627,6 +645,12 @@ define(function(require) {
context.foundation('tab', 'reflow');
$('[href=' + activaTabHref + ']', context).trigger("click");
if (hooks) {
$.each(hooks, function(i, hook){
hook.post(info, contextTabId);
});
}
}
//Runs a predefined action. Wraps the calls to opennebula.js and

View File

@ -37,6 +37,10 @@ define(function(require) {
require('./vms-tab/dialogs/saveas-template')
];
var _panelsHooks = [
require('./vms-tab/hooks/state')
];
var _panels = [
require('./vms-tab/panels/info'),
require('./vms-tab/panels/capacity'),
@ -70,6 +74,7 @@ define(function(require) {
actions: Actions,
dataTable: new Table(DATATABLE_ID, {actions: true, info: true}),
panels: _panels,
panelsHooks: _panelsHooks,
formPanels: _formPanels,
dialogs: _dialogs
};

View File

@ -0,0 +1,75 @@
/* -------------------------------------------------------------------------- */
/* Copyright 2002-2015, 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) {
/*
DEPENDENCIES
*/
var OpenNebulaVM = require('opennebula/vm');
var StateActions = require('../utils/state-actions');
/*
CONSTANTS
*/
var TAB_ID = require('../tabId');
var RESOURCE = "VM";
var XML_ROOT = "VM";
/*
FUNCTION DEFINITIONS
*/
function _pre(info, contextTabId) {
var element = info[XML_ROOT];
var state;
if (element.STATE == OpenNebulaVM.STATES.ACTIVE) {
state = OpenNebulaVM.shortLcmStateStr(element.LCM_STATE);
} else {
state = OpenNebulaVM.stateStr(element.STATE);
}
$('.resource-info-header', '#' + TAB_ID).text(element.NAME);
$('.resource-info-header-small', '#' + TAB_ID).text(state);
// Enable only action buttons for the current state
StateActions.disableAllStateActions();
StateActions.enableStateActions(element.STATE, element.LCM_STATE);
// Enable / disable vnc button
if (OpenNebulaVM.isVNCSupported(element)) {
$(".vnc-right-info").show();
} else {
$(".vnc-right-info").hide();
}
if (OpenNebulaVM.isSPICESupported(element)) {
$(".spice-right-info").show();
} else {
$(".spice-right-info").hide();
}
}
function _post(info, contextTabId) {
}
return {
'pre': _pre,
'post': _post
};
});

View File

@ -25,7 +25,6 @@ define(function(require) {
var PermissionsTable = require('utils/panel/permissions-table');
var TemplateTable = require('utils/panel/template-table');
var OpenNebulaVM = require('opennebula/vm');
var StateActions = require('../utils/state-actions');
/*
TEMPLATES
@ -108,32 +107,6 @@ define(function(require) {
}
function _setup(context) {
var state;
if (this.element.STATE == OpenNebulaVM.STATES.ACTIVE) {
state = OpenNebulaVM.shortLcmStateStr(this.element.LCM_STATE);
} else {
state = OpenNebulaVM.stateStr(this.element.STATE);
}
$('.resource-info-header', '#' + TAB_ID).text(this.element.NAME);
$('.resource-info-header-small', '#' + TAB_ID).text(state);
// Enable only action buttons for the current state
StateActions.disableAllStateActions();
StateActions.enableStateActions(this.element.STATE, this.element.LCM_STATE);
// Enable / disable vnc button
if (OpenNebulaVM.isVNCSupported(this.element)) {
$(".vnc-right-info").show();
} else {
$(".vnc-right-info").hide();
}
if (OpenNebulaVM.isSPICESupported(this.element)) {
$(".spice-right-info").show()
} else {
$(".spice-right-info").hide();;
}
RenameTr.setup(RESOURCE, this.element.ID, context);
PermissionsTable.setup(TAB_ID, RESOURCE, this.element, context);