2
0
forked from Wavyzz/dolibarr

New: Selection of project use the new select2 component.

This commit is contained in:
Laurent Destailleur
2015-01-30 19:57:38 +01:00
parent 291340a39f
commit 275e198041
13 changed files with 46 additions and 34 deletions

View File

@@ -1894,7 +1894,7 @@ if ($action == 'create')
print '</tr></table>'; print '</tr></table>';
print '</td><td colspan="3">'; print '</td><td colspan="3">';
if ($action == 'classify') { if ($action == 'classify') {
$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0); $form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1);
} else { } else {
$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0); $form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0);
} }

View File

@@ -1975,7 +1975,7 @@ if ($action == 'create' && $user->rights->commande->creer) {
print '</td><td colspan="3">'; print '</td><td colspan="3">';
// print "$object->id, $object->socid, $object->fk_project"; // print "$object->id, $object->socid, $object->fk_project";
if ($action == 'classify') { if ($action == 'classify') {
$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0); $form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1);
} else { } else {
$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0); $form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0);
} }

View File

@@ -486,11 +486,11 @@ else if ($id)
print '</td><td colspan="3">'; print '</td><td colspan="3">';
if ($action == 'classify') if ($action == 'classify')
{ {
$form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project,'projectid'); $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project,'projectid', 0, 0, 1);
} }
else else
{ {
$form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project,'none'); $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project,'none', 0, 0);
} }
print '</td>'; print '</td>';
print '</tr>'; print '</tr>';

View File

@@ -3352,7 +3352,7 @@ if ($action == 'create')
print '</td><td colspan="3">'; print '</td><td colspan="3">';
if ($action == 'classify') { if ($action == 'classify') {
$form->form_project($_SERVER['PHP_SELF'] . '?facid=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0); $form->form_project($_SERVER['PHP_SELF'] . '?facid=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1);
} else { } else {
$form->form_project($_SERVER['PHP_SELF'] . '?facid=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0); $form->form_project($_SERVER['PHP_SELF'] . '?facid=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0);
} }

View File

@@ -1192,11 +1192,11 @@ else
print '</td><td colspan="3">'; print '</td><td colspan="3">';
if ($action == "classify") if ($action == "classify")
{ {
$form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id,$object->socid,$object->fk_project,"projectid"); $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id,$object->socid,$object->fk_project,"projectid", 0, 0, 1);
} }
else else
{ {
$form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id,$object->socid,$object->fk_project,"none"); $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id,$object->socid,$object->fk_project,"none", 0, 0);
} }
print "</td></tr>"; print "</td></tr>";
} }

View File

