statping/source/js/main.js

154 lines
5.0 KiB
JavaScript
Raw Normal View History

2018-08-16 06:22:20 +00:00
/*
* Statup
* Copyright (C) 2018. Hunter Long and the project contributors
* Written by Hunter Long <info@socialeck.com> and the project contributors
*
* https://github.com/hunterlong/statup
*
* The licenses for most software and other practical works are designed
* to take away your freedom to share and change the works. By contrast,
* the GNU General Public License is intended to guarantee your freedom to
* share and change all versions of a program--to make sure it remains free
* software for all its users.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
2018-08-23 07:28:48 +00:00
$('.service_li').on('click', function() {
2018-06-27 02:59:59 +00:00
var id = $(this).attr('data-id');
2018-08-23 07:28:48 +00:00
var position = $('#service_id_' + id).offset();
window.scroll(0, position.top - 23);
2018-06-27 02:59:59 +00:00
return false;
2018-06-28 07:28:07 +00:00
});
2018-06-30 02:19:19 +00:00
$('form').submit(function() {
2018-08-23 07:28:48 +00:00
console.log(this);
$(this).find('button[type=submit]').prop('disabled', true);
2018-06-30 00:57:05 +00:00
});
$('select#service_type').on('change', function() {
var selected = $('#service_type option:selected').val();
2018-08-23 07:28:48 +00:00
if (selected === 'tcp') {
$('#service_port').parent().parent().removeClass('d-none');
$('#service_check_type').parent().parent().addClass('d-none');
$('#service_url').attr('placeholder', 'localhost');
$('#post_data').parent().parent().addClass('d-none');
$('#service_response').parent().parent().addClass('d-none');
$('#service_response_code').parent().parent().addClass('d-none');
} else {
2018-08-23 07:28:48 +00:00
$('#post_data').parent().parent().removeClass('d-none');
$('#service_response').parent().parent().removeClass('d-none');
$('#service_response_code').parent().parent().removeClass('d-none');
$('#service_check_type').parent().parent().removeClass('d-none');
$('#service_url').attr('placeholder', 'https://google.com');
2018-08-23 07:28:48 +00:00
$('#service_port').parent().parent().addClass('d-none');
}
});
2018-07-22 22:17:38 +00:00
$('select#service_check_type').on('change', function() {
var selected = $('#service_check_type option:selected').val();
2018-08-23 07:28:48 +00:00
if (selected === 'POST') {
$('#post_data').parent().parent().removeClass('d-none');
2018-07-22 22:17:38 +00:00
} else {
2018-08-23 07:28:48 +00:00
$('#post_data').parent().parent().addClass('d-none');
2018-07-22 22:17:38 +00:00
}
});
$(function() {
var pathname = window.location.pathname;
2018-08-23 07:28:48 +00:00
if (pathname === '/logs') {
var lastline;
2018-08-23 07:28:48 +00:00
var logArea = $('#live_logs');
setInterval(function() {
2018-08-23 07:28:48 +00:00
$.get('/logs/line', function(data, status) {
if (lastline !== data) {
var curr = $.trim(logArea.text());
2018-08-23 07:28:48 +00:00
var line = data.replace(/(\r\n|\n|\r)/gm, ' ');
line = line + '\n';
logArea.text(line + curr);
lastline = data;
}
});
}, 200);
}
});
2018-06-30 00:57:05 +00:00
2018-08-23 07:28:48 +00:00
$('.confirm-btn').on('click', function() {
var r = confirm('Are you sure you want to delete?');
if (r === true) {
2018-07-08 21:06:10 +00:00
return true;
} else {
return false;
}
});
2018-06-30 02:19:19 +00:00
2018-08-23 07:28:48 +00:00
$('.select-input').on('click', function() {
2018-07-17 09:18:20 +00:00
$(this).select();
});
2018-08-23 07:28:48 +00:00
// $('input[name=password], input[name=password_confirm]').on('change keyup input paste', function() {
// var password = $('input[name=password]'),
// repassword = $('input[name=password_confirm]'),
// both = password.add(repassword).removeClass('is-valid is-invalid');
//
// var btn = $(this).parents('form:first').find('button[type=submit]');
// password.addClass(
// password.val().length > 0 ? 'is-valid' : 'is-invalid'
// );
// repassword.addClass(
// password.val().length > 0 ? 'is-valid' : 'is-invalid'
// );
//
// if (password.val() !== repassword.val()) {
// both.addClass('is-invalid');
// btn.prop('disabled', true);
// } else {
// btn.prop('disabled', false);
// }
// });
2018-06-28 07:28:07 +00:00
var ranVar = false;
var ranTheme = false;
2018-08-23 07:28:48 +00:00
var ranMobile = false;
$('a[data-toggle=pill]').on('shown.bs.tab', function(e) {
var target = $(e.target).attr('href');
if (target === '#v-pills-style' && !ranVar) {
var sass_vars = CodeMirror.fromTextArea(document.getElementById('sass_vars'), {
2018-06-28 07:28:07 +00:00
lineNumbers: true,
matchBrackets: true,
2018-08-23 07:28:48 +00:00
mode: 'text/x-scss',
colorpicker: true
2018-06-28 07:28:07 +00:00
});
2018-08-23 07:28:48 +00:00
sass_vars.setSize(null, 900);
2018-06-28 07:28:07 +00:00
ranVar = true;
2018-08-23 07:28:48 +00:00
} else if (target === '#pills-theme' && !ranTheme) {
var theme_css = CodeMirror.fromTextArea(document.getElementById('theme_css'), {
2018-06-28 07:28:07 +00:00
lineNumbers: true,
matchBrackets: true,
2018-08-23 07:28:48 +00:00
mode: 'text/x-scss',
colorpicker: true
2018-06-28 07:28:07 +00:00
});
2018-08-23 07:28:48 +00:00
theme_css.setSize(null, 900);
2018-06-28 07:28:07 +00:00
ranTheme = true;
2018-08-23 07:28:48 +00:00
} else if (target === '#pills-mobile' && !ranMobile) {
var mobile_css = CodeMirror.fromTextArea(document.getElementById('mobile_css'), {
lineNumbers: true,
matchBrackets: true,
mode: 'text/x-scss',
colorpicker: true
});
mobile_css.setSize(null, 900);
ranMobile = true;
2018-06-28 07:28:07 +00:00
}
2018-06-27 02:59:59 +00:00
});