var Info = React.createClass({
    mixins: [FormMixin],
    getInitialState() {
        return {
            name: '',
            phase: 'open',
            applicationID: '',
            value: ''
        }
    },
    getName() {
        return this.props.obj==='launch'
             ? {
                   name: TRIM(this.state.name),
                   phase: this.state.phase,
                   applicationID: TRIM(this.state.applicationID)
               }
             : TRIM(this.state.name);
    },
    handleSubmit(e) {
        api.info(this.props.obj==='launch' ? 'domain' : this.props.obj, this.getName(), function(code, data) {
            switch(code) {
            case '2501':
                logout();
                break;
            default:
                this.setState({value: data});
            }
        }.bind(this));
    },
    render() {
        switch(this.props.obj) {
        case 'domain':
        case 'host':
        case 'contact':
            return (
                <div>
                <table align="center" border="0" className="formtable">
                <tbody>
                  <tr>
                    <td align="center">{this.props.children}</td>
                  </tr>
                  <tr>
                    <td>
                      <input {...this.linkState({
                          name: 'name',
                          type: 'text',
                          size: '40',
                          onFocus: this.onSetState({name:'', value:''})
                      })}/>
                    </td>
                  </tr>
                  <tr>
                    <td align="center">
                      <input type="button" value="提交" onClick={this.handleSubmit}/>
                    </td>
                  </tr>
                </tbody>
                </table>
                <OpResult content={this.state.value} />
                </div>
            );
        case 'launch':
            return (
                <div>
                <table className="formtable" border="0" align="center">
                <tbody>
                  <tr>
                    <td align="center" colSpan="2">{this.props.children}</td>
                  </tr>
                  <tr>
                    <td>域名:</td>
                    <td>
                      <input {...this.linkState({
                          name: 'name',
                          type: 'text',
                          size: '40',
                          onFocus: this.onSetState({name:'', value:''})
                      })}/>
                    </td>
                  </tr>
                  <tr>
                    <td>phase:</td>
                    <td><LaunchPhase {...this.linkState({name: 'phase'})}/></td>
                  </tr>
                  <tr>
                    <td>applicationID:</td>
                    <td>
                      <input {...this.linkState({
                          name: 'applicationID',
                          type: 'text',
                          size: '21',
                          onFocus: this.onSetState({applicationID:'', value:''})
                      })}/>
                    </td>
                  </tr>
                  <tr>
                    <td align="center" colSpan="2">
                      <input type="button" value="提交" onClick={this.handleSubmit}/>
                    </td>
                  </tr>
                </tbody>
                </table>
                <OpResult content={this.state.value} />
                </div>
            );
        }
    }
});
