230 lines
6.7 KiB
JavaScript
230 lines
6.7 KiB
JavaScript
var action_queue = [];
|
|
|
|
$(function() {
|
|
$('#update-host').on('submit', update_host);
|
|
$('#verify-dns').on('click', verify_dns);
|
|
$('#verify-https').on('click', verify_https);
|
|
$('#verify-http').on('click', verify_http);
|
|
$('#cert-method').on('change', toggle_cert_method);
|
|
$('#update-cert').on('submit', update_cert);
|
|
$('#update-common').on('submit', update_common);
|
|
$('#app-manager')
|
|
.on('click', '.app-visible', update_app_visibility)
|
|
.on('click', '.app-autostart', update_app_autostart)
|
|
.on('click', '.app-start', start_app)
|
|
.on('click', '.app-stop', stop_app)
|
|
.on('click', '.app-install', install_app)
|
|
.on('click', '.app-uninstall', uninstall_app);
|
|
$('#update-password').on('submit', update_password);
|
|
$('#reboot-vm').on('click', reboot_vm);
|
|
$('#shutdown-vm').on('click', shutdown_vm);
|
|
window.setInterval(check_progress, 1000);
|
|
});
|
|
|
|
function update_host() {
|
|
$('#host-submit').hide();
|
|
$('#host-message').hide();
|
|
$('#host-wait').show();
|
|
$.post('/update-host', {'domain': $('#domain').val(), 'port': $('#port').val()}, function(data) {
|
|
$('#host-wait').hide();
|
|
if (data.error) {
|
|
$('#host-message').attr('class','error').html(data.error).show();
|
|
$('#host-submit').show();
|
|
} else {
|
|
$('#host-message').attr('class','info').html(data.ok).show();
|
|
$('input').prop('disabled', true);
|
|
$('.setup-box').slice(1).css('opacity', '0.5');
|
|
}
|
|
});
|
|
return false;
|
|
}
|
|
|
|
function verify_dns() {
|
|
$('#verify-dns').hide();
|
|
$('#dns-message').hide();
|
|
$('#dns-wait').show();
|
|
$.get('/verify-dns', function(data) {
|
|
$('#dns-wait').hide();
|
|
if (data.error) {
|
|
$('#dns-message').attr('class','error').html(data.error).show();
|
|
$('#verify-dns').show();
|
|
} else {
|
|
$('#dns-message').attr('class','info').html(data.ok).show();
|
|
}
|
|
});
|
|
return false;
|
|
}
|
|
|
|
function _verify_http(proto) {
|
|
$('#verify-'+proto).hide();
|
|
$('#'+proto+'-message').hide();
|
|
$('#'+proto+'-wait').show();
|
|
$.get('/verify-' + proto, function(data) {
|
|
$('#'+proto+'-wait').hide();
|
|
if (data.error) {
|
|
$('#'+proto+'-message').attr('class','error').html(data.error).show();
|
|
$('#verify-'+proto).show();
|
|
} else {
|
|
$('#'+proto+'-message').attr('class','info').html(data.ok).show();
|
|
}
|
|
});
|
|
return false;
|
|
}
|
|
|
|
function verify_http() {
|
|
return _verify_http('http');
|
|
}
|
|
|
|
function verify_https() {
|
|
return _verify_http('https');
|
|
}
|
|
|
|
function toggle_cert_method() {
|
|
if ($('#cert-method').val() == 'manual') {
|
|
$('.cert-upload').show();
|
|
} else {
|
|
$('.cert-upload').hide();
|
|
}
|
|
}
|
|
|
|
function update_cert() {
|
|
$('#cert-submit').hide();
|
|
$('#cert-message').hide();
|
|
$('#cert-wait').show();
|
|
$.ajax({url: '/update-cert', type: 'POST', data: new FormData($('#update-cert')[0]), cache: false, contentType: false, processData: false, success: function(data) {
|
|
$('#cert-wait').hide();
|
|
if (data.error) {
|
|
$('#cert-message').attr('class','error').html(data.error).show();
|
|
$('#cert-submit').show();
|
|
} else {
|
|
$('#cert-message').attr('class','info').html(data.ok).show();
|
|
}
|
|
}});
|
|
return false;
|
|
}
|
|
|
|
function update_common() {
|
|
$('#common-submit').hide();
|
|
$('#common-message').hide();
|
|
$('#common-wait').show();
|
|
$.post('/update-common', {'email': $('#email').val(), 'gmaps-api-key': $('#gmaps-api-key').val()}, function(data) {
|
|
$('#common-wait').hide();
|
|
if (data.error) {
|
|
$('#common-message').attr('class','error').html(data.error).show();
|
|
$('#common-submit').show();
|
|
} else {
|
|
$('#common-message').attr('class','info').html(data.ok).show();
|
|
$('#common-submit').show();
|
|
}
|
|
});
|
|
return false;
|
|
}
|
|
|
|
function _update_app(item, ev) {
|
|
var el = $(ev.target);
|
|
var app = el.closest('tr').data('app');
|
|
var value = el.is(':checked') ? 'true' : '';
|
|
$.post('/update-app-'+item, {'app': app, 'value': value}, function(data) {
|
|
if (data.error) {
|
|
el.prop('checked', !value);
|
|
alert(data.error);
|
|
}
|
|
});
|
|
}
|
|
|
|
function update_app_visibility(ev) {
|
|
return _update_app('visibility', ev);
|
|
}
|
|
|
|
function update_app_autostart(ev) {
|
|
return _update_app('autostart', ev);
|
|
}
|
|
|
|
function _do_app(action, ev) {
|
|
var el = $(ev.target);
|
|
var tr = el.closest('tr');
|
|
var td = el.closest('td');
|
|
td.html('<div class="loader"></div>');
|
|
$.post('/'+action+'-app', {'app': tr.data('app')}, function(data) {
|
|
if (data.error) {
|
|
td.attr('class','error').html(data.error);
|
|
} else if (action) {
|
|
tr.html(data.html);
|
|
action_queue.push(data.id);
|
|
}
|
|
});
|
|
return false;
|
|
}
|
|
|
|
function start_app(ev) {
|
|
return _do_app('start', ev);
|
|
}
|
|
|
|
function stop_app(ev) {
|
|
return _do_app('stop', ev);
|
|
}
|
|
|
|
function install_app(ev) {
|
|
return _do_app('install', ev);
|
|
}
|
|
|
|
function uninstall_app(ev) {
|
|
var app = $(ev.target).closest('tr').children().first().text()
|
|
if (confirm('Opravdu chcete odinstalovat aplikaci '+app+'?')) {
|
|
return _do_app('uninstall', ev);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
function check_progress() {
|
|
if (action_queue.length) {
|
|
$.post('/get-progress', {'ids': action_queue}, function(data) {
|
|
for (id in data) {
|
|
var app = id.split(':')[0];
|
|
$('#app-manager tr[data-app="'+app+'"]').html(data[id].html);
|
|
if (data[id].last) {
|
|
action_queue = action_queue.filter(function(item) {
|
|
return item !== id
|
|
});
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
function update_password() {
|
|
$('#password-submit').hide();
|
|
$('#password-message').hide();
|
|
$('#password-wait').show();
|
|
$.post('/update-password', {'oldpassword': $('#oldpassword').val(), 'newpassword': $('#newpassword').val(), 'newpassword2': $('#newpassword2').val()}, function(data) {
|
|
$('#password-wait').hide();
|
|
if (data.error) {
|
|
$('#password-message').attr('class','error').html(data.error).show();
|
|
$('#password-submit').show();
|
|
} else {
|
|
$('#password-message').attr('class','info').html(data.ok).show();
|
|
}
|
|
});
|
|
return false;
|
|
}
|
|
|
|
function _do_vm(action) {
|
|
$.get('/'+action+'-vm', function(data) {
|
|
$('#vm-message').attr('class','info').html(data.ok).show();
|
|
});
|
|
}
|
|
|
|
function reboot_vm() {
|
|
if (confirm('Opravdu chcete restartovat VM?')) {
|
|
_do_vm('reboot');
|
|
}
|
|
return false;
|
|
}
|
|
|
|
function shutdown_vm() {
|
|
if (confirm('Opravdu chcete vypnout VM?')) {
|
|
_do_vm('shutdown');
|
|
}
|
|
return false;
|
|
}
|