webui: navigation: unique names on entity facet menu items

Fixes issue where it is not possible to define under the same parent:
  { entity: 'bar', facet: 'baz' }
  { entity: 'foo', facet: 'baz' }

Error reporting of invalid menu item names was improved.

Reviewed-By: David Kupka <dkupka@redhat.com>
Reviewed-By: Thierry Bordaz <tbordaz@redhat.com>
This commit is contained in:
Petr Vobornik 2015-04-29 17:51:02 +02:00
parent 8f60139520
commit 6a2b486e50

View File

@ -84,8 +84,17 @@ return declare([Evented],
// each item must have a name and a label // each item must have a name and a label
// FIXME: consider to move entity and facet stuff outside of this object // FIXME: consider to move entity and facet stuff outside of this object
item.name = item.name || item.facet || item.entity; if (!item.name) {
if (!name) throw 'Missing menu item property: name'; if (item.facet && item.entity) {
item.name = item.entity + '_' + item.facet;
} else {
item.name = item.facet || item.entity;
}
}
if (!item.name) {
window.console.error('Missing menu item property: \'name\'', item);
return false;
}
if (item.label) item.label = text.get(item.label); if (item.label) item.label = text.get(item.label);
if (item.title) item.title = text.get(item.title); if (item.title) item.title = text.get(item.title);
@ -101,7 +110,6 @@ return declare([Evented],
if (!facet) { if (!facet) {
return false; //quit return false; //quit
} }
item.name = facet.name;
if (!item.label) item.label = facet.label; if (!item.label) item.label = facet.label;
if (!item.title) item.title = facet.title; if (!item.title) item.title = facet.title;
} }
@ -135,7 +143,12 @@ return declare([Evented],
delete item.children; delete item.children;
// finally add the item // finally add the item
this.items.add(item); try {
this.items.add(item);
} catch(e) {
window.console.error("Unable to add menu item", item);
throw e;
}
// add children // add children
if (children) { if (children) {