451 lines
14 KiB
JavaScript
Executable File
451 lines
14 KiB
JavaScript
Executable File
function tr(string) {
|
|
if (window.locale === 'tm') {
|
|
return string
|
|
}
|
|
|
|
return {
|
|
'TÜRKMENISTANYŇ "TÜRKMENBAŞY" PAÝDARLAR TÄJIRÇILIK BANKY': 'АКЦИОНЕРНЫЙ КОММЕРЧЕСКИЙ БАНК ТУРКМЕНИСТАНА «ТУРКМЕНБАШИ»',
|
|
'Sorag-jogap merkezi:': 'Вопросы:',
|
|
'Gözleg': 'Поиск',
|
|
'«ALTYN ASYR» töleg ulgamynyň bankomatlaryny ulanmak boýunça gözükdiriji': 'Руководство по использованию банкоматов платежной системы «ALTYN ASYR»',
|
|
'Töleg terminalyny ulanmak boýunça gözükdiriji': 'Руководство по использованию платежного терминала',
|
|
'Töleg terminallaryny gurnamak üçin hödürlenmeli resminamalaryň sanawy': 'Перечень документов, которые необходимо предоставить для установки платежных терминалов',
|
|
'TÄZELIKLER WE MAKALALAR': 'НОВОСТИ И БЛОГИ',
|
|
'Çandybil şaýoly, 121': 'Чандыбил Шайолы',
|
|
'Aşgabat, Türkmenistan, 744000': 'Ашхабад, Туркменистан',
|
|
'Aşgabat (Merkezi diwany):': 'Ашхабад (Merkezi diwany):'
|
|
}[string];
|
|
}
|
|
|
|
function $_ID(id) {
|
|
return document.getElementById(id)
|
|
}
|
|
|
|
function removeByClassName(className) {
|
|
Array.from(document.getElementsByClassName(className)).forEach(item => item.remove())
|
|
}
|
|
|
|
function baseUrl() {
|
|
return 'http://localhost:5050';
|
|
}
|
|
|
|
function postData(url = '', data = {}) {
|
|
return fetch(baseUrl() + url, {
|
|
method: 'GET',
|
|
headers: {
|
|
'Accept': 'application/json',
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify(data)
|
|
})
|
|
.then(response => response.json());
|
|
}
|
|
|
|
function getCurrentLang()
|
|
{
|
|
return window.location.search.includes('lang=ru') ? 'ru' : '';
|
|
}
|
|
|
|
function isHomepage() {
|
|
return location.pathname === '/';
|
|
}
|
|
|
|
function isCategoryPage() {
|
|
return location.pathname === '/page.html';
|
|
}
|
|
|
|
function isBannerPage() {
|
|
return location.pathname === '/banner.html';
|
|
}
|
|
|
|
function isMiniCategoryPage() {
|
|
return location.pathname === '/action.html';
|
|
}
|
|
|
|
function isNewsPage() {
|
|
return location.pathname === '/news.html';
|
|
}
|
|
|
|
function initializeBasicFunctions() {
|
|
|
|
}
|
|
|
|
function setTranslations() {
|
|
const pageURL = new URL(location);
|
|
window.locale = ! pageURL.searchParams.has('lang') || pageURL.searchParams.get('lang') !== 'ru' ? 'tm' : 'ru';
|
|
|
|
if (window.locale !== 'ru') {
|
|
return;
|
|
}
|
|
|
|
Array.from(document.getElementsByClassName('translate-text')).forEach(item => {
|
|
item.innerText = tr(item.innerText)
|
|
})
|
|
|
|
Array.from(document.getElementsByClassName('translate-placeholder')).forEach(item => {
|
|
item.placeholder = tr(item.placeholder)
|
|
})
|
|
}
|
|
|
|
function fetchPhoneNumbers()
|
|
{
|
|
fetch(baseUrl() + '/api/v1/setting/get')
|
|
.then(response => response.json())
|
|
.then(response => {
|
|
if (! response.status) {
|
|
return;
|
|
}
|
|
|
|
removeByClassName('phone-loaders');
|
|
|
|
$_ID('fax-number').innerText = response.data.faxNumber
|
|
$_ID('phone-number').innerText = response.data.phoneNumber
|
|
$_ID('help-number').innerText = tr('Sorag-jogap merkezi:') + ' ' + response.data.helpNumber
|
|
$_ID('year-logo').src = baseUrl() + response.data.logoR;
|
|
|
|
// second alignment of phone numbers
|
|
if (isHomepage()) {
|
|
$_ID('fax-number-second').innerText = response.data.faxNumber
|
|
$_ID('phone-number-second').innerText = response.data.phoneNumber
|
|
$_ID('help-number-second').innerText = tr('Sorag-jogap merkezi:') + ' ' + response.data.helpNumber
|
|
}
|
|
|
|
// Footer phone numbers
|
|
$_ID('footer-phone-number').innerText = response.data.phoneNumber
|
|
$_ID('footer-fax-number').innerText = response.data.faxNumber
|
|
})
|
|
}
|
|
|
|
async function fetchMenuItems() {
|
|
const container = $_ID('menu-items-container')
|
|
const sideBarMenuItems = $_ID('sidebar-menu-items')
|
|
|
|
const response = await postData('/api/v1/category/categories')
|
|
|
|
response.data.forEach(menuItem => {
|
|
let subcategoriesTemplate = '';
|
|
|
|
if (menuItem.subCat && menuItem.subCat.length > 0 ) {
|
|
menuItem.subCat.forEach(subcategory => {
|
|
if (subcategory.UUID && subcategory.name) {
|
|
subcategoriesTemplate += `
|
|
<li>
|
|
<a class="bg-trasparent lg:bg-white" href="${
|
|
(subcategory.link || subcategory.pdf)
|
|
? subcategory.link ? subcategory.link : subcategory.pdf
|
|
: '/page.html?uuid=' + subcategory.UUID + '&lang=' + getCurrentLang()
|
|
}">
|
|
${subcategory.name[window.locale]}
|
|
</a>
|
|
</li>
|
|
`;
|
|
}
|
|
})
|
|
}
|
|
|
|
container.insertAdjacentHTML('beforeend', `
|
|
<div class="dropdown" style="z-index:1000">
|
|
<button class="dropbtn flex items-center">
|
|
${menuItem.name[window.locale]}
|
|
${
|
|
subcategoriesTemplate !== ''
|
|
? '<img class="w-4 h-4" src="/images/arrow-down.svg" alt="">'
|
|
: ''
|
|
}
|
|
</button>
|
|
<div class="dropdown-content">
|
|
${subcategoriesTemplate}
|
|
</div>
|
|
</div>
|
|
`)
|
|
|
|
sideBarMenuItems.insertAdjacentHTML('beforeend', `
|
|
${
|
|
subcategoriesTemplate === ''
|
|
? `<li><a>${menuItem.name[window.locale]}</a></li>`
|
|
: `
|
|
<li>
|
|
<details class="w-[250px]">
|
|
<summary>${menuItem.name[window.locale]}</summary>
|
|
<ul>
|
|
${subcategoriesTemplate}
|
|
</ul>
|
|
</details>
|
|
</li>
|
|
`
|
|
}
|
|
`)
|
|
})
|
|
}
|
|
|
|
async function fetchSliders() {
|
|
const imageSliderContainer = $_ID('slider-images-container')
|
|
|
|
const response = await postData('/api/v1/main_slider/get-all')
|
|
|
|
removeByClassName('homepage-slider-loader')
|
|
|
|
response.data.forEach(slider => {
|
|
imageSliderContainer.insertAdjacentHTML('beforeend', `
|
|
<swiper-slide>
|
|
|
|
<a href="${
|
|
slider.UUID
|
|
? `/banner.html?uuid=${slider.UUID}` + '&lang=' + getCurrentLang()
|
|
: ''
|
|
}">
|
|
<img
|
|
src="${baseUrl() + slider.slider}"
|
|
class="mx-auto w-fit cursor-pointer" alt="slider"
|
|
>
|
|
</a>
|
|
|
|
</swiper-slide>
|
|
|
|
`)
|
|
})
|
|
}
|
|
|
|
async function fetchMiniSliders() {
|
|
const imageSliderContainer = $_ID('mini-slider')
|
|
const dotsContainer = $_ID('mini-slider-dots-container')
|
|
|
|
const response = await postData('/api/v1/mini_slider/get-all')
|
|
|
|
removeByClassName('minislider-loader')
|
|
|
|
let count = 0;
|
|
response.data.forEach(slider => {
|
|
count++;
|
|
|
|
imageSliderContainer.insertAdjacentHTML('beforeend', `
|
|
<div class="mySlides fade w-full relative">
|
|
<div class="numbertext"></div>
|
|
<img class="w-full" src="${baseUrl() + slider.path}" loading="lazy">
|
|
<div
|
|
class="text mb-5 py-5 px-3 text-white text-2xl"
|
|
style="background-color: rgba(0, 0, 0, .75)"
|
|
>${slider.title['tm']}</div>
|
|
</div>
|
|
`)
|
|
})
|
|
|
|
initializeMiniSlider()
|
|
}
|
|
|
|
async function fetchMiniCategories() {
|
|
const miniCategoryContainer = $_ID('mini-category-content-container')
|
|
|
|
const response = await postData('/api/v1/mini_category/get-all')
|
|
|
|
removeByClassName('mini-categories-loader')
|
|
|
|
response.data.forEach(category => {
|
|
miniCategoryContainer.insertAdjacentHTML('beforeend', `
|
|
<a href="/action.html?uuid=${category.UUID + '&lang=' + getCurrentLang()}">
|
|
<div class="bg-gray-100 flex flex-1 flex-col items-center gap-3 py-7 px-3 mt-2 rounded-md">
|
|
<img src="${baseUrl() + category.path}" class="w-16 h-16" alt="..." loading="lazy">
|
|
<h1 class="text-gray-700 uppercase text-center">${category.title[window.locale]}</h1>
|
|
</div>
|
|
</a>
|
|
`)
|
|
})
|
|
}
|
|
|
|
async function fetchCurrencies() {
|
|
const currencyTable = $_ID('currency-table')
|
|
const response = await postData('/api/v1/currency/get')
|
|
|
|
removeByClassName('currency-table-loader')
|
|
currencyTable.innerHTML = response.data.content[window.locale];
|
|
currencyTable.querySelector('table').classList.add('table-auto', 'bg-gray-500', 'text-sm', 'text-white', 'w-full')
|
|
|
|
Array.from(currencyTable.getElementsByTagName('th')).forEach(item => {
|
|
item.classList.add('p-2')
|
|
})
|
|
|
|
Array.from(currencyTable.getElementsByTagName('td')).forEach(item => {
|
|
item.classList.add('p-2')
|
|
|
|
if (item.hasAttribute('colwidth') && item.getAttribute('colwidth') !== '' || item.getAttribute('colwidth') !== null) {
|
|
item.setAttribute('style', `width: ${item.getAttribute('colwidth')}px`);
|
|
}
|
|
})
|
|
|
|
$_ID('currency-message-container').innerHTML = response.data.title[window.locale];
|
|
}
|
|
|
|
async function fetchNews() {
|
|
const newsContainer = $_ID('news-content-container')
|
|
const response = await postData('/api/v1/news/get-all')
|
|
|
|
removeByClassName('news-loaders')
|
|
let count = 0;
|
|
response.data.forEach(news => {
|
|
count++;
|
|
|
|
if (count > 6) {
|
|
return
|
|
}
|
|
|
|
newsContainer.insertAdjacentHTML('beforeend', `
|
|
<a href="news.html?uuid=${news.UUID + '&lang=' + getCurrentLang()}">
|
|
<div class="flex flex-col px-3 mt-3">
|
|
<div class="h-60">
|
|
<img src="${baseUrl() + news.path}" class="news-img-size" alt="..." loading="lazy">
|
|
</div>
|
|
<h1 class="text-base text-gray-800 mt-2 py-2 px-1 text-center">${news.title[window.locale]}</h1>
|
|
</div>
|
|
</a>
|
|
`)
|
|
})
|
|
}
|
|
|
|
async function fetchSubCategory() {
|
|
const pageURL = new URL(location);
|
|
|
|
if (! pageURL.searchParams.has('uuid')) {
|
|
return;
|
|
}
|
|
|
|
const pageContent = $_ID('page-content');
|
|
|
|
const response = await postData('/api/v1/category/sub-get', {
|
|
UUID: pageURL.searchParams.get('uuid')
|
|
})
|
|
|
|
removeByClassName('page-content-loader')
|
|
|
|
pageContent.innerHTML = `
|
|
<h1 id="page-title" class="uppercase mt-5 mb-5 text-center text-lg green-color text-bold">
|
|
${response.data.name[window.locale]}
|
|
</h1>
|
|
|
|
<div>
|
|
${response.data.content[window.locale]}
|
|
</div>
|
|
`;
|
|
}
|
|
|
|
async function fetchBannerContent() {
|
|
const pageURL = new URL(location);
|
|
|
|
if (! pageURL.searchParams.has('uuid')) {
|
|
return;
|
|
}
|
|
|
|
const pageContent = $_ID('page-content');
|
|
|
|
const response = await postData('/api/v1/main_slider/get', {
|
|
UUID: pageURL.searchParams.get('uuid')
|
|
})
|
|
|
|
removeByClassName('page-content-loader')
|
|
|
|
pageContent.innerHTML = `
|
|
<h1 id="page-title" class="uppercase mt-5 mb-5 text-center text-lg green-color text-bold">
|
|
${response.data.title[window.locale]}
|
|
</h1>
|
|
|
|
<div>
|
|
<img src="${baseUrl() + response.data.path}" class="w-full">
|
|
</div>
|
|
|
|
<div>
|
|
${response.data.content[window.locale]}
|
|
</div>
|
|
`;
|
|
}
|
|
|
|
async function fetchMiniCategory() {
|
|
const pageURL = new URL(location);
|
|
|
|
if (! pageURL.searchParams.has('uuid')) {
|
|
return;
|
|
}
|
|
|
|
const pageContent = $_ID('page-content');
|
|
|
|
const response = await postData('/api/v1/mini_category/get', {
|
|
UUID: pageURL.searchParams.get('uuid')
|
|
})
|
|
|
|
removeByClassName('page-content-loader')
|
|
|
|
pageContent.innerHTML = `
|
|
<h1 id="page-title" class="uppercase mt-5 mb-5 text-center text-lg green-color text-bold">
|
|
${response.data.title[window.locale]}
|
|
</h1>
|
|
|
|
<div>
|
|
${response.data.content[window.locale]}
|
|
</div>
|
|
`;
|
|
}
|
|
|
|
async function fetchNewsContent() {
|
|
const pageURL = new URL(location);
|
|
|
|
if (! pageURL.searchParams.has('uuid')) {
|
|
return;
|
|
}
|
|
|
|
const pageContent = $_ID('page-content');
|
|
|
|
const response = await postData('/api/v1/news/get', {
|
|
UUID: pageURL.searchParams.get('uuid')
|
|
})
|
|
|
|
removeByClassName('page-content-loader')
|
|
|
|
pageContent.innerHTML = `
|
|
<h1 id="page-title" class="uppercase mt-5 mb-5 text-center text-lg green-color text-bold">
|
|
${response.data.title[window.locale]}
|
|
</h1>
|
|
|
|
<div class="mb-5">
|
|
<img class="w-full max-h-[600px] object-contain" src="${baseUrl() + response.data.path}">
|
|
</div>
|
|
|
|
<div>
|
|
<p class="mb-2">
|
|
${ new Date(response.data.date).toLocaleDateString('en-GB').replace(/\//g, '.') + 'ý' }
|
|
</p>
|
|
|
|
${response.data.content[window.locale]}
|
|
</div>
|
|
`;
|
|
}
|
|
|
|
document.addEventListener('DOMContentLoaded', event => {
|
|
initializeBasicFunctions()
|
|
setTranslations()
|
|
fetchPhoneNumbers()
|
|
fetchMenuItems()
|
|
|
|
if (isHomepage()) {
|
|
fetchSliders()
|
|
fetchCurrencies()
|
|
fetchMiniSliders()
|
|
fetchNews()
|
|
}
|
|
|
|
if (isCategoryPage()) {
|
|
fetchSubCategory()
|
|
}
|
|
|
|
if (isBannerPage()) {
|
|
fetchBannerContent()
|
|
}
|
|
|
|
if (isMiniCategoryPage()) {
|
|
fetchMiniCategory()
|
|
}
|
|
|
|
if (isNewsPage()) {
|
|
fetchNewsContent()
|
|
}
|
|
|
|
fetchMiniCategories()
|
|
})
|