/* * 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 . */ import UserAvatar from '../avatar/UserAvatar' const {IconButton, Checkbox, FlatButton, RaisedButton, ListItem, FontIcon, Avatar, Divider, Subheader, List} = require('material-ui') const {muiThemeable} = require('material-ui/styles') const {Loader, PydioContextConsumer} = require('pydio').requireLib('boot') import EmptyStateView from '../../views/EmptyStateView' import AlphaPaginator from './AlphaPaginator' import SearchForm from './SearchForm' class UsersList extends React.Component{ constructor(props, context){ super(props, context); this.state = {select: false, selection:[]}; } render(){ const {item, mode, paginatorType, loading, enableSearch, showSubheaders, getMessage} = this.props; const folders = item.collections || []; const leafs = item.leafs || []; const foldersSubHeader = folders.length && (leafs.length || showSubheaders) ? [{subheader:getMessage('532')}] : []; let usersSubHeader = []; if((showSubheaders || paginatorType) && leafs.length){ usersSubHeader = [{subheader: paginatorType ? : getMessage('249')}]; } const items = [...foldersSubHeader, ...folders, ...usersSubHeader, ...leafs]; const total = items.length; let elements = []; const toggleSelect = () => {this.setState({select:!this.state.select, selection:[]})}; const createAction = () => {this.props.onCreateAction(item)}; const deleteAction = () => {this.props.onDeleteAction(item, this.state.selection); this.setState({select: false, selection: []})}; const activeTbarColor = this.props.muiTheme.palette.accent2Color; const toolbar = (
{mode === "selector" && item._parent && {this.props.onFolderClicked(item._parent)}}/>} {mode === 'book' && total > 0 && item.actions && item.actions.multiple && }
{item.label}
{mode === 'book' && item.actions && item.actions.create && !this.state.select && } {mode === 'book' && item.actions && item.actions.remove && this.state.select && } {enableSearch && }
); // PARENT NODE if(item._parent && mode === 'book' && item._parent._parent){ elements.push( {e.stopPropagation(); this.props.onFolderClicked(item._parent)}} leftAvatar={}/>} /> ); if(total){ elements.push(); } } // ITEMS items.forEach(function(item, index){ if(item.subheader){ elements.push({item.subheader}); return; } const fontIcon = ( ); let rightIconButton; let touchTap = (e)=>{e.stopPropagation(); this.props.onItemClicked(item)}; if(folders.indexOf(item) > -1 && this.props.onFolderClicked){ touchTap = (e)=>{e.stopPropagation(); this.props.onFolderClicked(item) }; if(mode === 'selector' && !item._notSelectable){ rightIconButton = ( {this.props.onItemClicked(item)}} /> ); } }else if(mode === 'inner' && this.props.onDeleteAction){ rightIconButton = ( {this.props.onDeleteAction(this.props.item, [item])}} /> ); } const select = (e, checked) => { if(checked) { this.setState({selection: [...this.state.selection, item]}); }else { const stateSel = this.state.selection; const selection = [...stateSel.slice(0, stateSel.indexOf(item)), ...stateSel.slice(stateSel.indexOf(item)+1)]; this.setState({selection: selection}); } }; elements.push( -1} onCheck={select}/>} />); if(mode !== 'inner' && index < total - 1){ elements.push(); } }.bind(this)); let emptyState; if(!elements.length){ let emptyStateProps = { style : {backgroundColor: 'rgb(250, 250, 250)'}, iconClassName : 'mdi mdi-account-off', primaryTextId : this.props.emptyStatePrimaryText || getMessage(629), secondaryTextId : mode === 'book' ? ( this.props.emptyStateSecondaryText || null ) : null }; if(mode === 'book' && item.actions && item.actions.create){ emptyStateProps = { ...emptyStateProps, actionLabelId: getMessage(item.actions.create), actionCallback: createAction }; } emptyState = ; } return (
{mode !== 'inner' && /*(!emptyState || mode !== 'book') &&*/ !this.props.noToolbar && toolbar} {!emptyState && !loading && {this.props.subHeader && {this.props.subHeader}} {elements} } {loading && } {!loading && emptyState}
); } } UsersList.propTypes ={ item: React.PropTypes.object, onCreateAction:React.PropTypes.func, onDeleteAction:React.PropTypes.func, onItemClicked:React.PropTypes.func, onFolderClicked:React.PropTypes.func, mode:React.PropTypes.oneOf(['book', 'selector', 'inner']) }; UsersList = PydioContextConsumer(UsersList); UsersList = muiThemeable()(UsersList); export {UsersList as default}