mirror of
https://github.com/getnamingo/registry.git
synced 2025-07-24 19:38:26 +02:00
194 lines
No EOL
8.2 KiB
Twig
194 lines
No EOL
8.2 KiB
Twig
{% extends "layouts/app.twig" %}
|
|
|
|
{% block title %}{{ __('Request Domain Transfer') }}{% endblock %}
|
|
|
|
{% block content %}
|
|
<div class="page-wrapper">
|
|
<!-- Page header -->
|
|
<div class="page-header d-print-none">
|
|
<div class="container-xl">
|
|
<div class="row g-2 align-items-center">
|
|
<div class="col">
|
|
<!-- Page pre-title -->
|
|
<div class="page-pretitle">
|
|
{{ __('Overview') }}
|
|
</div>
|
|
<h2 class="page-title">
|
|
{{ __('Request Domain Transfer') }}
|
|
</h2>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<!-- Page body -->
|
|
<div class="page-body">
|
|
<div class="container-xl">
|
|
<div class="col-12">
|
|
{% include 'partials/flash.twig' %}
|
|
<div class="card">
|
|
<div class="card-body">
|
|
<form id="domainTransferForm" action="/transfer/request" method="post">
|
|
{{ csrf.field | raw }}
|
|
<div class="mb-3">
|
|
<label for="domainName" class="form-label required">{{ __('Domain Name') }}</label>
|
|
<input type="text" class="form-control mb-2" placeholder="example.com" name="domainName" id="domainName" required="required" autocapitalize="none">
|
|
</div>
|
|
|
|
{% if registrars and not registrar %}
|
|
<div class="form-group mb-3">
|
|
<label for="registrarDropdown" class="form-label required">{{ __('Gaining Registrar') }}</label>
|
|
<select id="registrarDropdown" name="registrar" class="form-control">
|
|
{% for registrar in registrars %}
|
|
<option value="{{ registrar.id }}">{{ registrar.name }}</option>
|
|
{% endfor %}
|
|
</select>
|
|
</div>
|
|
{% endif %}
|
|
|
|
<!-- AuthInfo -->
|
|
<div class="mb-3">
|
|
<label for="authInfo" class="form-label required">{{ __('Auth Info') }}</label>
|
|
<input type="text" class="form-control" id="authInfo" name="authInfo" required>
|
|
</div>
|
|
|
|
<!-- Slider for years -->
|
|
<div class="mb-3">
|
|
<label for="transferYears" class="form-label">{{ __('Transfer And Renew') }}</label>
|
|
<input type="range" class="form-range" min="1" max="10" step="1" id="transferYears" name="transferYears" value="1">
|
|
<span id="yearValue">1 Year</span>
|
|
</div>
|
|
|
|
<!-- Placeholder for displaying domain price -->
|
|
<div class="mb-3" id="domainPriceDisplay" style="display:none;">
|
|
<strong>{{ __('Estimated Price') }}: </strong><span id="domainPrice">{{ currency }} 0.00</span>
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label for="token" class="form-label">{{ __('Allocation Token') }}</label>
|
|
<input type="text" class="form-control" placeholder="{{ __('Allocation token') }}" name="token" autocapitalize="none">
|
|
</div>
|
|
|
|
</div>
|
|
<div class="card-footer">
|
|
<div class="row align-items-center">
|
|
<div class="col-auto">
|
|
<button type="submit" class="btn btn-primary">{{ __('Request Transfer') }}</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
{% include 'partials/footer.twig' %}
|
|
</div>
|
|
<script>
|
|
document.addEventListener("DOMContentLoaded", function() {
|
|
|
|
window.currencySymbol = "{{ currencySymbol }}";
|
|
window.currencyPosition = "{{ currencyPosition }}";
|
|
|
|
const yearSlider = document.getElementById('transferYears');
|
|
const yearValueDisplay = document.getElementById('yearValue');
|
|
|
|
// Display year value from slider
|
|
yearSlider.addEventListener('input', function() {
|
|
yearValueDisplay.textContent = `${yearSlider.value} Year${yearSlider.value > 1 ? 's' : ''}`;
|
|
});
|
|
|
|
const domainInput = document.getElementById('domainName');
|
|
const yearInput = document.getElementById('transferYears');
|
|
const priceDisplay = document.getElementById('domainPriceDisplay');
|
|
const priceValue = document.getElementById('domainPrice');
|
|
|
|
function extractTLD(domain) {
|
|
const parts = domain.split('.');
|
|
|
|
// If the domain has more than two segments (e.g., 'test.com.test'), return the last two segments
|
|
if (parts.length > 2) {
|
|
return parts.slice(-2).join('.').toLowerCase();
|
|
}
|
|
// If the domain has two or fewer segments (e.g., 'test.test' or 'test'), return the last segment
|
|
else {
|
|
return parts[parts.length - 1].toLowerCase();
|
|
}
|
|
}
|
|
|
|
function getDomainPrice(domain, years) {
|
|
const tld = extractTLD(domain);
|
|
if (!tld) {
|
|
return Promise.reject("Invalid TLD");
|
|
}
|
|
|
|
// Regular expression for exact TLD match
|
|
const tldRegex = new RegExp(`${tld.toLowerCase()}$`);
|
|
|
|
// Fetch both promotional pricing and regular pricing
|
|
return Promise.all([
|
|
fetch(`/api/records/promotion_pricing?join=domain_tld`).then(response => response.json()),
|
|
fetch(`/api/records/domain_price?join=domain_tld`).then(response => response.json())
|
|
])
|
|
.then(([promoData, pricingData]) => {
|
|
const today = new Date();
|
|
|
|
// Check for a valid promotion
|
|
const promo = promoData.records.find(record =>
|
|
record.tld_id && tldRegex.test(record.tld_id.tld.toLowerCase()) &&
|
|
new Date(record.start_date) <= today &&
|
|
new Date(record.end_date) >= today &&
|
|
(!record.years_of_promotion || record.years_of_promotion >= years)
|
|
);
|
|
|
|
// Find the regular price for the TLD
|
|
const tldData = pricingData.records.find(record =>
|
|
record.tldid && tldRegex.test(record.tldid.tld.toLowerCase()) &&
|
|
record.command === 'transfer'
|
|
);
|
|
|
|
if (tldData) {
|
|
const priceField = `m${years * 12}`;
|
|
let price = parseFloat(tldData[priceField]);
|
|
if (!isNaN(price)) {
|
|
if (promo) {
|
|
// Apply the promotion discount
|
|
price -= (price * parseFloat(promo.discount_percentage) / 100);
|
|
}
|
|
return price;
|
|
}
|
|
}
|
|
return Promise.reject("TLD price not found");
|
|
})
|
|
.catch(error => {
|
|
console.error("Error fetching pricing data:", error);
|
|
return Promise.reject("Error fetching pricing data");
|
|
});
|
|
}
|
|
|
|
function formatPrice(price) {
|
|
switch(window.currencyPosition) {
|
|
case 'before':
|
|
return `{{ currency }} ${price.toFixed(2)}`;
|
|
case 'after':
|
|
return `${price.toFixed(2)} {{ currency }}`;
|
|
default:
|
|
return price.toFixed(2);
|
|
}
|
|
}
|
|
|
|
function updatePrice() {
|
|
if (domainInput.value) {
|
|
getDomainPrice(domainInput.value, yearInput.value).then(price => {
|
|
priceValue.innerText = formatPrice(price);
|
|
priceDisplay.style.display = 'block';
|
|
});
|
|
} else {
|
|
priceDisplay.style.display = 'none';
|
|
}
|
|
}
|
|
|
|
domainInput.addEventListener('input', updatePrice);
|
|
yearInput.addEventListener('input', updatePrice);
|
|
});
|
|
</script>
|
|
{% endblock %} |