You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

368 lines
14 KiB

function check_auth(){
<!-- Получение наименования типа техники -->
var response = false;
$.ajax({
type: 'GET',
url: '/access/check_auth/',
async: false,
success: function(data) {
if (data.code == '1'){
response = true
}
}
});
return response;
}
function auth_go(error){
if (error){
var theForm = $(document.forms['error_auth_form']).serialize();
} else {
var theForm = $(document.forms['auth_form']).serialize();
}
$('p#error_auth').html('');
$.ajax({
type: 'POST',
url: '/access/auth/',
data: theForm,
async: false,
success: function(data) {
if (data.code == '1'){
$('p#error_auth').html('');
$('p#error_auth').fadeOut('fast');
location.reload(false)
} else {
$('p#error_auth').html(data.response);
$('p#error_auth').fadeIn('fast')
}
},
error: function(xhr, str){
console.log('Возникла ошибка auth_go(): ' + xhr.responseCode);
}
});
}
function super_auth_go(error){
if (error){
var theForm = $(document.forms['error_super_auth_form']).serialize();
} else {
var theForm = $(document.forms['super_auth_form']).serialize();
}
$('p#error_super_auth').html('');
$.ajax({
type: 'POST',
url: '/access/auth_from_admin/',
data: theForm,
async: false,
success: function(data) {
if (data.code == '1'){
$('p#error_super_auth').html('');
$('p#error_super_auth').fadeOut('fast');
location.reload(false)
} else {
$('p#error_super_auth').html(data.response);
$('p#error_super_auth').fadeIn('fast')
}
},
error: function(xhr, str){
console.log('Возникла ошибка auth_go(): ' + xhr.responseCode);
}
});
}
function forgot(){
var theForm = $(document.forms['forgot_form']).serialize();
$('#error_forgot').html('');
$.ajax({
type: 'GET',
url: '/access/forgot/',
data: theForm,
async: false,
success: function(data) {
if (data.code == '1'){
$('p#error_forgot').html('');
$('#error_forgot').fadeOut('fast');
document.forms['forgot_form'].reset();
$('#myModal3').modal('hide');
$('#myModal4').modal('show')
} else {
$('#error_forgot').html(data.response);
$('#error_forgot').fadeIn('fast')
}
},
error: function(xhr, str){
console.log('Возникла ошибка forgot(): ' + xhr.responseCode);
}
})
}
function registry_go(){
if ($('#checkBox').prop('checked') != true){
console.log('NOT PASS')
$('#error_registration').html('Перед регистрацией ознакомтесь с договором-оферты');
$('#error_registration').fadeIn('fast');
} else {
console.log('PASS')
$('#error_registration').html('');
$('#error_registration').fadeIn('fast');
var theForm = $(document.forms['registration_form']).serialize();
console.log(theForm)
$.ajax({
type: 'POST',
url: '/access/registration/',
data: theForm,
async: false,
success: function(data) {
if (data.code == '1'){
$('#error_registration').html('');
$('#myModal').modal('hide');
$('#PostRegistration').modal('show');
$('[name=final_form]').append('<input type=text value="'+$('[name=registration_form]').find($('[name=email]')).val()+'" name="email" readonly style="display: none">' +
'<input type=text value="'+$('[name=registration_form]').find($('[name=password1]')).val()+'" name="password" readonly style="display: none">');
document.forms['registration_form'].reset()
} else {
$('#error_registration').html(data.response)
}
},
error: function(xhr, str){
console.log('Возникла ошибка registry_go(): ' + str);
}
});
}
}
function registry_go2(){
$('#error_registration2').html('');
$('#error_registration2').fadeIn('fast');
var theForm = $(document.forms['registration_form2']).serialize();
$.ajax({
type: 'POST',
url: '/access/registration/',
data: theForm,
async: false,
success: function(data) {
if (data.code == '1'){
$('#error_registration').html('');
$('#myModal').modal('hide');
$('#PostRegistration').modal('show');
$('[name=final_form]').append('<input type=text value="'+$('[name=registration_form2]').find($('[name=email]')).val()+'" name="email" readonly style="display: none">' +
'<input type=text value="'+$('[name=registration_form2]').find($('[name=password1]')).val()+'" name="password" readonly style="display: none">');
document.forms['registration_form'].reset()
} else {
$('#error_registration2').html(data.response)
}
},
error: function(xhr, str){
console.log('Возникла ошибка registry_go(): ' + str);
}
});
}
function change_password_func(){
$('#error_change_password').html('');
var theForm = $(document.forms['change_password_form']).serialize();
$('#error_change_password').fadeIn('fast');
$.ajax({
type: 'POST',
url: '/access/change_password/',
data: theForm,
async: false,
success: function(data) {
if (data.code == '1'){
$('#error_change_password').html('Пароль успешно изменен. Авторизуйтесь, используя новый пароль.');
document.forms['change_password_form'].reset();
$(document.forms['change_password_form']).find('input').attr('class', '');
setTimeout(function(){window.location.href=location.protocol+'//'+location.host+'/?auth=true'}, 4000);
} else {
$('#error_change_password').html(data.response)
}
},
error: function(xhr, str){
console.log('Возникла ошибка change_password(): ' + str);
}
});
}
function get_settings_data(){
var response;
$.ajax({
type: 'GET',
url: '/access/get_settings_data/',
async: false,
success: function(data) {
response = data;
},
error: function(xhr, str){
console.log('Возникла ошибка get_settings_data(): ' + xhr.responseCode);
}
});
return response
}
function set_settings_data (){
var data = get_settings_data();
if (data.code == '1'){
$("img[name=user_settings_avatar]").attr('src', data['data']['avatar']);
$("input[name=user_settings_fname]").val(data['data']['fname']);
$("input[name=user_settings_name]").val(data['data']['name']);
$("input[name=user_settings_oname]").val(data['data']['oname']);
$("input[name=user_settings_phone]").val(data['data']['phone']);
$("input[name=user_settings_email]").val(data['data']['email']);
$("input[name=user_settings_city]").val(data['data']['city']).kladr({
type: $.kladr.type.city,
limit: 5
});
$("input[name=user_settings_bday]").val(data['data']['bday']);
$("input[name=user_settings_bday]").datepicker({
format: 'dd.mm.yyyy',
language: 'ru'
});
if (data['data']['avatar_code']){
$('input[name=avatar_code]').val(data['data']['avatar_code']);
$('button[name=user_settings_avatar_remove]').show()
}
}
$('#settingsModal').modal('show')
}
function change_settings(){
$('#error_user_settings').html('');
$('#error_user_settings').fadeIn('fast');
var theForm = $(document.forms['user_settings']).serialize();
$.ajax({
type: 'POST',
url: '/access/send_settings_data/',
data: theForm,
async: false,
success: function(data) {
if (data.code == '1'){
if (data['response']){
$('#error_user_settings').html(data['response'])
} else {
$('#error_user_settings').html('Данные сохранены');
}
reload_user_data();
$('[name=service_request_phone_number]').html($('[name=user_settings_phone]').val())
} else {
$('#error_user_settings').html(data.response)
}
},
error: function(xhr, str){
console.log('Возникла ошибка change_settings(): ' + data.response);
}
});
}
function change_subscription(){
$('#error_subscription').html('');
$('#error_subscription').fadeIn('');
var theForm = $(document.forms['subscription_form']).serialize();
$.ajax({
type: 'POST',
url: '/access/send_subscription_data/',
data: theForm,
async: false,
success: function(data) {
if (data.code == '1'){
if (data['response']){
$('#error_subscription').html(data['response'])
} else {
$('#error_subscription').html('Данные сохранены');
}
} else {
$('#error_subscription').html(data.response)
}
},
error: function(xhr, str){
console.log('Возникла ошибка change_subscription(): ' + data.response);
}
});
}
function get_subscription_data(){
var response;
$.ajax({
type: 'GET',
url: '/access/get_subscription_data/',
async: false,
success: function(data) {
response = data;
},
error: function(xhr, str){
console.log('Возникла ошибка get_settings_data(): ' + xhr.responseCode);
}
});
return response
}
function set_subscription_data (){
var data = get_subscription_data();
if (data.code == '1'){
for (var i in data.data){
if (data['data'][i]){
$('[name=subscription_'+i+']').attr('checked', true)
} else {
$('[name=subscription_'+i+']').attr('checked', false)
}
}
}
$('#subscriptionModal').modal('show')
}
function check_password_compare(){
var passwd = $("input[name$='password2']");
if (passwd.val().length >= 6 && passwd.val() == $("input[name$='password1']").val()){
passwd.attr('class', 'alert-success');
} else {
passwd.attr('class', 'alert-danger');
}
}
function get_user_role(id){
var response = '';
$.ajax({
type: 'GET',
url: '/access/get_user_role/',
data: {'id': id},
async: false,
success: function(data) {
if (data.code == '1'){
response = data['data']
}
}
});
return response;
}
function reload_user_data(){
var data = get_settings_data();
// Имя reloader_name="avatar"
$('img[reloader_name=avatar]').attr('src', data['data']['avatar']);
// Аватар
$('[reloader_name=user_name]').html(data['data']['short_name']);
$('[reloader_name=name]').html(data['data']['name']);
$('[reloader_name=fname]').html(data['data']['fname']);
$('[reloader_name=oname]').html(data['data']['oname']);
$('[reloader_name=city]').html('г. ' + data['data']['city']);
}
function check_active(){
var response = '';
if ($('[name=REQUEST_USER_ID]').val() != 'None'){
$.ajax({
type: 'GET',
url: '/access/check_active/',
async: false,
success: function(data) {
if (data.code == '1'){
response = true;
} else {
response = false;
}
}
});
} else {
$('#myModal').modal('show');
response = false;
}
return response;
}
function resent_active_email(){
$.ajax({url: '/access/resent_active_email'});
}