This repository has been archived by the owner on Apr 23, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
react-redux-collectionContainer.jsx
97 lines (92 loc) · 3.45 KB
/
react-redux-collectionContainer.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
88
89
90
91
92
93
94
95
96
97
import React from "react";
import { connect } from 'react-redux';
import Dragggable from 'react-draggable';
import { Row, Col, Input} from "react-bootstrap";
const Collection = React.createClass({
maybeInsertMediaElements: function (index, coverImageUrl) {
if (index == "1") {
return (
<div className="row" style={{padding: "7px"}}>
<Col xsOffset={1}>
<Input standalone
type="text"
label="Image URL"
labelClassName="col-xs-2"
defaultValue={coverImageUrl}
wrapperClassName="col-xs-3" />
<Input standalone
type="text"
label="Vimeo ID"
labelClassName="col-xs-2"
wrapperClassName="col-xs-2" />
</Col>
</div>
)
}
return null
},
percolateUntil: function (el, targetClassName) {
if (el.classList.contains(targetClassName))
return el
else
return this.percolateUntil(el.parentElement, targetClassName)
},
calculatePlacement: function (el) {
var elements = document.getElementsByClassName('react-draggable')
Object.keys(elements).map( function (key) {
var el = elements[key]
console.log('clientTop ', el.clientTop)
console.log('bound client ', el.getBoundingClientRect().top)
} )
},
getPlacement: function(draggableElem) {
const labelElem = draggableElem.firstChild.children[1].firstChild;
const placement = parseInt(labelElem.getAttribute('data-placement'));
return placement
},
handleStart: function (event, ui) {
console.log('>->->->->->->->->->>');
const draggableElem = this.percolateUntil(event.target, 'react-draggable')
const placement = this.getPlacement(draggableElem)
console.log('Event: ', event);
console.log('Position: ', ui.position);
this.startPlacement = placement
},
handleStop: function (event, ui) {
console.log('--------------------');
const draggableElem = this.percolateUntil(event.target, 'react-draggable')
const placement = this.getPlacement(draggableElem)
console.log('Event: ', event);
console.log('Position: ', ui.position);
this.stopPlacement = placement
if (this.startPlacement !== this.stopPlacement)
this.props.swapCollections(this.props.env, this.startPlacement, this.stopPlacement)
},
render: function() {
const index = parseInt(this.props.index);
const placement = index + 1;
const collection = this.props.collection.collection;
const coverImageUrl = collection ? collection.coverImageUrl : "";
const collectionId = collection ? collection.collectionId : "";
const collectionTitle = this.props.collection.longTitle || "";
const highlightStyle = {
backgroundColor: placement % 2 === 0 ? "#00000" : "#f6f6f6"
};
return (
<Dragggable
axis="y"
onStart={this.handleStart}
zIndex={-1}
onStop={this.handleStop} >
<div className="row" style={highlightStyle} >
<div className="row" style={{padding: "7px"}}>
<Input standalone type="text" data-placement={placement} label={"Placement " + placement} labelClassName="col-xs-2" wrapperClassName="col-xs-3" defaultValue={collectionId}/>
<Input standalone type="text" wrapperClassName="col-xs-6" defaultValue={collectionTitle}/>
</div>
{this.maybeInsertMediaElements(placement, coverImageUrl)}
</div>
</Dragggable>
);
}
});
export default Collection;