This repository has been archived by the owner on Jan 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
vendors.jsx
87 lines (75 loc) · 1.95 KB
/
vendors.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
"use strict"
const {Base,React} = require('./base')
const Vendor = require('./vendor')
const {vendorActions, vendorStore} = require('../alt/Vendor')
const {Grid,Row,Col,Well, Panel, ListGroup, ListGroupItem, Button, Glyphicon}= require('react-bootstrap')
class Vendors extends Base{
constructor(props){
super(props)
this.state = {
error: '',
vendors: [],
vendor: {}
}
}
componentDidMount(){
vendorStore.listen(this.onChange)
vendorActions.fetch()
}
componentWillUnmount(){
vendorStore.unlisten(this.onChange)
}
onChange(vendors){
this.setState(vendors)
}
showError(res){
this.setState({
error: res.responseText
})
}
render(){
let header
if(this.state.vendor_action == 'new'){
header = `New Vendor`
}else{
header = `Edit Vendor ${this.state.vendor.name}`
}
return(
<div>
<p>{this.state.error}</p>
<Grid fluid>
<Row>
<Col sm={4} md={2}>
<ListGroup>
<ListGroupItem header="Vendors"><Button bsStyle="info" onClick={this.showNew.bind(this)} bsSize="xsmall"><Glyphicon glyph="plus" />add new</Button></ListGroupItem>
{this.state.vendors.map( (vendor,index) => {
return <ListGroupItem key={index} onClick={vendorActions.edit.bind(this, index)}>{vendor.name}</ListGroupItem>
})}
</ListGroup>
</Col>
<Col sm={8} md={8}>
<Panel header={header}>
<Vendor action={this.state.vendor_action}
data={this.state.vendor}
/>
</Panel>
</Col>
</Row>
</Grid>
</div>
)
}
showNew(){
this.setState({
vendor_action: 'new',
vendor: {}
})
}
editVendor(index){
this.setState({
vendor_action: 'edit',
vendor: this.state.vendors[index]
})
}
}
module.exports = Vendors