diff --git a/htdocs/core/ajax/selectsearchbox.php b/htdocs/core/ajax/selectsearchbox.php new file mode 100644 index 00000000000..c7a1c7f6d30 --- /dev/null +++ b/htdocs/core/ajax/selectsearchbox.php @@ -0,0 +1,48 @@ + + * + * 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file htdocs/core/ajax/selectsearchbox.php + * \ingroup core + * \brief This script returns content of possible search + */ + + +// This script is called with a POST method. +// Directory to scan (full path) is inside POST['dir']. + +if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL',1); // Disables token renewal +//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1'); +if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1'); +if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1'); +if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1'); + +$res=@include '../../main.inc.php'; +include_once DOL_DOCUMENT_ROOT.'/core/lib/json.lib.php'; + + +$search_boxvalue=GETPOST('q'); + +$arrayresult=array('a'=>'aaaa', 'b'=>'bbbb'); + +if ($conf->projet->enabled) +{ + $arrayresult['searchintoproject']=$langs->trans("SearchIntoProject", $search_boxvalue); +} +print dol_json_encode($arrayresult); + +if (is_object($db)) $db->close(); diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index fe4852d839b..5f75eccade6 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -4500,70 +4500,71 @@ class Form * Return a HTML select string, built from an array of key+value but content returned into select come from an Ajax call of an URL. * Note: Do not apply langs->trans function on returned content, content may be entity encoded twice. * - * @param string $htmlname Name of html select area - * @param string $url Url - * @param string $id Preselected key - * @param int $show_empty 0 no empty value allowed, 1 to add an empty value into list (value is '' or ' '). - * @param int $key_in_label 1 pour afficher la key dans la valeur "[key] value" - * @param int $value_as_key 1 to use value as key - * @param string $moreparam Add more parameters onto the select tag - * @param int $translate Translate and encode value - * @param int $maxlen Length maximum for labels - * @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. + * @param string $htmlname Name of html select area + * @param string $url Url + * @param string $id Preselected key + * @param string $moreparam Add more parameters onto the select tag + * @param string $moreparamtourl Add more parameters onto the Ajax called URL + * @param int $disabled Html select box is disabled + * @param int $minimumInputLength Minimum Input Length + * @param string $morecss Add more class to css styles + * @return string HTML select string. */ - static function selectArrayAjax($htmlname, $url, $id='', $show_empty=0, $key_in_label=0, $value_as_key=0, $moreparam='', $translate=0, $maxlen=0, $disabled=0, $sort='', $morecss='', $addjscombo=0) + static function selectArrayAjax($htmlname, $url, $id='', $moreparam='', $moreparamtourl='', $disabled=0, $minimumInputLength=1, $morecss='') { $out = ''; - // Add code for jquery to use select2 - if ($addjscombo && empty($conf->dol_use_jmobile)) - { - $tmpplugin='select2'; - $out.=' - '; - } - else - { - // TODO get all values from $url into $array + $tmpplugin='select2'; + $out.=' + '; - $out.=self::selectarray('.'.$htmlname, $array, $id, $show_empty, $key_in_label, $value_as_key, '', $translate, $maxlen, $disabled, $sort, '', 0); + $out.=''; + return $out; } diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang index 6a37ad3ae78..e5390bcdfee 100644 --- a/htdocs/langs/en_US/main.lang +++ b/htdocs/langs/en_US/main.lang @@ -747,4 +747,5 @@ ShortFriday=F ShortSaturday=S ShortSunday=S SelectMailModel=Select email template -SetRef=Set ref \ No newline at end of file +SetRef=Set ref +SearchIntoProject=Search %s into projects \ No newline at end of file diff --git a/htdocs/public/test/test_forms.php b/htdocs/public/test/test_forms.php index a6a361620e9..5e7b2f2434f 100644 --- a/htdocs/public/test/test_forms.php +++ b/htdocs/public/test/test_forms.php @@ -45,18 +45,9 @@ print '

'."\n"; print "Test 3: We must have here 1970-01-01 00:00:00 selected (fields are mandatory)
\n"; $form->select_date(dol_get_first_day(1970,1,false), 'test3', 1, 1, 0); -/*print '

'."\n"; - -print "Test 4c: a select with ajax refresh
\n"; -//$array=array(0=>'',1=>'Search into xxx',2=>'Search into yyy',3=>'Search into zzz'); -$array=array(); -$selected=-1; -print $form->selectArrayAjax('testselectc', DOL_URL_ROOT.'/core/ajax/selecsearchbox.php', $selected, 1, 0, 0, 'style="min-width: 250px;"', 0, 0, 0, '', '', 1); -*/ - print '

'."\n"; -// Test4: a select +// Test4a: a select print "Test 4a: a select
\n"; $array=array(1=>'Value 1',2=>'Value 2',3=>'Value 3 ith a very long text. aze eazeae e ae aeae a e a ea ea ea e a e aea e ae aeaeaeaze.'); $selected=3; @@ -73,20 +64,29 @@ print $form->selectarray('selectarray',$array); print '

'."\n"; -// Test4d: form->select_thirdparty -print "Test 4d: Select thirdparty
\n"; +print "Test 4d: a select with ajax refresh
\n"; +//$array=array(0=>'',1=>'Search into xxx',2=>'Search into yyy',3=>'Search into zzz'); +$array=array(); +$selected=-1; +print $form->selectArrayAjax('testselectc', DOL_URL_ROOT.'/core/ajax/selectsearchbox.php', $selected, 'style="min-width: 250px;"', '', 0, 1, ''); + + +print '

'."\n"; + +// Test5a: form->select_thirdparty +print "Test 5a: Select thirdparty
\n"; print $form->select_company(0,'thirdpartytest'); print '

'."\n"; -// Test4e: form->select_product -print "Test 4e: Select product (using ajax)
\n"; +// Test5b: form->select_product +print "Test 5b: Select product (using ajax)
\n"; $form->select_produits(0,'producttest'); print '

'."\n"; -// Test5: a multiselect -print "Test 5: a multiselect
\n"; +// Test5c: a multiselect +print "Test 5c: a multiselect
\n"; $array=array(1=>'Value 1',2=>'Value 2',3=>'Value 3'); $arrayselected=array(1,3); print $form->multiselectarray('testmulti', $array, $arrayselected, '', 0, '', 0, 250);