New htmlid can be use instead of htmlname for select projects

This commit is contained in:
phf 2017-01-31 12:20:45 +01:00
parent 10bacda820
commit e73c60b526
2 changed files with 16 additions and 12 deletions

View File

@ -60,9 +60,10 @@ class FormProjets
* @param int $nooutput No print output. Return it only. * @param int $nooutput No print output. Return it only.
* @param int $forceaddid Force to add project id in list, event if not qualified * @param int $forceaddid Force to add project id in list, event if not qualified
* @param string $morecss More css * @param string $morecss More css
* @param int $htmlid Html id to use instead of htmlname
* @return string Return html content * @return string Return html content
*/ */
function select_projects($socid=-1, $selected='', $htmlname='projectid', $maxlength=16, $option_only=0, $show_empty=1, $discard_closed=0, $forcefocus=0, $disabled=0, $mode = 0, $filterkey = '', $nooutput=0, $forceaddid=0, $morecss='') function select_projects($socid=-1, $selected='', $htmlname='projectid', $maxlength=16, $option_only=0, $show_empty=1, $discard_closed=0, $forcefocus=0, $disabled=0, $mode = 0, $filterkey = '', $nooutput=0, $forceaddid=0, $morecss='', $htmlid='')
{ {
global $langs,$conf,$form; global $langs,$conf,$form;
@ -90,7 +91,7 @@ class FormProjets
} }
else else
{ {
$out.=$this->select_projects_list($socid, $selected, $htmlname, $maxlength, $option_only, $show_empty, $discard_closed, $forcefocus, $disabled, 0, $filterkey, 1); $out.=$this->select_projects_list($socid, $selected, $htmlname, $maxlength, $option_only, $show_empty, $discard_closed, $forcefocus, $disabled, 0, $filterkey, 1, $forceaddid, $htmlid);
if ($discard_closed) if ($discard_closed)
{ {
if (class_exists('Form')) if (class_exists('Form'))
@ -125,9 +126,10 @@ class FormProjets
* @param string $filterkey Key to filter * @param string $filterkey Key to filter
* @param int $nooutput No print output. Return it only. * @param int $nooutput No print output. Return it only.
* @param int $forceaddid Force to add project id in list, event if not qualified * @param int $forceaddid Force to add project id in list, event if not qualified
* @param int $htmlid Html id to use instead of htmlname
* @return int Nb of project if OK, <0 if KO * @return int Nb of project if OK, <0 if KO
*/ */
function select_projects_list($socid=-1, $selected='', $htmlname='projectid', $maxlength=24, $option_only=0, $show_empty=1, $discard_closed=0, $forcefocus=0, $disabled=0, $mode=0, $filterkey = '', $nooutput=0, $forceaddid=0) function select_projects_list($socid=-1, $selected='', $htmlname='projectid', $maxlength=24, $option_only=0, $show_empty=1, $discard_closed=0, $forcefocus=0, $disabled=0, $mode=0, $filterkey = '', $nooutput=0, $forceaddid=0, $htmlid='')
{ {
global $user,$conf,$langs; global $user,$conf,$langs;
@ -173,14 +175,14 @@ class FormProjets
if (! empty($conf->use_javascript_ajax)) if (! empty($conf->use_javascript_ajax))
{ {
include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
$comboenhancement = ajax_combobox($htmlname, array(), 0, $forcefocus); $comboenhancement = ajax_combobox($htmlname, array(), 0, $forcefocus,'resolve',$htmlid);
$out.=$comboenhancement; $out.=$comboenhancement;
$nodatarole=($comboenhancement?' data-role="none"':''); $nodatarole=($comboenhancement?' data-role="none"':'');
$minmax='minwidth100 maxwidth300'; $minmax='minwidth100 maxwidth300';
} }
if (empty($option_only)) { if (empty($option_only)) {
$out.= '<select class="flat'.($minmax?' '.$minmax:'').'"'.($disabled?' disabled="disabled"':'').' id="'.$htmlname.'" name="'.$htmlname.'"'.$nodatarole.'>'; $out.= '<select class="flat'.($minmax?' '.$minmax:'').'"'.($disabled?' disabled="disabled"':'').' id="'.(empty($htmlid?$htmlname:$htmlid)).'" name="'.$htmlname.'"'.$nodatarole.'>';
} }
if (!empty($show_empty)) { if (!empty($show_empty)) {
$out.= '<option value="0">&nbsp;</option>'; $out.= '<option value="0">&nbsp;</option>';

View File

@ -357,12 +357,14 @@ function ajax_dialog($title,$message,$w=350,$h=150)
* @param int $minLengthToAutocomplete Minimum length of input string to start autocomplete * @param int $minLengthToAutocomplete Minimum length of input string to start autocomplete
* @param int $forcefocus Force focus on field * @param int $forcefocus Force focus on field
* @param string $widthTypeOfAutocomplete 'resolve' or 'off' * @param string $widthTypeOfAutocomplete 'resolve' or 'off'
* @param int $htmlid Html id to use instead of htmlname
* @return string Return html string to convert a select field into a combo, or '' if feature has been disabled for some reason. * @return string Return html string to convert a select field into a combo, or '' if feature has been disabled for some reason.
*/ */
function ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve') function ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve',$htmlid='')
{ {
global $conf; global $conf;
if (empty($htmlid)) $htmlid = $htmlname;
if (! empty($conf->browser->phone)) return ''; // select2 disabled for smartphones with standard browser (does not works, popup appears outside screen) if (! empty($conf->browser->phone)) return ''; // select2 disabled for smartphones with standard browser (does not works, popup appears outside screen)
if (! empty($conf->dol_use_jmobile)) return ''; // select2 works with jmobile but it breaks the autosize feature of jmobile. if (! empty($conf->dol_use_jmobile)) return ''; // select2 works with jmobile but it breaks the autosize feature of jmobile.
if (! empty($conf->global->MAIN_DISABLE_AJAX_COMBOX)) return ''; if (! empty($conf->global->MAIN_DISABLE_AJAX_COMBOX)) return '';
@ -371,10 +373,10 @@ function ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $
if (empty($minLengthToAutocomplete)) $minLengthToAutocomplete=0; if (empty($minLengthToAutocomplete)) $minLengthToAutocomplete=0;
$tmpplugin='select2'; $tmpplugin='select2';
$msg='<!-- JS CODE TO ENABLE '.$tmpplugin.' for id '.$htmlname.' --> $msg='<!-- JS CODE TO ENABLE '.$tmpplugin.' for id '.$htmlid.' -->
<script type="text/javascript"> <script type="text/javascript">
$(document).ready(function () { $(document).ready(function () {
$(\''.(preg_match('/^\./',$htmlname)?$htmlname:'#'.$htmlname).'\').'.$tmpplugin.'({ $(\''.(preg_match('/^\./',$htmlid)?$htmlid:'#'.$htmlid).'\').'.$tmpplugin.'({
dir: \'ltr\', dir: \'ltr\',
width: \''.$widthTypeOfAutocomplete.'\', /* off or resolve */ width: \''.$widthTypeOfAutocomplete.'\', /* off or resolve */
minimumInputLength: '.$minLengthToAutocomplete.' minimumInputLength: '.$minLengthToAutocomplete.'
@ -385,17 +387,17 @@ function ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $
if (count($events)) if (count($events))
{ {
$msg.= ' $msg.= '
jQuery("#'.$htmlname.'").change(function () { jQuery("#'.$htmlid.'").change(function () {
var obj = '.json_encode($events).'; var obj = '.json_encode($events).';
$.each(obj, function(key,values) { $.each(obj, function(key,values) {
if (values.method.length) { if (values.method.length) {
runJsCodeForEvent'.$htmlname.'(values); runJsCodeForEvent'.$htmlid.'(values);
} }
}); });
}); });
function runJsCodeForEvent'.$htmlname.'(obj) { function runJsCodeForEvent'.$htmlid.'(obj) {
var id = $("#'.$htmlname.'").val(); var id = $("#'.$htmlid.'").val();
var method = obj.method; var method = obj.method;
var url = obj.url; var url = obj.url;
var htmlname = obj.htmlname; var htmlname = obj.htmlname;