|
| 1 | +var React = require('react/addons') |
| 2 | +var CodeEditor = require('./CodeEditor') |
| 3 | +var Catalyst = require('../Mixins/Catalyst') |
| 4 | + |
| 5 | +var Select = require('react-select') |
| 6 | + |
| 7 | +// TODO: remove |
| 8 | +var options = [ |
| 9 | + { value: 'one', label: 'One' }, |
| 10 | + { value: 'two', label: 'Two' } |
| 11 | +] |
| 12 | + |
| 13 | +var LaunchModal = React.createClass({ |
| 14 | + mixins: [Catalyst.LinkedStateMixin], |
| 15 | + propTypes: { |
| 16 | + submit: React.PropTypes.func, |
| 17 | + close: React.PropTypes.func |
| 18 | + }, |
| 19 | + getInitialState: function () { |
| 20 | + return { |
| 21 | + snippet: { |
| 22 | + description: '', |
| 23 | + mode: 'javascript', |
| 24 | + content: '', |
| 25 | + callSign: '', |
| 26 | + tags: [] |
| 27 | + }, |
| 28 | + blueprint: { |
| 29 | + title: '', |
| 30 | + content: '', |
| 31 | + tags: [] |
| 32 | + }, |
| 33 | + currentTab: 'snippet' |
| 34 | + } |
| 35 | + }, |
| 36 | + handleClick: function (e) { |
| 37 | + e.stopPropagation() |
| 38 | + }, |
| 39 | + selectSnippetTab: function () { |
| 40 | + this.setState({currentTab: 'snippet'}) |
| 41 | + }, |
| 42 | + selectBlueprintTab: function () { |
| 43 | + this.setState({currentTab: 'blueprint'}) |
| 44 | + }, |
| 45 | + handleSnippetTagsChange: function (selected, all) { |
| 46 | + var snippet = this.state.snippet |
| 47 | + snippet.tags = all |
| 48 | + this.setState({snippet: snippet}) |
| 49 | + }, |
| 50 | + handleSnippetContentChange: function (e, value) { |
| 51 | + var snippet = this.state.snippet |
| 52 | + snippet.content = value |
| 53 | + this.setState({snippet: snippet}) |
| 54 | + }, |
| 55 | + handleBlueprintTagsChange: function (selected, all) { |
| 56 | + var blueprint = this.state.blueprint |
| 57 | + blueprint.tags = all |
| 58 | + this.setState({blueprint: blueprint}) |
| 59 | + }, |
| 60 | + handleBlueprintContentChange: function (e, value) { |
| 61 | + var blueprint = this.state.blueprint |
| 62 | + blueprint.content = value |
| 63 | + this.setState({blueprint: blueprint}) |
| 64 | + }, |
| 65 | + submit: function () { |
| 66 | + // this.props.submit('yolo') |
| 67 | + if (this.state.currentTab === 'snippet') { |
| 68 | + console.log(this.state.snippet) |
| 69 | + } else { |
| 70 | + console.log(this.state.blueprint) |
| 71 | + } |
| 72 | + }, |
| 73 | + render: function () { |
| 74 | + var form |
| 75 | + if (this.state.currentTab === 'snippet') { |
| 76 | + form = ( |
| 77 | + <div> |
| 78 | + <div className='form-group'> |
| 79 | + <textarea className='block-input' valueLink={this.linkState('snippet.description')} placeholder='Description'/> |
| 80 | + </div> |
| 81 | + <div className='form-group'> |
| 82 | + <input className='inline-input' valueLink={this.linkState('snippet.callSign')} type='text' placeholder='Callsign'/> |
| 83 | + <select className='inline-input' valueLink={this.linkState('snippet.mode')}> |
| 84 | + <option value='javascript'>Javascript</option> |
| 85 | + <option value='html'>HTML</option> |
| 86 | + <option value='css'>CSS</option> |
| 87 | + </select> |
| 88 | + </div> |
| 89 | + <div className='form-group'> |
| 90 | + <CodeEditor onChange={this.handleSnippetContentChange} code={this.state.snippet.content} mode={this.state.snippet.mode}/> |
| 91 | + </div> |
| 92 | + <div className='form-group'> |
| 93 | + <Select |
| 94 | + name='tags' |
| 95 | + multi={true} |
| 96 | + allowCreate={true} |
| 97 | + value={this.state.snippet.tags} |
| 98 | + placeholder='Tags...' |
| 99 | + options={options} |
| 100 | + onChange={this.handleSnippetTagsChange} |
| 101 | + /> |
| 102 | + </div> |
| 103 | + </div> |
| 104 | + ) |
| 105 | + } else { |
| 106 | + form = ( |
| 107 | + <div> |
| 108 | + <div className='form-group'> |
| 109 | + <input className='block-input' valueLink={this.linkState('blueprint.title')} placeholder='Title'/> |
| 110 | + </div> |
| 111 | + <div className='form-group'> |
| 112 | + <CodeEditor onChange={this.handleBlueprintContentChange} code={this.state.blueprint.content} mode={'markdown'}/> |
| 113 | + </div> |
| 114 | + <div className='form-group'> |
| 115 | + <Select |
| 116 | + name='tags' |
| 117 | + multi={true} |
| 118 | + allowCreate={true} |
| 119 | + value={this.state.blueprint.tags} |
| 120 | + placeholder='Tags...' |
| 121 | + options={options} |
| 122 | + onChange={this.handleBlueprintTagsChange} |
| 123 | + /> |
| 124 | + </div> |
| 125 | + </div> |
| 126 | + ) |
| 127 | + } |
| 128 | + |
| 129 | + return ( |
| 130 | + <div onClick={this.handleClick} className='modal launch-modal'> |
| 131 | + <div className='modal-body'> |
| 132 | + <div className='modal-tab form-group'> |
| 133 | + <button className={this.state.currentTab === 'snippet' ? 'btn-primary active' : 'btn-default'} onClick={this.selectSnippetTab}>Snippet</button> <button className={this.state.currentTab === 'blueprint' ? 'btn-primary active' : 'btn-default'} onClick={this.selectBlueprintTab}>Blueprint</button> |
| 134 | + </div> |
| 135 | + {form} |
| 136 | + </div> |
| 137 | + <div className='modal-footer'> |
| 138 | + <div className='modal-control'> |
| 139 | + <button onClick={this.props.close} className='btn-default'>Cancle</button> |
| 140 | + <button onClick={this.submit} className='btn-primary'>Launch</button> |
| 141 | + </div> |
| 142 | + </div> |
| 143 | + </div> |
| 144 | + ) |
| 145 | + } |
| 146 | +}) |
| 147 | + |
| 148 | +module.exports = LaunchModal |
0 commit comments