@@ -1226,12 +1226,13 @@ class Form
if ($num) if ($num)
{ {
// Enhance with select2 // Enhance with select2
if ($conf->use_javascript_ajax) $nodatarole='';
/*if ($conf->use_javascript_ajax)
{ {
include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
$out.= ajax_combobox($htmlname); $out.= ajax_combobox($htmlname);
$nodatarole=' data-role="none"'; $nodatarole=' data-role="none"';
} }*/
$out.= '<select class="flat" id="'.$htmlname.'" name="'.$htmlname.'"'.($disabled?' disabled="disabled"':'').$nodatarole.'>'; $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"':'').'>&nbsp;</option>'."\n"; if ($show_empty) $out.= '<option value="-1"'.((empty($selected) || $selected==-1)?' selected="selected"':'').'>&nbsp;</option>'."\n";
@@ -3147,9 +3148,10 @@ class Form
* @param string $htmlname Name of select field * @param string $htmlname Name of select field
* @param int $discard_closed Discard closed projects (0=Keep,1=hide completely,2=Disable) * @param int $discard_closed Discard closed projects (0=Keep,1=hide completely,2=Disable)
* @param int $maxlength Max length * @param int $maxlength Max length
* @param int $forcefocus Force focus on field (works with javascript only)
* @return void * @return void
*/ */
function form_project($page, $socid, $selected='', $htmlname='projectid', $discard_closed=0, $maxlength=20) function form_project($page, $socid, $selected='', $htmlname='projectid', $discard_closed=0, $maxlength=20, $forcefocus=0)
{ {
global $langs; global $langs;
@@ -3161,12 +3163,13 @@ class Form
$langs->load("project"); $langs->load("project");
if ($htmlname != "none") if ($htmlname != "none")
{ {
print "\n";
print '<form method="post" action="'.$page.'">'; print '<form method="post" action="'.$page.'">';
print '<input type="hidden" name="action" value="classin">'; print '<input type="hidden" name="action" value="classin">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<table class="nobordernopadding" cellpadding="0" cellspacing="0">'; print '<table class="nobordernopadding" cellpadding="0" cellspacing="0">';
print '<tr><td>'; print '<tr><td>';
$formproject->select_projects($socid,$selected,$htmlname,$maxlength,0,1,$discard_closed); $formproject->select_projects($socid,$selected,$htmlname,$maxlength,0,1,$discard_closed, $forcefocus);
print '</td>'; print '</td>';
print '<td align="left"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>'; print '<td align="left"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
print '</tr></table></form>'; print '</tr></table></form>';

View File

@@ -52,9 +52,10 @@ class FormProjets
* @param int $option_only Return only html options lines without the select tag * @param int $option_only Return only html options lines without the select tag
* @param int $show_empty Add an empty line * @param int $show_empty Add an empty line
* @param int $discard_closed Discard closed projects (0=Keep,1=hide completely,2=Disable) * @param int $discard_closed Discard closed projects (0=Keep,1=hide completely,2=Disable)
* @param int $forcefocus Force focus on field (works with javascript only)
* @return int Nber of project if OK, <0 if KO * @return int Nber of project if OK, <0 if KO
*/ */
function select_projects($socid=-1, $selected='', $htmlname='projectid', $maxlength=24, $option_only=0, $show_empty=1, $discard_closed=0) function select_projects($socid=-1, $selected='', $htmlname='projectid', $maxlength=24, $option_only=0, $show_empty=1, $discard_closed=0, $forcefocus=0)
{ {
global $user,$conf,$langs; global $user,$conf,$langs;
@@ -85,8 +86,17 @@ class FormProjets
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)
{ {
// Use select2 selector
$nodatarole='';
if (! empty($conf->use_javascript_ajax))
{
include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
$out.= ajax_combobox($htmlname, '', 0, $forcefocus);
$nodatarole=' data-role="none"';
}
if (empty($option_only)) { if (empty($option_only)) {
$out.= '<select class="flat" name="'.$htmlname.'">'; $out.= '<select class="flat" id="'.$htmlname.'" name="'.$htmlname.'"'.$nodatarole.'>';
} }
if (!empty($show_empty)) { if (!empty($show_empty)) {
$out.= '<option value="0">&nbsp;</option>'; $out.= '<option value="0">&nbsp;</option>';
@@ -162,14 +172,9 @@ class FormProjets
if (empty($option_only)) { if (empty($option_only)) {
$out.= '</select>'; $out.= '</select>';
} }
print $out; print $out;
// Use select2 selector
if (! empty($conf->use_javascript_ajax))
{
}
$this->db->free($resql); $this->db->free($resql);
return $num; return $num;
} }

View File

@@ -314,9 +314,10 @@ function ajax_dialog($title,$message,$w=350,$h=150)
* @param string $htmlname Name of html select field * @param string $htmlname Name of html select field
* @param array $events More events option. Example: array(array('method'=>'getContacts', 'url'=>dol_buildpath('/core/ajax/contacts.php',1), 'htmlname'=>'contactid', 'params'=>array('add-customer-contact'=>'disabled'))) * @param array $events More events option. 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 * @param int $minLengthToAutocomplete Minimum length of input string to start autocomplete
* @param int $forcefocus Force focus on field
* @return string Return html string to convert a select field into a combo * @return string Return html string to convert a select field into a combo
*/ */
function ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0) function ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0)
{ {
global $conf; global $conf;
@@ -332,7 +333,9 @@ function ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0)
$(\'#'.$htmlname.'\').select2({ $(\'#'.$htmlname.'\').select2({
width: \'resolve\', width: \'resolve\',
minimumInputLength: '.$minLengthToAutocomplete.', minimumInputLength: '.$minLengthToAutocomplete.',
});'; })';
if ($forcefocus) $msg.= '.select2(\'focus\')';
$msg.= ';';
if (count($event)) if (count($event))
{ {

View File

@@ -337,11 +337,11 @@ if ($id > 0 || ! empty($ref))
print '</td><td colspan="2">'; print '</td><td colspan="2">';
if ($action == 'classify') if ($action == 'classify')
{ {
$form->form_project($_SERVER['PHP_SELF'].'?id='.$commande->id, $commande->socid, $commande->fk_project, 'projectid'); $form->form_project($_SERVER['PHP_SELF'].'?id='.$commande->id, $commande->socid, $commande->fk_project, 'projectid', 0, 0, 1);
} }
else else
{ {
$form->form_project($_SERVER['PHP_SELF'].'?id='.$commande->id, $commande->socid, $commande->fk_project, 'none'); $form->form_project($_SERVER['PHP_SELF'].'?id='.$commande->id, $commande->socid, $commande->fk_project, 'none', 0, 0);
} }
print '</td></tr>'; print '</td></tr>';
} }

View File

@@ -1270,11 +1270,11 @@ else if ($id > 0 || ! empty($ref))
print '</td><td colspan="3">'; print '</td><td colspan="3">';
if ($action == 'classify') if ($action == 'classify')
{ {
$form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project,'projectid'); $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project,'projectid', 0, 0, 1);
} }
else else
{ {
$form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project,'none'); $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project,'none', 0, 0);
} }
print '</td>'; print '</td>';
print '</tr>'; print '</tr>';

View File

@@ -1615,7 +1615,7 @@ elseif (! empty($object->id))
//print "$object->id, $object->socid, $object->fk_project"; //print "$object->id, $object->socid, $object->fk_project";
if ($action == 'classify') if ($action == 'classify')
{ {
$form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, empty($conf->global->PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS)?$object->socid:'-1', $object->fk_project, 'projectid', 0, 0); $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, (empty($conf->global->PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS)?$object->socid:'-1'), $object->fk_project, 'projectid', 0, 0, 1);
} }
else else
{ {

View File

@@ -215,6 +215,7 @@ if ($resql)
$userstatic = new User($db); $userstatic = new User($db);
$objectstatic=new CommandeFournisseur($db); $objectstatic=new CommandeFournisseur($db);
$projectstatic=new Project($db);
while ($i < min($num,$conf->liste_limit)) while ($i < min($num,$conf->liste_limit))
{ {

View File

@@ -1941,7 +1941,7 @@ else
print '</td><td colspan="3">'; print '</td><td colspan="3">';
if ($action == 'classify') if ($action == 'classify')
{ {
$form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, empty($conf->global->PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS)?$object->socid:'-1', $object->fk_project, 'projectid', 0, 0); $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, (empty($conf->global->PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS)?$object->socid:'-1'), $object->fk_project, 'projectid', 0, 0, 1);
} }
else else
{ {