2
0
forked from Wavyzz/dolibarr

Qual: Prepare to merge editfield and editInPlace

This commit is contained in:
Laurent Destailleur
2011-11-05 15:12:37 +01:00
parent cd514693c5
commit 3f30cebce3
2 changed files with 62 additions and 65 deletions

View File

@@ -68,14 +68,14 @@ class Form
/** /**
* Output key field for an editable field * Output key field for an editable field
* *
* @param string $text Text of label * @param string $text Text of label or key to translate
* @param string $htmlname Name of select field * @param string $htmlname Name of select field
* @param string $preselected Preselected value for parameter * @param string $preselected Value to show/edit
* @param string $paramkey Key of parameter (unique if there is several parameter to show) * @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 * @param string $paramvalue Value of parameter for Url
* @param boolean $perm Permission to allow button to edit parameter * @param boolean $perm Permission to allow button to edit parameter
* @param string $typeofdata Type of data (string by default, email, ...) * @param string $typeofdata Type of data ('string' by default, 'email', 'text' or 'textarea', 'day', ...)
* @return string HTML edit field * @return string HTML edit field
* TODO no GET or POST in class file, use a param * TODO no GET or POST in class file, use a param
*/ */
function editfieldkey($text,$htmlname,$preselected,$paramkey,$paramvalue,$perm,$typeofdata='string') function editfieldkey($text,$htmlname,$preselected,$paramkey,$paramvalue,$perm,$typeofdata='string')
@@ -91,17 +91,17 @@ class Form
} }
/** /**
* Output val field for an editable field * Output val field for an editable field
* *
* @param string $text Text of label (not used in this function) * @param string $text Text of label (not used in this function)
* @param string $htmlname Name of select field * @param string $htmlname Name of select field
* @param string $preselected Preselected value for parameter * @param string $preselected Value to show/edit
* @param string $paramkey Key of parameter (unique if there is several parameter to show) * @param string $paramkey Key of parameter (unique if there is several parameter to show)
* @param boolean $perm Permission to allow button to edit parameter * @param boolean $perm Permission to allow button to edit parameter
* @param string $typeofdata Type of data ('string' by default, 'email', 'text', 'day', ...) * @param string $typeofdata Type of data ('string' by default, 'email', 'text' or 'textarea', 'day', ...)
* @param string $editvalue Use this value instead $preselected * @param string $editvalue Use this value instead $preselected
* @return string HTML edit field * @return string HTML edit field
* TODO no GET or POST in class file, use a param * 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,$preselected,$paramkey,$paramvalue,$perm,$typeofdata='string',$editvalue='')
{ {
@@ -118,11 +118,11 @@ class Form
$ret.='<tr><td>'; $ret.='<tr><td>';
if (in_array($typeofdata,array('string','email'))) if (in_array($typeofdata,array('string','email')))
{ {
$ret.='<input type="text" name="'.$htmlname.'" value="'.($editvalue?$editvalue:$preselected).'">'; $ret.='<input type="text" id="'.$htmlname.'" name="'.$htmlname.'" value="'.($editvalue?$editvalue:$preselected).'">';
} }
else if ($typeofdata == 'text') else if ($typeofdata == 'text' || $typeofdata == 'textarea')
{ {
$ret.='<textarea name="'.$htmlname.'">'.($editvalue?$editvalue:$preselected).'</textarea>'; $ret.='<textarea id="'.$htmlname.'" name="'.$htmlname.'" wrap="soft" cols="70">'.($editvalue?$editvalue:$preselected).'</textarea>';
} }
else if ($typeofdata == 'day') else if ($typeofdata == 'day')
{ {
@@ -136,22 +136,23 @@ class Form
} }
else else
{ {
if ($typeofdata == 'email') $ret.=dol_print_email($preselected,0,0,0,0,1); if ($typeofdata == 'email') $ret.=dol_print_email($preselected,0,0,0,0,1);
if ($typeofdata == 'day') $ret.=dol_print_date($preselected,'day'); elseif ($typeofdata == 'day') $ret.=dol_print_date($preselected,'day');
elseif ($typeofdata == 'text' || $typeofdata == 'textarea') $ret.=dol_htmlentitiesbr($preselected);
else $ret.=$preselected; else $ret.=$preselected;
} }
return $ret; return $ret;
} }
/** /**
* Output edit in place form * Output edit in place form
* *
* @param string $value Value to show/edit * @param string $value Value to show/edit
* @param string $htmlname DIV ID (field name) * @param string $htmlname DIV ID (field name)
* @param int $condition Condition to edit * @param int $condition Condition to edit
* @param string $inputType Type of input * @param string $inputType Type of input
* @param string $inputOption Input option * @param string $inputOption Input option
* @return string HTML edit in place * @return string HTML edit in place
*/ */
function editInPlace($value, $htmlname, $condition, $inputType='textarea', $inputOption='') function editInPlace($value, $htmlname, $condition, $inputType='textarea', $inputOption='')
{ {

View File

@@ -56,6 +56,7 @@ $result = restrictedArea($user, 'ficheinter', $id, 'fichinter');
$object = new Fichinter($db); $object = new Fichinter($db);
/* /*
* Actions * Actions
*/ */
@@ -219,6 +220,18 @@ if ($action == 'setdescription')
$result=$object->set_description($user,$_POST['description']); $result=$object->set_description($user,$_POST['description']);
if ($result < 0) dol_print_error($db,$object->error); if ($result < 0) dol_print_error($db,$object->error);
} }
if ($action == 'setnote_public')
{
$object->fetch($id);
$result=$object->update_note_public($_POST['note_public']);
if ($result < 0) dol_print_error($db,$object->error);
}
if ($action == 'setnote_private')
{
$object->fetch($id);
$result=$object->update_note($_POST['note_private']);
if ($result < 0) dol_print_error($db,$object->error);
}
// Add line // Add line
if ($action == "addline" && $user->rights->ficheinter->creer) if ($action == "addline" && $user->rights->ficheinter->creer)
@@ -802,35 +815,12 @@ else if ($id > 0 || ! empty($ref))
print '</tr>'; print '</tr>';
// Description (must be a textarea and not html must be allowed (used in list view) // Description (must be a textarea and not html must be allowed (used in list view)
print '<tr><td>'; print '<tr><td valign="top">';
if (! empty($conf->global->MAIN_USE_JQUERY_JEDITABLE)) 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 $langs->trans('Description'); print '</td><td colspan="3">';
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');
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');
}
else
{
print '<table class="nobordernopadding" width="100%"><tr><td>';
print $langs->trans('Description');
print '</td>';
if ($action != 'editdescription' && $object->statut == 0) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editdescription&amp;id='.$object->id.'">'.img_edit($langs->trans('Modify'),1).'</a></td>';
print '</tr></table>';
print '</td><td colspan="3">';
if ($action == 'editdescription')
{
print '<form name="editdescription" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="setdescription">';
print '<textarea name="description" wrap="soft" cols="70" rows="'.ROWS_3.'">'.dol_htmlentitiesbr_decode($object->description).'</textarea><br>';
print '<input type="submit" class="button" value="'.$langs->trans('Modify').'">';
print '</form>';
}
else
{
print dol_nl2br($object->description);
}
}
print '</td>'; print '</td>';
print '</tr>'; print '</tr>';
@@ -868,17 +858,23 @@ else if ($id > 0 || ! empty($ref))
print '<tr><td>'.$langs->trans("Status").'</td><td>'.$object->getLibStatut(4).'</td></tr>'; print '<tr><td>'.$langs->trans("Status").'</td><td>'.$object->getLibStatut(4).'</td></tr>';
// Public note // Public note
print '<tr><td valign="top">'.$langs->trans("NotePublic").'</td>'; print '<tr><td valign="top">';
print '<td valign="top" colspan="3">'; if (! empty($conf->global->MAIN_USE_JQUERY_JEDITABLE)) print $langs->trans('NotePublic');
print $form->editInPlace($object->note_public, 'note_public', $user->rights->ficheinter->creer, 'textarea'); else 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 "</td></tr>"; print "</td></tr>";
// Private note // Private note
if (! $user->societe_id) if (! $user->societe_id)
{ {
print '<tr><td valign="top">'.$langs->trans("NotePrivate").'</td>'; print '<tr><td valign="top">';
print '<td valign="top" colspan="3">'; if (! empty($conf->global->MAIN_USE_JQUERY_JEDITABLE)) print $langs->trans('NotePrivate');
print $form->editInPlace($object->note_private, 'note_private', $user->rights->ficheinter->creer, 'textarea'); else 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 "</td></tr>"; print "</td></tr>";
} }