NEW Introduce a method getDefaultCreateValueForField for developers to
get a default value to use for a form in create mode. Implement it for public and private notes.
This commit is contained in:
parent
ee683049a6
commit
da6a1d6629
@ -1414,11 +1414,7 @@ if ($action == 'create')
|
||||
print '<tr>';
|
||||
print '<td class="border" valign="top">' . $langs->trans('NotePublic') . '</td>';
|
||||
print '<td valign="top" colspan="2">';
|
||||
$note_public = '';
|
||||
if (is_object($objectsrc)) // Take value from source object
|
||||
{
|
||||
$note_public = $objectsrc->note_public;
|
||||
}
|
||||
$note_public = $object->getDefaultCreateValueFor('note_public', (is_object($objectsrc)?$objectsrc->note_public:null));
|
||||
$doleditor = new DolEditor('note_public', $note_public, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, '90%');
|
||||
print $doleditor->Create(1);
|
||||
|
||||
@ -1428,11 +1424,7 @@ if ($action == 'create')
|
||||
print '<tr>';
|
||||
print '<td class="border" valign="top">' . $langs->trans('NotePrivate') . '</td>';
|
||||
print '<td valign="top" colspan="2">';
|
||||
$note_private = '';
|
||||
if (! empty($origin) && ! empty($originid) && is_object($objectsrc)) // Take value from source object
|
||||
{
|
||||
$note_private = $objectsrc->note_private;
|
||||
}
|
||||
$note_private = $object->getDefaultCreateValueFor('note_private', ((! empty($origin) && ! empty($originid) && is_object($objectsrc))?$objectsrc->note_private:null));
|
||||
$doleditor = new DolEditor('note_private', $note_private, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, '90%');
|
||||
print $doleditor->Create(1);
|
||||
// print '<textarea name="note_private" wrap="soft" cols="70" rows="'.ROWS_3.'">'.$note_private.'.</textarea>
|
||||
|
||||
@ -1292,8 +1292,8 @@ if ($action == 'create' && $user->rights->commande->creer)
|
||||
|
||||
$datedelivery = (! empty($objectsrc->date_livraison) ? $objectsrc->date_livraison : '');
|
||||
|
||||
$note_private = (! empty($objectsrc->note_private) ? $objectsrc->note_private : (! empty($objectsrc->note_private) ? $objectsrc->note_private : ''));
|
||||
$note_public = (! empty($objectsrc->note_public) ? $objectsrc->note_public : '');
|
||||
$note_private = $object->getDefaultCreateValueFor('note_private', (! empty($objectsrc->note_private) ? $objectsrc->note_private : null));
|
||||
$note_public = $object->getDefaultCreateValueFor('note_public', (! empty($objectsrc->note_public) ? $objectsrc->note_public : null));
|
||||
|
||||
// Object source contacts list
|
||||
$srccontactslist = $objectsrc->liste_contact(- 1, 'external', 1);
|
||||
@ -1311,6 +1311,9 @@ if ($action == 'create' && $user->rights->commande->creer)
|
||||
$remise_absolue = 0;
|
||||
$dateorder = empty($conf->global->MAIN_AUTOFILL_DATE_ORDER)?-1:'';
|
||||
$projectid = 0;
|
||||
|
||||
$note_private = $object->getDefaultCreateValueFor('note_private');
|
||||
$note_public = $object->getDefaultCreateValueFor('note_public');
|
||||
}
|
||||
$absolute_discount=$soc->getAvailableDiscounts();
|
||||
|
||||
|
||||
@ -2285,11 +2285,7 @@ if ($action == 'create')
|
||||
print '<tr>';
|
||||
print '<td class="border" valign="top">' . $langs->trans('NotePublic') . '</td>';
|
||||
print '<td valign="top" colspan="2">';
|
||||
$note_public = '';
|
||||
if (is_object($objectsrc)) // Take value from source object
|
||||
{
|
||||
$note_public = $objectsrc->note_public;
|
||||
}
|
||||
$note_public = $object->getDefaultCreateValueFor('note_public', (is_object($objectsrc)?$objectsrc->note_public:null));
|
||||
$doleditor = new DolEditor('note_public', $note_public, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, '90%');
|
||||
print $doleditor->Create(1);
|
||||
|
||||
@ -2299,11 +2295,7 @@ if ($action == 'create')
|
||||
print '<tr>';
|
||||
print '<td class="border" valign="top">' . $langs->trans('NotePrivate') . '</td>';
|
||||
print '<td valign="top" colspan="2">';
|
||||
$note_private = '';
|
||||
if (! empty($origin) && ! empty($originid) && is_object($objectsrc)) // Take value from source object
|
||||
{
|
||||
$note_private = $objectsrc->note_private;
|
||||
}
|
||||
$note_private = $object->getDefaultCreateValueFor('note_private', ((! empty($origin) && ! empty($originid) && is_object($objectsrc))?$objectsrc->note_private:null));
|
||||
$doleditor = new DolEditor('note_private', $note_private, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, '90%');
|
||||
print $doleditor->Create(1);
|
||||
// print '<textarea name="note_private" wrap="soft" cols="70" rows="'.ROWS_3.'">'.$note_private.'.</textarea>
|
||||
|
||||
@ -3549,7 +3549,47 @@ abstract class CommonObject
|
||||
|
||||
/* Functions common to commonobject and commonobjectline */
|
||||
|
||||
/* For default values */
|
||||
|
||||
/**
|
||||
* Return the default value to use for a field when showing the create form of object.
|
||||
* Return values in this order:
|
||||
* 1) If parameter is available into POST, we return it first.
|
||||
* 2) If not but an alternate value was provided as parameter of function, we return it.
|
||||
* 3) If not but a constant $conf->global->OBJECTELEMENT_FIELDNAME is set, we return it (It is better to use the dedicated table).
|
||||
* 4) Return value found into database (TODO No yet implemented)
|
||||
*
|
||||
* @param string $fieldname Name of field
|
||||
* @param string $alternatevalue Alternate value to use
|
||||
* @return string Default value
|
||||
**/
|
||||
function getDefaultCreateValueFor($fieldname, $alternatevalue=null)
|
||||
{
|
||||
global $conf, $_POST;
|
||||
|
||||
// If param is has been posted with use this value first.
|
||||
if (isset($_POST[$fieldname])) return GETPOST($fieldname, 2);
|
||||
|
||||
if (isset($alternatevalue)) return $alternatevalue;
|
||||
|
||||
$newelement=$this->element;
|
||||
if ($newelement == 'facture') $newelement='invoice';
|
||||
if ($newelement == 'commande') $newelement='order';
|
||||
if (empty($newelement))
|
||||
{
|
||||
dol_syslog("Ask a default value using common method getDefaultCreateValueForField on an object with no property ->element defined. Return empty string.", LOG_WARNING);
|
||||
return '';
|
||||
}
|
||||
|
||||
$keyforfieldname=strtoupper($newelement.'_DEFAULT_'.$fieldname);
|
||||
//var_dump($keyforfieldname);
|
||||
if (isset($conf->global->$keyforfieldname)) return $conf->global->$keyforfieldname;
|
||||
|
||||
// TODO Ad here a scan into table llx_overwrite_default with a filter on $this->element and $fieldname
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* For triggers */
|
||||
|
||||
|
||||
|
||||
@ -1460,8 +1460,8 @@ if ($action=='create')
|
||||
|
||||
$datedelivery = (! empty($objectsrc->date_livraison) ? $objectsrc->date_livraison : '');
|
||||
|
||||
$note_private = (! empty($objectsrc->note_private) ? $objectsrc->note_private : (! empty($objectsrc->note_private) ? $objectsrc->note_private : ''));
|
||||
$note_public = (! empty($objectsrc->note_public) ? $objectsrc->note_public : '');
|
||||
$note_private = $object->getDefaultCreateValueFor('note_private', (! empty($objectsrc->note_private) ? $objectsrc->note_private : null));
|
||||
$note_public = $object->getDefaultCreateValueFor('note_public', (! empty($objectsrc->note_public) ? $objectsrc->note_public : null));
|
||||
|
||||
// Object source contacts list
|
||||
$srccontactslist = $objectsrc->liste_contact(- 1, 'external', 1);
|
||||
@ -1471,6 +1471,9 @@ if ($action=='create')
|
||||
{
|
||||
$cond_reglement_id = $societe->cond_reglement_supplier_id;
|
||||
$mode_reglement_id = $societe->mode_reglement_supplier_id;
|
||||
|
||||
$note_private = $object->getDefaultCreateValueFor('note_private');
|
||||
$note_public = $object->getDefaultCreateValueFor('note_public');
|
||||
}
|
||||
|
||||
print '<form name="add" action="'.$_SERVER["PHP_SELF"].'" method="post">';
|
||||
|
||||
@ -1477,7 +1477,8 @@ if ($action == 'create')
|
||||
// Public note
|
||||
print '<tr><td>'.$langs->trans('NotePublic').'</td>';
|
||||
print '<td>';
|
||||
$doleditor = new DolEditor('note_public', GETPOST('note_public'), '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, 70);
|
||||
$note_public = $object->getDefaultCreateValueFor('note_public');
|
||||
$doleditor = new DolEditor('note_public', $note_public, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, 70);
|
||||
print $doleditor->Create(1);
|
||||
print '</td>';
|
||||
// print '<td><textarea name="note" wrap="soft" cols="60" rows="'.ROWS_5.'"></textarea></td>';
|
||||
@ -1486,7 +1487,8 @@ if ($action == 'create')
|
||||
// Private note
|
||||
print '<tr><td>'.$langs->trans('NotePrivate').'</td>';
|
||||
print '<td>';
|
||||
$doleditor = new DolEditor('note_private', GETPOST('note_private'), '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, 70);
|
||||
$note_private = $object->getDefaultCreateValueFor('note_private');
|
||||
$doleditor = new DolEditor('note_private', $note_private, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, 70);
|
||||
print $doleditor->Create(1);
|
||||
print '</td>';
|
||||
// print '<td><textarea name="note" wrap="soft" cols="60" rows="'.ROWS_5.'"></textarea></td>';
|
||||
|
||||
Loading…
Reference in New Issue
Block a user