Skip to content

Commit

Permalink
F #2312: Remote Connection from datatable (#285)
Browse files Browse the repository at this point in the history
Signed-off-by: Frederick Borges <[email protected]>
  • Loading branch information
Frederick Borges authored Oct 5, 2020
1 parent e672fb8 commit 675140f
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@
<input type="radio" wizard_field="TYPE" name="graphics_type" ID="radioNoneType{{uniqueId}}" value="">
<label for="radioNoneType{{uniqueId}}">{{tr "None"}}</label>
<input type="radio" wizard_field="TYPE" name="graphics_type" ID="radioVncType{{uniqueId}}" value="VNC" checked>
<label for="radioVncType{{uniqueId}}">VNC</label>
<label for="radioVncType{{uniqueId}}">VNC
<span class="hypervisor only_vcenter vmrc_inout_option">&nbsp;/&nbsp;VMRC</span>
<span class="hypervisor only_kvm guac_inout_option">&nbsp;/&nbsp;GUAC</span>
</label>
<input type="radio" wizard_field="TYPE" name="graphics_type" ID="radioSdlType{{uniqueId}}" value="SDL" class="hypervisor only_kvm not_lxd" >
<label class="hypervisor only_kvm not_lxd" for="radioSdlType{{uniqueId}}">SDL</label>
<input type="radio" wizard_field="TYPE" name="graphics_type" ID="radioSpiceType{{uniqueId}}" value="SPICE" class="hypervisor only_kvm not_lxd" >
Expand Down
73 changes: 67 additions & 6 deletions src/sunstone/public/app/tabs/vms-tab/datatable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -233,13 +234,73 @@ define(function(require) {
});

$('#' + this.dataTableId).on("click", '.vnc', function() {
var data = $(this).data();
var that = this;

function promiseVmInfo(id, success) {
return $.ajax({
url: "vm/" + id,
type: "GET",
dataType: "json",
success: success
})
}

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 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;
Expand Down

0 comments on commit 675140f

Please sign in to comment.