mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
webui: menu and navigation fixes
fixes: 1. When navigation is initiated from clicking and a link with hash, update of facet state causes that subsequent click on a link with hash will be ignored. Caused by a code which prevents infinite loop because of facet state update. Now hash update is done only if it was really changed. 2. registered correct handler for standalone pages 3. fix selection of menu item where the items differ only in args. Chooses the item with the most similar state to current facet. https://fedorahosted.org/freeipa/ticket/3129 Reviewed-By: Martin Kosek <mkosek@redhat.com> Reviewed-By: Tomas Babej <tbabej@redhat.com>
This commit is contained in:
parent
8d8aa60dbd
commit
392809f984
@ -379,9 +379,36 @@ define([
|
||||
items = this.menu.query({ parent: null });
|
||||
}
|
||||
|
||||
// select first
|
||||
if (items.total) {
|
||||
return items[0];
|
||||
if (items.total === 1) return items[0];
|
||||
|
||||
// select the menu item with the most similar state as the facet
|
||||
var best = items[0];
|
||||
var best_score = 0;
|
||||
var item, i, j, l, score;
|
||||
var state = facet.state;
|
||||
for (i=0, l=items.total; i<l; i++) {
|
||||
item = items[i];
|
||||
score = 0;
|
||||
if (item.pkeys && facet.get_pkeys) {
|
||||
var pkeys = facet.get_pkeys();
|
||||
for (j=0, j=item.pkeys.length; j<l; j++) {
|
||||
if (pkeys.indexOf(item.pkeys[j]) > -1) score++;
|
||||
}
|
||||
}
|
||||
if (item.args) {
|
||||
for (var name in item.args) {
|
||||
if (!item.args.hasOwnProperty(name)) continue;
|
||||
if (state[name] == item.args[name]) score++;
|
||||
}
|
||||
}
|
||||
if (score > best_score) {
|
||||
best_score = score;
|
||||
best = item;
|
||||
}
|
||||
}
|
||||
|
||||
return best;
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -66,7 +66,6 @@ define(['dojo/_base/declare',
|
||||
*/
|
||||
ignore_next: false,
|
||||
|
||||
|
||||
/**
|
||||
* Register a route-handler pair to a dojo.router
|
||||
* Handler will be run in context of this object
|
||||
@ -111,6 +110,7 @@ define(['dojo/_base/declare',
|
||||
* @param {boolean} Whether to suppress following hash change handler
|
||||
*/
|
||||
update_hash: function(hash, ignore_change) {
|
||||
if (window.location.hash === "#" + hash) return;
|
||||
this.ignore_next = !!ignore_change;
|
||||
router.go(hash);
|
||||
},
|
||||
|
@ -166,7 +166,7 @@ var routing = {
|
||||
*/
|
||||
navigate_to_facet: function(facet, options) {
|
||||
var hash = this.create_hash(facet, options);
|
||||
return this.router.navigate_to_hash(hash);
|
||||
return this.router.navigate_to_hash(hash, facet);
|
||||
},
|
||||
|
||||
update_hash: function(facet, options) {
|
||||
@ -494,7 +494,7 @@ routing.init = function(router) {
|
||||
var entity_n = new routing.EntityNavigator();
|
||||
this.add_hash_creator(generic_hc);
|
||||
this.add_hash_creator(entity_hc);
|
||||
this.add_route(this.routes, generic_rh);
|
||||
this.add_route(this.page_routes, generic_rh);
|
||||
this.add_route(this.entity_routes, entity_rh);
|
||||
this.add_navigator(generic_n);
|
||||
this.add_navigator(entity_n);
|
||||
|
Loading…
Reference in New Issue
Block a user