var DomainStore = require('../stores').Domains; var React = require('react'); var deepMerge = require('../util').deepMerge; var TextName = React.createClass({ getName: function() { return { name: this.refs.name.getDOMNode().value.trim() } }, clear: function() { this.refs.name.getDOMNode().value = ""; }, render: function() { return ( ) } }); var SRVName = React.createClass({ getName: function() { return { data: { service: this.refs.service.getDOMNode().value.trim(), proto: this.refs.proto.getDOMNode().value } } }, clear: function() { this.refs.service.getDOMNode().value = ""; this.refs.proto.getDOMNode().value = "_udp"; }, render: function() { var record = this.props.record; var data = record && record.data || {}; var protos = ['_udp', '_tcp', '_tls']; var options = protos.map(function(proto) { return }); return (
) } }); var TextValue = React.createClass({ getValue: function() { return { content: this.refs.value.getDOMNode().value.trim() } }, clear: function() { this.refs.value.getDOMNode().value = ""; }, render: function() { return ( ) } }); var MXValue = React.createClass({ getValue: function() { return { content: this.refs.value.getDOMNode().value.trim(), priority: this.refs.priority.getDOMNode().value.trim() } }, clear: function() { this.refs.value.getDOMNode().value = ""; this.refs.priority.getDOMNode().value = ""; }, render: function() { return (
) } }); var SRVValue = React.createClass({ getValue: function() { return { data: { name: this.refs.name.getDOMNode().value.trim(), priority: this.refs.priority.getDOMNode().value.trim(), weight: this.refs.weight.getDOMNode().value.trim(), port: this.refs.port.getDOMNode().value.trim(), target: this.refs.target.getDOMNode().value.trim() } } }, clear: function() { this.refs.name.getDOMNode().value = ""; this.refs.priority.getDOMNode().value = ""; this.refs.weight.getDOMNode().value = ""; this.refs.port.getDOMNode().value = ""; this.refs.target.getDOMNode().value = ""; }, render: function() { var record = this.props.record; var data = record && record.data || {}; return (
) } }); function getNameComponent(type) { switch(type) { case 'SRV': return SRVName; default: return TextName; } } function getValueComponent(type) { switch(type) { case 'MX': return MXValue; case 'SRV': return SRVValue; default: return TextValue; } } var CloudActive = React.createClass({ render: function() { var record = this.props.record; if(record.proxiable.val()) { var active = record.proxied.val(); if(active) { return } else { return } } else { return ; } } }); var RecordCreate = React.createClass({ getInitialState: function() { return {saving: false, type: 'A'}; }, types: ['A', 'AAAA', 'CNAME', 'LOC', 'MX', 'NS', 'SPF', 'SRV', 'TXT'], changeType: function(event) { this.setState({ type: event.target.value }); }, finishSave: function(promise) { promise.then(function() { this.setState({saving: false}); this.reset(); }.bind(this)); }, reset: function() { this.refs.name.clear(); this.refs.value.clear(); }, commitAdd: function() { this.setState({saving: true}); var newRecord = deepMerge({ type: this.refs.type.getDOMNode().value, ttl: 1 // automatic }, this.refs.name.getName(), this.refs.value.getValue()); this.finishSave(DomainStore.recordAdd(this.props.domain, newRecord)); }, render: function() { var className = this.state.saving ? 'saving' : ''; var options = this.types.map(function(type) { return }); var Name = getNameComponent(this.state.type); var Value = getValueComponent(this.state.type); return ( ) } }); var Record = React.createClass({ getInitialState: function() { return {state: 'view', saving: false}; }, componentWillReceiveProps: function() { this.setState({state: 'view', saving: false}); }, setDeleting: function() { this.setState({state: 'delete'}); }, setEditing: function() { this.setState({state: 'edit'}); }, cancelEdit: function() { this.setState({state: 'view'}); }, commitDelete: function() { this.setState({saving: true}); var record = this.props.record; DomainStore.recordDelete(record.zone_name.val(), record.id.val()); }, commitEdit: function() { this.setState({saving: true}); var record = this.props.record; var newRecord = deepMerge({ id: record.id.val(), type: record.type.val(), ttl: 1 // automatic }, this.refs.name.getName(), this.refs.value.getValue()); if(record.proxied.val()) { newRecord.proxied = record.proxied.val(); } DomainStore.recordEdit(record.zone_name.val(), newRecord); }, toggleProxy: function() { this.setState({saving: true}); var record = this.props.record; var newRecord = { id: record.id.val(), type: record.type.val(), name: record.name.val(), content: record.content.val(), proxied: !record.proxied.val(), ttl: 1 }; DomainStore.recordEdit(record.zone_name.val(), newRecord); }, render: function() { var record = this.props.record; var className = this.state.saving ? 'saving' : ''; var displayName = record.name.val(); var zoneName = '.'+record.zone_name.val(); var limit = displayName.length - zoneName.length; if(limit > 0 && displayName.substring(limit) === zoneName) { displayName = displayName.substring(0, limit); } if(this.state.state === 'edit') { var Name = getNameComponent(record.type.val()); var Value = getValueComponent(record.type.val()); return ( {record.type.val()} Cancel ); } else if(this.state.state === 'delete') { return ( {record.type.val()} {displayName} {record.content.val()} Cancel ); } else { return ( {record.type.val()} {displayName} {record.content.val()} ); } } }); var RecordList = React.createClass({ render: function() { var records = this.props.records.map(function(record) { return }.bind(this)); var body; if(records.length === 0) { body = ( Loading... ); } else { body = ( {records} ); } return (
{body}
Type Name Value Proxy Actions
); } }); module.exports = RecordList;