From d8b8f8c646ec3434263ccf5bba6746737bf21532 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 4 Feb 2014 20:49:07 +0100 Subject: [PATCH] Uniformize code for contacts forms. --- ChangeLog | 4 +- htdocs/admin/user.php | 21 -- htdocs/comm/action/contact.php | 191 ++----------------- htdocs/compta/facture/contact.php | 8 +- htdocs/core/class/conf.class.php | 7 +- htdocs/core/class/extrafields.class.php | 8 +- htdocs/core/class/html.form.class.php | 37 ++-- htdocs/core/class/html.formcompany.class.php | 81 ++++++-- htdocs/core/lib/ajax.lib.php | 28 +-- htdocs/core/tpl/contacts.tpl.php | 36 ++-- htdocs/expedition/contact.php | 186 +----------------- htdocs/projet/tasks/contact.php | 26 ++- 12 files changed, 178 insertions(+), 455 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1f76a3d4351..603d7a5930f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -41,13 +41,15 @@ For developers: - New: Add new hook function addMoreActionsButtons to allow a module to add/replace action buttons into an element. - New: Normalize code for barcode generation to match other modules. +- New: Uniformize code for contacts forms. WARNING: Following change may create regression for some external modules, but was necessary to make Dolibarr better: - The deprecated way (with 4 parameters) to declare a new tab into a module descriptor file has been removed. You must now use the 6 parameters way. See file modMyModule.class.php for example. -- +- Remove the javascrit function ac_delay() that is not used anymore by core code. + ***** ChangeLog for 3.5 compared to 3.4.* ***** For users: diff --git a/htdocs/admin/user.php b/htdocs/admin/user.php index f0ceb6dedea..77dec6ce2a3 100644 --- a/htdocs/admin/user.php +++ b/htdocs/admin/user.php @@ -135,27 +135,6 @@ else } print ''; -/* -// USER_USE_SEARCH_TO_SELECT -$var=!$var; -print ""; -print ''.$langs->trans("HideClosedUserComboBox").''; -print ' '; -if (! empty($conf->global->USER_HIDE_INACTIVE_IN_COMBOBOX)) -{ - print ''; - print img_picto($langs->trans("Activated"),'switch_on'); - print ''; -} -else -{ - print ''; - print img_picto($langs->trans("Disabled"),'switch_off'); - print ''; -} -print ''; -*/ - print ''; dol_fiche_end(); diff --git a/htdocs/comm/action/contact.php b/htdocs/comm/action/contact.php index 642842ac568..2ec18b1bd0a 100644 --- a/htdocs/comm/action/contact.php +++ b/htdocs/comm/action/contact.php @@ -60,8 +60,8 @@ $object = new ActionComm($db); * Actions */ -// Add new nouveau contact -if ($action == 'addcontact') +// Add new contact +if ($action == 'addcontact' && $user->rights->action->creer) { $result = $object->fetch($id); @@ -233,189 +233,20 @@ if ($id > 0 || ! empty($ref)) // Location print ''.$langs->trans("Location").''.$object->location.''; - print ''; - print ''; - /* - * Lignes de contacts - */ - print '
'; - - /* - * Ajouter une ligne de contact - * Non affiche en mode modification de ligne - */ - if ($action != 'editline') + dol_fiche_end(); + + print '
'; + + // Contacts lines (modules that overwrite templates must declare this into descriptor) + $dirtpls=array_merge($conf->modules_parts['tpl'],array('/core/tpl')); + foreach($dirtpls as $reldir) { - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print "\n"; - - $var = false; - - print ''; - print ''; - print ''; - print ''; - print ''; - - // Ligne ajout pour contact interne - print ""; - - print ''; - - print ''; - - print ''; - print ''; - print ''; - print ''; - - print ''; - - print ''; - print ''; - print ''; - print ''; - print ''; - - // Line to add external contact. Only if project is linked to a third party. - if ($object->socid) - { - $var=!$var; - print ""; - - print ''; - - print ''; - - print ''; - print ''; - print ''; - print ''; - } - - print ""; - - print ''; + $res=@include dol_buildpath($reldir.'/contacts.tpl.php'); + if ($res) break; } - // Liste des contacts lies - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print "\n"; - - $companystatic = new Societe($db); - $var = true; - - foreach(array('internal','external') as $source) - { - $tab = $object->liste_contact(-1,$source); - $num=count($tab); - - $i = 0; - while ($i < $num) - { - $var = !$var; - - print ''; - - // Source - print ''; - - // Societe - print ''; - - // Contact - print ''; - - // Type de contact - print ''; - - // Statut - print ''; - - // Icon update et delete - print ''; - - print "\n"; - - $i ++; - } - } - print "
'.$langs->trans("Source").''.$langs->trans("Company").''.$langs->trans("Contacts").''.$langs->trans("ContactType").' 
'; - print img_object('','user').' '.$langs->trans("Users"); - print ''; - print $conf->global->MAIN_INFO_SOCIETE_NOM; - print ''; - // On recupere les id des users deja selectionnes - $form->select_users($user->id,'contactid',0); - print ''; - $formcompany->selectTypeContact($object, '', 'type','internal','rowid'); - print '
'; - print img_object('','contact').' '.$langs->trans("ThirdPartyContacts"); - print ''; - $selectedCompany = isset($_GET["newcompany"])?$_GET["newcompany"]:$object->socid; - $selectedCompany = $formcompany->selectCompaniesForNewContact($object, 'id', $selectedCompany, 'newcompany'); - print ''; - $nbofcontacts=$form->select_contacts($selectedCompany,'','contactid'); - if ($nbofcontacts == 0) print $langs->trans("NoContactDefinedForThirdParty"); - print ''; - $formcompany->selectTypeContact($object,'','type','external','rowid'); - print '
 
