Settings.jsx 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. var DomainStore = require('../stores').Domains;
  2. var React = require('react');
  3. var DevModeToggle = React.createClass({
  4. getInitialState: function() {
  5. return {toggling: false};
  6. },
  7. componentWillReceiveProps: function() {
  8. this.setState({toggling: false});
  9. },
  10. toggleDevMode: function() {
  11. this.setState({toggling: true});
  12. DomainStore.setDevelopmentMode(this.props.domain, this.props.devMode == 0);
  13. },
  14. render: function() {
  15. if(this.state.toggling) {
  16. return <button className="btn btn-warning" disabled>{this.props.devMode > 0 ? 'Disabling...' : 'Enabling...'}</button>
  17. }
  18. else if(this.props.devMode > 0) {
  19. var date = new Date(this.props.devMode*1000);
  20. var dateString = date.getFullYear()+'/'+(1+date.getMonth())+'/'+date.getDate()+' '+date.getHours()+':'+date.getMinutes();
  21. return (
  22. <div>
  23. <button className='btn btn-success' onClick={this.toggleDevMode}>On</button>
  24. <span> Active until {dateString}</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;