|
| 1 | +var React = require('react/addons') |
| 2 | +var Select = require('react-select') |
| 3 | +var Catalyst = require('../Mixins/Catalyst') |
| 4 | + |
| 5 | +module.exports = React.createClass({ |
| 6 | + mixins: [Catalyst.LinkedStateMixin], |
| 7 | + propTypes: { |
| 8 | + close: React.PropTypes.func, |
| 9 | + currentPlanet: React.PropTypes.object |
| 10 | + }, |
| 11 | + getInitialState: function () { |
| 12 | + return { |
| 13 | + currentTab: 'planetProfile', |
| 14 | + planetName: this.props.currentPlanet.name, |
| 15 | + isDeletePlanetChecked: false |
| 16 | + } |
| 17 | + }, |
| 18 | + activePlanetProfile: function () { |
| 19 | + this.setState({currentTab: 'planetProfile'}) |
| 20 | + |
| 21 | + }, |
| 22 | + activeManageMember: function () { |
| 23 | + this.setState({currentTab: 'manageMember'}) |
| 24 | + }, |
| 25 | + doubleCheckDeletePlanet: function () { |
| 26 | + if (this.state.isDeletePlanetChecked) { |
| 27 | + console.log('delete it') |
| 28 | + return |
| 29 | + } |
| 30 | + this.setState({isDeletePlanetChecked: true}) |
| 31 | + React.findDOMNode(this.refs.deleteCancelButton).focus() |
| 32 | + }, |
| 33 | + cancelDeletePlanet: function () { |
| 34 | + this.setState({isDeletePlanetChecked: false}) |
| 35 | + }, |
| 36 | + interceptClick: function (e) { |
| 37 | + e.stopPropagation() |
| 38 | + }, |
| 39 | + render: function () { |
| 40 | + var content |
| 41 | + if (this.state.currentTab === 'planetProfile') { |
| 42 | + content = ( |
| 43 | + <div className='planetProfile'> |
| 44 | + <div className='planetProfileForm'> |
| 45 | + <label>Planet name </label> |
| 46 | + <input valueLink={this.linkState('planetName')} className='inline-input'/> |
| 47 | + <button className='saveButton btn-primary'>Save</button> |
| 48 | + </div> |
| 49 | + |
| 50 | + <div className='planetDeleteForm'> |
| 51 | + <div className='planetDeleteControl'> |
| 52 | + <div className={'toggle' + (this.state.isDeletePlanetChecked ? '' : ' hide')}> |
| 53 | + <div className='planetDeleteLabel'>Are you sure to delete this planet?</div> |
| 54 | + <button ref='deleteCancelButton' onClick={this.cancelDeletePlanet} className='cancelButton btn-default'>Cancel</button> |
| 55 | + </div> |
| 56 | + <button onClick={this.doubleCheckDeletePlanet} className='deleteButton btn-primary'>{!this.state.isDeletePlanetChecked ? 'Delete Planet' : 'Confirm'}</button> |
| 57 | + </div> |
| 58 | + </div> |
| 59 | + </div> |
| 60 | + ) |
| 61 | + } else { |
| 62 | + var members = this.props.currentPlanet.Users.map(function (user) { |
| 63 | + return ( |
| 64 | + <li key={'user-' + user.id}> |
| 65 | + <img className='userPhoto' width='44' height='44' src='../vendor/dummy.jpg'/> |
| 66 | + <div className='userName'>{user.name}</div> |
| 67 | + <div className='userControl'> |
| 68 | + {this.props.currentPlanet.OwnerId !== user.id ? <button className='btn-default'>Delete</button> : <span className='ownerLabel'>Owner</span>} |
| 69 | + </div> |
| 70 | + </li> |
| 71 | + ) |
| 72 | + }.bind(this)) |
| 73 | + |
| 74 | + content = ( |
| 75 | + <div className='manageMember'> |
| 76 | + <ul className='userList'> |
| 77 | + {members} |
| 78 | + </ul> |
| 79 | + <div className='addUserForm'> |
| 80 | + <div className='addUserLabel'>Invite user</div> |
| 81 | + <div className='addUserControl'> |
| 82 | + <Select className='addUserSelect'/> |
| 83 | + <button className='addUserSubmit btn-primary'>Invite</button> |
| 84 | + </div> |
| 85 | + </div> |
| 86 | + </div> |
| 87 | + ) |
| 88 | + } |
| 89 | + |
| 90 | + return ( |
| 91 | + <div onClick={this.interceptClick} className='PlanetSettingModal modal'> |
| 92 | + <div className='settingNav'> |
| 93 | + <h1>Planet setting</h1> |
| 94 | + <nav> |
| 95 | + <button className={this.state.currentTab === 'planetProfile' ? 'active' : ''} onClick={this.activePlanetProfile}><i className='fa fa-globe'/> Planet profile</button> |
| 96 | + <button className={this.state.currentTab === 'manageMember' ? 'active' : ''} onClick={this.activeManageMember}><i className='fa fa-group'/> Manage member</button> |
| 97 | + </nav> |
| 98 | + </div> |
| 99 | + |
| 100 | + <div className='settingBody'> |
| 101 | + {content} |
| 102 | + </div> |
| 103 | + </div> |
| 104 | + ) |
| 105 | + } |
| 106 | +}) |
0 commit comments