Просмотр исходного кода

#3002 Menus badges need to be loaded asynchronously via separate AJAX call

Alex Trofimov 6 лет назад
Родитель
Сommit
102630d4f0

+ 1 - 0
inc/classes/BxDolMenu.php

@@ -54,6 +54,7 @@
  * - target: menu item target.
  * - icon: menu item icon, please note that some templates can still display menu as text without icons.
  * - addon: display additional data near menu item, only for supported menu templates, this is serialized array of service call parameters: module - module name, method - service method name, params - array of parameters.
+ * - markers: service method to provide additional replacement markers, this is serialized array of service call parameters: module - module name, method - service method name, params - array of parameters.
  * - visible_for_levels: bit field with set of member level ids. To use member level id in bit field - the level id minus 1 as power of 2 is used, for example:
  *      - user level id = 1 -> 2^(1-1) = 1
  *      - user level id = 2 -> 2^(2-1) = 2

+ 1 - 0
install/sql/system.sql

@@ -4073,6 +4073,7 @@ CREATE TABLE IF NOT EXISTS `sys_menu_items` (
   `target` varchar(255) NOT NULL,
   `icon` varchar(255) NOT NULL,
   `addon` text NOT NULL,
+  `markers` text NOT NULL,
   `submenu_object` varchar(64) NOT NULL,
   `submenu_popup` tinyint(4) NOT NULL DEFAULT '0',
   `visible_for_levels` int(11) NOT NULL DEFAULT '2147483647',

+ 4 - 4
modules/boonex/credits/install/sql/enable.sql

@@ -79,13 +79,13 @@ INSERT INTO `sys_menu_items` (`set_name`, `module`, `name`, `title_system`, `tit
 
 -- MENU: member toolbar
 SET @iMenuToolbarMenuOrder = (SELECT IFNULL(MAX(`order`), 0) FROM `sys_menu_items` WHERE `set_name`='sys_toolbar_member' LIMIT 1);
-INSERT INTO `sys_menu_items`(`set_name`, `module`, `name`, `title_system`, `title`, `link`, `onclick`, `target`, `icon`, `addon`, `submenu_object`, `submenu_popup`, `visible_for_levels`, `active`, `copyable`, `order`) VALUES 
-('sys_toolbar_member', 'bx_credits', 'credits-history', '_bx_credits_menu_item_title_system_history', '_bx_credits_menu_item_title_history', 'page.php?i=credits-history-common', '', '', '', 'a:2:{s:6:"module";s:10:"bx_credits";s:6:"method";s:26:"get_menu_item_addon_amount";}', '', 0, 2147483646, 0, 1, 0);
+INSERT INTO `sys_menu_items`(`set_name`, `module`, `name`, `title_system`, `title`, `link`, `onclick`, `target`, `icon`, `addon`, `markers`, `submenu_object`, `submenu_popup`, `visible_for_levels`, `active`, `copyable`, `order`) VALUES 
+('sys_toolbar_member', 'bx_credits', 'credits-history', '_bx_credits_menu_item_title_system_history', '_bx_credits_menu_item_title_history', 'page.php?i=credits-history-common', '', '', '', '', 'a:2:{s:6:"module";s:10:"bx_credits";s:6:"method";s:26:"get_menu_item_addon_amount";}', '', 0, 2147483646, 0, 1, 0);
 
 -- MENU: Notifications
 SET @iAccountNotificationsMenuOrder = (SELECT IFNULL(MAX(`order`), 0) FROM `sys_menu_items` WHERE `set_name` = 'sys_account_notifications' AND `order` < 9999);
-INSERT INTO `sys_menu_items` (`set_name`, `module`, `name`, `title_system`, `title`, `link`, `onclick`, `target`, `icon`, `addon`, `submenu_object`, `submenu_popup`, `visible_for_levels`, `active`, `copyable`, `order`) VALUES
-('sys_account_notifications', 'bx_credits', 'notifications-credits', '_bx_credits_menu_item_title_system_notifications', '_bx_credits_menu_item_title_notifications', 'page.php?i=credits-history-common', '', '', 'copyright col-green3', 'a:2:{s:6:"module";s:10:"bx_credits";s:6:"method";s:26:"get_menu_item_addon_amount";}', '', '0', 2147483646, 1, 1, @iAccountNotificationsMenuOrder + 1);
+INSERT INTO `sys_menu_items` (`set_name`, `module`, `name`, `title_system`, `title`, `link`, `onclick`, `target`, `icon`, `addon`, `markers`, `submenu_object`, `submenu_popup`, `visible_for_levels`, `active`, `copyable`, `order`) VALUES
+('sys_account_notifications', 'bx_credits', 'notifications-credits', '_bx_credits_menu_item_title_system_notifications', '_bx_credits_menu_item_title_notifications', 'page.php?i=credits-history-common', '', '', 'copyright col-green3', '', 'a:2:{s:6:"module";s:10:"bx_credits";s:6:"method";s:26:"get_menu_item_addon_amount";}', '', '0', 2147483646, 1, 1, @iAccountNotificationsMenuOrder + 1);
 
 -- MENU: account dashboard
 SET @iAccountDashboardMenuOrder = (SELECT IFNULL(MAX(`order`), 0) FROM `sys_menu_items` WHERE `set_name`='sys_account_dashboard' LIMIT 1);

+ 16 - 4
template/scripts/BxBaseMenu.php

@@ -156,11 +156,15 @@ class BxBaseMenu extends BxDolMenu
 
         if ($this->_bDisplayAddons) {
             $mixedAddon = $this->_getMenuAddon($a);
-            if(!is_array($mixedAddon))
+            if (!is_array($mixedAddon)) {
                 $this->addMarkers(array('addon' => $mixedAddon));
-            else
-                $this->addMarkers($mixedAddon);
+                $a = $this->_replaceMarkers($a);
+            }
+        }
 
+        $aMarkers = $this->_getMenuMarkers($a);
+        if ($aMarkers && is_array($aMarkers)) {
+            $this->addMarkers($aMarkers);
             $a = $this->_replaceMarkers($a);
         }
 
@@ -200,7 +204,7 @@ class BxBaseMenu extends BxDolMenu
             ),
         );
 
-        $aTmplVarsAddon = $this->_bDisplayAddons ? $this->_getTmplVarsAddon($mixedAddon, $a) : array();
+        $aTmplVarsAddon = $this->_bDisplayAddons ? $this->_getTmplVarsAddon($mixedAddon, $a) : array('addon' => '', 'addonf' => '');
         $a['bx_if:addon'] = array (
             'condition' => $this->_bDisplayAddons && !empty($aTmplVarsAddon['addon']),
             'content' => $aTmplVarsAddon
@@ -244,6 +248,14 @@ class BxBaseMenu extends BxDolMenu
         return BxDolService::callSerialized($aMenuItem['addon'], $this->_aMarkers);
     }
     
+    protected function _getMenuMarkers ($aMenuItem)
+    {
+        if (empty($aMenuItem['markers']))
+            return '';
+
+        return BxDolService::callSerialized($aMenuItem['markers'], $this->_aMarkers);
+    }
+
     protected function _getMenuAttrs ($aMenuItem)
     {
         $sAttrs = '';

+ 1 - 0
template/scripts/BxBaseMenuDashboardManageTools.php

@@ -16,6 +16,7 @@ class BxBaseMenuDashboardManageTools extends BxTemplMenu
     public function __construct ($aObject, $oTemplate)
     {
         parent::__construct ($aObject, $oTemplate);
+        $this->_bDisplayAddons = true;
     }
     
     protected function _getMenuIcon ($a)