App.jsx 2.2 KB

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