%PDF- %PDF-
| Direktori : /proc/self/root/home/bitrix/www/local/templates/UB/components/UB/main.profile/.default/ |
| Current File : //proc/self/root/home/bitrix/www/local/templates/UB/components/UB/main.profile/.default/script.js |
function showFeedback() {
$('#help_profile_popup').modal('hide');
$('#main-feedback-button').click();
}
function showWelcome(name) {
$.get(
name,
function(data) {
$('#help_profile_popup div.modal-body').html(data);
$('#help_profile_popup').modal('show');
}
);
}
function toTranslit(text) {
return text.replace(/([а-яё])|([\s_-])|([^a-z\d])/gi,
function (all, ch, space, words, i) {
if (space || words) {
return space ? '_' : '';
}
var code = ch.charCodeAt(0),
index = code == 1025 || code == 1105 ? 0 :
code > 1071 ? code - 1071 : code - 1039,
t = ['yo', 'a', 'b', 'v', 'g', 'd', 'e', 'zh',
'z', 'i', 'y', 'k', 'l', 'm', 'n', 'o', 'p',
'r', 's', 't', 'u', 'f', 'h', 'c', 'ch', 'sh',
'shch', '', 'y', '', 'e', 'yu', 'ya'
];
return t[index];
}).toLowerCase();
}
function checkForm() {
var errors = '';
$('form#form_main_profile').find('input[data-required]').each(function(){
$('#'+$(this).attr('data-required')).removeClass('required_error');
if ($(this).val().length<3) {
errors += LO_MESS["REQUIRED_FIELD"]+$('#'+$(this).attr('data-required')).text().replace(/: \*/g,'')+LO_MESS["IS_NOT_FILLED"];
$('#'+$(this).attr('data-required')).addClass('required_error');
}
});
$('form#form_main_profile').find('select[data-required]').each(function(){
$('#'+$(this).attr('data-required')).removeClass('required_error');
if ($(this).find('option:selected').length==0 || $(this).find('option:selected').attr('value')==0) {
errors += LO_MESS["FOR_REQUIRED_FIELD"]+$('#'+$(this).attr('data-required')).text().replace(/: \*/g,'')+LO_MESS["VALUE_IS_NOT_SELECT"];
$('#'+$(this).attr('data-required')).addClass('required_error');
}
});
bdate = $('form#form_main_profile input#PERSONAL_BIRTHDAY').val();
if (bdate.length==0 || bdate=='__.__.____' || bdate=='__/__/____')
$('form#form_main_profile input#PERSONAL_BIRTHDAY').val('');
else {
// Выделить год из шаблона даты и проверить
a = bdate.split('.');
if (parseInt(a[2])>yearEnd_BD) errors = LO_MESS["SPECIFIED_YEAR_OF_BIRTH_IS_NOT_VALID"];
}
// Проверяем социальные сети
$('form#form_main_profile').find('input[name="UF_SOCIAL[]"]').each(function() {
url = $(this).val();
if (url.length>0 && $(this).val().indexOf($(this).attr('data-url'))==-1) {
$(this).val($(this).attr('data-url')+'.com/'+$(this).val());
}
});
if (errors.length>0) {
// выводим сообщение об ошибке (в предварительно определенный слой)
$('#required-error-alert > span').html(errors);
$('#required-error-alert').show();
scroll(0,0);
return false;
}
else {
$("input[name='SINGLE_PROFILE']").prop("disabled",false);
return true;
};
}
function addSocItem(){
$('#socItems').append(
'<input type="text" class="form-control" name="UF_SOCIAL[]" maxlength="255" value="" />'
);
}
function addAliasItem(alias) {
if (alias.length==0) return;
if (alias.length>40) alias = alias.substr(0,40);
exist=false;
$('#PROFILE_NAME > option').each(function(){
if ($(this).val()==alias) exist=true;
});
if (exist) return;
$('#PROFILE_NAME').append('<option>'+alias+'</option>');
}
function prof_name_vs(setDef) {
// Формирование вариантов отбражения
var names = [$('input[name="PERSONAL_PROFESSION"]').val(),$('input[name="NAME"]').val(),$('input[name="LAST_NAME"]').val()];
if (setDef) { // Стираем старые варианты
$('#PROFILE_NAME').html("");
$("#PROFILE_NAME").trigger("chosen:updated");
}
addAliasItem($('input[name="PERSONAL_PROFESSION"]').val());
names.forEach(function(value, index, ar) {
if (value.length>0) {
ar.forEach(function(v,i,a){
if (v.length>0 && index!=i) value += ' '+v;
});
}
addAliasItem(value);
});
$("#PROFILE_NAME").trigger("chosen:updated");
if (setDef) $("#PROFILE_CODE").attr('value', toTranslit($("#PROFILE_NAME").find('option:selected').text()));
}
var listCountries = $.masksSort($.masksLoad("/phone-codes.json"), ['#'], /[0-9]|#/, "mask");
var maskOpts = {
inputmask: {
definitions: {
'#': {
validator: "[0-9]",
cardinality: 1
}
},
showMaskOnHover: false,
autoUnmask: true,
clearMaskOnLostFocus: false
},
match: /[0-9]/,
replace: '#',
listKey: "mask"
};
$(document).ready(function(){
$('#change_password').click(function(){
$('tr.password').show();
$('tr.change_password').hide();
});
$("input[name='SINGLE_PROFILE']").change(function(){
if ($(this).prop("checked")){
$("#btn-merge").click();
$(this).prop("checked", false);
};
});
$("#merge_yes").click(function(){
$("input[name='SINGLE_PROFILE']").prop("checked", true);
$("#subm_save").click();
});
$('.bx-auth-profile').find('select').chosen({disable_search_threshold: 10, width: "100%"});
$('#PROFILE_NAME').chosen().change(function(){
$("#PROFILE_CODE").attr('value', toTranslit($("#PROFILE_NAME").find('option:selected').text()));
});
$("#PROFILE_NAME").each(function(){
$("input.prof_fio").each(function(){
prof_name_vs(false);
$("input.prof_fio").keyup(function(){
prof_name_vs(true);
});
});
});
$("#PERSONAL_STATE").change(function () {
sid = $(this).val();
$.ajax({
url: "/local/components/UB/main.profile/ajax.php",
type: "GET",
data: {v: 2, sid: sid},
dataType: "html",
success: function(html){
$('#PERSONAL_CITY').html(html);
if ($('input#arUser_prof_CITY').attr('value')>0)
$('#PERSONAL_CITY option[value="'+$('input#arUser_prof_CITY').attr('value')+'"]').prop("selected", true);
$("#PERSONAL_CITY").prop('disabled',false);
$("#PERSONAL_CITY").trigger('chosen:updated');
}
});
});
$("#PERSONAL_COUNTRY").chosen().change(function () {
sid = $(this).val();
$("#PERSONAL_CITY").html('');
$("#PERSONAL_STATE").html('');
$("#PERSONAL_STATE").prop('disabled',true);
$("#PERSONAL_CITY").prop('disabled',true);
$("#PERSONAL_STATE").trigger('chosen:updated');
$("#PERSONAL_CITY").trigger('chosen:updated');
$.ajax({
url: "/local/components/UB/main.profile/ajax.php",
type: "GET",
data: {v: 1, sid: sid},
dataType: "html",
success: function(html){
if (html!='<option value=""></option>') { // Если регионы для страны определены
$("#PERSONAL_STATE").html(html);
if ($('input#arUser_prof_RN').attr('value')>0)
$('#PERSONAL_STATE option[value="'+$('input#arUser_prof_RN').attr('value')+'"]').prop("selected", true);
else
$('#PERSONAL_STATE :first').remove();
$("#PERSONAL_STATE").prop('disabled',false);
$("#PERSONAL_STATE").trigger('chosen:updated');
$("#PERSONAL_STATE").trigger('change');
}
else {
$.ajax({
url: "/local/components/UB/main.profile/ajax.php",
type: "GET",
data: {v: 2, sid: sid},
dataType: "html",
success: function(html){
$("#PERSONAL_CITY").html(html);
if ($('input#arUser_prof_CITY').attr('value')>0) {
$('#PERSONAL_CITY option[value="'+$('input#arUser_prof_CITY').attr('value')+'"]').prop("selected", true);
}
$("#PERSONAL_CITY").prop('disabled',false);
$("#PERSONAL_CITY").trigger('chosen:updated');
}
});
}
}
});
});
$("#PERSONAL_COUNTRY").trigger('change');
/*
if($("#PERSONAL_COUNTRY").val()>0) $("#PERSONAL_COUNTRY").trigger('change')
else {
$("#PERSONAL_STATE").prop('disabled',false);
$("#PERSONAL_STATE").trigger('chosen:updated');
$("#PERSONAL_CITY").prop('disabled',false);
$("#PERSONAL_CITY").trigger('chosen:updated');
}
*/
$('input[id^="PHONE"]').inputmasks($.extend(true, {}, maskOpts, {
list: listCountries
}));
});
function removeElement(arr, sElement)
{
var tmp = new Array();
for (var i = 0; i<arr.length; i++) if (arr[i] != sElement) tmp[tmp.length] = arr[i];
arr=null;
arr=new Array();
for (var i = 0; i<tmp.length; i++) arr[i] = tmp[i];
tmp = null;
return arr;
}
function SectionClick(id)
{
var div = document.getElementById('user_div_'+id);
if (div.className == "profile-block-hidden")
{
opened_sections[opened_sections.length]=id;
}
else
{
opened_sections = removeElement(opened_sections, id);
}
document.cookie = cookie_prefix + "_user_profile_open=" + opened_sections.join(",") + "; expires=Thu, 31 Dec 2020 23:59:59 GMT; path=/;";
div.className = div.className == 'profile-block-hidden' ? 'profile-block-shown' : 'profile-block-hidden';
}