'.$langs->trans("Source").''.$langs->trans("Company").''.$langs->trans("Contacts").''.$langs->trans("ContactType").''.$langs->trans("Status").' 
'; - if ($tab[$i]['source']=='internal') print $langs->trans("User"); - if ($tab[$i]['source']=='external') print $langs->trans("ThirdPartyContact"); - print ''; - if ($tab[$i]['socid'] > 0) - { - $companystatic->fetch($tab[$i]['socid']); - print $companystatic->getNomUrl(1); - } - if ($tab[$i]['socid'] < 0) - { - print $conf->global->MAIN_INFO_SOCIETE_NOM; - } - if (! $tab[$i]['socid']) - { - print ' '; - } - print ''; - if ($tab[$i]['source']=='internal') - { - print ''; - print img_object($langs->trans("ShowUser"),"user").' '.$tab[$i]['nom'].''; - } - if ($tab[$i]['source']=='external') - { - print ''; - print img_object($langs->trans("ShowContact"),"contact").' '.$tab[$i]['nom'].''; - } - print ''.$tab[$i]['libelle'].''; - // Activation desativation du contact - if ($object->statut >= 0 ) print ''; - print $contactstatic->LibStatut($tab[$i]['status'],3); - if ($object->statut >= 0 ) print ''; - print ''; - /*if ($user->rights->business->write && $userAccess) - {*/ - print ' '; - print ''; - print img_delete(); - print ''; - //} - print '
"; } else { diff --git a/htdocs/compta/facture/contact.php b/htdocs/compta/facture/contact.php index 9b8689a8e6d..f593d6a1742 100644 --- a/htdocs/compta/facture/contact.php +++ b/htdocs/compta/facture/contact.php @@ -71,16 +71,16 @@ if ($action == 'addcontact' && $user->rights->facture->creer) if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') { $langs->load("errors"); - $mesg = '
'.$langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType").'
'; + setEventMessage($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), 'errors'); } else { - $mesg = '
'.$object->error.'
'; + setEventMessage($object->error, 'errors'); } } } -// bascule du statut d'un contact +// Bascule du statut d'un contact else if ($action == 'swapstatut' && $user->rights->facture->creer) { if ($object->fetch($id)) @@ -179,7 +179,7 @@ if ($id > 0 || ! empty($ref)) print ''.$object->client->getNomUrl(1,'compta').''; print ""; - print ''; + dol_fiche_end(); print '
'; diff --git a/htdocs/core/class/conf.class.php b/htdocs/core/class/conf.class.php index 903694128f9..c068830a4aa 100644 --- a/htdocs/core/class/conf.class.php +++ b/htdocs/core/class/conf.class.php @@ -345,7 +345,12 @@ class Conf $this->use_javascript_ajax=1; if (isset($this->global->MAIN_DISABLE_JAVASCRIPT)) $this->use_javascript_ajax=! $this->global->MAIN_DISABLE_JAVASCRIPT; // If no javascript_ajax, Ajax features are disabled. - if (! $this->use_javascript_ajax) $this->global->PRODUIT_USE_SEARCH_TO_SELECT=0; + if (empty($this->use_javascript_ajax)) + { + unset($this->global->PRODUIT_USE_SEARCH_TO_SELECT); + unset($this->global->COMPANY_USE_SEARCH_TO_SELECT); + unset($this->global->CONTACT_USE_SEARCH_TO_SELECT); + } // conf->currency if (empty($this->global->MAIN_MONNAIE)) $this->global->MAIN_MONNAIE='EUR'; diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index f0428457700..e15d1eac8a7 100644 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -673,7 +673,6 @@ class ExtraFields $out = ''; if ($conf->use_javascript_ajax && $conf->global->COMPANY_USE_SEARCH_TO_SELECT && ! $forcecombo) { - //$minLength = (is_numeric($conf->global->COMPANY_USE_SEARCH_TO_SELECT)?$conf->global->COMPANY_USE_SEARCH_TO_SELECT:2); $out.= ajax_combobox('options_'.$key, $event, $conf->global->COMPANY_USE_SEARCH_TO_SELECT); } @@ -693,7 +692,6 @@ class ExtraFields $out = ''; if ($conf->use_javascript_ajax && $conf->global->COMPANY_USE_SEARCH_TO_SELECT && ! $forcecombo) { - //$minLength = (is_numeric($conf->global->COMPANY_USE_SEARCH_TO_SELECT)?$conf->global->COMPANY_USE_SEARCH_TO_SELECT:2); $out.= ajax_combobox('options_'.$key, $event, $conf->global->COMPANY_USE_SEARCH_TO_SELECT); } @@ -959,18 +957,18 @@ class ExtraFields } $sql.= " WHERE ".$selectkey."='".$this->db->escape($value)."'"; //$sql.= ' AND entity = '.$conf->entity; - + dol_syslog(get_class($this).':showOutputField:$type=sellist sql='.$sql); $resql = $this->db->query($sql); if ($resql) { $value=''; // value was used, so now we reste it to use it to build final output - + $obj = $this->db->fetch_object($resql); // Several field into label (eq table:code|libelle:rowid) $fields_label = explode('|',$InfoFieldList[1]); - + if(is_array($fields_label)) { foreach ($fields_label as $field_toshow) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 49aff9b83c0..aca67c810e0 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -683,14 +683,14 @@ class Form $out=''; - /* TODO Use ajax autocompletion (not finished) + /* TODO Use ajax_autocompleter like for products (not finished) if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->COMPANY_USE_SEARCH_TO_SELECT) && ! $forcecombo) { $placeholder=''; if ($selected && empty($selected_input_value)) { - require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; + require_once DOL_DOCUMENT_ROOT.'/societe/ajaxcompanies.php'; $societe = new Societe($this->db); $societe->fetch($selected); $selected_input_value=$societe->ref; @@ -728,13 +728,13 @@ class Form * @param int $showempty Add an empty field * @param int $showtype Show third party type in combolist (customer, prospect or supplier) * @param int $forcecombo Force to use combo box - * @param array $event Event options. Example: array(array('method'=>'getContacts', 'url'=>dol_buildpath('/core/ajax/contacts.php',1), 'htmlname'=>'contactid', 'params'=>array('add-customer-contact'=>'disabled'))) + * @param array $events Event options. Example: array(array('method'=>'getContacts', 'url'=>dol_buildpath('/core/ajax/contacts.php',1), 'htmlname'=>'contactid', 'params'=>array('add-customer-contact'=>'disabled'))) * @return string HTML string with * @deprecated Use select_thirdparty instead */ - function select_company($selected='', $htmlname='socid', $filter='', $showempty=0, $showtype=0, $forcecombo=0, $event=array()) + function select_company($selected='', $htmlname='socid', $filter='', $showempty=0, $showtype=0, $forcecombo=0, $events=array()) { - return $this->select_thirdparty_list($selected,$htmlname, $filter, $showempty, $showtype, $forcecombo, $event); + return $this->select_thirdparty_list($selected, $htmlname, $filter, $showempty, $showtype, $forcecombo, $events); } /** @@ -746,13 +746,13 @@ class Form * @param int $showempty Add an empty field * @param int $showtype Show third party type in combolist (customer, prospect or supplier) * @param int $forcecombo Force to use combo box - * @param array $event Event options. Example: array(array('method'=>'getContacts', 'url'=>dol_buildpath('/core/ajax/contacts.php',1), 'htmlname'=>'contactid', 'params'=>array('add-customer-contact'=>'disabled'))) + * @param array $events Event options. Example: array(array('method'=>'getContacts', 'url'=>dol_buildpath('/core/ajax/contacts.php',1), 'htmlname'=>'contactid', 'params'=>array('add-customer-contact'=>'disabled'))) * @param string $filterkey Filter on key value * @param int $outputmode 0=HTML select string, 1=Array * @param int $limit Limit number of answers * @return string HTML string with */ - function select_thirdparty_list($selected='',$htmlname='socid',$filter='',$showempty=0, $showtype=0, $forcecombo=0, $event=array(), $filterkey='', $outputmode=0, $limit=20) + function select_thirdparty_list($selected='',$htmlname='socid',$filter='',$showempty=0, $showtype=0, $forcecombo=0, $events=array(), $filterkey='', $outputmode=0, $limit=20) { global $conf,$user,$langs; @@ -800,8 +800,7 @@ class Form { if ($conf->use_javascript_ajax && $conf->global->COMPANY_USE_SEARCH_TO_SELECT && ! $forcecombo) { - //$minLength = (is_numeric($conf->global->COMPANY_USE_SEARCH_TO_SELECT)?$conf->global->COMPANY_USE_SEARCH_TO_SELECT:2); - $out.= ajax_combobox($htmlname, $event, $conf->global->COMPANY_USE_SEARCH_TO_SELECT); + $out.= ajax_combobox($htmlname, $events, $conf->global->COMPANY_USE_SEARCH_TO_SELECT); } // Construct $out and $outarray @@ -943,13 +942,13 @@ class Form * @param string $moreclass Add more class to class style * @param string $showsoc Add company into label * @param int $forcecombo Force to use combo box - * @param array $event Event options. Example: array(array('method'=>'getContacts', 'url'=>dol_buildpath('/core/ajax/contacts.php',1), 'htmlname'=>'contactid', 'params'=>array('add-customer-contact'=>'disabled'))) + * @param array $events Event options. Example: array(array('method'=>'getContacts', 'url'=>dol_buildpath('/core/ajax/contacts.php',1), 'htmlname'=>'contactid', 'params'=>array('add-customer-contact'=>'disabled'))) * @param bool $options_only Return options only (for ajax treatment) * @return int <0 if KO, Nb of contact in list if OK */ - function select_contacts($socid,$selected='',$htmlname='contactid',$showempty=0,$exclude='',$limitto='',$showfunction=0, $moreclass='', $showsoc=0, $forcecombo=0, $event=array(), $options_only=false) + function select_contacts($socid,$selected='',$htmlname='contactid',$showempty=0,$exclude='',$limitto='',$showfunction=0, $moreclass='', $showsoc=0, $forcecombo=0, $events=array(), $options_only=false) { - print $this->selectcontacts($socid,$selected,$htmlname,$showempty,$exclude,$limitto,$showfunction, $moreclass, $options_only, $showsoc, $forcecombo, $event); + print $this->selectcontacts($socid,$selected,$htmlname,$showempty,$exclude,$limitto,$showfunction, $moreclass, $options_only, $showsoc, $forcecombo, $events); return $this->num; } @@ -967,10 +966,10 @@ class Form * @param bool $options_only Return options only (for ajax treatment) * @param string $showsoc Add company into label * @param int $forcecombo Force to use combo box - * @param array $event Event options. Example: array(array('method'=>'getContacts', 'url'=>dol_buildpath('/core/ajax/contacts.php',1), 'htmlname'=>'contactid', 'params'=>array('add-customer-contact'=>'disabled'))) - * @return int <0 if KO, Nb of contact in list if OK + * @param array $events Event options. Example: array(array('method'=>'getContacts', 'url'=>dol_buildpath('/core/ajax/contacts.php',1), 'htmlname'=>'contactid', 'params'=>array('add-customer-contact'=>'disabled'))) + * @return int <0 if KO, Nb of contact in list if OK */ - function selectcontacts($socid,$selected='',$htmlname='contactid',$showempty=0,$exclude='',$limitto='',$showfunction=0, $moreclass='', $options_only=false, $showsoc=0, $forcecombo=0, $event=array()) + function selectcontacts($socid,$selected='',$htmlname='contactid',$showempty=0,$exclude='',$limitto='',$showfunction=0, $moreclass='', $options_only=false, $showsoc=0, $forcecombo=0, $events=array()) { global $conf,$langs; @@ -1000,7 +999,7 @@ class Form if ($conf->use_javascript_ajax && $conf->global->CONTACT_USE_SEARCH_TO_SELECT && ! $forcecombo && ! $options_only) { - $out.= ajax_combobox($htmlname, $event, $conf->global->CONTACT_USE_SEARCH_TO_SELECT); + $out.= ajax_combobox($htmlname, $events, $conf->global->CONTACT_USE_SEARCH_TO_SELECT); } if ($htmlname != 'none' || $options_only) $out.= ''; print ''; print ''; print ''; print '
'; - print $this->select_company($selected, $htmlname, $filter, $showempty, $showtype, $forcecombo, $event); + print $this->select_company($selected, $htmlname, $filter, $showempty, $showtype, $forcecombo, $events); print '
'; diff --git a/htdocs/core/class/html.formcompany.class.php b/htdocs/core/class/html.formcompany.class.php index 76b2810d59b..39f1ae43402 100644 --- a/htdocs/core/class/html.formcompany.class.php +++ b/htdocs/core/class/html.formcompany.class.php @@ -203,7 +203,7 @@ class FormCompany * un code donnee mais dans ce cas, le champ pays differe). * Ainsi les liens avec les departements se font sur un departement independemment de son nom. * - * @param string $selected Code state preselected (mus be state id) + * @param string $selected Code state preselected (mus be state id) * @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 @@ -501,7 +501,7 @@ class FormCompany /** - * Return list of third parties + * Output list of third parties. * * @param object $object Object we try to find contacts * @param string $var_id Name of id field @@ -509,12 +509,11 @@ class FormCompany * @param string $htmlname Name of HTML form * @param array $limitto Disable answers that are not id in this array list * @param int $forceid This is to force another object id than object->id - * @return int The selected third party ID - * TODO obsolete ? - * cette fonction doit utiliser du javascript quoi qu'il en soit ! - * autant utiliser le système combobox sans rechargement de page non ? + * @param array $event Event options. Example: array(array('method'=>'getContacts', 'url'=>dol_buildpath('/core/ajax/contacts.php',1), 'htmlname'=>'contactid', 'params'=>array('add-customer-contact'=>'disabled'))) + * @param string $moreparam String with more param to add into url when noajax search is used. + * @return int The selected third party ID */ - function selectCompaniesForNewContact($object, $var_id, $selected='', $htmlname='newcompany', $limitto='', $forceid=0) + function selectCompaniesForNewContact($object, $var_id, $selected='', $htmlname='newcompany', $limitto='', $forceid=0, $events=array(), $moreparam='') { global $conf, $langs; @@ -539,6 +538,7 @@ class FormCompany { if ($conf->use_javascript_ajax && ! empty($conf->global->COMPANY_USE_SEARCH_TO_SELECT)) { + // Use Ajax search $minLength = (is_numeric($conf->global->COMPANY_USE_SEARCH_TO_SELECT)?$conf->global->COMPANY_USE_SEARCH_TO_SELECT:2); $socid=0; @@ -548,18 +548,63 @@ class FormCompany $socid = $obj->rowid?$obj->rowid:''; } - // We call a page after a small delay when a new input has been selected - $javaScript = "window.location=\'".$_SERVER['PHP_SELF']."?".$var_id."=".($forceid>0?$forceid:$object->id)."&".$htmlname."=\' + document.getElementById(\'".$htmlname."\').value;"; - $htmloption = 'onChange="ac_delay(\''.$javaScript.'\',\'500\');"'; // When we select with mouse - $htmloption.= 'onKeyUp="if (event.keyCode== 13) { ac_delay(\''.$javaScript.'\',\'500\'); }"'; // When we select with keyboard + // We recall a page after a small delay when a new input has been selected + $htmloption=''; + //$javaScript = "window.location=\'".$_SERVER['PHP_SELF']."?".$var_id."=".($forceid>0?$forceid:$object->id)."&".$htmlname."=\' + document.getElementById(\'".$htmlname."\').value;"; + //$htmloption.= 'onChange="ac_delay(\''.$javaScript.'\',\'500\');"'; // When we select with mouse + //$htmloption.= 'onKeyUp="if (event.keyCode== 13) { ac_delay(\''.$javaScript.'\',\'500\'); }"'; // When we select with keyboard + + if (count($events)) // If there is some ajax events to run once selection is done, we add code here to run events + { + print ''; + } print "\n".''."\n"; print ''; print '
'; if ($obj->rowid == 0) { - //$langs->load("companies"); - //print ''; print ''; } else @@ -575,8 +620,14 @@ class FormCompany } else { - $javaScript = "window.location='".$_SERVER['PHP_SELF']."?".$var_id."=".($forceid>0?$forceid:$object->id)."&".$htmlname."=' + form.".$htmlname.".options[form.".$htmlname.".selectedIndex].value;"; - print 'use_javascript_ajax) + { + $javaScript = "window.location='".$_SERVER['PHP_SELF']."?".$var_id."=".($forceid>0?$forceid:$object->id).$moreparam."&".$htmlname."=' + form.".$htmlname.".options[form.".$htmlname.".selectedIndex].value;"; + print ' onChange="'.$javaScript.'"'; + } + print '>'; $num = $this->db->num_rows($resql); $i = 0; if ($num) diff --git a/htdocs/core/lib/ajax.lib.php b/htdocs/core/lib/ajax.lib.php index cc5ca841c52..aee2ff5dff6 100644 --- a/htdocs/core/lib/ajax.lib.php +++ b/htdocs/core/lib/ajax.lib.php @@ -25,7 +25,8 @@ /** - * Get value of an HTML field, do Ajax process and show result + * Get value of an HTML field, do Ajax process and show result. + * The HTML field must be an input text with id=search_$htmlname. * * @param string $selected Preselecte value * @param string $htmlname HTML name of input field @@ -54,11 +55,12 @@ function ajax_autocompleter($selected, $htmlname, $url, $urloption='', $minLengt $("#'.$htmlname.'").val(""); }); $("input#search_'.$htmlname.'").change(function() { - //console.log(\'keyup\'); + //console.log(\'change\'); $("#'.$htmlname.'").trigger("change"); }); // Check when keyup $("input#search_'.$htmlname.'").onDelayedKeyup({ handler: function() { + //console.log(\'keyup\'); if ($(this).val().length == 0) { $("#search_'.$htmlname.'").val(""); @@ -120,9 +122,9 @@ function ajax_autocompleter($selected, $htmlname, $url, $urloption='', $minLengt }, dataType: "json", minLength: '.$minLength.', - select: function( event, ui ) { + select: function( event, ui ) { // Function ran when new value is selected into javascript combo //console.log(\'set value of id with \'+ui.item.id); - $("#'.$htmlname.'").val(ui.item.id).trigger("change"); + $("#'.$htmlname.'").val(ui.item.id).trigger("change"); // Select new value // Disable an element if (options.option_disabled) { if (ui.item.disabled) { @@ -162,6 +164,7 @@ function ajax_autocompleter($selected, $htmlname, $url, $urloption='', $minLengt } }); } + $("#search_'.$htmlname.'").trigger("change"); // To tell that input text field was modified } }).data( "autocomplete" )._renderItem = function( ul, item ) { return $( "
  • " ) @@ -169,6 +172,7 @@ function ajax_autocompleter($selected, $htmlname, $url, $urloption='', $minLengt .append( \'\' + item.label + "" ) .appendTo(ul); }; + });'; $script.= ''; @@ -293,14 +297,16 @@ function ajax_dialog($title,$message,$w=350,$h=150) } /** - * Convert a html select field into an ajax combobox + * Convert a html select field into an ajax combobox. + * Use ajax_combobox() only for small combo list! If not, use instead ajax_autocompleter(). + * TODO: It is used when COMPANY_USE_SEARCH_TO_SELECT and CONTACT_USE_SEARCH_TO_SELECT are set by html.formcompany.class.php. Should use ajax_autocompleter instead like done by html.form.class.php for select_produits. * - * @param string $htmlname Name of html select field - * @param array $event Event options. Example: array(array('method'=>'getContacts', 'url'=>dol_buildpath('/core/ajax/contacts.php',1), 'htmlname'=>'contactid', 'params'=>array('add-customer-contact'=>'disabled'))) - * @param int $minLengthToAutocomplete Minimum length of input string to start autocomplete - * @return string Return html string to convert a select field into a combo + * @param string $htmlname Name of html select field + * @param array $events Event options. Example: array(array('method'=>'getContacts', 'url'=>dol_buildpath('/core/ajax/contacts.php',1), 'htmlname'=>'contactid', 'params'=>array('add-customer-contact'=>'disabled'))) + * @param int $minLengthToAutocomplete Minimum length of input string to start autocomplete + * @return string Return html string to convert a select field into a combo */ -function ajax_combobox($htmlname, $event=array(), $minLengthToAutocomplete=0) +function ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0) { global $conf; @@ -326,7 +332,7 @@ function ajax_combobox($htmlname, $event=array(), $minLengthToAutocomplete=0) $("#'.$htmlname.'").combobox({ minLengthToAutocomplete : '.$minLengthToAutocomplete.', selected : function(event,ui) { - var obj = '.json_encode($event).'; + var obj = '.json_encode($events).'; $.each(obj, function(key,values) { if (values.method.length) { getMethod(values); diff --git a/htdocs/core/tpl/contacts.tpl.php b/htdocs/core/tpl/contacts.tpl.php index c2c2ef9a452..35849720e7d 100644 --- a/htdocs/core/tpl/contacts.tpl.php +++ b/htdocs/core/tpl/contacts.tpl.php @@ -17,6 +17,7 @@ * * This template needs: * $object + * $withproject (if we are on task contact) */ if (! class_exists('Contact')) { @@ -34,6 +35,9 @@ elseif ($module == 'fichinter') { $permission=$user->rights->ficheinter->creer elseif ($module == 'invoice_supplier') { $permission=$user->rights->fournisseur->facture->creer; } elseif ($module == 'order_supplier') { $permission=$user->rights->fournisseur->commande->creer; } elseif ($module == 'project') { $permission=$user->rights->projet->creer; } +elseif ($module == 'action') { $permission=$user->rights->agenda->myactions->create; } +elseif ($module == 'shipping') { $permission=$user->rights->expedition->creer; } +elseif ($module == 'project_task') { $permission=$user->rights->projet->creer; } elseif (! isset($permission)) { $permission=$user->rights->$module->creer; } // If already defined by caller page $formcompany= new FormCompany($db); @@ -64,6 +68,7 @@ $userstatic=new User($db); + '; ?>
    trans("Users"); ?>
    global->MAIN_INFO_SOCIETE_NOM; ?>
    select_dolusers($user->id, 'userid', 0, (! empty($userAlreadySelected)?$userAlreadySelected:null), 0, null, null, 0, 56); ?>
    @@ -79,29 +84,24 @@ $userstatic=new User($db); + '; ?>
    trans("ThirdPartyContacts"); ?>
    - use_javascript_ajax && ! empty($conf->global->COMPANY_USE_SEARCH_TO_SELECT)) { ?> + 'getContacts', 'url' => dol_buildpath('/core/ajax/contacts.php',1), 'htmlname' => 'contactid', 'params' => array('add-customer-contact' => 'disabled')); + ?>
    - 'getContacts', 'url' => dol_buildpath('/core/ajax/contacts.php',1), 'htmlname' => 'contactid', 'params' => array('add-customer-contact' => 'disabled')); - print $form->select_company($object->socid,'socid','',1,0,0,$events); - ?> -
    -
    - select_contacts($object->socid, '', 'contactid'); ?> -
    - -
    socid; ?> - selectCompaniesForNewContact($object, 'id', $selectedCompany, 'newcompany'); ?> + selectCompaniesForNewContact($object, 'id', $selectedCompany, 'newcompany', '', 0, $events); ?>
    select_contacts($selectedCompany, '', 'contactid'); ?>
    -
    - selectTypeContact($object, '', 'type','external'); ?> + element == 'shipping' && is_object($objectsrc)) $tmpobject=$objectsrc; + $formcompany->selectTypeContact($tmpobject, '', 'type','external'); ?>
     
    @@ -124,7 +124,11 @@ $userstatic=new User($db); liste_contact(-1,$source); + + $tmpobject=$object; + if ($object->element == 'shipping' && is_object($objectsrc)) $tmpobject=$objectsrc; + + $tab = $tmpobject->liste_contact(-1,$source); $num=count($tab); $i = 0; diff --git a/htdocs/expedition/contact.php b/htdocs/expedition/contact.php index ef5faa79e3b..6cfd835925d 100644 --- a/htdocs/expedition/contact.php +++ b/htdocs/expedition/contact.php @@ -106,9 +106,9 @@ else if ($action == 'swapstatut' && $user->rights->expedition->creer) } // Efface un contact -else if ($action == 'deleteline' && $user->rights->expedition->creer) +else if ($action == 'deletecontact' && $user->rights->expedition->creer) { - $result = $objectsrc->delete_contact($_GET["lineid"]); + $result = $objectsrc->delete_contact(GETPOST("lineid")); if ($result >= 0) { @@ -233,186 +233,20 @@ if ($id > 0 || ! empty($ref)) print "
    "; - print ''; + dol_fiche_end(); // Lignes de contacts - echo '
    '; + echo '
    '; - /* - * Ajouter une ligne de contact. Non affiche en mode modification de ligne - */ - if ($action != 'editline' && $user->rights->expedition->creer) + + // Contacts lines (modules that overwrite templates must declare this into descriptor) + $dirtpls=array_merge($conf->modules_parts['tpl'],array('/core/tpl')); + foreach($dirtpls as $reldir) { - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print "\n"; - - $var = false; - - print ''; - print ''; - print ''; - print ''; - print ''; - - // Ligne ajout pour contact interne - print ''; - - print ''; - - print ''; - - print ''; - print ''; - print ''; - print ''; - - print ''; - - print ''; - print ''; - print ''; - print ''; - print ''; - - // Ligne ajout pour contact externe - $var=!$var; - print ''; - - print ''; - - print ''; - - print ''; - print ''; - print ''; - print ''; - - print ""; - - print ''; + $res=@include dol_buildpath($reldir.'/contacts.tpl.php'); + if ($res) break; } - // List of linked contacts - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print "\n"; - - $companystatic=new Societe($db); - $var = true; - - foreach(array('internal','external') as $source) - { - $tab = $objectsrc->liste_contact(-1,$source); - $num=count($tab); - - $i = 0; - while ($i < $num) - { - $var = !$var; - - print ''; - - // Source - print ''; - - // Societe - print ''; - - // Contact - print ''; - - // Type de contact - print ''; - - // Statut - print ''; - - // Icon update et delete - print ''; - - print "\n"; - - $i ++; - } - } - print "
    '.$langs->trans("Source").''.$langs->trans("Company").''.$langs->trans("Contacts").''.$langs->trans("ContactType").'  
    '; - print img_object('','user').' '.$langs->trans("Users"); - print ''; - print $conf->global->MAIN_INFO_SOCIETE_NOM; - print ''; - $form->select_users($user->id,'contactid'); - print ''; - $formcompany->selectTypeContact($objectsrc, '', 'type','internal'); - print '
    '; - print img_object('','contact').' '.$langs->trans("ThirdPartyContacts"); - print ''; - $selectedCompany = isset($_GET["newcompany"])?$_GET["newcompany"]:$object->client->id; - $selectedCompany = $formcompany->selectCompaniesForNewContact($objectsrc, 'id', $selectedCompany, 'newcompany', '', $object->id); - print ''; - $nbofcontacts=$form->select_contacts($selectedCompany, '', 'contactid'); - if ($nbofcontacts == 0) print $langs->trans("NoContactDefined"); - print ''; - - $formcompany->selectTypeContact($objectsrc, '', 'type','external'); - print '
     
    '.$langs->trans("Source").''.$langs->trans("Company").''.$langs->trans("Contacts").''.$langs->trans("ContactType").''.$langs->trans("Status").' 
    '; - if ($tab[$i]['source']=='internal') print $langs->trans("User"); - if ($tab[$i]['source']=='external') print $langs->trans("ThirdPartyContact"); - print ''; - if ($tab[$i]['socid'] > 0) - { - $companystatic->fetch($tab[$i]['socid']); - print $companystatic->getNomUrl(1); - } - if ($tab[$i]['socid'] < 0) - { - print $conf->global->MAIN_INFO_SOCIETE_NOM; - } - if (! $tab[$i]['socid']) - { - print ' '; - } - print ''; - if ($tab[$i]['source']=='internal') - { - $userstatic->id=$tab[$i]['id']; - $userstatic->lastname=$tab[$i]['lastname']; - $userstatic->firstname=$tab[$i]['firstname']; - print $userstatic->getNomUrl(1); - } - if ($tab[$i]['source']=='external') - { - $contactstatic->id=$tab[$i]['id']; - $contactstatic->lastname=$tab[$i]['lastname']; - $contactstatic->firstname=$tab[$i]['firstname']; - print $contactstatic->getNomUrl(1); - } - print ''.$tab[$i]['libelle'].''; - // Activation desativation du contact - if ($object->statut >= 0) print ''; - print $contactstatic->LibStatut($tab[$i]['status'],3); - if ($object->statut >= 0) print ''; - print ''; - if ($object->statut < 5 && $user->rights->expedition->creer) - { - print ' '; - print ''; - print img_delete(); - print ''; - } - print '
    "; } llxFooter(); diff --git a/htdocs/projet/tasks/contact.php b/htdocs/projet/tasks/contact.php index 80ddc0cd178..0d8ffcc3fe4 100644 --- a/htdocs/projet/tasks/contact.php +++ b/htdocs/projet/tasks/contact.php @@ -260,7 +260,17 @@ if ($id > 0 || ! empty($ref)) /* * Lignes de contacts */ - print '
    '; + print '
    '; +/* + // Contacts lines (modules that overwrite templates must declare this into descriptor) + $dirtpls=array_merge($conf->modules_parts['tpl'],array('/core/tpl')); + foreach($dirtpls as $reldir) + { + $res=@include dol_buildpath($reldir.'/contacts.tpl.php'); + if ($res) break; + } +*/ + print '
    '; /* * Ajouter une ligne de contact @@ -283,7 +293,7 @@ if ($id > 0 || ! empty($ref)) print ''; print ''; print ''; - print ''; + if ($withproject) print ''; // Ligne ajout pour contact interne print ""; @@ -299,7 +309,7 @@ if ($id > 0 || ! empty($ref)) print ''; print '"; @@ -326,20 +337,22 @@ if ($id > 0 || ! empty($ref)) print ''; print ''; print ''; print ''; - print ''; print ''; @@ -442,6 +455,7 @@ if ($id > 0 || ! empty($ref)) } } print "
    '; // On recupere les id des users deja selectionnes $contactsofproject=$projectstatic->getListContactId('internal'); - $form->select_users($user->id,'contactid',0,'',0,'',$contactsofproject); + $form->select_users($user->id,'userid',0,'',0,'',$contactsofproject); print ''; $formcompany->selectTypeContact($object, '', 'type','internal','rowid'); @@ -317,6 +327,7 @@ if ($id > 0 || ! empty($ref)) print ''; print ''; print ''; + if ($withproject) print ''; $var=!$var; print "
    '; + $events=array(); + $events[]=array('method' => 'getContacts', 'url' => dol_buildpath('/core/ajax/contacts.php',1), 'htmlname' => 'contactid', 'params' => array('add-customer-contact' => 'disabled')); + $thirdpartyofproject=$projectstatic->getListContactId('thirdparty'); $selectedCompany = isset($_GET["newcompany"])?$_GET["newcompany"]:$projectstatic->societe->id; - $selectedCompany = $formcompany->selectCompaniesForNewContact($object, 'id', $selectedCompany, 'newcompany',$thirdpartyofproject); + $selectedCompany = $formcompany->selectCompaniesForNewContact($object, 'id', $selectedCompany, 'newcompany', $thirdpartyofproject, 0, $events, '&withproject='.$withproject); print ''; $contactofproject=$projectstatic->getListContactId('external'); $nbofcontacts=$form->select_contacts($selectedCompany,'','contactid',0,'',$contactofproject); - if ($nbofcontacts == 0) print $langs->trans("NoContactDefined"); print ''; $formcompany->selectTypeContact($object, '', 'type','external','rowid'); print '
    "; + } else {