-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFormReOrderView.jsx
79 lines (57 loc) · 1.9 KB
/
FormReOrderView.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
import React from 'react';
import {Modal,Button} from 'react-bootstrap';
import update from 'immutability-helper';
import TruncatedLabel from '../customcomponents/TruncatedLabel.jsx'
import {SortableContainer, SortableElement , arrayMove} from 'react-sortable-hoc'
const SortableItem = SortableElement(({value}) => <div className="SortableItem">{value}</div>);
const SortableList = SortableContainer(({items}) => {
return (
<ul className="SortableList">
{items.map(({fieldId,fieldName}, index) =>
<SortableItem key={`item-${index}`} index={index} value={fieldName} style = {{zIndex: 10000}}/>
)}
</ul>
);
});
class FormReOrderView extends React.Component {
constructor(props)
{
super(props);
this.state = ({showModal:false,formElements:[]})
}
showListOrder(formElements = [])
{
this.setState({formElements:formElements,showModal:true})
}
close()
{
this.setState({ showModal: false });
}
onSortEnd(indexMapper)
{
this.setState({
formElements: arrayMove(this.state.formElements, indexMapper.oldIndex, indexMapper.newIndex)
});
this.props.updateSorting(this.state.formElements)
};
render (){
return (
<Modal show={this.state.showModal} onHide={this.close.bind(this)} bsSize="small" aria-labelledby="contained-modal-title-sm">
<Modal.Header closeButton>
<Modal.Title>Form Re-Order</Modal.Title>
</Modal.Header>
<Modal.Body>
<SortableList items={this.state.formElements} helperClass="SortableHelper"
onSortEnd={this.onSortEnd.bind(this)} />
</Modal.Body>
<Modal.Footer>
<Button onClick={this.close.bind(this)}>Close</Button>
</Modal.Footer>
</Modal>
)
}
}
FormReOrderView.propTypes = {
updateSorting:React.PropTypes.func
}
export default FormReOrderView