Skip to content

Commit

Permalink
New: add editInPlace function
Browse files Browse the repository at this point in the history
  • Loading branch information
hregis committed Oct 27, 2011
1 parent 894e9a3 commit cdcb15f
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 24 deletions.
38 changes: 17 additions & 21 deletions htdocs/compta/deplacement/fiche.php
Expand Up @@ -170,7 +170,7 @@

llxHeader();

$html = new Form($db);
$form = new Form($db);

/*
* Action create
Expand All @@ -191,17 +191,17 @@

print "<tr>";
print '<td width="25%" class="fieldrequired">'.$langs->trans("Type").'</td><td>';
print $html->select_type_fees(GETPOST("type"),'type',1);
print $form->select_type_fees(GETPOST("type"),'type',1);
print '</td></tr>';

print "<tr>";
print '<td class="fieldrequired">'.$langs->trans("Person").'</td><td>';
print $html->select_users(GETPOST("fk_user"),'fk_user',1);
print $form->select_users(GETPOST("fk_user"),'fk_user',1);
print '</td></tr>';

print "<tr>";
print '<td class="fieldrequired">'.$langs->trans("Date").'</td><td>';
print $html->select_date($datec?$datec:-1,'','','','','add',1,1);
print $form->select_date($datec?$datec:-1,'','','','','add',1,1);
print '</td></tr>';

// Km
Expand All @@ -210,7 +210,7 @@
// Company
print "<tr>";
print '<td>'.$langs->trans("CompanyVisited").'</td><td>';
print $html->select_societes(GETPOST("socid"),'socid','',1);
print $form->select_societes(GETPOST("socid"),'socid','',1);
print '</td></tr>';

// Public note
Expand Down Expand Up @@ -272,18 +272,18 @@
// Type
print "<tr>";
print '<td class="fieldrequired">'.$langs->trans("Type").'</td><td>';
print $html->select_type_fees($_POST["type"]?$_POST["type"]:$object->type,'type',0);
print $form->select_type_fees($_POST["type"]?$_POST["type"]:$object->type,'type',0);
print '</td></tr>';

// Who
print "<tr>";
print '<td class="fieldrequired">'.$langs->trans("Person").'</td><td>';
print $html->select_users($_POST["fk_user"]?$_POST["fk_user"]:$object->fk_user,'fk_user',0);
print $form->select_users($_POST["fk_user"]?$_POST["fk_user"]:$object->fk_user,'fk_user',0);
print '</td></tr>';

// Date
print '<tr><td class="fieldrequired">'.$langs->trans("Date").'</td><td>';
print $html->select_date($object->date,'','','','','update');
print $form->select_date($object->date,'','','','','update');
print '</td></tr>';

// Km
Expand All @@ -294,7 +294,7 @@
// Where
print "<tr>";
print '<td>'.$langs->trans("CompanyVisited").'</td><td>';
print $html->select_societes($soc->id,'socid','',1);
print $form->select_societes($soc->id,'socid','',1);
print '</td></tr>';

// Public note
Expand Down Expand Up @@ -329,7 +329,7 @@
*/
if ($action == 'delete')
{
$ret=$html->form_confirm($_SERVER["PHP_SELF"]."?id=".$id,$langs->trans("DeleteTrip"),$langs->trans("ConfirmDeleteTrip"),"confirm_delete");
$ret=$form->form_confirm($_SERVER["PHP_SELF"]."?id=".$id,$langs->trans("DeleteTrip"),$langs->trans("ConfirmDeleteTrip"),"confirm_delete");
if ($ret == 'html') print '<br>';
}

Expand All @@ -346,7 +346,7 @@
// Ref
print "<tr>";
print '<td width="20%">'.$langs->trans("Ref").'</td><td>';
print $html->showrefnav($object,'id','',1,'rowid','ref','');
print $form->showrefnav($object,'id','',1,'rowid','ref','');
print '</td></tr>';

// Type
Expand All @@ -366,7 +366,7 @@

// Km/Price
print '<tr><td>'.$langs->trans("FeesKilometersOrAmout").'</td>';
print '<td><div class="edit_numeric" id="km">'.$object->km.'</div></td></tr>';
print '<td>'.$form->editInPlace($object->km, 'km', $object->element, 'text').'</td></tr>';

// Where
print '<tr><td>'.$langs->trans("CompanyVisited").'</td>';
Expand All @@ -384,7 +384,7 @@
print '<table class="nobordernopadding" width="100%"><tr><td>';
print $langs->trans('Project');
print '</td>';
if ($action != 'classify')
if ($action != 'classify' && $user->rights->deplacement->creer)
{
print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=classify&amp;id='.$object->id.'">';
print img_edit($langs->trans('SetProject'),1);
Expand All @@ -394,11 +394,11 @@
print '</td><td colspan="3">';
if ($action == 'classify')
{
$html->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');
}
else
{
$html->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');
}
print '</td>';
print '</tr>';
Expand All @@ -410,19 +410,15 @@
// Public note
print '<tr><td valign="top">'.$langs->trans("NotePublic").'</td>';
print '<td valign="top" colspan="3">';
print '<div class="edit_area" id="note_public">';
print ($object->note_public ? dol_nl2br($object->note_public) : "&nbsp;");
print '</div>';
print $form->editInPlace(($object->note_public ? dol_nl2br($object->note_public) : "&nbsp;"), 'note_public', $object->element);
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 '<div class="edit_area" id="note">';
print ($object->note_private ? dol_nl2br($object->note_private) : "&nbsp;");
print '</div>';
print $form->editInPlace(($object->note_private ? dol_nl2br($object->note_private) : "&nbsp;"), 'note', $object->element);
print "</td></tr>";
}

Expand Down
31 changes: 30 additions & 1 deletion htdocs/core/class/html.form.class.php
Expand Up @@ -4,7 +4,7 @@
* Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
* Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
* Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
* Copyright (C) 2005-2010 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2005-2011 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
* Copyright (C) 2006 Marc Barilley/Ocebo <marc@ocebo.com>
* Copyright (C) 2007 Franky Van Liedekerke <franky.van.liedekerker@telenet.be>
Expand Down Expand Up @@ -141,6 +141,35 @@ function editfieldval($text,$htmlname,$preselected,$paramkey,$paramvalue,$perm,$
}
return $ret;
}

/**
* Output edit in place form
*
* @param string $value Value to show/edit
* @param string $htmlname DIV ID (field name)
* @param string $element Type of element
* @param string $area Type of edit
* @return string HTML edit in place
*/
function editInPlace($value, $htmlname, $element, $type='area')
{
global $user;

$out='';

if ($user->rights->$element->creer || $user->rights->$element->write)
{
$out.= '<div class="edit_'.$type.'" id="'.$htmlname.'">';
$out.= $value;
$out.= '</div>';
}
else
{
$out = $value;
}

return $out;
}

/**
* Show a text and picto with tooltip on text or picto
Expand Down
5 changes: 3 additions & 2 deletions htdocs/core/lib/functions2.lib.php
@@ -1,6 +1,7 @@
<?php
/* Copyright (C) 2008-2011 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2008 Raphael Bertrand (Resultic) <raphael.bertrand@resultic.fr>
/* Copyright (C) 2008-2011 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2008-2011 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2008 Raphael Bertrand (Resultic) <raphael.bertrand@resultic.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down

0 comments on commit cdcb15f

Please sign in to comment.