Browse Source

Style actions in GB

Use twig for actions
experimental
Paweł Jedwabny 3 years ago
parent
commit
ed3a870046
2 changed files with 32 additions and 21 deletions
  1. +20
    -21
      modules/Utils/GenericBrowser/GenericBrowser_0.php
  2. +12
    -0
      modules/Utils/GenericBrowser/theme/actions.twig

+ 20
- 21
modules/Utils/GenericBrowser/GenericBrowser_0.php View File

@@ -964,30 +964,29 @@ class Utils_GenericBrowser extends Module {
else $column_no = count($this->columns);
$col[$column_no]['attrs'] = '';
if (!empty($this->actions[$i])) {
$fa_icons = FontAwesome::get();
uasort($this->actions[$i], array($this, 'sort_actions'));
$actions = '<div class="btn-group">'.
'<button type="button" class="btn btn-default dropdown-toggle btn-xs" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" style="border-radius: 65px">'.
'<span class="glyphicon glyphicon-option-vertical"></span></button><div class="dropdown-menu-container"><ul class="dropdown-menu" style="padding: 5px 0" id="menu-icons">';
foreach ($this->actions[$i] as $icon => $arr) {
$actions .= '<div style="padding: 3px;" <li><a ' . Utils_TooltipCommon::open_tag_attrs($arr['tooltip'] !== null ? $arr['tooltip'] : $arr['label'], $arr['tooltip'] === null) . ' ' . $arr['tag_attrs'] . ' style="padding: 5px">';
if(array_key_exists('fa-'.$icon,$fa_icons)) {
$actions .= "<i class='fa fa-$icon fa-lg fa-fw text-info' style='margin-right: 5px'></i>";
} elseif ($icon=='view' || $icon=='delete' || $icon=='edit' || $icon=='info' || $icon=='restore' || $icon=='append data' || $icon=='active-on' || $icon=='active-off' || $icon=='history' || $icon=='move-down' || $icon=='move-up' || $icon=='history_inactive' || $icon=='print' || $icon == 'move-up-down') {
$ico = $this->font_awesome_translate[$icon];
$actions .= "<i class='fa fa-$ico fa-lg fa-fw text-info' style='margin-right: 5px'></i>";
} elseif (file_exists($icon)) {
$actions .= '<img class="action_button" src="' . $icon . '" border="0" style="margin-right: 1rem">';
} else {
$actions .= $arr['label'];
}
$actions .= $arr['label'].'</a></li></div>';
}
$actions .= '</ul></div></div>';
uasort($this->actions[$i], array($this, 'sort_actions'));

$actions_data = array_map(function($icon, $arr) {
if(array_key_exists('fa-'.$icon, FontAwesome::get())) {
} elseif (array_key_exists($icon,$this->font_awesome_translate)) {
$icon = $this->font_awesome_translate[$icon];
} else {
//FIXME: Add warning about invalid icon
}

return [
'tooltip' => Utils_TooltipCommon::open_tag_attrs($arr['tooltip'] !== null ? $arr['tooltip'] : $arr['label'], $arr['tooltip'] === null),
'attrs' => $arr['tag_attrs'],
'label' => $arr['label'],
'icon' => $icon
];
}, array_keys($this->actions[$i]), array_values($this->actions[$i]));

$actions = $this->twig_render('actions.twig', ['actions' => $actions_data]);
$col[$column_no]['label'] = $actions;
$col[$column_no]['attrs'] .= ' class="Utils_GenericBrowser__actions Utils_GenericBrowser__td"';
} else {
$col[$column_no]['label'] = '&nbsp;';
$col[$column_no]['label'] = '';
$col[$column_no]['attrs'] .= 'nowrap="nowrap"' . ' class="Utils_GenericBrowser__td"';
}
if (isset($this->no_actions[$i]))


+ 12
- 0
modules/Utils/GenericBrowser/theme/actions.twig View File

@@ -0,0 +1,12 @@
<div class="item-action dropdown">
<a href="javascript:void(0)" data-toggle="dropdown" class="icon" aria-expanded="false"><i
class="fe fe-more-vertical"></i></a>
<div class="dropdown-menu dropdown-menu-right" x-placement="bottom-end"
style="position: absolute; transform: translate3d(-181px, 20px, 0px); top: 0px; left: 0px; will-change: transform;">
{% for action in actions %}
<a {{ action.tooltip | raw }} {{ action.attrs | raw }} class="dropdown-item">
<i class="dropdown-icon fa fa-{{ action.icon }}"></i> {{ action.label }}
</a>
{% endfor %}
</div>
</div>

Loading…
Cancel
Save