View file public/system/ajax.js

File size: 7.28Kb
/*
	Вывод поиска пользователей
*/
function showSearchPeople(type) {
	switch(type) {
		case 2: {
			if($('#searchPeople2').length) {
				$('#searchPeople2').modal('show');
			}
			else {
				SendPost('/application/backstage/Modals.php', {
					searchPeople2: 1
				}, (Result) => {
					$('body').append(Result.Content);
				});
			}
			
			break;
		}
		
		default: {
			if($('#searchPeople').length) {
				$('#searchPeople').modal('show');
			}
			else {
				SendPost('/application/backstage/Modals.php', {
					searchPeople: 1
				}, (Result) => {
					$('body').append(Result.Content);
				});
			}
		}
	}
}

/*
	Массовая рассылка
*/
function showMassMailing() {
	if($('#massMailing').length) {
		$('#massMailing').modal('show');
	}
	else {
		SendPost('/application/backstage/Modals.php', {
			massMailing: 1
		}, (Result) => {
			$('body').append(Result.Content);
		});
	}
}

/*
	Добавление к массовой рассылке
*/
function addMassMailing(userid, name) {
	if(isAddMassMailing(userid)) {
		return;
	}
	
	$('#massMailing form > .Recipients > .Header > .List').append(`
		<div class="Item" data-userid="` + userid + `">
			<span>` + name + `</span>
			<button onclick="removeRecipients(` + userid + `);" type="button"><i class="bi bi-trash"></i></button>
			<input type="hidden" name="recipient[]" value="` + userid + `">
		</div>
	`);
}

function isAddMassMailing(userid) {
	return $('#massMailing form > .Recipients > .Header > .List').find('[data-userid="' + userid + '"]').length;
}

/*
	Удаление получателя
*/
function removeRecipients(userid) {
	$('#massMailing form > .Recipients > .Header > .List').find('[data-userid="' + userid + '"]').remove();
}

/*
	Правки при изменение размеров
*/
function handleResize() {
	if(isMobile.any()) {
		if($('#SendMessage').length) {
			$('.Messenger > .Start').css({
				'display': 'none'
			});
		}
	}
	else {
		$('.Messenger > .Start').css({
			'display': 'flex'
		});
	}
}

/*
	Отправка уведомлений в Браузер
*/
/*function sendNoty(title, message, link) {
	if(Notification.permission === "granted") {
		const options = {
			icon: "/public/images/system/favicon.svg",
			body: message
		};
		
		var Noty = new Notification(title, options);
		
		Noty.onclick = (Event) => {
			Event.preventDefault();
			window.open(link);
		};
	}
	else if(Notification.permission !== 'denied') {
		Notification.requestPermission().then(function(permission) {
			if(permission === "granted") {
				sendNoty(title, message);
			}
		});
	}
}*/

$(function() {
	handleResize();
	
	$(window).resize(function() {
		handleResize();
	});
	
	$('form[data-action]').submit(function(Event) {
		Event.preventDefault();
		
		switch($(this).data('action')) {
			/* Авторизация */
			case 'AccountAuth': {
				SendPost('/application/backstage/Guest.php', {
					Auth: 1, this: this
				}, (Result) => {
					ShowToasty(Result.Message, Result.Alert);
					
					switch(Result.Alert) {
						case 'Info':
						case 'Success':
							Redirect('/', 300);
						break;
					}
				});
				
				break;
			}
			
			/* Регистрация */
			case 'AccountRegister': {
				SendPost('/application/backstage/Guest.php', {
					Register: 1, this: this
				}, (Result) => {
					ShowToasty(Result.Message, Result.Alert);
					
					switch(Result.Alert) {
						case 'Info':
						case 'Success':
							Redirect('/account/auth', 300);
						break;
					}
				});
				
				break;
			}
			
			/* Изменение имени */
			case 'SettingsEditName': {
				SendPost('/application/backstage/Settings.php', {
					EditName: 1, this: this
				}, (Result) => {
					ShowToasty(Result.Message, Result.Alert);
				});
				
				break;
			}
			
			/* Изменение пароля */
			case 'SettingsEditPassword': {
				SendPost('/application/backstage/Settings.php', {
					EditPassword: 1, this: this
				}, (Result) => {
					ShowToasty(Result.Message, Result.Alert);
				});
				
				break;
			}
			
			/* Изменение аватара */
			case 'SettingsChangeImage': {
				SendPost('/application/backstage/Settings.php', {
					changeImage: 1, this: this
				}, (Result) => {
					if(Result.Alert != 'Error') {
						$('[data-action="SettingsChangeImage"]')[0].reset();
						$('.Avatar > img').attr('src', Result.Image);
					}
					
					ShowToasty(Result.Message, Result.Alert);
				});
				
				break;
			}
			
			/* Изменение основных настроек */
			case 'AdminChangePrimary': {
				SendPost('/application/backstage/Admin.php', {
					AdminChangePrimary: 1, this: this
				}, (Result) => {
					ShowToasty(Result.Message, Result.Alert);
				});
				
				break;
			}
			
			/* Редактирование учётной записи */
			case 'AdminChangePeople': {
				SendPost('/application/backstage/Admin.php', {
					AdminChangePeople: 1, this: this
				}, (Result) => {
					ShowToasty(Result.Message, Result.Alert);
				});
				
				break;
			}
			
			default: {
				Lang($('#language').val(), function(data) {
					ShowToasty(data.system_action_not_valid, 'warning');
				});
			}
		}
	});
	
	$('[data-bs-toggle=\'popover\']').popover();
	$('[data-bs-toggle=\'tooltip\']').tooltip();
	
	if($('.js-smartphoto').length) {
		$('.js-smartphoto').SmartPhoto();
	}
	
	/*
		Проверка на использование Хрома
	*/
	if(isMobile.any() == null) {
		if(detectOS() === 'Windows') {
			if(localStorage.getItem("infoChromeClose") != "1") {
				if(!isChrome) {
					Lang($('#language').val(), function(data) {
						if(/Windows NT 10/.test(navigator.userAgent)) {
							$('body').append(`
								<div class="installChrome">
									<img src="/public/images/system/chrome.svg">
									<span>` + data.system_chrome + `</span>
									
									${is64Bit ? '<a href="/public/uploads/programs/windows10/ChromeStandaloneSetup64.exe" download="ChromeStandaloneSetup64.exe">Google Chrome</a>' : '<a href="/public/uploads/programs/windows10/ChromeStandaloneSetup.exe" download="ChromeStandaloneSetup.exe">Google Chrome</a>'}
									
									<button onclick="dontShowInfoChrome();">
										<i class="bi bi-x"></i>
									</button>
								</div>
							`);
						}
						else if(/Windows NT 6.1/.test(navigator.userAgent)) {
							$('body').append(`
								<div class="installChrome">
									<img src="/public/images/system/chrome.svg">
									<span>` + data.system_chrome + `</span>
									
									${is64Bit ? '<a href="/public/uploads/programs/windows7/ChromeStandaloneSetup64.exe" download="ChromeStandaloneSetup64.exe">Google Chrome</a>' : '<a href="/public/uploads/programs/windows7/ChromeStandaloneSetup.exe" download="ChromeStandaloneSetup.exe">Google Chrome</a>'}
									
									<button onclick="dontShowInfoChrome();">
										<i class="bi bi-x"></i>
									</button>
								</div>
							`);
						}
					});
				}
			}
		}
	}
	
	/*
		Включение уведомлений
	*/
	/*if('Notification' in window) {
		if(Notification.permission !== 'denied') {
			Notification.requestPermission().then;
		}
	}*/
});