templates/front/includes/company_data/company_js.twig line 1

Open in your IDE?
  1. {% set language =  app.request.locale %}
  2. <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyApPskY-64e2AFF_RDSK2XHyyGQAlN0qN0&language={{ language }}&libraries=places&callback=initAutoComplete"
  3.         async defer></script>
  4. <script>
  5.     Dropzone.autoDiscover = false;
  6.     let BulledValue = '';
  7.     let ResponseData = [];
  8.     let ListData = [];
  9.     let token = '';
  10.     let autocomplete;
  11.     let autocomplete_2;
  12.     let company = `{{ company is defined and not null and company != '' ? company.numberOfEmployers : '' }}`;
  13.    
  14.     const INPUT_HIDDEN = (i, name, value) => {
  15.        return `<input type="hidden" name="offer[`+ name +`][selected][`+ i +`]" value="`+ value +`" class="input-list-point_`+ name +` input_bulleted_list_`+name+`_`+ i +`">`;
  16.     };
  17.     function initAutoComplete() {
  18.         $(document).on('click', '.city', function () {
  19.             let city = $(this)[0];
  20.             autocomplete = new google.maps.places.Autocomplete(
  21.                 city,
  22.                 {
  23.                     types: ['(cities)'],
  24.                     fields: ['name', 'address_components', 'geometry']
  25.                 });
  26.             autocomplete.addListener('place_changed', onPlaceChanged);
  27.         });
  28.         $(document).on('click', '.place', function () {
  29.             token = $(this).data('token');
  30.             let city = $(this)[0];
  31.             autocomplete = new google.maps.places.Autocomplete(
  32.                 city,
  33.                 {
  34.                     types: ['(regions)'],
  35.                     fields: ['name','address_components', 'geometry']
  36.                 });
  37.             autocomplete.addListener('place_changed', onRegionChanged);
  38.         });
  39.         $(document).on('click', '.city_2', function () {
  40.             let city2 = $(this)[0];
  41.             autocomplete_2 = new google.maps.places.Autocomplete(
  42.                 city2,
  43.                 {
  44.                     types: ['(cities)'],
  45.                     fields: ['name', 'address_components', 'geometry']
  46.                 });
  47.             autocomplete_2.addListener('place_changed', onPlaceChanged_2);
  48.         });
  49.     }
  50.     function getClearNameCity(name){
  51.         let clearName = '';
  52.         let length = name.length;
  53.         for(let i = 0; i<length; i++){
  54.             if(name.charAt(i) == ','){break;}
  55.             clearName += name.charAt(i);
  56.         }
  57.         return clearName;
  58.     }
  59.     function onRegionChanged(){
  60.         var place = autocomplete.getPlace();
  61.         let isLocality = 0;
  62.        
  63.         if (place) {
  64.             for (const component of place.address_components) {
  65.                 const componentType = component.types[0];
  66.               
  67.                 switch (componentType) {
  68.                     
  69.                      case "locality":
  70.                             isLocality = 1;
  71.                             $('#company_lat_'+token).val(place.geometry.location.lat);
  72.                             $('#company_lnt_'+token).val(place.geometry.location.lng);
  73.                             $('#company_place').val(getClearNameCity(component.long_name));
  74.                             $(".place_"+token).val(getClearNameCity(component.long_name));
  75.                             $(".city_"+token).val(getClearNameCity(component.long_name));
  76.                             $(".pl_name").val(component.long_name);
  77.                         break;
  78.                     case "administrative_area_level_1":
  79.                             if(isLocality != 1){
  80.                                 $('#company_lat_'+token).val(place.geometry.location.lat);
  81.                                 $('#company_lnt_'+token).val(place.geometry.location.lng);
  82.                                 $('#company_place').val(getClearNameCity(component.long_name));
  83.                                 $("#work-data-city").val(getClearNameCity(component.long_name));
  84.                                 $(".place_"+token).val(getClearNameCity(component.long_name));
  85.                                 $(".city_"+token).val(getClearNameCity(component.long_name));
  86.                                 $(".pl_name").val(getClearNameCity(component.long_name));
  87.                             }
  88.                         break;
  89.                     case "country":
  90.                         $('#company_lat_'+token).val(place.geometry.location.lat);
  91.                         $('#company_lnt_'+token).val(place.geometry.location.lng);
  92.                         $(".country").val(component.long_name);
  93.                         $(".pl_name").val(getClearNameCity(component.long_name));
  94.                         break;
  95.                 }
  96.             }
  97.         } else {
  98.             $(".place").val('');
  99.             $(".city").val('');
  100.             $(".country").val('');
  101.             $("#company_lat").val('');
  102.             $("#company_lnt").val('');
  103.             $("#company_place").val('');
  104.         }
  105.     }
  106.     function onPlaceChanged() {
  107.         var place = autocomplete.getPlace();
  108.         console.log(place);
  109.         if (place) {
  110.             for (const component of place.address_components) {
  111.                 const componentType = component.types[0];
  112.                 switch (componentType) {
  113.                     case "locality":
  114.                         $('#company_lat').val(place.geometry.location.lat);
  115.                         $('#company_lnt').val(place.geometry.location.lng);
  116.                         $('#company_place').val(component.long_name);
  117.                         $(".city").val(component.long_name);
  118.                         $(".pl_name").val(getClearNameCity(component.long_name));
  119.                         break;
  120.                     case "country":
  121.                         $(".country").val(component.long_name);
  122.                         break;
  123.                 }
  124.             }
  125.         } else {
  126.             $(".city").val('');
  127.             $(".country").val('');
  128.             $("#company_lat").val('');
  129.             $("#company_lnt").val('');
  130.             $("#company_place").val('');
  131.         }
  132.     }
  133.     function onPlaceChanged_2() {
  134.         var place = autocomplete_2.getPlace();
  135.         if (place) {
  136.             for (const component of place.address_components) {
  137.                 const componentType = component.types[0];
  138.                 switch (componentType) {
  139.                     case "locality":
  140.                         $(".city_2").val(component.long_name);
  141.                         $("#company_extra_lat").val(place.geometry.location.lat);
  142.                         $("#company_extra_lnt").val(place.geometry.location.lng);
  143.                         $("#company_extra_place").val(component.long_name);
  144.                         $(".pl_name_2").val(getClearNameCity(component.long_name));
  145.                         break;
  146.                     case "country":
  147.                         $(".country_2").val(component.long_name);
  148.                         break;
  149.                 }
  150.             }
  151.         } else {
  152.             $(".city_2").val('');
  153.             $(".country_2").val('');
  154.             $("#company_extra_lat").val('');
  155.             $("#company_extra_lnt").val('');
  156.             $("#company_extra_place").val('');
  157.         }
  158.     }
  159.     function checkIsExtraInvoiceData()
  160.     {
  161.         if($('.invoice-data-toggle').length >= 1){
  162.             if($('.invoice-data-toggle').prop('checked')){
  163.                 $('.invoice_extra_input_required').prop('required', true);
  164.             }else{
  165.                 $('.invoice_extra_input_required').prop('required', false);
  166.             }
  167.         }
  168.     }
  169.     $(document).ready(function(){
  170.         $('.ui-multiselect span:last-child').html(`{{ 'USER_ZONE.OFFER.SALARY.PERIOD.SELECT'|trans }}`);
  171.         $('.custom-select select.limit-education option:first-child').html(`{{ 'USER_ZONE.OFFER.SALARY.PERIOD.SELECT'|trans }}`);
  172.         checkIsExtraInvoiceData();
  173.     });
  174.     $(document).on('change', '.invoice-data-toggle', function (){
  175.         checkIsExtraInvoiceData();
  176.     });
  177.     $(document).on('click change', 'input[name="multiselect_lang-select"]', function(){
  178.         let active = $(this).prop('checked');
  179.         let divId  = $(this).val();
  180.         if(active == false){
  181.             $('#lang-'+divId).hide();
  182.         }
  183.     });
  184.     $(document).on('click change', '.ui-multiselect-checkboxes input[type="checkbox"]', function(){
  185.         let active = $(this).prop('checked');
  186.         let divId  = $(this).val();
  187.         if(active == false){
  188.             $('#education-'+divId).hide();
  189.         }
  190.     });
  191.     
  192.     $('.input-checkbox-form-place-cv').on('click', function (){
  193.         $('.input-checkbox-form-place-cv').prop('checked', false);
  194.         $(this).prop("checked", true);
  195.         if($(this).prop("id") == 'check-agre-checkbox-2'){
  196.             $('.box-input-surce').show();
  197.         }else{
  198.             $('.box-input-surce').hide();
  199.         }
  200.     });
  201.     $('.label-input-checkbox-form-place-cv').on('click', function (){
  202.         $('.input-checkbox-form-place-cv').prop('checked', false);
  203.         let idName = '#'+ $(this).attr('for');
  204.         $(idName).prop("checked", true);
  205.         if(idName == '#check-agre-checkbox-2'){
  206.             $('.box-input-surce').show();
  207.         }else{
  208.             $('.box-input-surce').hide();
  209.         }
  210.     });
  211.     $(document).on('click', '.size-input', function () {
  212.         let val = $(this).val();
  213.     });
  214.     $(document).on('click', '#check31', () => {
  215.         if ($('.button_invoice').val()) {
  216.             $('.button_invoice').removeClass('button_invoice');
  217.             $('.invoice_input').removeAttr('required');
  218.         } else {
  219.             $('#check31').addClass('button_invoice');
  220.             $('.invoice_input').attr('required', true);
  221.         }
  222.     });
  223.     $(".form-company-user").submit(function (e) {
  224.         $('.alert').css('display', 'none');
  225.     });
  226.     $(document).on('click', '.box_dropzone_logo', function(){
  227.         $("#dropzone1").click();
  228.     });
  229.     $("#dropzone1").dropzone({
  230.         maxFiles: 1,
  231.         createImageThumbnails: false,
  232.         previewsContainer: false,
  233.         acceptedFiles: 'image/png, image/jpg, image/svg, image/jpeg',
  234.         url: "{{ path('user-create-logo') }}",
  235.         success: function (file, response) {
  236.             if(response != ''){
  237.                 $('.logo-box').removeClass(['border-dotted', 'border-secondary']);
  238.                 $('.container-box-logo').addClass('d-none');
  239.                 $('.box-company-logo-set').show();
  240.                 $('.box-company-logo-is-add').hide();
  241.                 $('img').remove('.img-drop-logo-2');
  242.                 $('.box-to-set-logo').append(`
  243.                     <img src="` + '/firm/' + response.name + '.' + response.extension + `" class="img-drop-logo-2" alt="" style="max-width:100;max-height:60px;"/>
  244.                     <a href="#" class="remove-logo-button"><i class="fas fa-times"></i></a>
  245.                 `);
  246.                 $('input').remove('.company_logo');
  247.                 $('.form-company-user').append('<input type="hidden" name="company[logo]" value="' + response.id + '" class="company_logo">');
  248.                 $('.dz-message').hide();
  249.             }else{
  250.                 Dropzone.forElement('#dropzone1').removeAllFiles(true);
  251.             }
  252.         }
  253.     });
  254.     $(document).on('click', '.remove-logo-button', function () {
  255.         Dropzone.forElement('#dropzone1').removeAllFiles(true);
  256.         $('.container-box-logo').removeClass('d-none');
  257.         $('.box-company-logo-set').hide();
  258.         $('.remove-logo-button').hide();
  259.         $('input').remove('.company_logo');
  260.         $('.box-to-set-logo').remove('.img-drop-logo-2');
  261.         $('.dz-message').show();
  262.         $('.logo-box').addClass('border-dotted');
  263.         $('.logo-box').addClass('border-secondary');
  264.     });
  265.     $(document).on('click', '.close-row', function(){
  266.         let select      = $(this).data('select');
  267.         let education   = $(this).data('education');
  268.         let sizeOption  = 0;
  269.         let selected    = 0;
  270.         $('#'+select+' option[value='+education+']').prop('selected', false);
  271.         $('#'+select+' option[value='+education+']').prop('checked', false);
  272.         $('#'+select+'').trigger('change').multiselect('refresh');
  273.         $('.ui-multiselect-checkboxes input[value="'+education+'"]').prop('selected', false);
  274.         $('.ui-multiselect-checkboxes input[value="'+education+'"]').prop('checked', false);
  275.         $('.ui-multiselect-checkboxes input[value="'+education+'"]').trigger('change');
  276.         
  277.         $('.ui-multiselect span:last-child').html(`{{ 'USER_ZONE.OFFER.SALARY.PERIOD.SELECT'|trans }}`);
  278.     });
  279.     
  280.     
  281.     $(document).on('change', '#companyVatId', function (e) {
  282.         e.preventDefault();
  283.         let nip = $(this).val();
  284.         $.get('/gus/' + nip, function (data) {
  285.                 if (data.error == null){
  286.                     const name = data.reports[0].name;
  287.                     const postCode = data.reports[0].zipCode;
  288.                     const county = data.reports[0].district;
  289.                     const city = data.reports[0].city;
  290.                     const address = data.reports[0].street + ' ' + data.reports[0].propertyNumber + ' ' + data.reports[0].apartmentNumber;
  291.                     {#const country = `{{ 'USER_ZONE.OFFER.WORK_DATA.DEFAULT_VALUE_COUNTRY'|trans() }}`;#}
  292.                     const country = 'pl';
  293.                     $('#companyName').val(name);
  294.                     $('#companyAddress').val(address);
  295.                     $('#companyCity').val(city);
  296.                     $('#companyPostCode').val(postCode);
  297.                     $('#companyCountry').val(country);
  298.                     $('#company_place').val(city);
  299.                 }
  300.             }
  301.         );
  302.         return false;
  303.     });
  304.     $(document).on('change', '#companyVatId2', function (e) {
  305.         e.preventDefault();
  306.         let nip = $(this).val();
  307.         $.get('/gus/' + nip, function (data) {
  308.                 if (data.error == null){
  309.                     const name = data.reports[0].name;
  310.                     const postCode = data.reports[0].zipCode;
  311.                     const county = data.reports[0].district;
  312.                     const city = data.reports[0].city;
  313.                     const address = data.reports[0].street + ' ' + data.reports[0].propertyNumber + ' ' + data.reports[0].apartmentNumber;
  314.                     {#const country = `{{ 'USER_ZONE.OFFER.WORK_DATA.DEFAULT_VALUE_COUNTRY'|trans() }}`;#}
  315.                     const country = 'pl';
  316.                     $('#companyName2').val(name);
  317.                     $('#companyAddress2').val(address);
  318.                     $('#companyCity2').val(city);
  319.                     $('#companyPostCode2').val(postCode);
  320.                     $('#companyCountry2').val(country);
  321.                     $('#company_extra_place').val(city);
  322.                 }
  323.             }
  324.         );
  325.         return false;
  326.     });
  327. </script>