/*lang:ru*/ (function ($) { var o = null; var lang = { 'reg-host': 'https://reg.intrumnet.com', 'log-in': 'Войти', 'auth-title': 'Авторизация в Вашей CRM системе', 'email-field-hint': 'Ваш email', 'continue': 'Далее', 'password': 'Пароль' }; var Auth = function () { o = this; $(document).ready(function () { o.initialize(); }); }; var p = Auth.prototype; Auth.base_url = lang['reg-host']; Auth.default_url = '/'; Auth.IS_SANDBOX = false; p._requests = null; p._known_hosts = []; p.initialize = function() { var jLiItem = $('\
  • \ ' + lang['log-in'] + '\
  • \ '); jLiItem.find('a.auth').on('click', function () { o.showAuth(); return true; }); $('nav#navigation-menu ul.navbar-right').append(jLiItem); o._known_hosts = o._getKnownHosts(); o._initAuthBlock(); } p._getKnownHosts = function() { /* var keyValue = document.cookie.match(); return keyValue ? keyValue[2] : null; */ var list = []; var pattern = /(^|;)*known_host_([^=]*)=([^;]*)(;|$)/gi; var match; while (match = pattern.exec(document.cookie)){ list.push(match[2]); } return list; } p.initCloserOutclick = function () { $(document).on('click.auth-close', function (event) { if (!$(event.target).closest('div#auth-form').length) { if ($('div#auth-form').is(':visible')) { $('div#auth-form').parent().remove(); $(document).off('click.auth-close'); o._initAuthBlock(); } } }); } p._recaptchaReady = false; p._initRecaptcha = function (onReady) { if (!o._recaptchaReady) { // CSS var style = document.createElement('style'); style.type = 'text/css'; style.innerHTML = '\ .grecaptcha-badge {\ width: 70px !important;\ overflow: hidden !important;\ transition: all 0.3s ease !important;\ left: 4px !important;\ }\ .grecaptcha-badge:hover {\ width: 256px !important;\ }\ '; document.head.appendChild(style); // JS var script = document.createElement('script'); script.type = 'text/javascript'; script.src = 'https://www.google.com/recaptcha/api.js?render=6LfWAnUUAAAAAHmgWK8rGNGWQWDZ-AAMs5XTnG6S'; script.onload = function () { o._recaptchaReady = true; if (typeof onReady === 'function') onReady(); }; document.head.appendChild(script); } else { if (typeof onReady === 'function') onReady(); } } p._initAuthBlock = function () { o.jAuthBlock = $('\
    \
    \
    \

    ' + lang['auth-title'] + '

    \
    \
    \ \ \
    \
    \ \ \
    \
    \ \
    \
    \
    \
    \ '); } p.showAuth = function () { o.jAuthBlock.find('form#authorization-form').on('submit', function () { var jForm = $(this); var currentStep = jForm.attr('data-step'); switch (currentStep) { case '0': var jLoginField = o.jAuthBlock.find('input#email-or-login'); var emailOrLogin = jLoginField.val(); o.jAuthBlock.find('#form_auth_btn img').show().prev().hide(); if (o._recaptchaReady) { grecaptcha.ready(function() { grecaptcha.execute('6LfWAnUUAAAAAHmgWK8rGNGWQWDZ-AAMs5XTnG6S', {action: 'page_email'}) .then(function(token) { o.jAuthBlock.find('form#authorization-form input#token').remove(); if (typeof token !== 'undefined') { $('').insertAfter( o.jAuthBlock.find('form#authorization-form input#email-or-login') ); } o.getDomainByEmailOrLogin(emailOrLogin, o.onDomainReqSuccess, o.onDomainReqError); }); }); } else { o.getDomainByEmailOrLogin(emailOrLogin, o.onDomainReqSuccess, o.onDomainReqError); } break; case '1': if (jForm.find('input[name="password"]').val() != '') { setTimeout(function () { $(document).trigger('click.auth-close'); }, 1000); return true; } break; } return false; }); o.jAuthBlock.find('#auth-form').css({ 'position': 'absolute', 'right': '-15px', 'background-color': '#4e4e4e', 'padding': '15px 15px 10px 15px', 'width': '340px', 'top': '50px', 'border-radius': '5px' }); o.jAuthBlock.find('#form_auth_btn input, #auth_final_btn input').css({ 'height': '30px', 'padding': '0px 30px', 'line-height': '0px', 'vertical-align': 'middle', 'display': 'inline-block', 'margin-top': '10px', 'margin-bottom': '5px' }); if (o._known_hosts.length > 0) { o.jAuthBlock.find('div#auth-form').html('

    ' + lang['auth-title'] + '

    '); for (var i = 0; i < o._known_hosts.length; i++) { var host = o._known_hosts[i]; var fullHostname = host + '.' + location.hostname.split('.').slice(-2).join('.'); var jGotoBlock = $('\
    \
    ' + fullHostname + '
    \
    ' + lang['log-in'] + '
    \
    \
    \ '); jGotoBlock.appendTo(o.jAuthBlock.find('div#auth-form')); } } o.jAuthBlock.appendTo('nav#navigation-menu'); setTimeout(function () { o.initCloserOutclick(); }, 1); } p.onDomainReqSuccess = function (data) { var jForm = o.jAuthBlock.find('form#authorization-form'); if (data.success) { var forms = data.data; if (forms.length == 1) { var iForm = forms[0]; o.jAuthBlock.find('input#email-or-login').prop('name', iForm.type).val(iForm.login).attr('type', 'hidden').next().show(); o.jAuthBlock.find('span#founded-domain').text(iForm.host); jForm.attr('action', 'https://' + iForm.host + '/login').attr('target', '_blank').attr('method', 'POST'); o.jAuthBlock.find('.auth-step[step="1"]').show(); jForm.attr('data-step', 1); jForm.find('div#form_auth_btn').hide(); } else { o.jAuthBlock.find('div#auth-form').html('

    ' + lang['auth-title'] + '

    '); for (var i = 0; i < forms.length; i++) { var host = forms[i]['host']; var fullHostname = host;// + '.' + location.hostname.split('.').slice(-2).join('.'); var jGotoBlock = $('\
    \
    ' + fullHostname + '
    \
    ' + lang['log-in'] + '
    \
    \
    \ '); jGotoBlock.appendTo(o.jAuthBlock.find('div#auth-form')); } } } else { } if (data.error && data.hasOwnProperty('error_text')) { switch (data.error) { case 'nomatches': break; case 'captcha': o.jAuthBlock.find('#form_auth_btn img').show().prev().hide(); o._initRecaptcha(function (token) { o.jAuthBlock.find('form#authorization-form').trigger('submit'); }); break; } if (data.error_text) { o.jAuthBlock.find('#auth-error-descr').text(data.error_text); } } o.jAuthBlock.find('#form_auth_btn img').hide().prev().show(); } p.onDomainReqError = function () { o.jAuthBlock.find('#form_auth_btn img').hide().prev().show(); } p.getDomainByEmailOrLogin = function (loginOrEmail, onSuccess, onFail) { var params = { 'emailOrLogin': loginOrEmail }; var jToken = o.jAuthBlock.find('form#authorization-form input#token'); if (jToken.length > 0) { params['token'] = jToken.val(); } $.ajax({ url: Auth.base_url + '/getDomain', type: 'post', dataType: 'json', data: params, success: function(data) { if (typeof onSuccess == 'function') { onSuccess(data); } }, error: function () { if (typeof onFail == 'function') { onFail(); } } }); } window.auth = new Auth; }($));