NEW Use new select2 component for juridical status, country and state

selection.
This commit is contained in:
Laurent Destailleur 2015-05-31 12:25:33 +02:00
parent 01aad8516d
commit 1b681510a5
12 changed files with 71 additions and 35 deletions

View File

@ -420,7 +420,7 @@ if ($action == 'edit' || $action == 'updateedit')
print '<tr '.$bc[$var].'><td><label for="legal_form">'.$langs->trans("JuridicalStatus").'</label></td><td>';
if ($mysoc->country_code)
{
print $formcompany->select_juridicalstatus($conf->global->MAIN_INFO_SOCIETE_FORME_JURIDIQUE,$mysoc->country_code);
print $formcompany->select_juridicalstatus($conf->global->MAIN_INFO_SOCIETE_FORME_JURIDIQUE, $mysoc->country_code, '', 'legal_form');
}
else
{

View File

@ -503,7 +503,7 @@ class Form
$resql=$this->db->query($sql);
if ($resql)
{
$out.= '<select id="select'.$htmlname.'" class="flat selectcountry" name="'.$htmlname.'" '.$htmloption.'>';
$out.= '<select id="select'.$htmlname.'" class="flat selectcountry minwidth300" name="'.$htmlname.'" '.$htmloption.'>';
$num = $this->db->num_rows($resql);
$i = 0;
if ($num)
@ -531,7 +531,7 @@ class Form
if (empty($row['favorite']) && $atleastonefavorite)
{
$atleastonefavorite=0;
$out.= '<option value="" disabled>----------------------</option>';
$out.= '<option value="" disabled class="selectoptiondisabledwhite">----------------------</option>';
}
if ($selected && $selected != '-1' && ($selected == $row['rowid'] || $selected == $row['code_iso'] || $selected == $row['code_iso3'] || $selected == $row['label']) )
{
@ -554,6 +554,10 @@ class Form
dol_print_error($this->db);
}
// Make select dynamic
include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
$out .= ajax_combobox('select'.$htmlname);
return $out;
}
@ -4342,10 +4346,9 @@ class Form
<script type="text/javascript">
$(document).ready(function () {
$(\''.(preg_match('/^\./',$htmlname)?$htmlname:'#'.$htmlname).'\').'.$tmpplugin.'({
width:"resolve",
dir: \'ltr\',
width: \'off\',
minimumInputLength: 0
width: \'resolve\', /* off or resolve */
minimumInputLength: '.$minLengthToAutocomplete.'
});
});
</script>';

View File

@ -105,6 +105,10 @@ class FormAdmin
}
$out.= '</select>';
// Make select dynamic
include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
$out.= ajax_combobox($htmlname);
return $out;
}

View File

@ -210,6 +210,7 @@ class FormCompany
* @param string $country_codeid Country code or id: 0=list for all countries, otherwise country code or country rowid to show
* @param string $htmlname Id of department
* @return string String with HTML select
* @see select_country
*/
function select_state($selected='',$country_codeid=0, $htmlname='state_id')
{
@ -234,7 +235,7 @@ class FormCompany
$result=$this->db->query($sql);
if ($result)
{
if (!empty($htmlname)) $out.= '<select id="'.$htmlname.'" class="flat" name="'.$htmlname.'">';
if (!empty($htmlname)) $out.= '<select id="'.$htmlname.'" class="flat minwidth300" name="'.$htmlname.'">';
if ($country_codeid) $out.= '<option value="0">&nbsp;</option>';
$num = $this->db->num_rows($result);
$i = 0;
@ -277,13 +278,17 @@ class FormCompany
}
}
if (! empty($htmlname)) $out.= '</select>';
if (! empty($htmlname) && $user->admin) $out.= info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
if (! empty($htmlname) && $user->admin) $out.= ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
}
else
{
dol_print_error($this->db);
}
// Make select dynamic
include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
$out .= ajax_combobox($htmlname);
return $out;
}
@ -431,9 +436,10 @@ class FormCompany
* @param string $selected Preselected code of juridical type
* @param int $country_codeid 0=list for all countries, otherwise list only country requested
* @param string $filter Add a SQL filter on list
* @param string $htmlname HTML name of select
* @return string String with HTML select
*/
function select_juridicalstatus($selected='', $country_codeid=0, $filter='')
function select_juridicalstatus($selected='', $country_codeid=0, $filter='', $htmlname='forme_juridique_code')
{
global $conf,$langs,$user;
$langs->load("dict");
@ -454,7 +460,7 @@ class FormCompany
if ($resql)
{
$out.= '<div id="particulier2" class="visible">';
$out.= '<select class="flat" name="forme_juridique_code" id="legal_form">';
$out.= '<select class="flat minwidth200" name="'.$htmlname.'" id="'.$htmlname.'">';
if ($country_codeid) $out.= '<option value="0">&nbsp;</option>'; // When country_codeid is set, we force to add an empty line because it does not appears from select. When not set, we already get the empty line from select.
$num = $this->db->num_rows($resql);
@ -488,7 +494,7 @@ class FormCompany
// Show break when we are in multi country mode
if (empty($country_codeid) && $val['country_code'])
{
$out.= '<option value="0">----- '.$val['country']." -----</option>\n";
$out.= '<option value="0" disabled class="selectoptiondisabledwhite">----- '.$val['country']." -----</option>\n";
$country=$val['country'];
}
}
@ -508,6 +514,11 @@ class FormCompany
}
$out.= '</select>';
if ($user->admin) $out.= info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
// Make select dynamic
include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
$out .= ajax_combobox($htmlname);
$out.= '</div>';
}
else

