From ceba894d5748271162e7474b1184a2c6ea8edd97 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 5 Dec 2014 13:26:47 +0100 Subject: [PATCH] Start to work on new generation combo box. --- htdocs/comm/propal.php | 14 +- htdocs/core/class/conf.class.php | 3 + htdocs/core/class/html.form.class.php | 38 +++- htdocs/core/class/html.formcompany.class.php | 192 ++++++++---------- htdocs/core/lib/ajax.lib.php | 31 +-- htdocs/core/tpl/contacts.tpl.php | 14 +- .../jquery/plugins/select2/select2.js | 4 +- htdocs/langs/en_US/admin.lang | 2 + htdocs/projet/tasks/contact.php | 5 +- htdocs/public/test/test_forms.php | 9 +- htdocs/societe/admin/societe.php | 8 +- 11 files changed, 161 insertions(+), 159 deletions(-) diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index aa75945f0ea..5feb7769a43 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -1151,6 +1151,7 @@ if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->propal-> } } + /* * View */ @@ -1236,12 +1237,13 @@ if ($action == 'create') print '
'; print ''; print ''; - if ($origin != 'project' && $originid) { print ''; print ''; } + dol_fiche_head(); + print ''; // Reference @@ -1435,16 +1437,13 @@ if ($action == 'create') print "
\n"; - print '
'; - - /* * Combobox pour la fonction de copie */ if (empty($conf->global->PROPAL_CLONE_ON_CREATE_PAGE)) print ''; - if (! empty($conf->global->PROPAL_CLONE_ON_CREATE_PAGE) || ! empty($conf->global->PRODUCT_SHOW_WHEN_CREATE)) print ''; + if (! empty($conf->global->PROPAL_CLONE_ON_CREATE_PAGE) || ! empty($conf->global->PRODUCT_SHOW_WHEN_CREATE)) print '
'; if (! empty($conf->global->PROPAL_CLONE_ON_CREATE_PAGE)) { // For backward compatibility @@ -1514,9 +1513,10 @@ if ($action == 'create') } print ''; } - if (! empty($conf->global->PROPAL_CLONE_ON_CREATE_PAGE) || ! empty($conf->global->PRODUCT_SHOW_WHEN_CREATE)) print '

