New: Add new hook function addMoreActionsButtons to allow a module to

add/replace action buttons into an element.
This commit is contained in:
Laurent Destailleur 2014-01-24 11:15:25 +01:00
parent 101151630d
commit 8d916215cc
10 changed files with 234 additions and 200 deletions

View File

@ -8,7 +8,7 @@ For users:
- New: Add graph stats for suppliers orders in tab "stats" on products. - New: Add graph stats for suppliers orders in tab "stats" on products.
- New: Add option MAIN_HIDE_INACTIVETAB_ON_PRINT to hide inactive tabs when you - New: Add option MAIN_HIDE_INACTIVETAB_ON_PRINT to hide inactive tabs when you
use the "print" view on screen. use the "print" view on screen.
- New: Add menu entry to barcode genration page. - New: Add a menu entry to a barcode generation page.
- New: Add option MAIN_AUTO_TIMESTAMP_IN_PUBLIC_NOTES and MAIN_AUTO_TIMESTAMP_IN_PRIVATE_NOTES - New: Add option MAIN_AUTO_TIMESTAMP_IN_PUBLIC_NOTES and MAIN_AUTO_TIMESTAMP_IN_PRIVATE_NOTES
to automatically add timestamp and user line into editionf field when editing a note. to automatically add timestamp and user line into editionf field when editing a note.
- New: Add button cancel into edition of notes. - New: Add button cancel into edition of notes.
@ -27,7 +27,9 @@ For developers:
- New: Add option 'aZ' into GETPOST function to check parameters contains - New: Add option 'aZ' into GETPOST function to check parameters contains
only a to z or A to Z characters. only a to z or A to Z characters.
- New: Opensurvey polls tab cards can now be extended from external modules. - New: Opensurvey polls tab cards can now be extended from external modules.
- New: Triggers OPENSURVEY_CREATE, OPENSURVEY_DELETE - New: Triggers OPENSURVEY_CREATE, OPENSURVEY_DELETE added.
- New: Add new hook function addMoreActionsButtons to allow a module to add/replace
action buttons into an element.
WARNING: Following change may create regression for some external modules, but was necessary to make WARNING: Following change may create regression for some external modules, but was necessary to make
Dolibarr better: Dolibarr better:

View File

@ -167,8 +167,7 @@ if ($action == 'add_action')
$actioncomm->datep = $datep; $actioncomm->datep = $datep;
$actioncomm->datef = $datef; $actioncomm->datef = $datef;
$actioncomm->percentage = $percentage; $actioncomm->percentage = $percentage;
$actioncomm->duree=((float) (GETPOST('dureehour') * 60) + (float) GETPOST('dureemin')) * $actioncomm->duree=((float) (GETPOST('dureehour') * 60) + (float) GETPOST('dureemin')) * 60;
60;
$usertodo=new User($db); $usertodo=new User($db);
if ($_POST["affectedto"] > 0) if ($_POST["affectedto"] > 0)
@ -1072,6 +1071,10 @@ if ($id > 0)
print '<div class="tabsAction">'; print '<div class="tabsAction">';
$parameters=array();
$reshook=$hookmanager->executeHooks('addMoreActionsButtons',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
if (empty($reshook))
{
if ($action != 'edit') if ($action != 'edit')
{ {
if ($user->rights->agenda->allactions->create || if ($user->rights->agenda->allactions->create ||
@ -1094,6 +1097,7 @@ if ($id > 0)
print '<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="'.$langs->trans("NotAllowed").'">'.$langs->trans("Delete").'</a></div>'; print '<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="'.$langs->trans("NotAllowed").'">'.$langs->trans("Delete").'</a></div>';
} }
} }
}
print '</div>'; print '</div>';
} }

View File

@ -2127,6 +2127,10 @@ else
{ {
print '<div class="tabsAction">'; print '<div class="tabsAction">';
$parameters=array();
$reshook=$hookmanager->executeHooks('addMoreActionsButtons',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
if (empty($reshook))
{
if ($action != 'statut' && $action <> 'editline') if ($action != 'statut' && $action <> 'editline')
{ {
// Validate // Validate
@ -2219,6 +2223,7 @@ else
} }
} }
}
print '</div>'; print '</div>';
} }

View File

