,
// which closes the block early and turns the value into markup.
var suffix = ".healthcare.dvsoft.in";
// Mirrors the reserved list in App\Core\Tenant::isSlugAvailable().
var reserved = ['admin', 'app', 'www', 'api', 'control', 'support', 'billing', 'status', 'mail', 'test'];
function tidy(value) {
// Apostrophes vanish rather than becoming separators, matching
// SignupController::slugify(): "St Mary's" -> st-marys.
return value.toLowerCase()
.replace(/['’`]/g, '')
.replace(/[^a-z0-9]+/g, '-')
.replace(/^-+|-+$/g, '')
.slice(0, 40);
}
function review() {
var value = input.value;
var clean = tidy(value);
if (clean !== value) {
var atEnd = input.selectionStart === value.length;
input.value = clean;
if (atEnd) { input.setSelectionRange(clean.length, clean.length); }
}
if (clean === '') {
hint.className = 'small mt-1 text-secondary';
hint.textContent = '';
return;
}
if (!/^[a-z][a-z0-9-]{2,39}$/.test(clean)) {
hint.className = 'small mt-1 text-danger';
hint.textContent = 'Must start with a letter and be at least 3 characters.';
return;
}
if (reserved.indexOf(clean) !== -1) {
hint.className = 'small mt-1 text-danger';
hint.textContent = '"' + clean + '" is reserved. Please choose another.';
return;
}
hint.className = 'small mt-1 text-success';
hint.textContent = 'Your staff will sign in at https://' + clean + suffix;
}
input.addEventListener('input', review);
// Offer an address derived from the hospital name, until one is typed.
var name = document.getElementById('hospital_name');
if (name) {
name.addEventListener('input', function () {
if (input.dataset.touched === '1') { return; }
input.value = tidy(name.value);
review();
});
input.addEventListener('input', function () { input.dataset.touched = '1'; });
}
review();
}());
/**
* Show only the price the chosen country pays: rupees for India, dollars
* for everywhere else. Without JavaScript both lines stay visible, which is
* still correct. The server decides the price either way.
*/
(function () {
var country = document.getElementById('country');
if (!country) { return; }
function showPrices() {
var currency = country.value === 'IN' ? 'INR' : 'USD';
document.querySelectorAll('[data-price-currency]').forEach(function (el) {
el.hidden = el.getAttribute('data-price-currency') !== currency;
});
}
country.addEventListener('change', showPrices);
showPrices();
}());