Settings.jsx 2.0 KB

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