piano/js/components/Channel/Board.js

76 lines
2.1 KiB
JavaScript
Raw Permalink Normal View History

2014-11-09 18:12:03 +00:00
/*jshint browser:true */
2014-11-08 17:52:36 +00:00
/*globals React, App */
(function () {
'use strict';
/**
* Modal for managing channels
*
* @prop {channels: Array} List of channels
* @prop {switch: func} Called to switch a param on given channel
* @prop {open: func} Called to open the window
* @prop {close: func} Called to close the window
2014-11-08 17:52:36 +00:00
*/
App.components.modal('Channel', {
2014-11-09 12:10:27 +00:00
displayName: 'Board',
2014-11-08 17:52:36 +00:00
mixins: [React.addons.PureRenderMixin],
propTypes: {
channels: React.PropTypes.array,
switch: React.PropTypes.func,
2014-11-08 17:52:36 +00:00
open: React.PropTypes.func,
close: React.PropTypes.func
},
getDefaultProps: function () {
return {
channels: [],
switch: function () {},
2014-11-08 17:52:36 +00:00
open: function () {},
close: function () {}
};
},
/**
* Creates a function to switch a param on given channel
*
* @param {channel: object} Channel object
*/
switch: function (channel) {
return function (param) {
this.props.switch(param, channel.id);
}.bind(this);
},
2014-11-08 17:52:36 +00:00
/**
* Render modal
*/
render: function () {
2014-11-09 12:10:27 +00:00
var title = 'Instruments', channels;
2014-11-08 17:52:36 +00:00
console.log('rendering!');
2014-11-08 17:52:36 +00:00
channels = this.props.channels.map(function (channel) {
channel.key = 'channel-' + channel.id;
channel.switch = this.switch(channel);
2014-11-08 17:52:36 +00:00
return App.components.Channel.Channel(channel);
}, this);
2014-11-08 17:52:36 +00:00
return React.DOM.form({
className: 'vex-dialog-form channels'
}, [
React.DOM.h4({
key: 'title',
className: 'main-title'
}, title),
React.DOM.ul({
key: 'channels'
}, channels)
]);
}
});
}());