Viewing File: /usr/local/cpanel/whostmgr/docroot/cgi/ncssl/source/public/static/js/common.js
(function($) {
$(document).ready(function () {
const $ncssl = $('#ncssl');
const tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'));
const tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
return new bootstrap.Tooltip(tooltipTriggerEl)
})
$ncssl.find('[data-cta-btn]').each(function() {
let ctaBtn = $(this);
ctaBtn.click(function() {
const loadingText = ctaBtn.attr('data-ncssl-loading');
ctaBtn.attr('disabled', true);
ctaBtn.text(loadingText);
});
});
if ($('.certificates-table tr').length > 1) {
$('#ready-ssls-table').tableFilter({'filterInputField': '#table-input'});
$('#installed-ssls-table').tableFilter({'filterInputField': '#table-input'});
}
function showAlertMessage(type, message) {
const allowedTypes = ['danger', 'warning', 'success', 'info'];
if (!allowedTypes.includes(type)) {
console.error(`Wrong type of alert message. Only ${allowedTypes.join(', ')} are allowed!`);
}
$(
`<div class="alert alert-${type} alert-dismissible fade show" role="alert">
${message}
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>`
).prependTo('.alert-messages-holder');
}
function httpRedirectChangeHandler(event) {
const classLoader = 'loader';
const toggle = $(event.target);
const alertMessage = 'Oops, please switch toggle again or <a href="https://www.namecheap.com/support/live-chat/ssl.aspx" target="_blank">contact support.</a>'
toggle.addClass(classLoader);
// it's impossible to prevent checkbox. So state before click is reverted:
toggle.prop('checked', !toggle.is(':checked'));
const domain = toggle.data('name');
const certId = toggle.data('ncId');
const user = toggle.data('user');
const expectedStatus = toggle.is(':checked') ? 0 : 1;
const requestUrl = event.data?.endpoint === 'toggle_redirect'
? `index.live.php?p=/ssls/toggle_redirect&domain=${domain}&expectedStatus=${expectedStatus}&certId=${certId}`
: `index.live.php?p=/ssls/toggle_redirect_auto_general&user=${user}&expectedStatus=${expectedStatus}`;
$.get(
requestUrl,
function (data) {
if (data.status === 'fail') {
toggle.prop('checked', !expectedStatus);
showAlertMessage('danger', alertMessage);
} else {
toggle.prop('checked', !!expectedStatus);
}
}
).fail(function (err) {
toggle.prop('checked', !expectedStatus);
showAlertMessage('danger', alertMessage);
}).always(function(){
toggle.removeClass(classLoader);
});
}
$ncssl.find('[data-http-redirect-input] input').click({endpoint: 'toggle_redirect'}, httpRedirectChangeHandler);
// @TODO will work after SSLP-43535
$ncssl.find('[data-http-redirect-input-auto] input').click({endpoint: 'toggle_redirect_auto_general'}, httpRedirectChangeHandler);
$ncssl.find('[data-password-toggle]').click(function () {
const $input = $(this).closest('.input-group').find('input');
if ($input.length === 0) {
return false;
}
if ($input.attr('type') === 'password') {
$input.attr('type', 'text');
$(this).find('span').removeClass('glyphicon-eye-close').addClass('glyphicon glyphicon-eye-open');
} else {
$input.attr('type', 'password');
$(this).find('span').removeClass('glyphicon-eye-open').addClass('glyphicon glyphicon-eye-close');
}
return false;
});
/* Modal */
//Initialize modals for handling via JS
const renewalRedirectModal = new bootstrap.Modal('#renewalRedirectModal');
const reorderRedirectModal = new bootstrap.Modal('#reorderRedirectModal');
$ncssl.find('[data-renewal-modal-toggle]').click(function () {
const $modal = $ncssl.find('#renewalRedirectModal');
if (!$modal.length) {
return;
}
$modal.find('[data-redirect-link]').prop('href', $(this).data('href'));
renewalRedirectModal.show();
});
$ncssl.find('[data-reorder-modal-toggle]').click(function () {
const $modal = $ncssl.find('#reorderRedirectModal');
if (!$modal.length) {
return;
}
$modal.find('[data-redirect-link]').prop('href', $(this).data('href'));
reorderRedirectModal.show();
});
})
})(jQuery);
Back to Directory
File Manager