Browse Source

small refactor in ActionBar

experimental
Paweł Jedwabny 4 years ago
parent
commit
4e904f3d60
1 changed files with 93 additions and 91 deletions
  1. +93
    -91
      modules/Base/ActionBar/ActionBar_0.php

+ 93
- 91
modules/Base/ActionBar/ActionBar_0.php View File

@@ -11,6 +11,9 @@
* @package epesi-base
* @subpackage actionbar
*/

use Underscore\Types\Arrays;

defined("_VALID_ACCESS") || die('Direct access forbidden');

class Base_ActionBar extends Module
@@ -56,23 +59,25 @@ class Base_ActionBar extends Module
//sort
usort($icons, array($this, 'compare'));

//translate
foreach ($icons as &$i) {
$description = $i['description'];
if ($i['description'])
$t = Utils_TooltipCommon::open_tag_attrs($description);
else
$t = '';
$fa = array_key_exists('fa-' . $i['icon'], $fa_icons);
$i['open'] = '<a ' . $i['action'] . ' ' . $t . ' class="icon-' . ($fa ? $i['icon'] : md5($i['icon'])) . '">';
$i['close'] = '</a>';
if (!$fa && strpos($i['icon'], '/') !== false && file_exists($i['icon'])) {
$i['icon_url'] = $i['icon'];
unset($i['icon']);
//add open and close tags
$icons = array_map(function ($item) use ($fa_icons) {
$tooltip_tag = $item['description'] ? Utils_TooltipCommon::open_tag_attrs($item['description']) : '';
$fa_icon_exists = array_key_exists("fa-{$item['icon']}", $fa_icons);
$class = $fa_icon_exists ? $item['icon'] : md5($item['icon']);
$item['open'] = "<a {$item['action']} {$tooltip_tag} class='icon-{$class}'>";
$item['close'] = '</a>';
return $item;
}, $icons);

//translate icon
$icons = array_map(function ($item) use ($fa_icons) {
$fa_icon_exists = array_key_exists("fa-{$item['icon']}", $fa_icons);
if (!$fa_icon_exists && strpos($item['icon'], '/') !== false && file_exists($item['icon'])) {
$item['icon_url'] = $item['icon'];
unset($item['icon']);
}
//if (isset(Base_ActionBarCommon::$available_icons[$i['icon']]))
// $i['icon'] = Base_ThemeCommon::get_template_file('Base_ActionBar','icons/'.$i['icon'].'.png');
}
return $item;
}, $icons);

$launcher_left = [];

@@ -86,86 +91,83 @@ class Base_ActionBar extends Module
);