View File

@ -328,14 +328,17 @@ function ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $
if (empty($minLengthToAutocomplete)) $minLengthToAutocomplete=0;
$msg = '<script type="text/javascript">
$(document).ready(function() {
$(\'#'.$htmlname.'\').select2({
width: \'resolve\',
minimumInputLength: '.$minLengthToAutocomplete.',
})';
$tmpplugin='select2';
$msg='<!-- JS CODE TO ENABLE '.$tmpplugin.' for id '.$htmlname.' -->
<script type="text/javascript">
$(document).ready(function () {
$(\''.(preg_match('/^\./',$htmlname)?$htmlname:'#'.$htmlname).'\').'.$tmpplugin.'({
dir: \'ltr\',
width: \'resolve\', /* off or resolve */
minimumInputLength: '.$minLengthToAutocomplete.'
})';
if ($forcefocus) $msg.= '.select2(\'focus\')';
$msg.= ';';
$msg.= ';'."\n";
if (count($event))
{

View File

@ -1,5 +1,5 @@
<?php
/* Copyright (C) 2013-2014 Jean-François Ferry <jfefe@aternatik.fr>
/* Copyright (C) 2013-2014 Jean-François Ferry <jfefe@aternatik.fr>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -52,7 +52,7 @@ class modResource extends DolibarrModules
// Family can be 'crm','financial','hr','projects','products','ecm','technic','other'
// It is used to group modules in module setup page
$this->family = "hr";
$this->family = "projects";
// Module label (no space allowed)
// used if translation string 'ModuleXXXName' not found
// (where XXX is value of numeric property 'numero' of module)
@ -68,7 +68,7 @@ class modResource extends DolibarrModules
$this->const_name = 'MAIN_MODULE_' . strtoupper($this->name);
// Where to store the module in setup page
// (0=common,1=interface,2=others,3=very specific)
$this->special = 0;
$this->special = 2;
// Name of image file used for this module.
// If file is in theme/yourtheme/img directory under name object_pictovalue.png
// use this->picto='pictovalue'

View File

@ -39,7 +39,8 @@ insert into llx_c_regions (fk_pays,code_region,cheflieu,tncc,nom) values ( 1,
insert into llx_c_regions (fk_pays,code_region,cheflieu,tncc,nom) values ( 1, 2,'97209',3,'Martinique');
insert into llx_c_regions (fk_pays,code_region,cheflieu,tncc,nom) values ( 1, 3,'97302',3,'Guyane');
insert into llx_c_regions (fk_pays,code_region,cheflieu,tncc,nom) values ( 1, 4,'97411',3,'Réunion');
insert into llx_c_regions (fk_pays,code_region,cheflieu,tncc,nom) values ( 1, 6,'',3,'Mayotte');
insert into llx_c_regions (fk_pays,code_region,cheflieu,tncc,nom) values ( 1, 6,'97601',3,'Mayotte');
insert into llx_c_regions (fk_pays,code_region,cheflieu,tncc,nom) values ( 1, 11,'75056',1,'Île-de-France');
insert into llx_c_regions (fk_pays,code_region,cheflieu,tncc,nom) values ( 1, 21,'51108',0,'Champagne-Ardenne');
insert into llx_c_regions (fk_pays,code_region,cheflieu,tncc,nom) values ( 1, 22,'80021',0,'Picardie');

View File

@ -35,6 +35,12 @@
insert into llx_c_departements (fk_region, code_departement,cheflieu,tncc,ncc,nom) values ( 0, '0', '0',0,'-','-');
-- Departements France (id country=1)
insert into llx_c_departements (fk_region, code_departement,cheflieu,tncc,ncc,nom) values ( 1,'971','97105',3,'GUADELOUPE','Guadeloupe');
insert into llx_c_departements (fk_region, code_departement,cheflieu,tncc,ncc,nom) values ( 2,'972','97209',3,'MARTINIQUE','Martinique');
insert into llx_c_departements (fk_region, code_departement,cheflieu,tncc,ncc,nom) values ( 3,'973','97302',3,'GUYANE','Guyane');
insert into llx_c_departements (fk_region, code_departement,cheflieu,tncc,ncc,nom) values ( 4,'974','97411',3,'REUNION','Réunion');
insert into llx_c_departements (fk_region, code_departement,cheflieu,tncc,ncc,nom) values ( 6,'976','97601',3,'MAYOTTE','Mayotte');
insert into llx_c_departements (fk_region, code_departement,cheflieu,tncc,ncc,nom) values (82,'01','01053',5,'AIN','Ain');
insert into llx_c_departements (fk_region, code_departement,cheflieu,tncc,ncc,nom) values (22,'02','02408',5,'AISNE','Aisne');
insert into llx_c_departements (fk_region, code_departement,cheflieu,tncc,ncc,nom) values (83,'03','03190',5,'ALLIER','Allier');
@ -131,11 +137,6 @@ insert into llx_c_departements (fk_region, code_departement,cheflieu,tncc,ncc,no
insert into llx_c_departements (fk_region, code_departement,cheflieu,tncc,ncc,nom) values (11,'93','93008',3,'SEINE-SAINT-DENIS','Seine-Saint-Denis');
insert into llx_c_departements (fk_region, code_departement,cheflieu,tncc,ncc,nom) values (11,'94','94028',2,'VAL-DE-MARNE','Val-de-Marne');
insert into llx_c_departements (fk_region, code_departement,cheflieu,tncc,ncc,nom) values (11,'95','95500',2,'VAL-D OISE','Val-d Oise');
insert into llx_c_departements (fk_region, code_departement,cheflieu,tncc,ncc,nom) values ( 1,'971','97105',3,'GUADELOUPE','Guadeloupe');
insert into llx_c_departements (fk_region, code_departement,cheflieu,tncc,ncc,nom) values ( 2,'972','97209',3,'MARTINIQUE','Martinique');
insert into llx_c_departements (fk_region, code_departement,cheflieu,tncc,ncc,nom) values ( 3,'973','97302',3,'GUYANE','Guyane');
insert into llx_c_departements (fk_region, code_departement,cheflieu,tncc,ncc,nom) values ( 4,'974','97411',3,'REUNION','Réunion');
insert into llx_c_departements (fk_region, code_departement,cheflieu,tncc,ncc,nom) values ( 6,'976','97601',3,'MAYOTTE','Mayotte');
-- Provinces Belgium (id country=2)

View File

@ -73,7 +73,7 @@ insert into llx_c_forme_juridique (fk_pays, code, libelle) values (1,'31','Perso
insert into llx_c_forme_juridique (fk_pays, code, libelle) values (1,'32','Personne morale de droit étranger, non immatriculée au RCS');
insert into llx_c_forme_juridique (fk_pays, code, libelle) values (1,'35','Régime auto-entrepreneur');
insert into llx_c_forme_juridique (fk_pays, code, libelle) values (1,'41','Établissement public ou régie à caractère industriel ou commercial');
insert into llx_c_forme_juridique (fk_pays, code, libelle) values (1,'41','Etablissement public ou régie à caractère industriel ou commercial');
insert into llx_c_forme_juridique (fk_pays, code, libelle) values (1,'51','Société coopérative commerciale particulière');
insert into llx_c_forme_juridique (fk_pays, code, libelle) values (1,'52','Société en nom collectif');
@ -84,7 +84,7 @@ insert into llx_c_forme_juridique (fk_pays, code, libelle) values (1,'56','Soci
insert into llx_c_forme_juridique (fk_pays, code, libelle) values (1,'57','Société par actions simplifiée (SAS)');
insert into llx_c_forme_juridique (fk_pays, code, libelle) values (1,'58','Entreprise Unipersonnelle à Responsabilité Limitée (EURL)');
insert into llx_c_forme_juridique (fk_pays, code, libelle) values (1,'59','Société par actions simplifiée unipersonnelle (SASU)');
insert into llx_c_forme_juridique (fk_pays, code, libelle) values (1,'60', 'Entreprise Individuelle à Responsabilité Limitée (EIRL)');
insert into llx_c_forme_juridique (fk_pays, code, libelle) values (1,'60','Entreprise Individuelle à Responsabilité Limitée (EIRL)');
insert into llx_c_forme_juridique (fk_pays, code, libelle) values (1,'61','Caisse d''épargne et de prévoyance');
insert into llx_c_forme_juridique (fk_pays, code, libelle) values (1,'62','Groupement d''intérêt économique (GIE)');
insert into llx_c_forme_juridique (fk_pays, code, libelle) values (1,'63','Société coopérative agricole');
@ -94,7 +94,7 @@ insert into llx_c_forme_juridique (fk_pays, code, libelle) values (1,'69','Perso
insert into llx_c_forme_juridique (fk_pays, code, libelle) values (1,'71','Administration de l état');
insert into llx_c_forme_juridique (fk_pays, code, libelle) values (1,'72','Collectivité territoriale');
insert into llx_c_forme_juridique (fk_pays, code, libelle) values (1,'73','Établissement public administratif');
insert into llx_c_forme_juridique (fk_pays, code, libelle) values (1,'73','Etablissement public administratif');
insert into llx_c_forme_juridique (fk_pays, code, libelle) values (1,'74','Personne morale de droit public administratif');
insert into llx_c_forme_juridique (fk_pays, code, libelle) values (1,'81','Organisme gérant régime de protection social à adhésion obligatoire');

View File

@ -2,6 +2,7 @@
Language_ar_AR=Arabic
Language_ar_SA=Arabic
Language_bn_BD=Bengali
Language_bg_BG=Bulgarian
Language_bs_BA=Bosnian
Language_ca_ES=Catalan
@ -21,9 +22,10 @@ Language_en_SA=English (Saudi Arabia)
Language_en_US=English (United States)
Language_en_ZA=English (South Africa)
Language_es_ES=Spanish
Language_es_DO=Spanish (Dominican Republic)
Language_es_AR=Spanish (Argentina)
Language_es_CL=Spanish (Chile)
Language_es_CO=Spanish (Colombia)
Language_es_DO=Spanish (Dominican Republic)
Language_es_HN=Spanish (Honduras)
Language_es_MX=Spanish (Mexico)
Language_es_PY=Spanish (Paraguay)
@ -45,7 +47,10 @@ Language_id_ID=Indonesian
Language_is_IS=Icelandic
Language_it_IT=Italian
Language_ja_JP=Japanese
Language_ka_GE=Georgian
Language_kn_IN=Kannada
Language_ko_KR=Korean
Language_lo_LA=Lao
Language_lt_LT=Lithuanian
Language_lv_LV=Latvian
Language_mk_MK=Macedonian
@ -64,6 +69,7 @@ Language_sv_SV=Swedish
Language_sv_SE=Swedish
Language_sq_AL=Albanian
Language_sk_SK=Slovakian
Language_sw_SW=Kiswahili
Language_th_TH=Thai
Language_uk_UA=Ukrainian
Language_uz_UZ=Uzbek

View File

@ -7,7 +7,7 @@
* Copyright (C) 2008 Patrick Raguin <patrick.raguin@auguria.net>
* Copyright (C) 2010-2014 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2011-2013 Alexandre Spangaro <alexandre.spangaro@gmail.com>
* Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
* Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
* Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
@ -297,7 +297,7 @@ if (empty($reshook))
if ($ret < 0)
{
$error++;
$action = ($action=='add'?'create':'edit');
$action = ($action=='add'?'create':'edit');
}
if (GETPOST('deletephoto')) $object->logo = '';
@ -1136,7 +1136,7 @@ else
print '<td colspan="3" class="maxwidthonsmartphone">';
if ($object->country_id)
{
print $formcompany->select_juridicalstatus($object->forme_juridique_code,$object->country_code);
print $formcompany->select_juridicalstatus($object->forme_juridique_code, $object->country_code, '', 'legal_form');
}
else
{
@ -1686,7 +1686,7 @@ else
// Juridical type
print '<tr><td><label for="legal_form">'.$langs->trans('JuridicalStatus').'</label></td><td colspan="3">';
print $formcompany->select_juridicalstatus($object->forme_juridique_code,$object->country_code,'',0);
print $formcompany->select_juridicalstatus($object->forme_juridique_code, $object->country_code, '', 'legal_form');
print '</td></tr>';
// Capital

View File

@ -3256,6 +3256,10 @@ div.dataTables_length select {
/* Select2 */
/* ============================================================================== */
.selectoptiondisabledwhite {
background: #FFFFFF !important;
}
.select2-choice,
.select2-drop.select2-drop-above.select2-drop-active,
.select2-container-active .select2-choice,
@ -3281,6 +3285,8 @@ a span.select2-chosen
}
.select2-container .select2-choice {
background-image: none;
height: 24px;
line-height: 24px;
}
.select2-choices .select2-search-choice {
border: 1px solid #aaa !important;
@ -3299,6 +3305,7 @@ a span.select2-chosen
margin-bottom: 2px;
}
/* ============================================================================== */
/* JMobile */
/* ============================================================================== */