Settings.jsx 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. var DomainStore = require('../stores').Domains;
  2. var React = require('react');
  3. var dateToString = require('../util').dateToString;
  4. var DevModeToggle = React.createClass({
  5. getInitialState: function() {
  6. return {toggling: false};
  7. },
  8. componentWillReceiveProps: function() {
  9. this.setState({toggling: false});
  10. },
  11. toggleDevMode: function() {
  12. this.setState({toggling: true});
  13. DomainStore.setDevelopmentMode(this.props.domain, this.props.devMode == 0);
  14. },
  15. render: function() {
  16. if(this.state.toggling) {
  17. return <button className="btn btn-warning" disabled>{this.props.devMode > 0 ? 'Disabling...' : 'Enabling...'}</button>
  18. }
  19. else if(this.props.devMode > 0) {
  20. var date = new Date(this.props.devMode*1000);
  21. return (
  22. <div>
  23. <button className='btn btn-success' onClick={this.toggleDevMode}>On</button>
  24. <span> Active until {dateToString(date)}</span>
  25. </div>
  26. );
  27. }
  28. else {
  29. return <button className='btn btn-default' onClick={this.toggleDevMode}>Off</button>
  30. }
  31. }
  32. });
  33. var PurgeButton = React.createClass({
  34. getInitialState: function() {
  35. return {purging: false};
  36. },
  37. purgeCache: function() {
  38. this.setState({purging: true});
  39. var reset = function() {
  40. this.setState({purging: false});
  41. }.bind(this);
  42. DomainStore.purgeCache(this.props.domain).then(function(data) {
  43. var timeout = data.attributes.cooldown;
  44. setTimeout(reset, timeout*1000);
  45. });
  46. },
  47. render: function() {
  48. if(this.state.purging) {
  49. return <button className="btn btn-warning" disabled>Purging...</button>
  50. }
  51. else {
  52. return <button className="btn btn-success" onClick={this.purgeCache}>Purge</button>
  53. }
  54. }
  55. });
  56. var Settings = React.createClass({
  57. render: function() {
  58. if(!this.props.settings.val()) {
  59. return <div className="alert alert-info">Loading...</div>
  60. }
  61. return (
  62. <div>
  63. <table className="table">
  64. <tr>
  65. <td>Development Mode</td>
  66. <td><DevModeToggle domain={this.props.domain} devMode={this.props.settings.dev_mode.val()} /></td>
  67. </tr>
  68. <tr>
  69. <td>Purge Cache</td>
  70. <td><PurgeButton domain={this.props.domain} /></td>
  71. </tr>
  72. </table>
  73. </div>
  74. );
  75. }
  76. });
  77. module.exports = Settings;