@ -2392,12 +2392,14 @@ else
/* /*
* Boutons actions * Boutons actions
*/ */
if ($action != 'presend') if ($action != 'presend' && $action != 'editline')
{
if ($user->societe_id == 0 && $action <> 'editline')
{ {
print '<div class="tabsAction">'; print '<div class="tabsAction">';
$parameters=array();
$reshook=$hookmanager->executeHooks('addMoreActionsButtons',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
if (empty($reshook))
{
// Valid // Valid
if ($object->statut == 0 && $object->total_ttc >= 0 && $numlines > 0 && $user->rights->commande->valider) if ($object->statut == 0 && $object->total_ttc >= 0 && $numlines > 0 && $user->rights->commande->valider)
{ {
@ -2470,7 +2472,7 @@ else
} }
// Reopen a closed order // Reopen a closed order
if ($object->statut == 3) if ($object->statut == 3 && $user->rights->commande->creer)
{ {
print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=reopen">'.$langs->trans('ReOpen').'</a></div>'; print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=reopen">'.$langs->trans('ReOpen').'</a></div>';
} }
@ -2519,9 +2521,8 @@ else
print '<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="'.$langs->trans("ShippingExist").'">'.$langs->trans("Delete").'</a></div>'; print '<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="'.$langs->trans("ShippingExist").'">'.$langs->trans("Delete").'</a></div>';
} }
} }
print '</div>';
} }
print '</div>';
} }
print '<br>'; print '<br>';

View File

