Advertisement
Guest User

Untitled

a guest
Apr 27th, 2015
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. /**
  2. * @file React Component for Status
  3. */
  4.  
  5. var React = require('react');
  6. var _ = require('lodash');
  7. var config = require('../../../shared/config');
  8. var Api = require('../../../shared/lib/api')(config());
  9. var StatusMixin = require('../mixins/statusToggleMixin');
  10.  
  11. var StatusComponent = React.createClass({
  12.  
  13. displayName: 'StatusComponent',
  14.  
  15. mixins: [StatusMixin],
  16.  
  17. propTypes: {
  18.  
  19. /**
  20. * The state of the switch.
  21. */
  22. disabled: React.PropTypes.bool.isRequired,
  23.  
  24. /**
  25. * Unique Id for the switch to hold state.
  26. */
  27. id: React.PropTypes.string.isRequired,
  28.  
  29. campaign: React.PropTypes.object
  30.  
  31. },
  32. componentWillMount: function() {
  33. this.setState({disabled: this.props.disabled});
  34. },
  35.  
  36. changeStatus: function() {
  37.  
  38. if (this.props.publisher === 'facebook') {
  39. StatusMixin.facebookStatusToggle(this).publisherRequest(function(data) {
  40. this.setState({disabled: !(this.state.disabled)});
  41. });
  42. } else if (this.props.publisher === 'twitter') {
  43. StatusMixin.twitterStatusToggle(this).publisherRequest(function(data) {
  44. this.setState({disabled: !(this.state.disabled)});
  45. });
  46. } else if (this.props.statusType === 'lineItems') {
  47. StatusMixin.lineItemToggle(this).lineItemRequest(function(data) {
  48. this.setState({disabled: !(this.state.disabled)});
  49. });
  50. } else if (this.props.statusType === 'initiatives') {
  51. StatusMixin.initiativeToggle(this).initiativeRequest(function(data) {
  52. this.setState({disabled: !(this.state.disabled)});
  53. });
  54. }
  55.  
  56. if (!this.props.publisher) {
  57. return;
  58. }
  59. },
  60.  
  61. componentWillUpdate: function(nextProps, nextState) {
  62. debugger;
  63. },
  64.  
  65. render: function() {
  66. var disabled = this.state.disabled;
  67. var input = <input onChange={this.changeStatus} id={"statusSwitch_" + this.props.id} defaultChecked={!(disabled)} className="onoffswitch-checkbox" type="checkbox" name="onoffswitch"/>;
  68. if (this.props.statusType) {
  69. input = <input onChange={this.changeStatus} disabled={this.state.disabled} id={"statusSwitch_" + this.props.id} defaultChecked={!(disabled)} className="onoffswitch-checkbox" type="checkbox" name="onoffswitch"/>;
  70. }
  71.  
  72. return (
  73. <div className="onoffswitch">
  74. {input}
  75. <label htmlFor={"statusSwitch_" + this.props.id} className="onoffswitch-label">
  76. <span className="onoffswitch-inner"></span>
  77. <span className="onoffswitch-switch"></span>
  78. </label>
  79. </div>
  80.  
  81. );
  82. }
  83. });
  84.  
  85.  
  86. module.exports = StatusComponent;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement