From 675140ff153b70ee4ee1dd94129d5f0ea2855da5 Mon Sep 17 00:00:00 2001 From: Frederick Borges Date: Mon, 5 Oct 2020 18:23:50 +0200 Subject: [PATCH] F #2312: Remote Connection from datatable (#285) Signed-off-by: Frederick Borges --- .../create/wizard-tabs/io/html.hbs | 5 +- .../public/app/tabs/vms-tab/datatable.js | 73 +++++++++++++++++-- 2 files changed, 71 insertions(+), 7 deletions(-) diff --git a/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/io/html.hbs b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/io/html.hbs index 44895f3b27..0eff2ec226 100644 --- a/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/io/html.hbs +++ b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/io/html.hbs @@ -23,7 +23,10 @@ - + diff --git a/src/sunstone/public/app/tabs/vms-tab/datatable.js b/src/sunstone/public/app/tabs/vms-tab/datatable.js index e79f9cac60..4053aa729d 100644 --- a/src/sunstone/public/app/tabs/vms-tab/datatable.js +++ b/src/sunstone/public/app/tabs/vms-tab/datatable.js @@ -33,6 +33,7 @@ define(function(require) { var DashboardUtils = require('utils/dashboard'); var SearchDropdown = require('hbs!./datatable/search'); var TemplateUtils = require('utils/template-utils'); + var FireedgeValidator = require('utils/fireedge-validator'); /* CONSTANTS @@ -233,13 +234,73 @@ define(function(require) { }); $('#' + this.dataTableId).on("click", '.vnc', function() { - var data = $(this).data(); + var that = this; - if (!Vnc.lockStatus() && data.hasOwnProperty("id")) { - Vnc.lock(); - Sunstone.runAction("VM.startvnc_action", String(data.id)); - } else { - Notifier.notifyError(Locale.tr("VNC Connection in progress")); + function promiseVmInfo(id, success) { + return $.ajax({ + url: "vm/" + id, + type: "GET", + dataType: "json", + success: success + }) + } + + function callVNC() { + var data = $(that).data(); + + if (!Vnc.lockStatus() && data.hasOwnProperty("id")) { + Vnc.lock(); + Sunstone.runAction("VM.startvnc_action", String(data.id)); + } else { + Notifier.notifyError(Locale.tr("VNC Connection in progress")); + } + } + + function callVMRC(){ + var data = $(that).data(); + + (data.hasOwnProperty("id")) + ? Sunstone.runAction("VM.startvmrc_action", String(data.id), 'vnc') + : Notifier.notifyError(Locale.tr("VNC - Invalid action")); + } + + function callGuac(){ + var data = $(that).data(); + + (data.hasOwnProperty("id")) + ? Sunstone.runAction("VM.startguac_action", String(data.id), 'vnc') + : Notifier.notifyError(Locale.tr("VNC - Invalid action")); + } + + var success_function = function() { + sessionStorage.setItem(FireedgeValidator.sessionVar, "true"); + var data = $(that).data(); + // Get VM info + if (data.hasOwnProperty('id')){ + promiseVmInfo(data['id'], function(data){ + if (data && data.VM && data.VM.USER_TEMPLATE && data.VM.USER_TEMPLATE.HYPERVISOR == 'vcenter'){ + callVMRC(); + } + else{ + callGuac(); + } + }); + } + }; + + var error_function = function() { + sessionStorage.removeItem(FireedgeValidator.sessionVar); + callVNC(); + } + + if (!sessionStorage.getItem(FireedgeValidator.sessionVar)){ + FireedgeValidator.request(success_function,error_function); + } + else if (sessionStorage.getItem(FireedgeValidator.sessionVar) == 'true'){ + success_function(); + } + else{ + error_function(); } return false;