203 lines
6.3 KiB
JavaScript
203 lines
6.3 KiB
JavaScript
$(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-visible').on('click', update_app_visibility);
|
|
$('.app-autostart').on('click', update_app_autostart);
|
|
$('tr[data-app]').on('click', '.app-start', start_app).on('click', '.app-stop', stop_app);
|
|
$('#update-password').on('submit', update_password);
|
|
$('#reboot-vm').on('click', reboot_vm);
|
|
$('#shutdown-vm').on('click', shutdown_vm);
|
|
});
|
|
|
|
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_visibility(ev) {
|
|
var el = $(ev.target);
|
|
var app = el.closest('tr').data('app');
|
|
var value = el.is(':checked') ? 'true' : '';
|
|
$.post('/update-app-visibility', {'app': app, 'value': value}, function(data) {
|
|
if (data.error) {
|
|
el.prop('checked', !value);
|
|
alert(data.error);
|
|
}
|
|
});
|
|
}
|
|
|
|
function update_app_autostart(ev) {
|
|
var el = $(ev.target);
|
|
var app = el.closest('tr').data('app');
|
|
var value = el.is(':checked') ? 'true' : '';
|
|
$.post('/update-app-autostart', {'app': app, 'value': value}, function(data) {
|
|
if (data.error) {
|
|
el.prop('checked', !value);
|
|
alert(data.error);
|
|
}
|
|
});
|
|
}
|
|
|
|
function start_app(ev) {
|
|
var el = $(ev.target);
|
|
var app = el.closest('tr').data('app');
|
|
var td = el.closest('td');
|
|
td.html('<div class="loader"></div>');
|
|
$.post('/start-app', {'app': app}, function(data) {
|
|
if (data.error) {
|
|
td.attr('class','error').html(data.error);
|
|
} else {
|
|
td.removeAttr('class').html(data.ok);
|
|
}
|
|
});
|
|
return false;
|
|
}
|
|
|
|
function stop_app(ev) {
|
|
var el = $(ev.target);
|
|
var app = el.closest('tr').data('app');
|
|
var td = el.closest('td');
|
|
td.html('<div class="loader"></div>');
|
|
$.post('/stop-app', {'app': app}, function(data) {
|
|
if (data.error) {
|
|
td.attr('class','error').html(data.error);
|
|
} else {
|
|
td.removeAttr('class').html(data.ok);
|
|
}
|
|
});
|
|
return false;
|
|
}
|
|
|
|
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 reboot_vm() {
|
|
if (confirm('Do you really want to reboot VM?')) {
|
|
$.get('/reboot-vm', function(data) {
|
|
$('#vm-message').attr('class','info').html(data.ok).show();
|
|
});
|
|
}
|
|
return false;
|
|
}
|
|
|
|
function shutdown_vm() {
|
|
if (confirm('Do you really want to shutdown VM?')) {
|
|
$.get('/shutdown-vm', function(data) {
|
|
$('#vm-message').attr('class','info').html(data.ok).show();
|
|
});
|
|
}
|
|
return false;
|
|
}
|