App.jsx 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. DomainStore.loadSettings(domain);
  32. content.push(<Settings key="settings" domain={domain} settings={store.settings} />);
  33. }
  34. else {
  35. DomainStore.loadRecords(domain);
  36. content.push(<RecordList key="records" domain={domain} records={store.records} />);
  37. }
  38. }
  39. }
  40. else {
  41. title = "CloudFlare WebUI";
  42. content.push(<p key="content">Select a domain from the sidebar</p>);
  43. }
  44. return (
  45. <div className="row">
  46. <div id="domains" className="col-md-3">
  47. <DomainList currentDomain={domain} domains={this.props.domains} />
  48. </div>
  49. <div className="col-md-9">
  50. <h1>{title}</h1>
  51. {content}
  52. </div>
  53. </div>
  54. );
  55. },
  56. home: function() {
  57. return this.main();
  58. },
  59. domain: function(domain) {
  60. return this.main(domain, false);
  61. },
  62. settings: function(domain) {
  63. return this.main(domain, true);
  64. }
  65. });
  66. module.exports = App;