var INPI=0 var MAX_CAR=400; var $sect_activite $(function(){ $sect_activite= getQuestions('data-cond="type_activite"').eq(0).closest('.section_contrat') if ( $('.variable[name=code_activite_inpi],.variable[name=cai_autre] ').length ==0) INPI =0 else if ( $('.variable[name=cai_autre] ').length ==0) INPI=1 else INPI=2 if (INPI>=1){ var $list=$('#ML') if ( $list.length>0){ $('.inputs .options_form[data-cond=type_activite]').each(function() { var $this=$(this) var curr_id = $this.attr('id') html = $list.html().replace(/id="ML/g, 'id="' + curr_id) $this.html(html) var $section=$this.closest('.section_contrat') if ( ifset($section.attr('data-type-section')) !="decouverte") { html = $('#MLout').html().replace(/id="ML/g, 'id="' + curr_id) $section.find('.section_outputs [id=' + curr_id.replace('r0', '') + '_out]').html(html) }else{ /*$this.find('.Nsous_sections').html('') $this.find('.Nquestion_list').removeClass('closable') $this.removeClass('block-small')*/ $section.find('.section_outputs [id=' + curr_id.replace('r0', '') + '_out]').html('') } }).addClass('inpi_activites') $('#importationML').remove() // calc_radio_cache($('#'+curr_id).closest('.section_contrat ')) } var $list=$('#liste_activites_GU') if ( $list.length>0 ){ var $target= $('.inputs .options_form[data-cond=liste_activites_GU]').parent().html($list.html()) $target.children('[data-id="INPI_ACT"]').removeClass('hidden') $('#liste_activites_GU ').remove() } } if (INPI>0) MAX_CAR = 140 var $targets if (INPI==2) $targets =$('[name$="obj_autre"]') else $targets =$('[name$="objet_social"]') $targets.bind('keyup blur',function(){ var $this=$(this) var val=$this.val().trim() $this.nextAll('.user_obj_soc-error').remove() if (val.length>MAX_CAR){ $this.val(val.substr(0,MAX_CAR)) if (INPI>0) $this.addClass('error').after('') else $this.addClass('error').after('') if (val.length>MAX_CAR+2 && INPI==0){ var $EXT=$('textarea[name$="objet_social_ext"]').eq(0) $EXT.val(val.substr(MAX_CAR)).trigger('blur') active_question(getQuestions('ext_obj',null,false)) } } else { $this.removeClass('error').after('') } }) $('.variable[name$="objet_social"]').change(function(){ var $sect=$(this).closest('[data-multiple-name="activites"] ') var clo_id= getCloId( $sect ) active_question(getQuestions(clo_id+'activite','autre',null,null,$sect)) }) if (INPI>0){ if (INPI==1){ getQuestions('data-cond$="activite"').click(function(){ var $this=$(this) setTimeout(function(){get_INPI_code($this)},200) }) } $sect_activite.find('.Nquestion[data-libelle]').click(function(){ var $this=$(this) setTimeout(function(){get_INPI_code($this)},200) }) } if (INPI>1){ getQuestions('data-cond*="chkact"').add(getQuestions('data-cond$="type_activite"')).add(getQuestions('data-cond$="categorie_activ"')).click(function(e){ var $this=$(e.target) setTimeout(function(){calcART($this)},200) }) $sect_activite.find('.inputs input[name*="autre"]').change(calcObj) $sect_activite.find(' .remove_multiple').click(function(){ setTimeout(calcObj,500) }) getAutoActivite() setTimeout(calcObj,500) } }) var calcART = function($this){ var art=false, dreal=false, lib=false; var clo_id= getCloId( $this ) $art_quest=getQuestions(clo_id+'art_regl') getQuestions('data-cond^="'+clo_id+'chkact"',null,true,true,$sect_activite).each(function(){ var $elt = $(this) var name= $elt.parent().parent().attr('data-cond').replace('chkact','forme') var forme = $sect_activite.find('.outputs [data-name="'+name+'"]').attr('data-force-val') art = art || (forme=='ARTISANALE_REGLEMENTEE') lib = lib || (forme=='LIBERALE_REGLEMENTEE') dreal = dreal || (name.indexOf('dreal')!= -1) }) art = art || getQuestions(clo_id+'categorie_activ','ARTISANALE_REGLEMENTEE',true,true,$sect_activite).length>0 lib = lib || getQuestions(clo_id+'categorie_activ','LIBERALE_REGLEMENTEE',true,true,$sect_activite).length>0 active_question(getQuestions(clo_id+'art_regl',null,!art,null,$sect_activite)) active_question(getQuestions(clo_id+'lib_regl',null,!lib,null,$sect_activite)) active_question(getQuestions('dreal_sect',null,!dreal,null,$sect_activite)) calcObj($this) } var calcObj = function(){ obj='' getQuestions('data-cond*="chkact"',null,true,true,$sect_activite).add(getQuestions('data-cond*="type_activite"','autre',true,true,$sect_activite)) .each(function(){ var $elt = $(this) var name = $elt.parent().parent().attr('data-cond').replace('chkact','obj'); if (name.indexOf('type_activite') != -1) name=getCloId( $elt)+'obj_autre' $output=$sect_activite.find('.outputs [data-name="'+name+'"]') var txt='' if (name.indexOf('autre') == -1) txt= $output.attr('data-force-val') else txt = $output.eq(0).text() if (txt.trim() !='') obj += txt+'; ' }) $('.inputs input[name="objet_social').val(obj).removeAttr('empty').trigger('blur'); } var get_INPI_code = function($this){ var clo_id= getCloId( $this ) var libelle if ($this.is('[data-libelle]')){ libelle = $this.attr('data-libelle') $('.inputs input[name="'+clo_id+'cai_autre"]').val(libelle).removeAttr('empty').trigger('blur') } else libelle= $('.inputs input[name="'+clo_id+'code_activite_inpi"]').eq(0).val() $.ajax({ url: PHP_PATH+'ajax_dispatch_free.php', type: 'POST', data: { page:'api.php', action : 'getINPIcode', libelle:libelle, ajax:1, }, dataType: "json", success: function(data){ if (isset(data.success) && data.success==true && isset(data.forme) && data.forme!='') { if (data.forme=='GESTION_DE_BIENS' || data.forme =="AGENT_COMMERCIAL" ) data.forme='COMMERCIALE' else if (data.forme=='ARTISANALE') data.forme='art_NR' active_question(getQuestions('data-cond="'+clo_id+'categorie_activ"',data.forme,null,null,$this.closest('.section_contrat ')).eq(0)) if (INPI==2) calcART($this) } } }) } var searched='' var getAutoActivite = function(){ // use jquery autocomplete to get the activity // and put it in the input field [name=obj_autre"] $('.inputs input[name*="obj_autre"]').focus(function() { var $this = $(this) if (typeof $this.autocomplete('instance') !="undefined" && $this.autocomplete('instance').element[0]!=$this[0]) $this.autocomplete('instance').element[0]=$this[0] $this.autocomplete({ minlength: 2, delay: 50, classes: { "ui-autocomplete": "auto_activite" }, position: { my : "left top", at: "left bottom" ,'collision': 'flip' }, source: function (request, response) { searched = request.term.noAccent().trim() var matcher = new RegExp($.ui.autocomplete.escapeRegex(searched), "i"); var nb = 0, max_nb = 15 var output = $.grep(my_activites, function (value) { value = value.label.noAccent(); if (matcher.test(value)) return (nb++ < max_nb); }) if (output.length == 0) { nb = 0 searched.split(' ').forEach(function (word) { if (word.length > 2 && word.indexOf('service', 'vente', 'achat', 'par') == -1) { var matcher = new RegExp($.ui.autocomplete.escapeRegex(word), "i"); // add to output output = output.concat($.grep(my_activites, function (value) { value = value.label.noAccent(); if (matcher.test(value)) return (nb++ < max_nb); })) } }) } response( output ); }, select: function (event, ui) { var $sect = $(this).closest('.section_contrat') $(this).val(ui.item.value); var clo_id = getCloId($this) var fullcode = ui.item.code_inpi active_question(getQuestions('data-cond="' + clo_id + 'help_inpi"', 1, false, null, $sect).eq(0)) var code = '', i = 1, $question while (fullcode.length >= i * 3 - 1) { code = fullcode.substr(0, i * 3 - 1) $question = getQuestions('data-cond="' + clo_id + 'liste_activites_GU' + i + '"', code, null, null, $sect) active_question($question) i++ } get_INPI_code($question) return false; }, }) .autocomplete("instance")._renderItem = function (ul, item) { // faire un regex pour mettre en gras les mots recherchés en dehors des balise html var re, label = item.label var sh = searched.replace(/\(/g, '\\(').replace(/\)/g, '\\)') if (item.label.indexOf('>') != -1) { re = new RegExp('(\<.*?\>.*?)(' + sh + ')(.*?\<\/span.*?)', "gi"); label = label.replace(re, "$1$2$3"); re = new RegExp('(.*?\<\/span.*\>.*?)(' + sh + ')', "gi"); label = label.replace(re, "$1$2"); } else { re = new RegExp(sh, "gi"); label = label.replace(re, "$&"); } return $("
  • ") .append("
    " + label + "
    ") .appendTo(ul); }; if ($this.val().trim().length>3 && denomTimer == null) $this.autocomplete( "search", $this.val().trim() ); }) } /* TRIBUNAL COMPETENT ***/ /* https://www.infogreffe.fr/services/commun/rest/commun/communesInseeLucene/xxxx xxxx=debut du nom de la commune ex HORBOURG ***/ /* https://www.infogreffe.fr/services/commun/rest/referentiel/detailGreffe/n1/n2 n1= numero de commune n2=numero de département exemple: 145 / 068 */