App.jsx 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. var DomainStore = require('./stores').Domains;
  2. var React = require('react');
  3. var ReactMiniRouter = require('react-mini-router');
  4. var DomainList = require('./ui/DomainList');
  5. var RecordList = require('./ui/RecordList');
  6. var Settings = require('./ui/Settings');
  7. var App = React.createClass({
  8. mixins: [ReactMiniRouter.RouterMixin],
  9. routes: {
  10. '/': 'home',
  11. '/:domain': 'domain',
  12. '/:domain/settings': 'settings'
  13. },
  14. render: function() {
  15. return this.renderCurrentRoute();
  16. },
  17. main: function(domain, settings) {
  18. var title;
  19. var content = [];
  20. if(domain) {
  21. title = domain;
  22. content.push(
  23. <ul key="nav" className="nav nav-tabs">
  24. <li role="presentation" className={!settings ? 'active' : ''}><a href={'/'+domain}>DNS</a></li>
  25. <li role="presentation" className={settings ? 'active' : ''}><a href={'/'+domain+'/settings'}>Settings</a></li>
  26. </ul>
  27. );
  28. var store = DomainStore.find(domain);
  29. if(store) {
  30. if(settings) {
  31. content.push(<Settings key="settings" domain={domain} settings={store} />);
  32. }
  33. else {
  34. DomainStore.loadRecords(domain);
  35. content.push(<RecordList key="records" domain={domain} records={store.records} />);
  36. }
  37. }
  38. }
  39. else {
  40. title = "CloudFlare WebUI";
  41. content.push(<p key="content">Select a domain from the sidebar</p>);
  42. }
  43. return (
  44. <div className="row">
  45. <div id="domains" className="col-md-3">
  46. <DomainList currentDomain={domain} domains={this.props.domains} />
  47. </div>
  48. <div className="col-md-9">
  49. <h1>{title}</h1>
  50. {content}
  51. </div>
  52. </div>
  53. );
  54. },
  55. home: function() {
  56. return this.main();
  57. },
  58. domain: function(domain) {
  59. return this.main(domain, false);
  60. },
  61. settings: function(domain) {
  62. return this.main(domain, true);
  63. }
  64. });
  65. module.exports = App;