jam-cloud/web/app/assets/javascripts/react-components/SessionTrackVU.js.jsx.coffee

71 lines
2.0 KiB
CoffeeScript

context = window
@SessionTrackVU = React.createClass({
render: () ->
lights = []
redSwitch = Math.round(this.props.lightCount * 0.66);
lightClass = 'vu-red-off'
if this.props.orientation == 'horizontal'
for i in [0..this.props.lightCount-1]
lightClass = if i >= redSwitch then 'vu-red-off' else 'vu-green-off'
lightClasses = classNames('vulight', 'vu' + i, lightClass)
lights.push(`<td key={i} width={this.props.lightWidth} height={this.props.lightHeight} className={lightClasses}></td>`)
tableClasses = classNames('vu', 'horizontal')
`<table className={tableClasses} data-light-count={this.props.lightCount}>
<tbody>
<tr>
{lights}
</tr>
</tbody>
</table>`
else
for i in [0..this.props.lightCount-1].reverse()
lightClass = if (i >= redSwitch) then "vu-red-off" else "vu-green-off"
lightClasses = classNames('vulight', 'vu' + i, lightClass)
lights.push(`<tr key={i}><td width={this.props.lightWidth} height={this.props.lightHeight} className={lightClasses}></td></tr>`)
tableClasses = classNames('vu', 'vertical')
`<table className={tableClasses} data-light-count={this.props.lightCount}>
<tbody>
{lights}
</tbody>
</table>`
getInitialState: () ->
{registered: null}
registerVU: (mixerId) ->
return if @state.registered? || !mixerId?
$root = $(this.getDOMNode())
context.JK.VuHelpers.registerVU('single', mixerId, @render, @props.orientation == 'horizontal', @props.lightCount, $root.find('td'))
@setState(registered: {mixerId: mixerId, ptr: @render})
componentWillReceiveProps: (nextProps) ->
@registerVU(nextProps.mixers.mixer?.id)
componentDidMount: () ->
@registerVU(@props.mixers.mixer?.id)
componentWillUnmount: () ->
console.log("UNMOUNTING")
if @state.registered?
context.JK.VuHelpers.unregisterVU(@state.registered.mixerId, @state.registered.ptr)
})