@ -3547,12 +3547,14 @@ else if ($id > 0 || ! empty($ref))
// Boutons actions // Boutons actions
if ($action != 'prerelance' && $action != 'presend') if ($action != 'prerelance' && $action != 'presend' && $action != 'valid' && $action != 'editline')
{
if ($user->societe_id == 0 && $action <> 'valid' && $action <> 'editline')
{ {
print '<div class="tabsAction">'; print '<div class="tabsAction">';
$parameters=array();
$reshook=$hookmanager->executeHooks('addMoreActionsButtons',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
if (empty($reshook))
{
// Editer une facture deja validee, sans paiement effectue et pas exporte en compta // Editer une facture deja validee, sans paiement effectue et pas exporte en compta
if ($object->statut == 1) if ($object->statut == 1)
{ {
@ -3580,7 +3582,7 @@ else if ($id > 0 || ! empty($ref))
} }
// Reopen a standard paid invoice // Reopen a standard paid invoice
if (($object->type == 0 || $object->type == 1) && ($object->statut == 2 || $object->statut == 3)) // A paid invoice (partially or completely) if (($object->type == 0 || $object->type == 1) && ($object->statut == 2 || $object->statut == 3) && $user->rights->facture->creer) // A paid invoice (partially or completely)
{ {
if (! $objectidnext && $object->close_code != 'replaced') // Not replaced by another invoice if (! $objectidnext && $object->close_code != 'replaced') // Not replaced by another invoice
{ {

View File

@ -1026,10 +1026,12 @@ else
print "</div>"; print "</div>";
// Barre d'actions // Barre d'actions
if (! $user->societe_id)
{
print '<div class="tabsAction">'; print '<div class="tabsAction">';
$parameters=array();
$reshook=$hookmanager->executeHooks('addMoreActionsButtons',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
if (empty($reshook))
{
if ($user->rights->societe->contact->creer) if ($user->rights->societe->contact->creer)
{ {
print '<a class="butAction" href="fiche.php?id='.$object->id.'&amp;action=edit">'.$langs->trans('Modify').'</a>'; print '<a class="butAction" href="fiche.php?id='.$object->id.'&amp;action=edit">'.$langs->trans('Modify').'</a>';
@ -1054,9 +1056,9 @@ else
{ {
print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?action=disable&amp;id='.$object->id.'">'.$langs->trans("DisableUser").'</a>'; print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?action=disable&amp;id='.$object->id.'">'.$langs->trans("DisableUser").'</a>';
} }
}
print "</div><br>"; print "</div><br>";
}
print load_fiche_titre($langs->trans("TasksHistoryForThisContact"),'',''); print load_fiche_titre($langs->trans("TasksHistoryForThisContact"),'','');

View File

@ -134,6 +134,7 @@ class HookManager
if (in_array( if (in_array(
$method, $method,
array( array(
'addMoreActionsButtons',
'addStatisticLine', 'addStatisticLine',
'doActions', 'doActions',
'formObjectOptions', 'formObjectOptions',
@ -164,7 +165,7 @@ class HookManager
// test to avoid to run twice a hook, when a module implements several active contexts // test to avoid to run twice a hook, when a module implements several active contexts
if (in_array($module,$modulealreadyexecuted)) continue; if (in_array($module,$modulealreadyexecuted)) continue;
$modulealreadyexecuted[$module]=$module; $modulealreadyexecuted[$module]=$module;
// Hooks that return int (doActions, formObjectOptions, pdf_writelinedesc, paymentsupplierinvoices) // Hooks that must return int (hooks with type 'addreplace')
if ($hooktype == 'addreplace') if ($hooktype == 'addreplace')
{ {
$resaction += $actionclassinstance->$method($parameters, $object, $action, $this); // $object and $action can be changed by method ($object->id during creation for example or $action to go back to other action for example) $resaction += $actionclassinstance->$method($parameters, $object, $action, $this); // $object and $action can be changed by method ($object->id during creation for example or $action to go back to other action for example)

View File

@ -1285,8 +1285,12 @@ if (($action == 'clone' && (empty($conf->use_javascript_ajax) || ! empty($conf->
print "\n".'<div class="tabsAction">'."\n"; print "\n".'<div class="tabsAction">'."\n";
if ($action == '' || $action == 'view') $parameters=array();
$reshook=$hookmanager->executeHooks('addMoreActionsButtons',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
if (empty($reshook))
{ {
if ($action == '' || $action == 'view')
{
if ($user->rights->produit->creer || $user->rights->service->creer) if ($user->rights->produit->creer || $user->rights->service->creer)
{ {
if (! isset($object->no_button_edit) || $object->no_button_edit <> 1) print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&amp;id='.$object->id.'">'.$langs->trans("Modify").'</a></div>'; if (! isset($object->no_button_edit) || $object->no_button_edit <> 1) print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&amp;id='.$object->id.'">'.$langs->trans("Modify").'</a></div>';
@ -1328,6 +1332,7 @@ if ($action == '' || $action == 'view')
{ {
print '<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="'.$langs->trans("NotEnoughPermissions").'">'.$langs->trans("Delete").'</a></div>'; print '<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="'.$langs->trans("NotEnoughPermissions").'">'.$langs->trans("Delete").'</a></div>';
} }
}
} }
print "\n</div><br>\n"; print "\n</div><br>\n";

View File

@ -47,6 +47,8 @@ $mesg = '';
// Security check // Security check
$result=restrictedArea($user,'stock'); $result=restrictedArea($user,'stock');
// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
$hookmanager->initHooks(array('warehousecard'));
/* /*
@ -336,7 +338,11 @@ else
print "<div class=\"tabsAction\">\n"; print "<div class=\"tabsAction\">\n";
if ($action == '') $parameters=array();
$reshook=$hookmanager->executeHooks('addMoreActionsButtons',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
if (empty($reshook))
{
if (empty($action))
{ {
if ($user->rights->stock->creer) if ($user->rights->stock->creer)
print "<a class=\"butAction\" href=\"fiche.php?action=edit&id=".$object->id."\">".$langs->trans("Modify")."</a>"; print "<a class=\"butAction\" href=\"fiche.php?action=edit&id=".$object->id."\">".$langs->trans("Modify")."</a>";
@ -348,6 +354,7 @@ else
else else
print "<a class=\"butActionRefused\" href=\"#\">".$langs->trans("Delete")."</a>"; print "<a class=\"butActionRefused\" href=\"#\">".$langs->trans("Delete")."</a>";
} }
}
print "</div>"; print "</div>";

View File

@ -1818,6 +1818,10 @@ else
*/ */
print '<div class="tabsAction">'."\n"; print '<div class="tabsAction">'."\n";
$parameters=array();
$reshook=$hookmanager->executeHooks('addMoreActionsButtons',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
if (empty($reshook))
{
if (! empty($object->email)) if (! empty($object->email))
{ {
$langs->load("mails"); $langs->load("mails");
@ -1845,6 +1849,7 @@ else
print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'&amp;action=delete">'.$langs->trans('Delete').'</a></div>'."\n"; print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'&amp;action=delete">'.$langs->trans('Delete').'</a></div>'."\n";
} }
} }
}
print '</div>'."\n"; print '</div>'."\n";