From 4827198ebb27e2f2b3eecee03505a8dc09dd1d77 Mon Sep 17 00:00:00 2001 From: Abel Coronado Date: Fri, 24 Nov 2017 12:10:51 +0100 Subject: [PATCH] F #1495: Minimized overhead | VMs caching * Minimized overhead in Sinatra * Caching all pools --- src/sunstone/public/app/sunstone.js | 479 +++++++++--------- src/sunstone/public/app/tabs/dashboard-tab.js | 3 +- 2 files changed, 243 insertions(+), 239 deletions(-) diff --git a/src/sunstone/public/app/sunstone.js b/src/sunstone/public/app/sunstone.js index f0877366de..eb17c435bf 100644 --- a/src/sunstone/public/app/sunstone.js +++ b/src/sunstone/public/app/sunstone.js @@ -15,24 +15,24 @@ /* -------------------------------------------------------------------------- */ define(function(require) { - require('jquery'); + require("jquery"); //require('foundation.reveal'); //require('foundation.tab'); //require('foundation.dropdown'); - var Config = require('sunstone-config'); - var Locale = require('utils/locale'); - var Notifier = require('utils/notifier'); - var Menu = require('utils/menu'); - var Tips = require('utils/tips'); - var Navigo = require('Navigo'); + var Config = require("sunstone-config"); + var Locale = require("utils/locale"); + var Notifier = require("utils/notifier"); + var Menu = require("utils/menu"); + var Tips = require("utils/tips"); + var Navigo = require("Navigo"); var router; var TOP_INTERVAL = 10000; //ms - var CONFIRM_DIALOG_ID = require('utils/dialogs/confirm/dialogId'); - var CONFIRM_WITH_SELECT_DIALOG_ID = require('utils/dialogs/confirm-with-select/dialogId'); - var DASHBOARD_TAB_ID = require('tabs/dashboard-tab/tabId'); + var CONFIRM_DIALOG_ID = require("utils/dialogs/confirm/dialogId"); + var CONFIRM_WITH_SELECT_DIALOG_ID = require("utils/dialogs/confirm-with-select/dialogId"); + var DASHBOARD_TAB_ID = require("tabs/dashboard-tab/tabId"); var SunstoneCfg = { "actions" : {}, @@ -45,14 +45,14 @@ define(function(require) { _addActions(); $.each(Config.enabledTabs, function(i, tabName){ - var name = './tabs/' + tabName; + var name = "./tabs/" + tabName; var tabObj = require(name); var _tabId = tabObj.tabId; SunstoneCfg["tabs"][_tabId] = tabObj; var panels = tabObj.panels; if (panels) { - _addPanels(_tabId, panels) + _addPanels(_tabId, panels); } var panelsHooks = tabObj.panelsHooks; @@ -67,19 +67,19 @@ define(function(require) { var dialogs = tabObj.dialogs; if (dialogs) { - _addDialogs(dialogs) + _addDialogs(dialogs); } var formPanels = tabObj.formPanels; if (formPanels) { - _addFormPanels(_tabId, formPanels) + _addFormPanels(_tabId, formPanels); } }); - } + }; var _addActions = function() { $.each(Config.allTabs(), function(i, tabName){ - var name = './tabs/' + tabName; + var name = "./tabs/" + tabName; var tabObj = require(name); var actions = tabObj.actions; @@ -89,43 +89,43 @@ define(function(require) { }); } }); - } + }; var _addDialogs = function(dialogs) { $.each(dialogs, function(index, dialog) { - SunstoneCfg['dialogs'][dialog.DIALOG_ID] = dialog - }) + SunstoneCfg["dialogs"][dialog.DIALOG_ID] = dialog; + }); return false; - } + }; var _addPanelsHooks = function(tabId, hooks) { - SunstoneCfg["tabs"][tabId]['panelsHooks'] = hooks; + SunstoneCfg["tabs"][tabId]["panelsHooks"] = hooks; return false; - } + }; var _addInitHooks = function(tabId, hooks) { - SunstoneCfg["tabs"][tabId]['initHooks'] = hooks; + SunstoneCfg["tabs"][tabId]["initHooks"] = hooks; return false; - } + }; var _addPanels = function(tabId, panels) { - var indexedPanels = {} + var indexedPanels = {}; $.each(panels, function(index, panel) { - indexedPanels[panel.PANEL_ID] = panel - }) - SunstoneCfg["tabs"][tabId]['panels'] = indexedPanels; + indexedPanels[panel.PANEL_ID] = panel; + }); + SunstoneCfg["tabs"][tabId]["panels"] = indexedPanels; return false; - } + }; var _addFormPanels = function(tabId, formPanels) { - var indexedFormPanels = {} + var indexedFormPanels = {}; $.each(formPanels, function(index, formPanel) { - indexedFormPanels[formPanel.FORM_PANEL_ID] = formPanel - }) - SunstoneCfg["tabs"][tabId]['formPanels'] = indexedFormPanels; - SunstoneCfg["tabs"][tabId]['formPanelInstances'] = {}; + indexedFormPanels[formPanel.FORM_PANEL_ID] = formPanel; + }); + SunstoneCfg["tabs"][tabId]["formPanels"] = indexedFormPanels; + SunstoneCfg["tabs"][tabId]["formPanelInstances"] = {}; return false; - } + }; //Inserts all main tabs in the DOM var _insertTabs = function() { @@ -134,7 +134,7 @@ define(function(require) { _insertButtonsInTab(tabName); _setupDataTable(tabName); - var hooks = SunstoneCfg['tabs'][tabName].initHooks; + var hooks = SunstoneCfg["tabs"][tabName].initHooks; if (hooks) { $.each(hooks, function(i, hook){ @@ -155,61 +155,61 @@ define(function(require) { } _setupTabs(); - } + }; var _setupDataTable = function(tabName) { - var dataTable = SunstoneCfg['tabs'][tabName].dataTable; + var dataTable = SunstoneCfg["tabs"][tabName].dataTable; if (dataTable) { dataTable.initialize(); } - } + }; //Inserts a main tab in the DOM. This is done by //adding the content to the proper div and by adding a list item //link to the navigation menu var _insertTab = function(tabName) { - var tabInfo = SunstoneCfg['tabs'][tabName]; - var condition = tabInfo['condition']; - var tabClass = tabInfo['tabClass'] ? tabInfo['tabClass'] : 'topTab'; - var parent = tabInfo['parentTab'] ? tabInfo['parentTab'] : ''; + var tabInfo = SunstoneCfg["tabs"][tabName]; + var condition = tabInfo["condition"]; + var tabClass = tabInfo["tabClass"] ? tabInfo["tabClass"] : "topTab"; + var parent = tabInfo["parentTab"] ? tabInfo["parentTab"] : ""; //skip this tab if we do not meet the condition if (condition && !condition()) {return;} if (tabInfo.no_content === true) { - tabClass += " tab_with_no_content is-accordion-submenu-parent" + tabClass += " tab_with_no_content is-accordion-submenu-parent"; } else { - tabInfo['tabName'] = tabName; - var TabTemplate = require('hbs!sunstone/tab') - $('div.sunstone-content').append(TabTemplate(tabInfo)); + tabInfo["tabName"] = tabName; + var TabTemplate = require("hbs!sunstone/tab"); + $("div.sunstone-content").append(TabTemplate(tabInfo)); } var liItem; - var title = ''; + var title = ""; if (tabInfo.icon) { - title += ' '; + title += " "; } title += tabInfo.title; - if (parent !== '') { - liItem = '
  • ' + - '' + title + '' + - '
  • '; + if (parent !== "") { + liItem = "
  • " + + "" + title + "" + + "
  • "; - if ($('#menu ul#navigation #li_' + parent + ' .menu').length > 0) { - $('#menu ul#navigation #li_' + parent + ' .menu').append(liItem); + if ($("#menu ul#navigation #li_" + parent + " .menu").length > 0) { + $("#menu ul#navigation #li_" + parent + " .menu").append(liItem); } else { - $('#menu ul#navigation #li_' + parent).append( - '"); } } else { - liItem = '
  • ' + - '' + title + '' + - '
  • '; + liItem = "
  • " + + "" + title + "" + + "
  • "; - $('div#menu ul#navigation').append(liItem); + $("div#menu ul#navigation").append(liItem); } //if this is a submenu... @@ -224,12 +224,12 @@ define(function(require) { if (tabInfo.forms) { $.each(tabInfo.forms, function(key, value) { - Sunstone.addFormPanel(tabName, key, value) - }) + Sunstone.addFormPanel(tabName, key, value); + }); } if (tabInfo.setup) { - var context = $('div#' + tabName, $('div.sunstone-content')); + var context = $("div#" + tabName, $("div.sunstone-content")); tabInfo.setup(context); } @@ -248,14 +248,14 @@ define(function(require) { context = customContext; } else { customId = tabName; - context = $('div#' + tabName, $('div.sunstone-content')); + context = $("div#" + tabName, $("div.sunstone-content")); } - var actionBlock = $('div.action_blocks', context) + var actionBlock = $("div.action_blocks", context); if (actionBlock.length) { - var ButtonsTemplate = require('hbs!./sunstone/buttons') + var ButtonsTemplate = require("hbs!./sunstone/buttons"); var buttonsRow = $(ButtonsTemplate({customId: customId, customContext: customContext})); //for every button defined for this tab... @@ -268,20 +268,20 @@ define(function(require) { continue; } - var type = button.type + '_button'; - var strClass = [type] + var type = button.type + "_button"; + var strClass = [type]; switch (button.type) { case "select": break; case "image": - strClass.push("action_button") + strClass.push("action_button"); break; case "create_dialog": - strClass.push("action_button") - strClass.push("top_button") + strClass.push("action_button"); + strClass.push("top_button"); break; default: - strClass.push("top_button") + strClass.push("top_button"); } if (button.alwaysActive) { @@ -297,92 +297,92 @@ define(function(require) { switch (button.layout) { case "create": buttonContext = $("#" + customId + "create_buttons", buttonsRow); - icon = button.icon ? button.icon : ''; - text = button.text ? icon + ' ' + button.text : icon; + icon = button.icon ? button.icon : ""; + text = button.text ? icon + " " + button.text : icon; strClass.push("success", "button"); - buttonCode = ''; + buttonCode = ""; break; case "refresh": buttonContext = $("#" + customId + "refresh_buttons", buttonsRow); - icon = button.icon ? button.icon : ''; - text = button.text ? icon + ' ' + button.text : icon; + icon = button.icon ? button.icon : ""; + text = button.text ? icon + " " + button.text : icon; strClass.push("refresh", "button", "secondary"); - buttonCode = ''; + buttonCode = ""; break; case "top": buttonContext = $("#" + customId + "refresh_buttons", buttonsRow); - text = '' + - '' + - '' + - ''; + text = "" + + "" + + "" + + ""; strClass.push("toggle_top_button", "only-sunstone-list", "button", "hollow"); - buttonCode = '' + text + ''; + buttonCode = "" + text + ""; break; case "main": buttonContext = $("#" + customId + "main_buttons", buttonsRow); text = button.text; strClass.push("button"); - buttonCode = ''; + buttonCode = ""; break; case "vmsplay_buttons": buttonContext = $("#" + customId + "vmsplay_buttons", buttonsRow); text = button.text; strClass.push("button"); - buttonCode = ''; + buttonCode = ""; break; case "vmspause_buttons": buttonContext = $("#" + customId + "vmspause_buttons", buttonsRow); text = button.text; - buttonCode = '
  • ' + text + '
  • '; + buttonCode = "
  • " + text + "
  • "; break; case "vmsstop_buttons": buttonContext = $("#" + customId + "vmsstop_buttons", buttonsRow); text = button.text; - buttonCode = '
  • ' + text + '
  • '; + buttonCode = "
  • " + text + "
  • "; break; case "vmsrepeat_buttons": buttonContext = $("#" + customId + "vmsrepeat_buttons", buttonsRow); text = button.text; - buttonCode = '
  • ' + text + '
  • '; + buttonCode = "
  • " + text + "
  • "; break; case "vmsdelete_buttons": buttonContext = $("#" + customId + "vmsdelete_buttons", buttonsRow); text = button.text; - buttonCode = '
  • ' + text + '
  • '; + buttonCode = "
  • " + text + "
  • "; break; case "vmsplanification_buttons": buttonContext = $("#" + customId + "vmsplanification_buttons", buttonsRow); text = button.text; - buttonCode = '
  • ' + text + '
  • '; + buttonCode = "
  • " + text + "
  • "; break; case "more_select": buttonContext = $("#" + customId + "more_buttons", buttonsRow); text = button.text; - buttonCode = '
  • ' + text + '
  • '; + buttonCode = "
  • " + text + "
  • "; break; case "user_select": buttonContext = $("#" + customId + "user_buttons", buttonsRow); text = button.text; - buttonCode = '
  • ' + text + '
  • '; + buttonCode = "
  • " + text + "
  • "; break; case "del": buttonContext = $("#" + customId + "delete_buttons", buttonsRow); - text = ' '; + text = " "; strClass.push("alert", "button"); - buttonCode = ''; + buttonCode = ""; break; case "labels": buttonContext = $("#" + customId + "labels_buttons", buttonsRow); - text = ''; + text = ""; strClass.push("only-sunstone-info", "only-sunstone-list", "top_button", "secondary", "button", "dropdown"); - buttonCode = ''; + buttonCode = ""; break; default: buttonContext = $("#" + customId + "main_buttons", buttonsRow); text = button.text; strClass.push("button"); - buttonCode = ''; + buttonCode = ""; } buttonContext.append(buttonCode); @@ -392,78 +392,78 @@ define(function(require) { actionBlock.append(buttonsRow); //actionBlock.foundation(); - Foundation.reflow(actionBlock, 'dropdown'); + Foundation.reflow(actionBlock, "dropdown"); Tips.setup(actionBlock); if ($("#" + customId + "more_buttons li", actionBlock).length == 0) { - $("button[data-toggle=" + customId + "more_buttons]", actionBlock).remove() + $("button[data-toggle=" + customId + "more_buttons]", actionBlock).remove(); } if ($("#" + customId + "user_buttons li", actionBlock).length == 0) { - $("button[data-toggle=" + customId + "user_buttons]", actionBlock).remove() + $("button[data-toggle=" + customId + "user_buttons]", actionBlock).remove(); } if ($("#" + customId + "vmsplanification_buttons li", actionBlock).length == 0) { - $("button[data-toggle=" + customId + "vmsplanification_buttons]", actionBlock).remove() + $("button[data-toggle=" + customId + "vmsplanification_buttons]", actionBlock).remove(); } if ($("#" + customId + "vmsdelete_buttons li", actionBlock).length == 0) { - $("button[data-toggle=" + customId + "vmsdelete_buttons]", actionBlock).remove() + $("button[data-toggle=" + customId + "vmsdelete_buttons]", actionBlock).remove(); } if ($("#" + customId + "vmsstop_buttons li", actionBlock).length == 0) { - $("button[data-toggle=" + customId + "vmsstop_buttons]", actionBlock).remove() + $("button[data-toggle=" + customId + "vmsstop_buttons]", actionBlock).remove(); } if ($("#" + customId + "vmspause_buttons li", actionBlock).length == 0) { - $("button[data-toggle=" + customId + "vmspause_buttons]", actionBlock).remove() + $("button[data-toggle=" + customId + "vmspause_buttons]", actionBlock).remove(); } if ($("#" + customId + "vmsrepeat_buttons li", actionBlock).length == 0) { - $("button[data-toggle=" + customId + "vmsrepeat_buttons]", actionBlock).remove() + $("button[data-toggle=" + customId + "vmsrepeat_buttons]", actionBlock).remove(); } if ($("#" + customId + "user_buttons li", actionBlock).length == 0) { - $("button[data-toggle=" + customId + "user_buttons]", actionBlock).remove() + $("button[data-toggle=" + customId + "user_buttons]", actionBlock).remove(); } if ($("#" + customId + "labels_buttons button", buttonsRow).length != 0) { - $('#' + customId + 'labels_buttons').append( - ''); + $("#" + customId + "labels_buttons").append( + "
    "); } - $('#' + customId + 'labels_buttons').foundation(); + $("#" + customId + "labels_buttons").foundation(); //actionBlock.foundationButtons(); - $('.top_button, .list_button', actionBlock).prop('disabled', false); - $('.top_button, .list_button', actionBlock).prop('disabled', true); - $('.create_dialog_button', actionBlock).prop('disabled', false).removeAttr('disabled'); - $('.alwaysActive', actionBlock).prop('disabled', false).removeAttr('disabled'); + $(".top_button, .list_button", actionBlock).prop("disabled", false); + $(".top_button, .list_button", actionBlock).prop("disabled", true); + $(".create_dialog_button", actionBlock).prop("disabled", false).removeAttr("disabled"); + $(".alwaysActive", actionBlock).prop("disabled", false).removeAttr("disabled"); - $('#' + customId + 'reset_button', actionBlock).on("click", function() { + $("#" + customId + "reset_button", actionBlock).on("click", function() { _resetFormPanel(tabName); return false; - }) + }); - $('.submit_button', actionBlock).on("click", function() { + $(".submit_button", actionBlock).on("click", function() { _submitFormPanel(tabName); return false; - }) + }); }//if tab exists - } + }; var _setupButtons = function() { //Listen for .action_buttons //An action buttons runs a predefined action. If it has type //"multiple" it runs that action on the elements of a datatable. - $(document).on("click", '.action_button', function() { + $(document).on("click", ".action_button", function() { var error = 0; - var value = $(this).val() + var value = $(this).val(); if ($.isEmptyObject(value)) { - value = $(this).attr('href'); + value = $(this).attr("href"); } - $('.dropdown-pane').foundation('close'); + $(".dropdown-pane").foundation("close"); var action = SunstoneCfg["actions"][value]; if (!action) { @@ -485,23 +485,23 @@ define(function(require) { //Listen .confirm_buttons. These buttons show a confirmation dialog //before running the action. - $(document).on("click", '.confirm_button', function() { - var dialogInstance = _getDialogInstance(CONFIRM_DIALOG_ID) + $(document).on("click", ".confirm_button", function() { + var dialogInstance = _getDialogInstance(CONFIRM_DIALOG_ID); dialogInstance.reset(); - $('#' + CONFIRM_DIALOG_ID).data('buttonAction', $(this).attr('href')); - $('#' + CONFIRM_DIALOG_ID).data('buttonTab', $(this).parents('.tab').attr('id')); + $("#" + CONFIRM_DIALOG_ID).data("buttonAction", $(this).attr("href")); + $("#" + CONFIRM_DIALOG_ID).data("buttonTab", $(this).parents(".tab").attr("id")); dialogInstance.show(); return false; }); //Listen .confirm_buttons. These buttons show a confirmation dialog //with a select box before running the action. - $(document).on("click", '.confirm_with_select_button', function() { + $(document).on("click", ".confirm_with_select_button", function() { var dialogInstance = _getDialogInstance(CONFIRM_WITH_SELECT_DIALOG_ID); dialogInstance.setParams({ - 'buttonAction' : $(this).attr('href'), - 'buttonTab' : $(this).parents('.tab').attr('id') + "buttonAction" : $(this).attr("href"), + "buttonTab" : $(this).parents(".tab").attr("id") }); dialogInstance.reset(); @@ -517,26 +517,26 @@ define(function(require) { window.history.back(); e.preventDefault(); }); - } + }; var _setupTabs = function() { - Foundation.reflow($('#menu'), 'accordion-menu'); - Foundation.reflow($('div.sunstone-content'), 'sticky') + Foundation.reflow($("#menu"), "accordion-menu"); + Foundation.reflow($("div.sunstone-content"), "sticky"); var topTabs = $(".sunstone-menu-content ul li.topTab"); var subTabs = $(".sunstone-menu-content ul li.subTab > a"); subTabs.on("click", function() { - if ($(this).closest('li').hasClass('topTab')) { + if ($(this).closest("li").hasClass("topTab")) { return false; } else { - var tabName = $(this).closest('li').attr('id').substring(3); + var tabName = $(this).closest("li").attr("id").substring(3); _showTab(tabName); return false; } }); topTabs.on("click", function(e) { - var tabName = $(this).attr('id').substring(3); + var tabName = $(this).attr("id").substring(3); if ($(this).hasClass("tab_with_no_content")) { //Subtabs have a class with the name of this tab @@ -553,7 +553,7 @@ define(function(require) { }; var _showRighList = function(tabName) { - var tab = $('#' + tabName); + var tab = $("#" + tabName); $(".tab").hide(); tab.show(); @@ -563,11 +563,11 @@ define(function(require) { $(".only-sunstone-info", tab).hide(); $(".only-sunstone-form", tab).hide(); $(".only-sunstone-list", tab).fadeIn(); - $('.action_blocks', tab).removeClass('large-12').addClass('large-9'); + $(".action_blocks", tab).removeClass("large-12").addClass("large-9"); }; var _showRighInfo = function(tabName) { - var tab = $('#' + tabName); + var tab = $("#" + tabName); $(".tab").hide(); tab.show(); @@ -577,8 +577,8 @@ define(function(require) { $(".only-sunstone-list", tab).hide(); $(".only-sunstone-form", tab).hide(); $(".only-sunstone-info", tab).fadeIn(); - $('.action_blocks', tab).removeClass('large-9').addClass('large-12'); - } + $(".action_blocks", tab).removeClass("large-9").addClass("large-12"); + }; var _showTab = function(tabName) { if (_getTab() == tabName && _rightListVisible()){ @@ -590,12 +590,12 @@ define(function(require) { _routerShowTab(tabName); } } - } + }; var _routerShowTab = function(tabName) { - $('.labels-tree', '#navigation').remove(); + $(".labels-tree", "#navigation").remove(); - if (!SunstoneCfg['tabs'][tabName]) { + if (!SunstoneCfg["tabs"][tabName]) { return false; } @@ -605,7 +605,7 @@ define(function(require) { // TODO check if necessary // last_selected_row = null; - if (tabName.indexOf('#') == 0) { + if (tabName.indexOf("#") == 0) { tabName = tabName.substring(1); } @@ -613,24 +613,29 @@ define(function(require) { $("#navigation li").removeClass("navigation-active-li"); $("#navigation li#li_" + tabName).addClass("navigation-active-li"); - var tab = $('#' + tabName); + var tab = $("#" + tabName); //show tab _showRighList(tabName); - var dataTable = SunstoneCfg['tabs'][tabName]['dataTable']; + var dataTable = SunstoneCfg["tabs"][tabName]["dataTable"]; if (dataTable) { dataTable.recountCheckboxes(); } - var res = SunstoneCfg['tabs'][tabName]['resource'] + var hashRes = ["Dashboard", "Settings", "NetworkTopology"]; + var res = SunstoneCfg["tabs"][tabName]["resource"]; if (res) { - Sunstone.runAction(res + ".refresh"); + if (!hashRes.includes(res)){ + Sunstone.runAction(res + ".list"); + } else { + Sunstone.runAction(res + ".refresh"); + } } - } + }; var _getTab = function() { return $(".tab:visible").attr("id"); - } + }; var _showElement = function(tabName, elementId) { if(!Config.isTabEnabled(tabName)){ @@ -642,7 +647,7 @@ define(function(require) { }else{ _routerShowElement(tabName, elementId); } - } + }; var _routerShowElement = function(tabName, elementId) { var resource = SunstoneCfg["tabs"][tabName].resource; @@ -655,39 +660,39 @@ define(function(require) { _routerShowTab(tabName); - var context = $('#' + tabName); + var context = $("#" + tabName); $(".resource-id", context).html(elementId); $(".resource-info-header", context).text(""); - var loading = '
    loading...
    '; + var loading = "
    \"loading...\"
    "; $(".sunstone-info", context).html(loading); _showRighInfo(tabName); Sunstone.runAction(infoAction, elementId); //enable action buttons - $('.top_button, .list_button', context).attr('disabled', false); - } + $(".top_button, .list_button", context).attr("disabled", false); + }; // Returns the element that is currently shown in the right info var _getElementRightInfo = function(tabName, context) { var context = context || $(".sunstone-info", $("#" + tabName)); - return context.data('element'); - } + return context.data("element"); + }; var _insertPanels = function(tabName, info, contextTabId, context) { var context = context || $(".sunstone-info", $("#" + tabName)); - context.data('element', info[Object.keys(info)[0]]); + context.data("element", info[Object.keys(info)[0]]); - var containerId = tabName + '-panels'; + var containerId = tabName + "-panels"; var activaTab = $("li.is-active a", $("#" + containerId)); if (activaTab) { - var activaTabHref = activaTab.attr('href'); + var activaTabHref = activaTab.attr("href"); } var isRefresh = (activaTabHref != undefined); - var prevPanelInstances = SunstoneCfg['tabs'][tabName]["panelInstances"]; + var prevPanelInstances = SunstoneCfg["tabs"][tabName]["panelInstances"]; var prevPanelStates = {}; if(isRefresh && prevPanelInstances != undefined){ @@ -698,7 +703,7 @@ define(function(require) { }); } - var hooks = SunstoneCfg['tabs'][tabName].panelsHooks; + var hooks = SunstoneCfg["tabs"][tabName].panelsHooks; if (hooks) { $.each(hooks, function(i, hook){ @@ -706,10 +711,10 @@ define(function(require) { }); } - var panels = SunstoneCfg['tabs'][tabName].panels; + var panels = SunstoneCfg["tabs"][tabName].panels; var active = false; - var templatePanelsParams = [] - SunstoneCfg['tabs'][tabName]["panelInstances"] = {}; + var templatePanelsParams = []; + SunstoneCfg["tabs"][tabName]["panelInstances"] = {}; $.each(panels, function(panelName, Panel) { if (Config.isTabPanelEnabled((contextTabId||tabName), panelName)) { @@ -718,20 +723,20 @@ define(function(require) { active = true; } } else { - activaTabHref = "#" + panelName + activaTabHref = "#" + panelName; active = true; } try { var panelInstance = new Panel(info, contextTabId); - SunstoneCfg['tabs'][tabName]["panelInstances"][panelName] = panelInstance; + SunstoneCfg["tabs"][tabName]["panelInstances"][panelName] = panelInstance; templatePanelsParams.push({ - 'panelName': panelName, - 'icon': panelInstance.icon, - 'title': panelInstance.title, - 'html': panelInstance.html(), - 'active': active - }) + "panelName": panelName, + "icon": panelInstance.icon, + "title": panelInstance.title, + "html": panelInstance.html(), + "active": active + }); } catch (err) { console.log(err); } @@ -740,14 +745,14 @@ define(function(require) { } }); - var TemplatePanels = require('hbs!./sunstone/panels'); + var TemplatePanels = require("hbs!./sunstone/panels"); var html = TemplatePanels({ - 'containerId': containerId, - 'panels': templatePanelsParams - }) + "containerId": containerId, + "panels": templatePanelsParams + }); context.html(html); - $.each(SunstoneCfg['tabs'][tabName]["panelInstances"], function(panelName, panel) { + $.each(SunstoneCfg["tabs"][tabName]["panelInstances"], function(panelName, panel) { panel.setup(context); if(isRefresh && prevPanelStates[panelName] && panel.setState){ @@ -755,19 +760,19 @@ define(function(require) { } }); - $('#' + containerId + 'Tabs', context).on('change.zf.tabs', function(target) { - var tabIdWithHash = $('.is-active > a', this)[0].hash; - var panel = SunstoneCfg['tabs'][tabName]["panelInstances"][tabIdWithHash.substring(1)]; + $("#" + containerId + "Tabs", context).on("change.zf.tabs", function(target) { + var tabIdWithHash = $(".is-active > a", this)[0].hash; + var panel = SunstoneCfg["tabs"][tabName]["panelInstances"][tabIdWithHash.substring(1)]; if (panel && panel.onShow) { panel.onShow(context); } }); - Foundation.reflow(context, 'tabs'); + Foundation.reflow(context, "tabs"); if(activaTabHref != undefined){ - $('[href="' + activaTabHref + '"]', context).trigger("click"); - $('#' + containerId + 'Tabs', context).trigger('change.zf.tabs'); + $("[href=\"" + activaTabHref + "\"]", context).trigger("click"); + $("#" + containerId + "Tabs", context).trigger("change.zf.tabs"); } if (hooks) { @@ -775,7 +780,7 @@ define(function(require) { hook.post(info, (contextTabId||tabName)); }); } - } + }; //Runs a predefined action. Wraps the calls to opennebula.js and //can be use to run action depending on conditions and notify them @@ -875,7 +880,7 @@ define(function(require) { } return 0; - } + }; function _showFormPanel(tabId, formPanelId, action, onShow2) { var context = $("#" + tabId); @@ -890,12 +895,12 @@ define(function(require) { if (!formPanelInstance) { formContext = - $('
    \ -
    \ -
    \ -
    ').appendTo( $(".contentForm", context) ); + $("
    \ +
    \ +
    \ +
    ").appendTo( $(".contentForm", context) ); // Create panelInstance, insert in the DOM and setup var formPanel = tab["formPanels"][formPanelId]; @@ -904,7 +909,7 @@ define(function(require) { return false; } // Panel not defined - Foundation.reflow(context, 'tabs'); + Foundation.reflow(context, "tabs"); formPanelInstance = new formPanel(); tab["formPanelInstances"][formPanelId] = formPanelInstance; @@ -927,7 +932,7 @@ define(function(require) { $(".wizard_tabs", context).show(); } else { $(".wizard_tabs", context).hide(); - $('a[href="#'+tab.tabName+'-wizardForms"]', context).click(); + $("a[href=\"#"+tab.tabName+"-wizardForms\"]", context).click(); } // Hide reset button if not defined @@ -943,14 +948,14 @@ define(function(require) { if (onShow2) { onShow2(formPanelInstance, formContext); } - }, 13) + }, 13); } var _submitFormPanel = function(tabId) { var context = $("#" + tabId); //_popFormPanelLoading(tabId); // Workaround until Foundation.abide support hidden forms - + var context = $("#" + tabId); $(".sunstone-form-title", context).text(Locale.tr("Submitting...")); $(".submit_button", context).text(Locale.tr("Submitting...")); @@ -958,15 +963,15 @@ define(function(require) { _disableFormPanelSubmit(tabId); setTimeout(function() { - var formPanelInstance = SunstoneCfg["tabs"][tabId].activeFormPanel + var formPanelInstance = SunstoneCfg["tabs"][tabId].activeFormPanel; if ($(".wizardForms", context).is(":visible")) { - $('#' + formPanelInstance.formPanelId + 'Wizard').submit(); + $("#" + formPanelInstance.formPanelId + "Wizard").submit(); } else if ($(".advancedForms", context).is(":visible")) { - $('#' + formPanelInstance.formPanelId + 'Advanced').submit(); + $("#" + formPanelInstance.formPanelId + "Advanced").submit(); } - }, 13) - } + }, 13); + }; /** * Resets the form panel. The loading screen is shown, then the panel is reset @@ -979,7 +984,7 @@ define(function(require) { */ var _resetFormPanel = function(tabId, formPanelId) { if (tabId == undefined){ - tabId = _getTab() + tabId = _getTab(); } _popFormPanelLoading(tabId); @@ -987,7 +992,7 @@ define(function(require) { setTimeout(function() { var formPanelInstance; if (formPanelId != undefined) { - formPanelInstance = SunstoneCfg["tabs"][tabId]['formPanelInstances'][formPanelId]; + formPanelInstance = SunstoneCfg["tabs"][tabId]["formPanelInstances"][formPanelId]; } else { formPanelInstance = SunstoneCfg["tabs"][tabId].activeFormPanel; } @@ -1003,8 +1008,8 @@ define(function(require) { if (_formPanelVisible($("#"+tabId))){ _showFormPanel(tabId, formPanelId); } - }, 13) - } + }, 13); + }; /** * Hides the form panel loading (spinning icon on submit), and resets @@ -1015,7 +1020,7 @@ define(function(require) { */ function _hideFormPanelLoading(tabId) { if (tabId == undefined){ - tabId = _getTab() + tabId = _getTab(); } var context = $("#" + tabId); @@ -1038,19 +1043,19 @@ define(function(require) { function _hideFormPanel(tabId) { if (tabId == undefined){ - tabId = _getTab() + tabId = _getTab(); } var context = $("#" + tabId); if (_formPanelVisible(context)){ - $('[href="back"]', context).trigger("click"); + $("[href=\"back\"]", context).trigger("click"); } } function _popFormPanelLoading(tabId) { if (tabId == undefined){ - tabId = _getTab() + tabId = _getTab(); } if(_getTab() != tabId){ @@ -1068,7 +1073,7 @@ define(function(require) { $(".only-sunstone-list", context).hide(); $(".only-sunstone-info", context).hide(); $(".only-sunstone-form", context).show(); - $('.action_blocks', context).removeClass('large-9').addClass('large-12'); + $(".action_blocks", context).removeClass("large-9").addClass("large-12"); $(".sunstone-form-title", context).text(Locale.tr("Loading...")); $(".submit_button", context).text(Locale.tr("Loading...")); @@ -1091,7 +1096,7 @@ define(function(require) { function _enableFormPanelSubmit(tabId) { if (tabId == undefined){ - tabId = _getTab() + tabId = _getTab(); } var context = $("#" + tabId); @@ -1119,51 +1124,51 @@ define(function(require) { button = buttons["action_list"]["actions"][buttonName]; } return button; - } + }; var _rightInfoVisible = function(context) { - return $(".sunstone-info", context).is(':visible'); - } + return $(".sunstone-info", context).is(":visible"); + }; var _rightListVisible = function(context) { - return $(".sunstone-list", context).is(':visible'); - } + return $(".sunstone-list", context).is(":visible"); + }; var _formPanelVisible = function(context) { - return $(".sunstone-form", context).is(':visible'); - } + return $(".sunstone-form", context).is(":visible"); + }; var _rightInfoResourceId = function(context) { return $(".resource-id", context).text(); - } + }; var _getAction = function(actionId) { return SunstoneCfg["actions"][actionId]; - } + }; var _getDataTable = function(tabName) { - if (SunstoneCfg['tabs'][tabName]) { - return SunstoneCfg['tabs'][tabName].dataTable; + if (SunstoneCfg["tabs"][tabName]) { + return SunstoneCfg["tabs"][tabName].dataTable; } - } + }; var _getResource = function(tabName) { - if (SunstoneCfg['tabs'][tabName]) { - return SunstoneCfg['tabs'][tabName].resource; + if (SunstoneCfg["tabs"][tabName]) { + return SunstoneCfg["tabs"][tabName].resource; } - } + }; var _getDialogInstance = function(dialogId) { - var dialogInstance = SunstoneCfg['dialogInstances'][dialogId]; + var dialogInstance = SunstoneCfg["dialogInstances"][dialogId]; if (dialogInstance == undefined) { - var Dialog = SunstoneCfg['dialogs'][dialogId] + var Dialog = SunstoneCfg["dialogs"][dialogId]; var dialogInstance = new Dialog(); dialogInstance.insert(); - SunstoneCfg['dialogInstances'][dialogId] = dialogInstance; + SunstoneCfg["dialogInstances"][dialogId] = dialogInstance; } return dialogInstance; - } + }; var _setupNavigoRoutes = function() { router = new Navigo(null, true); @@ -1177,7 +1182,7 @@ define(function(require) { }.bind(tabName)); router.on(new RegExp("(?:#|/)"+tabName+"/(\\d+)"), function(id){ - _routerShowElement(this, id) + _routerShowElement(this, id); }.bind(tabName)); router.on(new RegExp("(?:#|/)"+tabName), function(){ @@ -1197,7 +1202,7 @@ define(function(require) { }); router.resolve(); - } + }; var Sunstone = { "addMainTabs": _addMainTabs, @@ -1207,7 +1212,7 @@ define(function(require) { "insertPanels": _insertPanels, "getElementRightInfo": _getElementRightInfo, - 'showTab': _showTab, + "showTab": _showTab, "showElement" : _showElement, "getTab": _getTab, @@ -1237,7 +1242,7 @@ define(function(require) { "TOP_INTERVAL": TOP_INTERVAL, "setupNavigoRoutes": _setupNavigoRoutes - } + }; return Sunstone; }); diff --git a/src/sunstone/public/app/tabs/dashboard-tab.js b/src/sunstone/public/app/tabs/dashboard-tab.js index 8991f3cefa..e5fc30a0f3 100644 --- a/src/sunstone/public/app/tabs/dashboard-tab.js +++ b/src/sunstone/public/app/tabs/dashboard-tab.js @@ -87,8 +87,6 @@ define(function(require) { 'vms': { 'html': require('hbs!./dashboard-tab/vms'), 'onShow': function() { - Sunstone.runAction("VM.list"); - var end_time = -1; // today var start_time = Math.floor(new Date().getTime() / 1000); start_time = start_time - 604800; // 604800 = 7 days = 7*24*60*60 @@ -107,6 +105,7 @@ define(function(require) { success: function(req, response) { Accounting.fillAccounting($("#dashboard_vm_accounting"), req, response, no_table); Accounting.fillAccounting($("#dashboard_user_accounting"), req, response, no_table); + Sunstone.runAction("VM.list"); }, error: Notifier.onError, data: options