'; - + if (! empty($conf->global->PROPAL_CLONE_ON_CREATE_PAGE) || ! empty($conf->global->PRODUCT_SHOW_WHEN_CREATE)) print ''; + dol_fiche_end(); + $langs->load("bills"); print '
'; print ''; diff --git a/htdocs/core/class/conf.class.php b/htdocs/core/class/conf.class.php index e079efb8ecc..ece24bfee34 100644 --- a/htdocs/core/class/conf.class.php +++ b/htdocs/core/class/conf.class.php @@ -432,6 +432,9 @@ class Conf // Define list of limited modules if (! isset($this->global->MAIN_MODULES_FOR_EXTERNAL)) $this->global->MAIN_MODULES_FOR_EXTERNAL='user,facture,categorie,commande,fournisseur,contact,propal,projet,contrat,societe,ficheinter,expedition,agenda,adherent'; // '' means 'all'. Note that contact is added here as it should be a module later. + // Enable select2 + if (empty($conf->global->MAIN_USE_JQUERY_MULTISELECT)) $conf->global->MAIN_USE_JQUERY_MULTISELECT='select2'; + // Timeouts if (empty($this->global->MAIN_USE_CONNECT_TIMEOUT)) $this->global->MAIN_USE_CONNECT_TIMEOUT=10; if (empty($this->global->MAIN_USE_RESPONSE_TIMEOUT)) $this->global->MAIN_USE_RESPONSE_TIMEOUT=30; diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 14b7c78cc7d..08bc3b4c85e 100755 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -825,9 +825,22 @@ class Form } else { + if (! $forcecombo) + { + $out.=' + '; + } + if (count($events)) // Add management of event { - print ''; } else { @@ -4119,10 +4142,11 @@ class Form * @param int $disabled Html select box is disabled * @param int $sort 'ASC' or 'DESC' = Sort on label, '' or 'NONE' = Do not sort * @param string $morecss Add more class to css styles + * @param int $addjscombo Add js combo * @return string HTML select string. * @see multiselectarray */ - static function selectarray($htmlname, $array, $id='', $show_empty=0, $key_in_label=0, $value_as_key=0, $moreparam='', $translate=0, $maxlen=0, $disabled=0, $sort='', $morecss='') + static function selectarray($htmlname, $array, $id='', $show_empty=0, $key_in_label=0, $value_as_key=0, $moreparam='', $translate=0, $maxlen=0, $disabled=0, $sort='', $morecss='', $addjscombo=0) { global $conf, $langs; @@ -4131,13 +4155,15 @@ class Form $out=''; // Add code for jquery to use multiselect - if (empty($conf->dol_use_jmobile) && (! empty($conf->global->MAIN_USE_JQUERY_MULTISELECT) || defined('REQUIRE_JQUERY_MULTISELECT'))) + if ($addjscombo && empty($conf->dol_use_jmobile) && (! empty($conf->global->MAIN_USE_JQUERY_MULTISELECT) || defined('REQUIRE_JQUERY_MULTISELECT'))) { $tmpplugin=empty($conf->global->MAIN_USE_JQUERY_MULTISELECT)?constant('REQUIRE_JQUERY_MULTISELECT'):$conf->global->MAIN_USE_JQUERY_MULTISELECT; - $out=' + $out.=' '; diff --git a/htdocs/core/class/html.formcompany.class.php b/htdocs/core/class/html.formcompany.class.php index e45fffff759..413dc3d1544 100644 --- a/htdocs/core/class/html.formcompany.class.php +++ b/htdocs/core/class/html.formcompany.class.php @@ -520,118 +520,105 @@ 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 - * @param array $events More js events option. 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, $events=array(), $moreparam='') + function selectCompaniesForNewContact($object, $var_id, $selected='', $htmlname='newcompany', $limitto='', $forceid=0, $moreparam='') { global $conf, $langs; - // On recherche les societes - $sql = "SELECT s.rowid, s.nom as name FROM"; - $sql.= " ".MAIN_DB_PREFIX."societe as s"; - $sql.= " WHERE s.entity IN (".getEntity('societe', 1).")"; - if ($selected && $conf->use_javascript_ajax && ! empty($conf->global->COMPANY_USE_SEARCH_TO_SELECT)) $sql.= " AND s.rowid = ".$selected; + if (! empty($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; $name=''; + if ($selected > 0) + { + $tmpthirdparty=new Societe($this->db); + $result = $tmpthirdparty->fetch($selected); + if ($result > 0) + { + $socid = $selected; + $name = $tmpthirdparty->name; + } + } + + // Refresh contacts list on thirdparty list change + $htmloption=''; + + $events=array(); + $events[]=array('method' => 'getContacts', 'url' => dol_buildpath('/core/ajax/contacts.php',1), 'htmlname' => 'contactid', 'params' => array('add-customer-contact' => 'disabled')); + 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 ajax_autocompleter(($socid?$socid:-1),$htmlname,DOL_URL_ROOT.'/societe/ajaxcompanies.php','',$minLength); + return $socid; + } else { + // Search to list thirdparties + $sql = "SELECT s.rowid, s.nom as name FROM"; + $sql.= " ".MAIN_DB_PREFIX."societe as s"; + $sql.= " WHERE s.entity IN (".getEntity('societe', 1).")"; // For ajax search we limit here. For combo list, we limit later - if ($conf->use_javascript_ajax && $conf->global->COMPANY_USE_SEARCH_TO_SELECT - && is_array($limitto) && count($limitto)) + if (is_array($limitto) && count($limitto)) { $sql.= " AND s.rowid IN (".join(',',$limitto).")"; } - } - $sql.= " ORDER BY s.nom ASC"; + $sql.= " ORDER BY s.nom ASC"; - $resql = $this->db->query($sql); - if ($resql) - { - if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->COMPANY_USE_SEARCH_TO_SELECT)) + $resql = $this->db->query($sql); + if ($resql) { - // Use Ajax search - $minLength = (is_numeric($conf->global->COMPANY_USE_SEARCH_TO_SELECT)?$conf->global->COMPANY_USE_SEARCH_TO_SELECT:2); - - $socid=0; - if ($selected) - { - $obj = $this->db->fetch_object($resql); - $socid = $obj->rowid?$obj->rowid:''; - } - - // 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 ''; - //print ''; - //print '
'; - if ($obj->rowid == 0) - { - print ''; - } - else - { - print ''; - } - print ajax_autocompleter(($socid?$socid:-1),$htmlname,DOL_URL_ROOT.'/societe/ajaxcompanies.php','',$minLength); - //print '
'; - //print "\n"; - return $socid; - } - else - { - // No Ajax search print '\n"; return $firstCompany; } - } - else - { - dol_print_error($this->db); + else + { + dol_print_error($this->db); + print 'Error sql'; + } } } diff --git a/htdocs/core/lib/ajax.lib.php b/htdocs/core/lib/ajax.lib.php index 3966b29f874..df7c09d9274 100644 --- a/htdocs/core/lib/ajax.lib.php +++ b/htdocs/core/lib/ajax.lib.php @@ -323,34 +323,23 @@ function ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0) if (! empty($conf->browser->phone)) return ''; // combobox disabled for smartphones (does not works) if (! empty($conf->global->MAIN_DISABLE_AJAX_COMBOX)) return ''; - /* Some properties for combobox: - minLengthToAutocomplete: 2, - comboboxContainerClass: "comboboxContainer", - comboboxValueContainerClass: "comboboxValueContainer", - comboboxValueContentClass: "comboboxValueContent", - comboboxDropDownClass: "comboboxDropDownContainer", - comboboxDropDownButtonClass: "comboboxDropDownButton", - comboboxDropDownItemClass: "comboboxItem", - comboboxDropDownItemHoverClass: "comboboxItemHover", - comboboxDropDownGroupItemHeaderClass: "comboboxGroupItemHeader", - comboboxDropDownGroupItemContainerClass: "comboboxGroupItemContainer", - animationType: "slide", - width: "500px" */ - $msg = '