var cloudflare = require('../cloudflare'); var React = require('react'); var CloudActive = React.createClass({ render: function() { var record = this.props.record; if(record.type === 'A' || record.type === 'AAAA' || record.type === 'CNAME') { var active = record.service_mode === '1'; if(active) { return } else { return } } else { return ; } } }); var RecordCreate = React.createClass({ getInitialState: function() { return {saving: false}; }, types: ['A', 'AAAA', 'CNAME'], finishSave: function(promise) { promise.then(this.props.onEdit).then(function() { this.setState({saving: false}); this.reset(); }.bind(this)); }, reset: function() { this.refs.type.getDOMNode().value = this.types[0]; this.refs.name.getDOMNode().value = ""; this.refs.value.getDOMNode().value = ""; }, commitAdd: function() { this.setState({saving: true}); var newRecord = { type: this.refs.type.getDOMNode().value, name: this.refs.name.getDOMNode().value.trim(), content: this.refs.value.getDOMNode().value.trim() }; this.finishSave(cloudflare.record_add(this.props.domain, newRecord)); }, render: function() { var className = this.state.saving ? 'saving' : ''; var options = this.types.map(function(type) { return }); return ( ) } }); var Record = React.createClass({ getInitialState: function() { return {state: 'view', saving: false}; }, setDeleting: function() { this.setState({state: 'delete'}); }, setEditing: function() { this.setState({state: 'edit'}); }, cancelEdit: function() { this.setState({state: 'view'}); }, finishSave: function(promise) { promise.then(this.props.onEdit).then(function() { this.setState({state: 'view', saving: false}); }.bind(this)); }, commitDelete: function() { this.setState({saving: true}); var record = this.props.record; this.finishSave(cloudflare.record_delete(record.zone_name, record.rec_id)); }, commitEdit: function() { this.setState({saving: true}); var record = this.props.record; var newRecord = { id: record.rec_id, type: record.type, name: this.refs.name.getDOMNode().value.trim(), content: this.refs.value.getDOMNode().value.trim() }; if(record.service_mode) { newRecord.service_mode = record.service_mode; } this.finishSave(cloudflare.record_edit(record.zone_name, newRecord)); }, toggleProxy: function() { this.setState({saving: true}); var record = this.props.record; var newRecord = { id: record.rec_id, type: record.type, name: record.name, content: record.content, service_mode: record.service_mode === "1" ? "0" : "1" }; this.finishSave(cloudflare.record_edit(record.zone_name, newRecord)); }, render: function() { var record = this.props.record; var className = this.state.saving ? 'saving' : ''; if(this.state.state === 'edit') { return ( {record.type} Cancel ); } else if(this.state.state === 'delete') { return ( {record.type} {record.display_name} {record.display_content} Cancel ); } else { return ( {record.type} {record.display_name} {record.display_content} ); } } }); var RecordList = React.createClass({ getInitialState: function() { return {records: []}; }, componentDidMount: function() { this.reload(); }, componentWillReceiveProps: function(nextProps) { if(nextProps.domain != this.props.domain) { this.setState({records: []}); this.reload(nextProps); } }, reload: function(props) { if(!props) { props = this.props; } return cloudflare.records(props.domain).then(function(data) { this.setState({records: data.response.recs.objs}); }.bind(this)); }, render: function() { var records = this.state.records.map(function(record) { return }.bind(this)); return (
{records}
Type Name Value Proxy Actions
); } }); module.exports = RecordList;