Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Not able to set correct active link in admin menu #5349

Open
Jimmi08 opened this issue Oct 8, 2024 · 2 comments
Open

[Bug]: Not able to set correct active link in admin menu #5349

Jimmi08 opened this issue Oct 8, 2024 · 2 comments
Labels
type: bug A problem that should not be happening

Comments

@Jimmi08
Copy link
Contributor

Jimmi08 commented Oct 8, 2024

What e107 version are you using?

v2.3.3, Latest Github version (just updated)

Bug description

I am changing admin menu dynamically. Standart way with function init().

Admin UI works normally, if you check getAction() in class xy_ui extends e_admin_ui , it is correct.

Only problem is that not correct menu is marked as active.

After checking some request values and action values, they are not set correctly when admin menu is rendered.

action is always list

How to reproduce

This is classic menu settings:

	protected $adminMenu = array(
		//'main/prefs'		=> array('caption' => LAN_PREFS, 'perm' => 'P'),
		'main/list'			=> array('caption' => LAN_MANAGE,   'perm' => 'P'),
		'main/create'		=> array('caption' => _ADDNEWPANEL, 'perm' => 'P'), 
		'main/div0'      => array('divider' => true),
		//  'main/help'		=> array('caption'=> 'Help Page', 'perm' => 'P'),
	);

Then dynamically are menus added:

function init()
	{
		$panelTypes = e107::getEfiction()->getPanelTypes();

		foreach ($panelTypes as $key => $value)
		{
			$mode = "main";
			$action =  $key;

			$menu = $mode . '/' . $action;
			$this->adminMenu[$menu] = array(
				'caption' => $value,
				'perm' => 'P'
			);
		}

		$this->adminMenu['main/div1'] = array('divider' => true);

		$this->adminMenu['main/help'] = array(
			'caption' => 'Help Page',
			'perm' => 'P'
		);
	}

Active works for list, create and help items.

getAction() returns "list" for them (in renderMenu() in admin_ui class) where selected is set

but in class xy_ui extends e_admin_ui
getAction() returns the correct action and I am able to manipulate listQry() correctly.

I tried to use __construct() instead init(), but then menu items are not displayed at all.

Thanks for help

Expected behavior

Respect action parameter correctly

What browser(s) are you seeing the problem on?

Firefox

PHP Version

8.1

@Jimmi08 Jimmi08 added the type: bug A problem that should not be happening label Oct 8, 2024
@Jimmi08
Copy link
Contributor Author

Jimmi08 commented Oct 8, 2024

If you add Page methods , active works but admin UI Not (of course)

	public function APage()
	{
	}

	public function PPage() {

	}

_preDispatch() in admin_ui() is looking for a method for each action and if it is doesn't exist it sets it as the default

@Jimmi08
Copy link
Contributor Author

Jimmi08 commented Oct 8, 2024

This fixed it on localhost

$code = " 
$(document).ready(function() {
    var currentUrl = window.location.href;
    $('#admin-ui-nav-menu li').each(function() {
        var link = $(this).find('a').attr('href');
        if (link === currentUrl) {
            $('#admin-ui-nav-menu li').removeClass('active');
            $(this).addClass('active');
        }
    });
});
";

e107::js('footer-inline', $code);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A problem that should not be happening
Projects
None yet
Development

No branches or pull requests

1 participant