%PDF- %PDF-
Direktori : /home/bitrix/www/bitrix/templates/p4_new/components/p4/p.main.profile/.default/ |
Current File : //home/bitrix/www/bitrix/templates/p4_new/components/p4/p.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) { var err = LO_MESS["REQUIRED_FIELD"]+$('#'+$(this).attr('data-required')).text().replace(/: \*/g,'')+LO_MESS["IS_NOT_FILLED"]; errors += err; $('#'+$(this).attr('data-required')).addClass('required_error'); err = err.replace(/<.*?>/g, ""); $('#'+$(this).attr('data-required')+'1').attr("data-content",err); $('#'+$(this).attr('data-required')+'1').popover('show'); $(this).focus(function() { $('#'+$(this).attr('data-required')+'1').popover('hide'); }); $("#date_b button").focus(function() { $('#desc-bdate1').popover('hide'); }); } }); if ($("input[data-required='desc-name']").val().length<2){ $('#name_popup').popover('show'); }; $("input[data-required='desc-name']").focus(function() { $('#name_popup').popover('hide'); }); if ($("input[data-required='desc-last-name']").val().length<2){ $('#last-name-popup').popover('show'); $(this).focus(function() { $('#last-name-popup').popover('hide'); }); }; $("input[data-required='desc-last-name']").focus(function() { $('#last-name-popup').popover('hide'); }); if ($("#av_vign").find('*').length < 1){ $("#desc-av1").popover('show'); $(".avspan").addClass('required_error'); }; if ($("input[name='NEW_PASSWORD']").val().length>0 && $("input[name='NEW_PASSWORD']").val().length<6) { $("#passw_requir").popover('show'); errors += $("#passw_requir").attr("data-content"); $("#new_p_td").addClass('required_error'); $("input[name='NEW_PASSWORD']").focus(function() { $("#passw_requir").popover('hide'); $("#new_p_td").removeClass('required_error'); }); } if (!($("#sex_male").prop("checked")) && !($("#sex_female").prop("checked"))){ $("#desc-sex1").popover('show'); errors += $("#desc-sex1").attr("data-content"); $("#desc-sex").addClass('required_error'); }; $('#sex_male').change(function(){ $("#desc-sex1").popover('hide'); $("#desc-sex").removeClass('required_error'); }); $('#sex_female').change(function(){ $("#desc-sex1").popover('hide'); $("#desc-sex").removeClass('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) { var err = LO_MESS["FOR_REQUIRED_FIELD"]+$('#'+$(this).attr('data-required')).text().replace(/: \*/g,'')+LO_MESS["VALUE_IS_NOT_SELECT"]; errors += err; $('#'+$(this).attr('data-required')).addClass('required_error'); err = err.replace(/<.*?>/g, ""); $('#'+$(this).attr('data-required')+'1').attr("data-content",err); $('#'+$(this).attr('data-required')+'1').popover('show'); $('#PERSONAL_CITY_chosen').click(function() { $('#desc-city1').popover('hide'); }); } }); bdate = $('form#form_main_profile input#BDATE').val(); if (bdate.length==0 || bdate=='__.__.____' || bdate=='__/__/____') $('form#form_main_profile input#BDATE').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())); } BX.ready(function(){ $("#av_vign").click(function(){ $("#desc-av1").popover('hide'); $(".avspan").removeClass('required_error'); }); $(".avatdiv .avatbtn").click(function(){ $("#desc-av1").popover('hide'); $(".avspan").removeClass('required_error'); }); if($("#btn-reg-conf").attr("data-reg-conf") == "Y"){ $("#btn-reg-conf").click(); $("#btn-reg-conf").attr("data-reg-conf", "N"); }; $("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); $("#save_form_btn").click(); }); if($("#mls-lab2 input").prop("checked")) $("#male_outer2").attr('class', 'y-active-man'); if($("#fmls-lab2 input").prop("checked")) $("#female_outer2").attr('class', 'y-active-woman'); $("#male_outer2").click(function () { if($("#mls-lab2 input").prop("checked")) { $("#mls-lab2 input").attr("checked", "checked"); $("#male_outer2").attr('class', 'y-active-man'); $("#fmls-lab2 input").removeAttr("checked"); $("#female_outer2").attr('class', 'n-active-woman'); } else {$("#male_outer2").attr('class', 'n-active-man'); $("#mls-lab2 input").removeAttr("checked"); }; }); $("#female_outer2").click(function () { if($("#fmls-lab2 input").prop("checked")) { $("#fmls-lab2 input").attr("checked", "checked"); $("#female_outer2").attr('class', 'y-active-woman'); $("#mls-lab2 input").removeAttr("checked"); $("#male_outer2").attr('class', 'n-active-man'); } else {$("#female_outer2").attr('class', 'n-active-woman'); $("#fmls-lab2 input").removeAttr("checked"); }; }); $('#change_password').click(function(){ $('tr.password').show(); $('tr.change_password').hide(); }); $("#PERSONAL_CITY").chosen({disable_search_threshold: 0}); $('.popup_help').popover({ trigger: 'hover', placement: 'top', }); $("#old_passw[data-old-p='Y']").popover('show'); $("input[name='OLD_PASSWORD']").focus(function() { $("#old_passw[data-old-p='Y']").popover('hide'); $("#old_passw").attr('data-old-p','N'); $("#old_p_td").removeClass('required_error'); }); $('.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'); } */ /*$("#save_btn").click(function(){ $("#form_main_profile").submit(); });*/ $('select#PERSONAL_CITY').ajaxChosen( { type: 'GET', url: 'load_ref.php', dataType: 'json' }, function (data) { return data; } ); addRegionToCity = function() { var labelrn = $('select#PERSONAL_CITY option:selected').parent()[0].label.split(","); $('#PERSONAL_CITY_chosen .chosen-single span').text( $('#PERSONAL_CITY_chosen .chosen-single span').text() + ' (' + labelrn[0] + ')' ); } addSpanCity = function() { $('#PERSONAL_CITY_chosen .chosen-single span').text( ""+$("#PERSONAL_CITY").attr("data-placeholder")+"" ); } $('select#PERSONAL_CITY').chosen().change(function(){ addRegionToCity(); }); initCityList = function() { sid = $('input#arUser_prof_CITY').val(); $.ajax({ url: 'load_ref.php', type: "GET", data: {REF: 'CITY', SID: sid }, dataType: "html", success: function(html){ $('select#PERSONAL_CITY').html(html); if ($('input#arUser_prof_CITY').attr('value')>0){ $('select#PERSONAL_CITY option[value="'+$('input#arUser_prof_CITY').attr('value')+'"]').prop("selected", true); $("select#PERSONAL_CITY").trigger('chosen:updated'); addRegionToCity(); } else { $("select#PERSONAL_CITY").trigger('chosen:updated'); addSpanCity(); }; } }); } initCityList(); $("#PERSONAL_CITY_chosen .chosen-single div").html(''); }); 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'; }