diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index fff53e9d25c82474bbaebb324de00b22a2194e8d..94f0f463b31f14fc6be39c1153fd7bc626dfab1f 100755 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -816,84 +816,15 @@ class Form $resql=$this->db->query($sql); if ($resql) { - if (! empty($conf->use_javascript_ajax)) + if ($conf->use_javascript_ajax && ! $forcecombo) { - if (! empty($conf->global->COMPANY_USE_SEARCH_TO_SELECT) && ! $forcecombo) - { - include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; - $out.= ajax_combobox($htmlname, $events, $conf->global->COMPANY_USE_SEARCH_TO_SELECT); - } - else - { - if (! $forcecombo) - { - $out.=' - <script type="text/javascript"> - $(document).ready(function () { - $(\'#'.$htmlname.'\').select2({ - width: \'resolve\', - minimumInputLength: 0, - }); - }); - </script>'; - } - - if (count($events)) // Add management of event - { - $out.='<script type="text/javascript"> - $(document).ready(function() { - jQuery("#'.$htmlname.'").change(function () { - var obj = '.json_encode($events).'; - $.each(obj, function(key,values) { - if (values.method.length) { - runJsCodeForEvent'.$htmlname.'(values); - } - }); - }); - - function runJsCodeForEvent'.$htmlname.'(obj) { - var id = $("#'.$htmlname.'").val(); - var method = obj.method; - var url = obj.url; - var htmlname = obj.htmlname; - var showempty = obj.showempty; - $.getJSON(url, - { - action: method, - id: id, - htmlname: htmlname, - showempty: showempty - }, - function(response) { - $.each(obj.params, function(key,action) { - if (key.length) { - var num = response.num; - if (num > 0) { - $("#" + key).removeAttr(action); - } else { - $("#" + key).attr(action, action); - } - } - }); - $("select#" + htmlname).html(response.value); - if (response.num) { - var selecthtml_str = response.value; - var selecthtml_dom=$.parseHTML(selecthtml_str); - $("#inputautocomplete"+htmlname).val(selecthtml_dom[0][0].innerHTML); - } else { - $("#inputautocomplete"+htmlname).val(""); - } - $("select#" + htmlname).change(); /* Trigger event change */ - }); - } - }) - </script>'; - } - } + include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; + $out.= ajax_combobox($htmlname, $events, $conf->global->COMPANY_USE_SEARCH_TO_SELECT); + $nodatarole=' data-role="none"'; } // Construct $out and $outarray - $out.= '<select id="'.$htmlname.'" class="flat minwidth100" name="'.$htmlname.'">'."\n"; + $out.= '<select id="'.$htmlname.'" class="flat minwidth100" name="'.$htmlname.'"'.$nodatarole.'>'."\n"; $textifempty=''; // Do not use textempty = ' ' or ' ' here, or search on key will search on ' key'. @@ -1094,9 +1025,10 @@ class Form { include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; $out.= ajax_combobox($htmlname, $events, $conf->global->CONTACT_USE_SEARCH_TO_SELECT); + $nodatarole=' data-role="none"'; } - if ($htmlname != 'none' || $options_only) $out.= '<select class="flat'.($moreclass?' '.$moreclass:'').'" id="'.$htmlname.'" name="'.$htmlname.'">'; + if ($htmlname != 'none' || $options_only) $out.= '<select class="flat'.($moreclass?' '.$moreclass:'').'" id="'.$htmlname.'" name="'.$htmlname.'"'.$nodatarole.'>'; if ($showempty == 1) $out.= '<option value="0"'.($selected=='0'?' selected="selected"':'').'></option>'; if ($showempty == 2) $out.= '<option value="0"'.($selected=='0'?' selected="selected"':'').'>'.$langs->trans("Internal").'</option>'; $num = $this->db->num_rows($resql); @@ -1280,7 +1212,15 @@ class Form $i = 0; if ($num) { - $out.= '<select class="flat" id="'.$htmlname.'" name="'.$htmlname.'"'.($disabled?' disabled="disabled"':'').'>'; + // Enhance with select2 + if ($conf->use_javascript_ajax) + { + include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; + $out.= ajax_combobox($htmlname); + $nodatarole=' data-role="none"'; + } + + $out.= '<select class="flat" id="'.$htmlname.'" name="'.$htmlname.'"'.($disabled?' disabled="disabled"':'').$nodatarole.'>'; if ($show_empty) $out.= '<option value="-1"'.((empty($selected) || $selected==-1)?' selected="selected"':'').'> </option>'."\n"; $userstatic=new User($this->db); @@ -1355,16 +1295,6 @@ class Form $out.= '<option value="">'.$langs->trans("None").'</option>'; } $out.= '</select>'; - - $out.= '<script type="text/javascript"> - $(document).ready(function() { - - $(\'#'.$htmlname.'\').select2({ - width: \'resolve\', - minimumInputLength: 0 - }); - }) - </script>'; } else { @@ -4585,11 +4515,20 @@ class Form $resql=$this->db->query($sql); if ($resql) { - $num = $this->db->num_rows($resql); + // Enhance with select2 + if ($conf->use_javascript_ajax) + { + include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; + $out.= ajax_combobox($htmlname); + $nodatarole=' data-role="none"'; + } + + $out.= '<select class="flat" id="'.$htmlname.'" name="'.$htmlname.'"'.($disabled?' disabled="disabled"':'').$nodatarole.'>'; + + $num = $this->db->num_rows($resql); $i = 0; if ($num) { - $out.= '<select class="flat" id="'.$htmlname.'" name="'.$htmlname.'"'.($disabled?' disabled="disabled"':'').'>'; if ($show_empty) $out.= '<option value="-1"'.($selected==-1?' selected="selected"':'').'> </option>'."\n"; while ($i < $num) @@ -4618,8 +4557,8 @@ class Form } else { - $out.= '<select class="flat" name="'.$htmlname.'" disabled="disabled">'; - $out.= '<option value="">'.$langs->trans("None").'</option>'; + if ($show_empty) $out.= '<option value="-1"'.($selected==-1?' selected="selected"':'').'></option>'."\n"; + $out.= '<option value="" disabled="disabled">'.$langs->trans("NoUserGroupDefined").'</option>'; } $out.= '</select>'; } diff --git a/htdocs/core/lib/agenda.lib.php b/htdocs/core/lib/agenda.lib.php index 236f418dd8629c9a91e341df6bf90756bfd52d68..3d51490f6b2926d48983267e8edf6a74bb4b880a 100644 --- a/htdocs/core/lib/agenda.lib.php +++ b/htdocs/core/lib/agenda.lib.php @@ -70,36 +70,13 @@ function print_actions_filter($form, $canedit, $status, $year, $month, $day, $sh { print '<tr>'; print '<td class="nowrap">'; - //print $langs->trans("ActionsAskedBy"); - //print ' </td><td class="nowrap maxwidthonsmartphone">'; - //print $form->select_dolusers($filtera, 'userasked', 1, '', ! $canedit); - //print ' '.$langs->trans("or") . ' '; print $langs->trans("ActionsOwnedBy").' '; print '</td><td class="nowrap maxwidthonsmartphone">'; - //print $langs->trans("User"); print $form->select_dolusers($filtert, 'usertodo', 1, '', ! $canedit); - if (! empty($conf->use_javascript_ajax)) - { - include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; - print ajax_combobox('usertodo'); - } - if (empty($conf->dol_optimize_smallscreen)) print ' '.$langs->trans("or") . ' '; - else print '<br>'; - print $langs->trans("Group").' '; + if (empty($conf->dol_optimize_smallscreen)) print ' '.$langs->trans("or") . ' '.$langs->trans("Group").' '; print $form->select_dolgroups($usergroupid, 'usergroup', 1, '', ! $canedit); - if (! empty($conf->use_javascript_ajax)) - { - print ajax_combobox('usergroup'); - } print '</td></tr>'; - /*print '<tr>'; - print '<td class="nowrap">'; - print $langs->trans("or") . ' ' . $langs->trans("ActionsDoneBy"); - print ' </td><td class="nowrap maxwidthonsmartphone">'; - print $form->select_dolusers($filterd, 'userdone', 1, '', ! $canedit); - print '</td></tr>';*/ - include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php'; $formactions=new FormActions($db); @@ -147,16 +124,18 @@ function print_actions_filter($form, $canedit, $status, $year, $month, $day, $sh print '<tr>'; print '<td class="nowrap">'.$langs->trans("WorkingTimeRange").'</td>'; print "<td class='nowrap maxwidthonsmartphone'>"; - print '<input type="number" class="short" name="begin_h" value="'.$begin_h.'" min="0" max="23"> - '; + print '<input type="number" class="short" name="begin_h" value="'.$begin_h.'" min="0" max="23">'; + if (empty($conf->dol_use_jmobile)) print ' - '; print '<input type="number" class="short" name="end_h" value="'.$end_h.'" min="1" max="24">'; - print ' '.$langs->trans("H"); + if (empty($conf->dol_use_jmobile)) print ' '.$langs->trans("H"); print '</td></tr>'; // Filter on days print '<tr>'; print '<td class="nowrap">'.$langs->trans("WorkingDaysRange").'</td>'; print "<td class='nowrap maxwidthonsmartphone'>"; - print '<input type="number" class="short" name="begin_d" value="'.$begin_d.'" min="1" max="7"> - '; + print '<input type="number" class="short" name="begin_d" value="'.$begin_d.'" min="1" max="7">'; + if (empty($conf->dol_use_jmobile)) print ' - '; print '<input type="number" class="short" name="end_d" value="'.$end_d.'" min="1" max="7">'; print '</td></tr>'; } diff --git a/htdocs/core/lib/ajax.lib.php b/htdocs/core/lib/ajax.lib.php index df7c09d9274f8b92041e2384718c1e1d42507c6e..96c7bc8d05a6c112fcdbba9c2bbef25f89977cfb 100644 --- a/htdocs/core/lib/ajax.lib.php +++ b/htdocs/core/lib/ajax.lib.php @@ -320,63 +320,71 @@ function ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0) { global $conf; - if (! empty($conf->browser->phone)) return ''; // combobox disabled for smartphones (does not works) + //if (! empty($conf->browser->phone)) return ''; // combobox disabled for smartphones (does not works) + //if (! empty($conf->dol_use_jmobile)) return ''; // select2 works with jmobile if (! empty($conf->global->MAIN_DISABLE_AJAX_COMBOX)) return ''; - + if (empty($conf->use_javascript_ajax)) return ''; + + if (empty($minLengthToAutocomplete)) $minLengthToAutocomplete=0; + $msg = '<script type="text/javascript"> - $(document).ready(function() { + $(document).ready(function() { + $(\'#'.$htmlname.'\').select2({ + width: \'resolve\', + minimumInputLength: '.$minLengthToAutocomplete.', + });'; - $(\'#'.$htmlname.'\').select2({ - width: \'resolve\', - minimumInputLength: '.$minLengthToAutocomplete.', - }); - jQuery("#'.$htmlname.'").change(function () { + if (count($event)) + { + $msg.= ' + jQuery("#'.$htmlname.'").change(function () { var obj = '.json_encode($events).'; - $.each(obj, function(key,values) { - if (values.method.length) { - runJsCodeForEvent'.$htmlname.'(values); - } + $.each(obj, function(key,values) { + if (values.method.length) { + runJsCodeForEvent'.$htmlname.'(values); + } }); - }); - - - function runJsCodeForEvent'.$htmlname.'(obj) { - var id = $("#'.$htmlname.'").val(); - var method = obj.method; - var url = obj.url; - var htmlname = obj.htmlname; - var showempty = obj.showempty; - $.getJSON(url, - { - action: method, - id: id, - htmlname: htmlname, - showempty: showempty - }, - function(response) { - $.each(obj.params, function(key,action) { - if (key.length) { - var num = response.num; - if (num > 0) { - $("#" + key).removeAttr(action); - } else { - $("#" + key).attr(action, action); + }); + + function runJsCodeForEvent'.$htmlname.'(obj) { + var id = $("#'.$htmlname.'").val(); + var method = obj.method; + var url = obj.url; + var htmlname = obj.htmlname; + var showempty = obj.showempty; + $.getJSON(url, + { + action: method, + id: id, + htmlname: htmlname, + showempty: showempty + }, + function(response) { + $.each(obj.params, function(key,action) { + if (key.length) { + var num = response.num; + if (num > 0) { + $("#" + key).removeAttr(action); + } else { + $("#" + key).attr(action, action); + } } + }); + $("select#" + htmlname).html(response.value); + if (response.num) { + var selecthtml_str = response.value; + var selecthtml_dom=$.parseHTML(selecthtml_str); + $("#inputautocomplete"+htmlname).val(selecthtml_dom[0][0].innerHTML); + } else { + $("#inputautocomplete"+htmlname).val(""); } - }); - $("select#" + htmlname).html(response.value); - if (response.num) { - var selecthtml_str = response.value; - var selecthtml_dom=$.parseHTML(selecthtml_str); - $("#inputautocomplete"+htmlname).val(selecthtml_dom[0][0].innerHTML); - } else { - $("#inputautocomplete"+htmlname).val(""); + $("select#" + htmlname).change(); /* Trigger event change */ } - $("select#" + htmlname).change(); /* Trigger event change */ - }); - } - - });'."\n"; + ); + }'; + } + + $msg.= '});'."\n"; $msg.= "</script>\n"; return $msg; diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang index cbc4deb40d7e0acc23283f63b64cd60a43fe5f59..fd07d379a4488a74211e6d12201d04087512230f 100644 --- a/htdocs/langs/en_US/main.lang +++ b/htdocs/langs/en_US/main.lang @@ -169,6 +169,7 @@ User=User Users=Users Group=Group Groups=Groups +NoUserGroupDefined=No user group defined Password=Password PasswordRetype=Retype your password NoteSomeFeaturesAreDisabled=Note that a lot of features/modules are disabled in this demonstration.