diff --git a/src/sunstone/public/app/sunstone.js b/src/sunstone/public/app/sunstone.js index 2cd177cc06..f238945349 100644 --- a/src/sunstone/public/app/sunstone.js +++ b/src/sunstone/public/app/sunstone.js @@ -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 diff --git a/src/sunstone/public/app/tabs/vms-tab.js b/src/sunstone/public/app/tabs/vms-tab.js index dcd228faa2..a1a81f1de6 100644 --- a/src/sunstone/public/app/tabs/vms-tab.js +++ b/src/sunstone/public/app/tabs/vms-tab.js @@ -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 }; diff --git a/src/sunstone/public/app/tabs/vms-tab/hooks/state.js b/src/sunstone/public/app/tabs/vms-tab/hooks/state.js new file mode 100644 index 0000000000..1763411953 --- /dev/null +++ b/src/sunstone/public/app/tabs/vms-tab/hooks/state.js @@ -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 + }; +}); diff --git a/src/sunstone/public/app/tabs/vms-tab/panels/info.js b/src/sunstone/public/app/tabs/vms-tab/panels/info.js index 035aaf9592..d1e950a4d5 100644 --- a/src/sunstone/public/app/tabs/vms-tab/panels/info.js +++ b/src/sunstone/public/app/tabs/vms-tab/panels/info.js @@ -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);