$launcher_right = [];
if (Base_AclCommon::is_user()) {
$opts = Base_Menu_QuickAccessCommon::get_options();
if (!empty($opts)) {
self::$launchpad = array();
foreach ($opts as $k => $v) {
if (Base_ActionBarCommon::$quick_access_shortcuts
&& Base_User_SettingsCommon::get(Base_Menu_QuickAccessCommon::module_name(), $v['name'] . '_d')
) {
$ii = array();
$trimmed_label = trim(substr(strrchr($v['label'], ':'), 1));
$ii['label'] = $trimmed_label ? $trimmed_label : $v['label'];
$ii['description'] = $v['label'];
$arr = $v['link'];
$icon = null;
$icon_url = null;
if (isset($v['link']['__icon__'])) {
if (array_key_exists('fa-' . $v['link']['__icon__'], $fa_icons))
$icon = $v['link']['__icon__'];
else
$icon_url = Base_ThemeCommon::get_template_file($v['module'], $v['link']['__icon__']);
} else
$icon_url = Base_ThemeCommon::get_template_file($v['module'], 'icon.png');
if (!$icon && !$icon_url) $icon_url = 'cog';
$ii['icon'] = $icon;
$ii['icon_url'] = $icon_url;

if (isset($arr['__url__']))
$ii['open'] = '<a href="' . $arr['__url__'] . '" target="_blank" class="icon-' . ($icon ? $icon : md5($icon_url)) . '">';
if (Base_AclCommon::is_user() && $opts = Base_Menu_QuickAccessCommon::get_options()) {
self::$launchpad = array();
foreach ($opts as $k => $v) {
if (Base_ActionBarCommon::$quick_access_shortcuts
&& Base_User_SettingsCommon::get(Base_Menu_QuickAccessCommon::module_name(), $v['name'] . '_d')
) {
$ii = array();
$trimmed_label = trim(substr(strrchr($v['label'], ':'), 1));
$ii['label'] = $trimmed_label ? $trimmed_label : $v['label'];
$ii['description'] = $v['label'];
$arr = $v['link'];
$icon = null;
$icon_url = null;
if (isset($v['link']['__icon__'])) {
if (array_key_exists('fa-' . $v['link']['__icon__'], $fa_icons))
$icon = $v['link']['__icon__'];
else
$ii['open'] = '<a ' . Base_MenuCommon::create_href($this, $arr) . ' class="icon-' . ($icon ? $icon : md5($icon_url)) . '">';
$ii['close'] = '</a>';

if ($ii['label'] == 'Launchpad') {
$launcher_left[] = $ii;
} else {
$launcher_right[] = $ii;
}
$icon_url = Base_ThemeCommon::get_template_file($v['module'], $v['link']['__icon__']);
} else
$icon_url = Base_ThemeCommon::get_template_file($v['module'], 'icon.png');
if (!$icon && !$icon_url) $icon_url = 'cog';
$ii['icon'] = $icon;
$ii['icon_url'] = $icon_url;

if (isset($arr['__url__']))
$ii['open'] = '<a href="' . $arr['__url__'] . '" target="_blank" class="icon-' . ($icon ? $icon : md5($icon_url)) . '">';
else
$ii['open'] = '<a ' . Base_MenuCommon::create_href($this, $arr) . ' class="icon-' . ($icon ? $icon : md5($icon_url)) . '">';
$ii['close'] = '</a>';

if ($ii['label'] == 'Launchpad') {
$launcher_left[] = $ii;
} else {
$launcher_right[] = $ii;
}
if (Base_User_SettingsCommon::get(Base_Menu_QuickAccessCommon::module_name(), $v['name'] . '_l')) {
$ii = array();
$trimmed_label = trim(substr(strrchr($v['label'], ':'), 1));
$ii['label'] = $trimmed_label ? $trimmed_label : $v['label'];
$ii['description'] = $v['label'];
$arr = $v['link'];
if (isset($arr['__url__']))
$ii['open'] = '<a href="' . $arr['__url__'] . '" target="_blank" onClick="actionbar_launchpad_deactivate()">';
else {
$ii['open'] = '<a onClick="actionbar_launchpad_deactivate();' . Base_MenuCommon::create_href_js($this, $arr) . '" href="javascript:void(0)">';
}
$ii['close'] = '</a>';

$icon = null;
$icon_url = null;
if (isset($v['link']['__icon__'])) {
if (array_key_exists('fa-' . $v['link']['__icon__'], $fa_icons))
$icon = $v['link']['__icon__'];
else
$icon_url = Base_ThemeCommon::get_template_file($v['module'], $v['link']['__icon__']);
} else
$icon_url = Base_ThemeCommon::get_template_file($v['module'], 'icon.png');
if (!$icon && !$icon_url) $icon_url = 'cog';
$ii['icon'] = $icon;
$ii['icon_url'] = $icon_url;

self::$launchpad[] = $ii;
}
if (Base_User_SettingsCommon::get(Base_Menu_QuickAccessCommon::module_name(), $v['name'] . '_l')) {
$ii = array();
$trimmed_label = trim(substr(strrchr($v['label'], ':'), 1));
$ii['label'] = $trimmed_label ? $trimmed_label : $v['label'];
$ii['description'] = $v['label'];
$arr = $v['link'];
if (isset($arr['__url__']))
$ii['open'] = '<a href="' . $arr['__url__'] . '" target="_blank" onClick="actionbar_launchpad_deactivate()">';
else {
$ii['open'] = '<a onClick="actionbar_launchpad_deactivate();' . Base_MenuCommon::create_href_js($this, $arr) . '" href="javascript:void(0)">';
}
$ii['close'] = '</a>';

$icon = null;
$icon_url = null;
if (isset($v['link']['__icon__'])) {
if (array_key_exists('fa-' . $v['link']['__icon__'], $fa_icons))
$icon = $v['link']['__icon__'];
else
$icon_url = Base_ThemeCommon::get_template_file($v['module'], $v['link']['__icon__']);
} else
$icon_url = Base_ThemeCommon::get_template_file($v['module'], 'icon.png');
if (!$icon && !$icon_url) $icon_url = 'cog';
$ii['icon'] = $icon;
$ii['icon_url'] = $icon_url;

self::$launchpad[] = $ii;
}
}
usort(self::$launchpad, array($this, 'compare_launcher'));
if (!empty(self::$launchpad)) {
$th = $this->pack_module(Base_Theme::module_name());
usort(self::$launchpad, array($this, 'compare_launcher'));
if (!empty(self::$launchpad)) {
$th = $this->pack_module(Base_Theme::module_name());
usort(self::$launchpad, array($this, 'compare_launcher'));
$th->assign('icons', self::$launchpad);
eval_js_once('actionbar_launchpad_deactivate = function(){leightbox_deactivate(\'actionbar_launchpad\');}');
ob_start();
$th->display('launchpad');
$lp_out = ob_get_clean();
$big = count(self::$launchpad) > 10;
Libs_LeightboxCommon::display('actionbar_launchpad', $lp_out, __('Launchpad'), $big);
array_unshift($launcher_left, array('label' => __('Launchpad'), 'description' => 'Quick modules launcher', 'open' => '<a ' . Libs_LeightboxCommon::get_open_href('actionbar_launchpad') . '>', 'close' => '</a>', 'icon' => 'th-large'));
}
$th->assign('icons', self::$launchpad);
eval_js_once('actionbar_launchpad_deactivate = function(){leightbox_deactivate(\'actionbar_launchpad\');}');
ob_start();
$th->display('launchpad');
$lp_out = ob_get_clean();
$big = count(self::$launchpad) > 10;
Libs_LeightboxCommon::display('actionbar_launchpad', $lp_out, __('Launchpad'), $big);
array_unshift($launcher_left, array('label' => __('Launchpad'), 'description' => 'Quick modules launcher', 'open' => '<a ' . Libs_LeightboxCommon::get_open_href('actionbar_launchpad') . '>', 'close' => '</a>', 'icon' => 'th-large'));
}
}



Loading…
Cancel
Save