define('application/formatters/menuitem', [
'rofl/widgets/container',
'antie/formatter',
'antie/iterator',
'antie/runtimecontext',
'rofl/widgets/label',
'application/widgets/menu/item'
], function (
Container,
Formatter,
Iterator,
RuntimeContext,
Label,
MenuButton
) {
'use strict';
var menuItemClass = 'menu-item',
menuIconClass = 'menu-icon',
menuLabelClass = 'menu-label',
rightArrowClass = 'arrow-right';
return Formatter.extend({
/**
* Formatter function for the menu items.
*
* @param {Iterator|MenuItemModel} menuItem - List or item to format.
* @returns {MenuButton} - The formatted widget.
*/
format: function (menuItem) {
var label,
widget;
if (menuItem instanceof Iterator) {
menuItem = menuItem.next();
}
widget = new MenuButton('');
widget.setMenuItem(menuItem);
widget.addClass([menuItemClass, menuItem.getAction().getRoute()]);
if (menuItem.getIcon()) {
label = new Label({ text: '', classNames: [menuIconClass, 'icon', menuItem.getIcon().toLowerCase()] });
widget.appendChildWidget(label);
}
if (menuItem.getLabel()) {
label = new Label({ text: menuItem.getLabel(), classNames: [menuLabelClass] });
widget.appendChildWidget(label);
}
if (menuItem.hasSubmenu()) {
label = new Label({ text: '', classNames: [rightArrowClass, 'icon'] });
widget.appendChildWidget(label);
}
return widget;
}
});
});