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

71 lines
2.0 KiB
CoffeeScript

context = window
ptrCount = 0
@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, ptr: ptrCount++}
registerVU: (mixer) ->
return if @state.registered? || !mixer?
$root = $(this.getDOMNode())
context.JK.VuHelpers.registerVU('single', mixer, @state.ptr, @props.orientation == 'horizontal', @props.lightCount, $root.find('td'))
@setState(registered: {mixer: mixer, ptr: @state.ptr})
componentWillReceiveProps: (nextProps) ->
@registerVU(nextProps.mixers?.vuMixer)
componentDidMount: () ->
@registerVU(@props.mixers?.vuMixer)
componentWillUnmount: () ->
if @state.registered?
context.JK.VuHelpers.unregisterVU(@state.registered.mixer, @state.registered.ptr)
})