Actions are defined in the config/common/{model}.config.php file.
The best way to proceed is to be inspired by the default existing actions of Novius OS.
Action’s configuration contains {{placeholders}}.
Replaced with PHP :
- {{model_label}}: the model name
- {{controller_base_url}}: URL of the model’s controller
Every other placeholders are replaced according to the data of the item: {{_id}} and {{_title}} in this case, but also any field defined in the data_mapping.
There are 3 possibles targets for the actions:
add action:
edit action:
delete action:
<?php
return array(
// Default ADD action
'add' => array(
'label' => __('Add {{model_label}}'),
'primary' => true,
// Opens a new tab on click
'action' => array(
'action' => 'nosTabs',
'method' => 'add',
'tab' => array(
'url' => '{{controller_base_url}}insert_update?context={{context}}',
),
),
// The ation is only be shown in the App Desk's toobar
'targets' => array(
'toolbar-grid' => true,
),
),
// default EDIT action
'edit' => array(
'label' => __('Edit'),
'primary' => true,
'icon' => 'pencil',
// Opens the item on click (will refocus the tab when existing)
'action' => array(
'action' => 'nosTabs',
'tab' => array(
'url' => "{{controller_base_url}}insert_update/{{_id}}",
'label' => '{{_title}}',
),
),
// The action is only be shown in the main grid
'targets' => array(
'grid' => true,
),
),
// Default DELETE action
'delete' => array(
'label' => __('Delete'),
'primary' => true,
'icon' => 'trash',
'red' => true,
// Opens a confirmation popup on click
'action' => array(
'action' => 'confirmationDialog',
'dialog' => array(
'contentUrl' => '{{controller_base_url}}delete/{{_id}}',
'title' => strtr($config['i18n']['deleting item title'], array(
'{{title}}' => '{{_title}}',
)),
),
),
// The action is shown both in the main grid and the edition form...
'targets' => array(
'grid' => true,
'toolbar-edit' => true,
),
// ...but not for new items!
'visible' => function($params) {
return !isset($params['item']) || !$params['item']->is_new();
},
),
);