Merge editfield and editInPlace

This commit is contained in:
Laurent Destailleur 2011-11-05 18:25:04 +01:00
parent cf365593dc
commit 2b9285384c
3 changed files with 131 additions and 82 deletions

View File

@ -171,6 +171,24 @@ if ($action == 'setdated')
$result=$object->setValueFrom('dated',$dated,'','','date');
if ($result < 0) dol_print_error($db, $object->error);
}
if ($action == 'setkm')
{
$object->fetch($id);
$result=$object->setValueFrom('km',GETPOST('km'));
if ($result < 0) dol_print_error($db, $object->error);
}
if ($action == 'setnote_public')
{
$object->fetch($id);
$result=$object->setValueFrom('note_public',GETPOST('note_public'));
if ($result < 0) dol_print_error($db, $object->error);
}
if ($action == 'setnote')
{
$object->fetch($id);
$result=$object->setValueFrom('note',GETPOST('note'));
if ($result < 0) dol_print_error($db, $object->error);
}
/*
@ -309,7 +327,9 @@ else if ($id)
// Public note
print '<tr><td valign="top">'.$langs->trans("NotePublic").'</td>';
print '<td valign="top" colspan="3">';
print '<textarea name="note_public" cols="80" rows="8">'.$object->note_public."</textarea><br>";
require_once(DOL_DOCUMENT_ROOT."/core/class/doleditor.class.php");
$doleditor=new DolEditor('note_public',$object->note_public,600,200,'dolibarr_notes','In',false,true,true,ROWS_8,'100');
print $doleditor->Create(1);
print "</td></tr>";
// Private note
@ -317,7 +337,9 @@ else if ($id)
{
print '<tr><td valign="top">'.$langs->trans("NotePrivate").'</td>';
print '<td valign="top" colspan="3">';
print '<textarea name="note_private" cols="80" rows="8">'.$object->note_private."</textarea><br>";
require_once(DOL_DOCUMENT_ROOT."/core/class/doleditor.class.php");
$doleditor=new DolEditor('note_private',$object->note_private,600,200,'dolibarr_notes','In',false,true,true,ROWS_8,'100');
print $doleditor->Create(1);
print "</td></tr>";
}
@ -353,8 +375,10 @@ else if ($id)
print '</td></tr>';
// Type
print '<tr><td>'.$langs->trans("Type").'</td><td>';
print $form->editInPlace($langs->trans($object->type), 'type', $user->rights->deplacement->creer, 'select', 'types_fees');
print '<tr><td>';
print $form->editfieldkey("Type",'type',$langs->trans($object->type),'id',$object->id,$user->rights->deplacement->creer,'select:type_fees');
print '</td><td>';
print $form->editfieldval("Type",'type',$langs->trans($object->type),'id',$object->id,$user->rights->deplacement->creer,'select:type_fees');
print '</td></tr>';
// Who
@ -366,16 +390,17 @@ else if ($id)
// Date
print '<tr><td>';
if (! empty($conf->global->MAIN_USE_JQUERY_JEDITABLE)) print $langs->trans('Date');
else print $form->editfieldkey("Date",'dated',$object->date,'id',$object->id,$user->rights->deplacement->creer,'datepicker');
print '</td><td colspan="3">';
if (! empty($conf->global->MAIN_USE_JQUERY_JEDITABLE)) print $form->editInPlace($object->date, 'dated', $user->rights->deplacement->creer, 'datepicker');
else print $form->editfieldval("Date",'dated',$object->date,'id',$object->id,$user->rights->deplacement->creer,'datepicker');
print $form->editfieldkey("Date",'dated',$object->date,'id',$object->id,$user->rights->deplacement->creer,'datepicker');
print '</td><td>';
print $form->editfieldval("Date",'dated',$object->date,'id',$object->id,$user->rights->deplacement->creer,'datepicker');
print '</td></tr>';
// Km/Price
print '<tr><td>'.$langs->trans("FeesKilometersOrAmout").'</td>';
print '<td>'.$form->editInPlace($object->km, 'km', $user->rights->deplacement->creer, 'numeric').'</td></tr>';
print '<tr><td valign="top">';
print $form->editfieldkey("FeesKilometersOrAmout",'km',$object->km,'id',$object->id,$user->rights->deplacement->creer,'numeric:6');
print '</td><td>';
print $form->editfieldval("FeesKilometersOrAmout",'km',$object->km,'id',$object->id,$user->rights->deplacement->creer,'numeric:6');
print "</td></tr>";
// Where
print '<tr><td>'.$langs->trans("CompanyVisited").'</td>';
@ -417,18 +442,20 @@ else if ($id)
print '<tr><td>'.$langs->trans("Status").'</td><td>'.$object->getLibStatut(4).'</td></tr>';
// Public note
print '<tr><td valign="top">'.$langs->trans("NotePublic").'</td>';
print '<td valign="top" colspan="3">';
print $form->editInPlace($object->note_public, 'note_public', $user->rights->deplacement->creer, 'ckeditor', 'dolibarr_notes');
print '<tr><td valign="top">';
print $form->editfieldkey("NotePublic",'note_public',$object->note_public,'id',$object->id,$user->rights->deplacement->creer,'ckeditor:dolibarr_notes:600:180:100:6');
print '</td><td>';
print $form->editfieldval("NotePublic",'note_public',$object->note_public,'id',$object->id,$user->rights->deplacement->creer,'ckeditor:dolibarr_notes:600:180:100:6');
print "</td></tr>";
// Private note
if (! $user->societe_id)
{
print '<tr><td valign="top">'.$langs->trans("NotePrivate").'</td>';
print '<td valign="top" colspan="3">';
print $form->editInPlace($object->note_private, 'note', $user->rights->deplacement->creer, 'ckeditor', 'dolibarr_notes');
print "</td></tr>";
print '<tr><td valign="top">';
print $form->editfieldkey("NotePrivate",'note',$object->note_private,'id',$object->id,$user->rights->deplacement->creer,'ckeditor:dolibarr_notes:600:180:100:6');
print '</td><td>';
print $form->editfieldval("NotePrivate",'note',$object->note_private,'id',$object->id,$user->rights->deplacement->creer,'ckeditor:dolibarr_notes:600:180:100:6');
print "</td></tr>";
}
print "</table>";

View File

@ -74,20 +74,24 @@ class Form
* @param string $paramkey Key of parameter for Url (unique if there is several parameter to show). In most cases "id".
* @param string $paramvalue Value of parameter for Url
* @param boolean $perm Permission to allow button to edit parameter
* @param string $typeofdata Type of data ('string' by default, 'email', 'text' or 'textarea', 'day' or 'datepicker', ...)
* @param string $typeofdata Type of data ('string' by default, 'email', 'text' or 'textarea', 'day' or 'datepicker', 'ckeditor:dolibarr_zzz', 'select:xxx'...)
* @return string HTML edit field
* TODO no GET or POST in class file, use a param
*/
function editfieldkey($text,$htmlname,$preselected,$paramkey,$paramvalue,$perm,$typeofdata='string')
{
global $langs;
$ret='';
$ret.='<table class="nobordernopadding" width="100%"><tr><td nowrap="nowrap">';
$ret.=$langs->trans($text);
$ret.='</td>';
if (GETPOST('action') != 'edit'.$htmlname && $perm) $ret.='<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=edit'.$htmlname.'&amp;'.$paramkey.'='.$paramvalue.'">'.img_edit($langs->trans('Edit'),1).'</a></td>';
$ret.='</tr></table>';
return $ret;
global $conf,$langs;
if (! empty($conf->global->MAIN_USE_JQUERY_JEDITABLE)) return $langs->trans($text);
else
{
$ret='';
$ret.='<table class="nobordernopadding" width="100%"><tr><td nowrap="nowrap">';
$ret.=$langs->trans($text);
$ret.='</td>';
if (GETPOST('action') != 'edit'.$htmlname && $perm) $ret.='<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=edit'.$htmlname.'&amp;'.$paramkey.'='.$paramvalue.'">'.img_edit($langs->trans('Edit'),1).'</a></td>';
$ret.='</tr></table>';
return $ret;
}
}
/**
@ -95,51 +99,67 @@ class Form
*
* @param string $text Text of label (not used in this function)
* @param string $htmlname Name of select field
* @param string $preselected Value to show/edit
* @param string $value Value to show/edit
* @param string $paramkey Key of parameter (unique if there is several parameter to show). In most cases "id".
* @param boolean $perm Permission to allow button to edit parameter
* @param string $typeofdata Type of data ('string' by default, 'email', 'text' or 'textarea', 'day' or 'datepicker', ...)
* @param string $editvalue Use this value instead $preselected
* @param string $typeofdata Type of data ('string' by default, 'email', 'numeric:99', 'text' or 'textarea', 'day' or 'datepicker', 'ckeditor:dolibarr_zzz:width:height:rows:cols', 'select:xxx'...)
* @param string $editvalue When in edit mode, use this value as $value instead of value
* @return string HTML edit field
* TODO no GET or POST in class file, use a param
*/
function editfieldval($text,$htmlname,$preselected,$paramkey,$paramvalue,$perm,$typeofdata='string',$editvalue='')
function editfieldval($text,$htmlname,$value,$paramkey,$paramvalue,$perm,$typeofdata='string',$editvalue='')
{
global $langs,$db;
global $conf,$langs,$db;
$ret='';
if (GETPOST('action') == 'edit'.$htmlname)
// When option to edit inline is activated
if (! empty($conf->global->MAIN_USE_JQUERY_JEDITABLE))
{
$ret.="\n";
$ret.='<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
$ret.='<input type="hidden" name="action" value="set'.$htmlname.'">';
$ret.='<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
$ret.='<input type="hidden" name="'.$paramkey.'" value="'.$paramvalue.'">';
$ret.='<table class="nobordernopadding" cellpadding="0" cellspacing="0">';
$ret.='<tr><td>';
if (in_array($typeofdata,array('string','email')))
{
$ret.='<input type="text" id="'.$htmlname.'" name="'.$htmlname.'" value="'.($editvalue?$editvalue:$preselected).'">';
}
else if ($typeofdata == 'text' || $typeofdata == 'textarea')
{
$ret.='<textarea id="'.$htmlname.'" name="'.$htmlname.'" wrap="soft" cols="70">'.($editvalue?$editvalue:$preselected).'</textarea>';
}
else if ($typeofdata == 'day' || $typeofdata == 'datepicker')
{
$html=new Form($db);
$ret.=$html->form_date($_SERVER['PHP_SELF'].($paramkey?'?'.$paramkey.'='.$paramvalue:''),$preselected,$htmlname);
}
$ret.='</td>';
if ($typeofdata != 'day' && $typeofdata != 'datepicker') $ret.='<td align="left"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
$ret.='</tr></table>'."\n";
$ret.='</form>'."\n";
$ret.=$this->editInPlace($value, $htmlname, $perm, $typeofdata);
}
else
{
if ($typeofdata == 'email') $ret.=dol_print_email($preselected,0,0,0,0,1);
elseif ($typeofdata == 'day' || $typeofdata == 'datepicker') $ret.=dol_print_date($preselected,'day');
elseif ($typeofdata == 'text' || $typeofdata == 'textarea') $ret.=dol_htmlentitiesbr($preselected);
else $ret.=$preselected;
if (GETPOST('action') == 'edit'.$htmlname)
{
$ret.="\n";
$ret.='<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
$ret.='<input type="hidden" name="action" value="set'.$htmlname.'">';
$ret.='<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
$ret.='<input type="hidden" name="'.$paramkey.'" value="'.$paramvalue.'">';
$ret.='<table class="nobordernopadding" cellpadding="0" cellspacing="0">';
$ret.='<tr><td>';
if (preg_match('/^(string|email|numeric)/',$typeofdata))
{
$tmp=explode(':',$typeofdata);
$ret.='<input type="text" id="'.$htmlname.'" name="'.$htmlname.'" value="'.($editvalue?$editvalue:$value).'"'.($tmp[1]?' size="'.$tmp[1].'"':'').'>';
}
else if ($typeofdata == 'text' || $typeofdata == 'textarea')
{
$ret.='<textarea id="'.$htmlname.'" name="'.$htmlname.'" wrap="soft" cols="70">'.($editvalue?$editvalue:$value).'</textarea>';
}
else if ($typeofdata == 'day' || $typeofdata == 'datepicker')
{
$ret.=$this->form_date($_SERVER['PHP_SELF'].($paramkey?'?'.$paramkey.'='.$paramvalue:''),$value,$htmlname);
}
else if (preg_match('/^ckeditor/',$typeofdata))
{
$tmp=explode(':',$typeofdata);
require_once(DOL_DOCUMENT_ROOT."/core/class/doleditor.class.php");
$doleditor=new DolEditor($htmlname,($editvalue?$editvalue:$value),($tmp[2]?$tmp[2]:''),($tmp[3]?$tmp[3]:'100'),($tmp[1]?$tmp[1]:'dolibarr_notes'),'In',false,true,true,($tmp[4]?$tmp[4]:ROWS_4),($tmp[5]?$tmp[5]:'100'));
$ret.=$doleditor->Create(1);
//$ret.='<textarea id="'.$htmlname.'" name="'.$htmlname.'" wrap="soft" cols="70">'.($editvalue?$editvalue:$value).'</textarea>';
}
$ret.='</td>';
if ($typeofdata != 'day' && $typeofdata != 'datepicker') $ret.='<td align="left"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
$ret.='</tr></table>'."\n";
$ret.='</form>'."\n";
}
else
{
if ($typeofdata == 'email') $ret.=dol_print_email($value,0,0,0,0,1);
elseif ($typeofdata == 'day' || $typeofdata == 'datepicker') $ret.=dol_print_date($value,'day');
elseif ($typeofdata == 'text' || $typeofdata == 'textarea') $ret.=dol_htmlentitiesbr($value);
else $ret.=$value;
}
}
return $ret;
}
@ -150,11 +170,10 @@ class Form
* @param string $value Value to show/edit
* @param string $htmlname DIV ID (field name)
* @param int $condition Condition to edit
* @param string $inputType Type of input
* @param string $inputOption Input option
* @param string $inputType Type of input ('numeric', 'datepicker', 'textarea', 'ckeditor:dolibarr_zzz', 'select:xxx')
* @return string HTML edit in place
*/
function editInPlace($value, $htmlname, $condition, $inputType='textarea', $inputOption='')
function editInPlace($value, $htmlname, $condition, $inputType='textarea')
{
global $conf;
@ -162,21 +181,30 @@ class Form
// Check parameters
if ($inputType == 'textarea') $value = dol_nl2br($value);
else if ($inputType == 'numeric') $value = price($value);
else if (preg_match('/^numeric/',$inputType)) $value = price($value);
else if ($inputType == 'datepicker') $value = dol_print_date($value, 'day');
if (! empty($conf->global->MAIN_USE_JQUERY_JEDITABLE) && $condition)
{
if ($inputType == 'datepicker')
if (preg_match('/^(string|email|numeric)/',$inputType))
{
$tmp=explode(':',$inputType);
$inputType=$tmp[0]; $inputOption=$tmp[1];
}
if ($inputType == 'datepicker')
{
$out.= '<input id="timeStamp" type="hidden"/>'; // Use for timestamp format
}
else if ($inputType == 'select' && ! empty($inputOption))
else if (preg_match('/^select/',$inputType))
{
$tmp=explode(':',$inputType);
$inputType=$tmp[0]; $inputOption=$tmp[1];
$out.= '<input id="loadmethod" value="'.$inputOption.'" type="hidden"/>';
}
else if ($inputType == 'ckeditor' && ! empty($inputOption))
else if (preg_match('/^ckeditor/',$inputType))
{
$tmp=explode(':',$inputType);
$inputType=$tmp[0]; $inputOption=$tmp[1];
if (! empty($conf->fckeditor->enabled))
{
$out.= '<input id="toolbar" value="'.$inputOption.'" type="hidden"/>';

View File

@ -816,11 +816,9 @@ else if ($id > 0 || ! empty($ref))
// Description (must be a textarea and not html must be allowed (used in list view)
print '<tr><td valign="top">';
if (! empty($conf->global->MAIN_USE_JQUERY_JEDITABLE)) print $langs->trans('Description');
else print $form->editfieldkey("Description",'description',$object->description,'id',$object->id,$object->statut == 0 && $user->rights->ficheinter->creer,'textarea');
print $form->editfieldkey("Description",'description',$object->description,'id',$object->id,$object->statut == 0 && $user->rights->ficheinter->creer,'textarea');
print '</td><td colspan="3">';
if (! empty($conf->global->MAIN_USE_JQUERY_JEDITABLE)) print $form->editInPlace($object->description, 'description', $user->rights->ficheinter->creer && $object->statut == 0, 'textarea');
else print $form->editfieldval("Description",'description',$object->description,'id',$object->id,$object->statut == 0 && $user->rights->ficheinter->creer,'textarea');
print $form->editfieldval("Description",'description',$object->description,'id',$object->id,$object->statut == 0 && $user->rights->ficheinter->creer,'textarea');
print '</td>';
print '</tr>';
@ -859,22 +857,18 @@ else if ($id > 0 || ! empty($ref))
// Public note
print '<tr><td valign="top">';
if (! empty($conf->global->MAIN_USE_JQUERY_JEDITABLE)) print $langs->trans('NotePublic');
else print $form->editfieldkey("NotePublic",'note_public',$object->note_public,'id',$object->id,$user->rights->ficheinter->creer,'textarea');
print $form->editfieldkey("NotePublic",'note_public',$object->note_public,'id',$object->id,$user->rights->ficheinter->creer,'textarea');
print '</td><td colspan="3">';
if (! empty($conf->global->MAIN_USE_JQUERY_JEDITABLE)) print $form->editInPlace($object->note_public, 'note_public', $user->rights->ficheinter->creer, 'textarea');
else print $form->editfieldval("NotePublic",'note_public',$object->note_public,'id',$object->id,$user->rights->ficheinter->creer,'textarea');
print $form->editfieldval("NotePublic",'note_public',$object->note_public,'id',$object->id,$user->rights->ficheinter->creer,'textarea');
print "</td></tr>";
// Private note
if (! $user->societe_id)
{
print '<tr><td valign="top">';
if (! empty($conf->global->MAIN_USE_JQUERY_JEDITABLE)) print $langs->trans('NotePrivate');
else print $form->editfieldkey("NotePrivate",'note_private',$object->note_private,'id',$object->id,$user->rights->ficheinter->creer,'textarea');
print $form->editfieldkey("NotePrivate",'note_private',$object->note_private,'id',$object->id,$user->rights->ficheinter->creer,'textarea');
print '</td><td colspan="3">';
if (! empty($conf->global->MAIN_USE_JQUERY_JEDITABLE)) print $form->editInPlace($object->note_private, 'note_private', $user->rights->ficheinter->creer, 'textarea');
else print $form->editfieldval("NotePrivate",'note_private',$object->note_private,'id',$object->id,$user->rights->ficheinter->creer,'textarea');
print $form->editfieldval("NotePrivate",'note_private',$object->note_private,'id',$object->id,$user->rights->ficheinter->creer,'textarea');
print "</td></tr>";
}