diff --git a/src/sunstone/public/app/tabs/vms-tab/dialogs/guac.js b/src/sunstone/public/app/tabs/vms-tab/dialogs/guac.js index f94e0509b3..04d2ca96cb 100644 --- a/src/sunstone/public/app/tabs/vms-tab/dialogs/guac.js +++ b/src/sunstone/public/app/tabs/vms-tab/dialogs/guac.js @@ -23,6 +23,7 @@ define(function(require) { var TemplateHTML = require('hbs!./guac/html'); var Sunstone = require('sunstone'); var GClient = require('utils/gclient'); + var Files = require('utils/files'); /* CONSTANTS @@ -64,11 +65,18 @@ define(function(require) { } function _setup(context) { + var that = this; + $("#open_in_a_new_window_gclient", context).on("click", function() { var dialog = Sunstone.getDialog(DIALOG_ID); dialog.hide(); }); + $("#takeScreenshot_gclient", context).on("click", function() { + var canvas = that.gClient.snapshot(); + Files.downloadImage('screenshot', canvas) + }); + return false; } diff --git a/src/sunstone/public/app/tabs/vms-tab/dialogs/guac/html.hbs b/src/sunstone/public/app/tabs/vms-tab/dialogs/guac/html.hbs index 8cfc11edc8..ea496b491e 100644 --- a/src/sunstone/public/app/tabs/vms-tab/dialogs/guac/html.hbs +++ b/src/sunstone/public/app/tabs/vms-tab/dialogs/guac/html.hbs @@ -23,6 +23,9 @@ + diff --git a/src/sunstone/public/app/utils/files.js b/src/sunstone/public/app/utils/files.js index a323d59931..e536743ce5 100644 --- a/src/sunstone/public/app/utils/files.js +++ b/src/sunstone/public/app/utils/files.js @@ -21,11 +21,12 @@ define(function(require) { return { "downloadWFile": _downloadWFile, "downloadRdpFile": _downloadRdpFile, + "downloadImage": _downloadImage, }; function _downloadRdpFile(ip, name = "vm_name", credentials = {}) { var file = _rdpFile(ip, credentials.USERNAME, credentials.PASSWORD); - _download(name, ".rdp", file); + _download(name, ".rdp", 'data:text/plain;charset=utf-8,' + encodeURIComponent(file)); } function _downloadWFile(response, vm_host, graphics_type, graphics_port) { @@ -57,12 +58,16 @@ define(function(require) { var proxy = protocol + "//" + proxy_host + ":" + proxy_port + "?token=" + token; var file = _wFile(graphics_type, filename, vm_host, graphics_port, proxy, password); - _download(filename, ".vv", file); + _download(filename, ".vv", 'data:text/plain;charset=utf-8,' + encodeURIComponent(file)); } - function _download(name, extension, text) { + function _downloadImage(name, image) { + _download(name, '.png', image.toDataURL('image/png')) + } + + function _download(name, extension, file) { var link = $("", { - href: 'data:text/plain;charset=utf-8,' + encodeURIComponent(text), + href: file, download: String(name).concat(extension), }).css({ display: 'none',