Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 62 additions & 3 deletions emhttp/plugins/dynamix.vm.manager/javascript/vmmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,56 @@ function displayWebUI(url) {
window.open(url, '_blank').focus();
}

function clampVMContextDropdownToViewport(id) {
var $dropdown = $('#dropdown-'+id);
if (!$dropdown.length) return;

var scrollTop = $(window).scrollTop();
var viewportTop = scrollTop + 8;
var viewportBottom = scrollTop + window.innerHeight - 8;
var menuHeight = $dropdown.outerHeight();
var top = parseFloat($dropdown.css('top'));

if (isNaN(top)) {
top = $dropdown.offset().top || viewportTop;
}

if (top < viewportTop) {
top = viewportTop;
}
if (top + menuHeight > viewportBottom) {
top = Math.max(viewportTop, viewportBottom - menuHeight);
}

$dropdown.css('top', top);
}

function applyVMContextDropdownFix(id, selector) {
var $dropdown = $('#dropdown-'+id);
if (!$dropdown.length) return;

$dropdown.css({
'z-index': 10001,
'max-height': '',
'overflow-y': '',
'overflow-x': ''
});
if (!$dropdown.children('.docker-dropdown-spacer').length) {
$dropdown.append('<li class="docker-dropdown-spacer" aria-hidden="true" style="position:absolute;top:100%;left:0;width:1px;height:60px;pointer-events:none;list-style:none"></li>');
}

if (selector) {
$(document)
.off('click.vmcontextfix contextmenu.vmcontextfix', selector)
.on('click.vmcontextfix contextmenu.vmcontextfix', selector, function() {
setTimeout(function() {
applyVMContextDropdownFix(id);
clampVMContextDropdownToViewport(id);
}, 0);
});
}
}

function downloadFile(source) {
var a = document.createElement('a');
a.setAttribute('href',source);
Expand Down Expand Up @@ -125,7 +175,7 @@ function addVMContext(name, uuid, template, state, vmrcurl, vmrcprotocol, log, f
}
}
if (rundivider) opts.push({divider:true});
context.settings({right:false,above:false});
context.settings({right:false,above:'auto'});
if (state == "running") {
opts.push({text:_("Stop"), icon:"fa-stop", action:function(e) {
e.preventDefault();
Expand Down Expand Up @@ -251,15 +301,23 @@ function addVMContext(name, uuid, template, state, vmrcurl, vmrcprotocol, log, f
});
}});
}
if (usage) { context.destroy('#vmusage-'+uuid); context.attach('#vmusage-'+uuid, opts); } else { context.destroy('#vm-'+uuid); context.attach('#vm-'+uuid, opts); }
if (usage) {
context.destroy('#vmusage-'+uuid);
context.attach('#vmusage-'+uuid, opts);
applyVMContextDropdownFix('vmusage-'+uuid, '#vmusage-'+uuid);
} else {
context.destroy('#vm-'+uuid);
context.attach('#vm-'+uuid, opts);
applyVMContextDropdownFix('vm-'+uuid, '#vm-'+uuid);
}
}
function addVMSnapContext(name, uuid, template, state, snapshotname, method){
var opts = [];
var path = location.pathname;
var x = path.indexOf("?");
if (x!=-1) path = path.substring(0,x);

context.settings({right:false,above:false});
context.settings({right:false,above:'auto'});


opts.push({text:_("Revert snapshot"), icon:"fa-fast-backward", action:function(e) {
Expand Down Expand Up @@ -287,6 +345,7 @@ function addVMSnapContext(name, uuid, template, state, snapshotname, method){
}});
context.destroy('#vmsnap-'+uuid);
context.attach('#vmsnap-'+uuid, opts);
applyVMContextDropdownFix('vmsnap-'+uuid, '#vmsnap-'+uuid);
}
function startAll() {
$('input[type=button]').prop('disabled',true);
Expand Down
Loading