/* * Copyright 2007-2017 Charles du Jeu - Abstrium SAS * This file is part of Pydio. * * Pydio is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Pydio is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with Pydio. If not, see . * * The latest code can be found at . */ const {Divider, Menu, MenuItem, FontIcon} = require('material-ui') function pydioActionsToItems(actions = []){ let items = []; let lastIsSeparator = false; actions.map(function(action, index){ if(action.separator) { if(lastIsSeparator) return; items.push(action); lastIsSeparator = true; return; } lastIsSeparator = false; const label = action.raw_name?action.raw_name:action.name; const iconClass = action.icon_class; let payload; if(action.subMenu){ const subItems = action.subMenuBeforeShow ? pydioActionsToItems(action.subMenuBeforeShow()) : action.subMenu; items.push({ text: label, iconClassName:iconClass, subItems: subItems }); }else{ items.push({ text: label, iconClassName:iconClass, payload: action.callback }); } }.bind(this)); if(lastIsSeparator){ items = items.slice(0, items.length - 1); } if(items.length && items[0] && items[0].separator){ items.shift(); } return items; } function itemsToMenu(items, closeMenuCallback, subItemsOnly = false, menuProps = {}){ menuProps = { display:'normal', width: 216, desktop: true, autoWidth: false, ...menuProps }; const menuItems = items.map((item, index) => { if(item.separator) return ; let subItems, payload; if(item.subItems){ subItems = itemsToMenu(item.subItems, closeMenuCallback, true); }else if(item.payload){ payload = () => { item.payload(); closeMenuCallback(); }; } let leftIcon, rightIcon; let {iconClassName} = item, inset = false; if(iconClassName === '__INSET__'){ iconClassName = ''; inset = true; } if(menuProps.display === 'normal'){ leftIcon = iconClassName ? : null; }else if(menuProps.display === 'right'){ rightIcon = iconClassName ? : null; } rightIcon = subItems && subItems.length ? : rightIcon; return ( ); }); if(subItemsOnly) { return menuItems; } else { return {menuItems} } } export default {pydioActionsToItems, itemsToMenu}