|
| 1 | +import React from 'react'; |
| 2 | +import { Link } from 'react-router-dom'; |
| 3 | +import messages from 'lib/text'; |
| 4 | +import GroupSelect from 'modules/customerGroups/select'; |
| 5 | +import DeleteConfirmation from 'modules/shared/deleteConfirmation'; |
| 6 | +import FontIcon from 'material-ui/FontIcon'; |
| 7 | +import IconMenu from 'material-ui/IconMenu'; |
| 8 | +import IconButton from 'material-ui/IconButton'; |
| 9 | +import MenuItem from 'material-ui/MenuItem'; |
| 10 | +import Dialog from 'material-ui/Dialog'; |
| 11 | +import FlatButton from 'material-ui/FlatButton'; |
| 12 | +import RaisedButton from 'material-ui/RaisedButton'; |
| 13 | +import TextField from 'material-ui/TextField'; |
| 14 | +import Search from './search'; |
| 15 | + |
| 16 | +export default class Buttons extends React.Component { |
| 17 | + constructor(props) { |
| 18 | + super(props); |
| 19 | + this.state = { |
| 20 | + groupId: null, |
| 21 | + openSetGroup: false, |
| 22 | + openDelete: false |
| 23 | + }; |
| 24 | + } |
| 25 | + |
| 26 | + showSetGroup = () => { |
| 27 | + this.setState({ openSetGroup: true }); |
| 28 | + }; |
| 29 | + |
| 30 | + showDelete = () => { |
| 31 | + this.setState({ openDelete: true }); |
| 32 | + }; |
| 33 | + |
| 34 | + closeSetGroup = () => { |
| 35 | + this.setState({ openSetGroup: false }); |
| 36 | + }; |
| 37 | + |
| 38 | + closeDelete = () => { |
| 39 | + this.setState({ openDelete: false }); |
| 40 | + }; |
| 41 | + |
| 42 | + deleteCustomers = () => { |
| 43 | + this.setState({ openDelete: false }); |
| 44 | + this.props.onDelete(); |
| 45 | + }; |
| 46 | + |
| 47 | + saveSetGroup = () => { |
| 48 | + this.setState({ openSetGroup: false }); |
| 49 | + this.props.onSetGroup(this.state.groupId); |
| 50 | + }; |
| 51 | + |
| 52 | + selectSetGroup = groupId => { |
| 53 | + this.setState({ groupId: groupId }); |
| 54 | + }; |
| 55 | + |
| 56 | + render() { |
| 57 | + const { search, setSearch, selectedCount, onDelete } = this.props; |
| 58 | + |
| 59 | + const actionsSetGroup = [ |
| 60 | + <FlatButton |
| 61 | + label={messages.cancel} |
| 62 | + onClick={this.closeSetGroup} |
| 63 | + style={{ marginRight: 10 }} |
| 64 | + />, |
| 65 | + <FlatButton |
| 66 | + label={messages.save} |
| 67 | + primary={true} |
| 68 | + keyboardFocused={true} |
| 69 | + onClick={this.saveSetGroup} |
| 70 | + /> |
| 71 | + ]; |
| 72 | + |
| 73 | + return ( |
| 74 | + <span> |
| 75 | + <Search value={search} setSearch={setSearch} /> |
| 76 | + {selectedCount > 0 && ( |
| 77 | + <span> |
| 78 | + <IconButton |
| 79 | + touch={true} |
| 80 | + tooltipPosition="bottom-left" |
| 81 | + tooltip={messages.actions_delete} |
| 82 | + onClick={this.showDelete} |
| 83 | + > |
| 84 | + <FontIcon color="#fff" className="material-icons"> |
| 85 | + delete |
| 86 | + </FontIcon> |
| 87 | + </IconButton> |
| 88 | + <IconButton |
| 89 | + touch={true} |
| 90 | + tooltipPosition="bottom-left" |
| 91 | + tooltip={messages.customers_setGroup} |
| 92 | + onClick={this.showSetGroup} |
| 93 | + > |
| 94 | + <FontIcon color="#fff" className="material-icons"> |
| 95 | + folder |
| 96 | + </FontIcon> |
| 97 | + </IconButton> |
| 98 | + <DeleteConfirmation |
| 99 | + open={this.state.openDelete} |
| 100 | + isSingle={false} |
| 101 | + itemsCount={selectedCount} |
| 102 | + onCancel={this.closeDelete} |
| 103 | + onDelete={this.deleteCustomers} |
| 104 | + /> |
| 105 | + <Dialog |
| 106 | + title={messages.customers_setGroup} |
| 107 | + actions={actionsSetGroup} |
| 108 | + modal={false} |
| 109 | + open={this.state.openSetGroup} |
| 110 | + onRequestClose={this.closeSetGroup} |
| 111 | + autoScrollBodyContent={true} |
| 112 | + > |
| 113 | + <GroupSelect |
| 114 | + onSelect={this.selectSetGroup} |
| 115 | + selectedId={this.state.groupId} |
| 116 | + showRoot={true} |
| 117 | + showAll={false} |
| 118 | + /> |
| 119 | + </Dialog> |
| 120 | + </span> |
| 121 | + )} |
| 122 | + </span> |
| 123 | + ); |
| 124 | + } |
| 125 | +} |
0 commit comments