Skip to content

Instantly share code, notes, and snippets.

@CoreyTrombley
Created March 10, 2015 22:26
Show Gist options
  • Save CoreyTrombley/144bcd0a439c44fcd4bb to your computer and use it in GitHub Desktop.
Save CoreyTrombley/144bcd0a439c44fcd4bb to your computer and use it in GitHub Desktop.
/**
* @file React Component for Status
*/
var React = require('react');
var _ = require('lodash');
var config = require('../../../shared/config');
var Api = require('../../../shared/lib/api')(config());
var StatusMixin = require('../mixins/statusToggleMixin');
var StatusComponent = React.createClass({
displayName: 'StatusComponent',
mixins: [StatusMixin],
propTypes: {
/**
* The state of the switch.
*/
disabled: React.PropTypes.bool.isRequired,
/**
* Unique Id for the switch to hold state.
*/
id: React.PropTypes.string.isRequired,
campaign: React.PropTypes.object
},
componentWillMount: function() {
this.setState({disabled: this.props.disabled});
},
changeStatus: function() {
if (this.props.publisher === 'facebook') {
StatusMixin.facebookStatusToggle(this).publisherRequest(function(data) {
this.setState({disabled: !(this.state.disabled)});
});
} else if (this.props.publisher === 'twitter') {
StatusMixin.twitterStatusToggle(this).publisherRequest(function(data) {
this.setState({disabled: !(this.state.disabled)});
});
} else if (this.props.statusType === 'lineItems') {
StatusMixin.lineItemToggle(this).lineItemRequest(function(data) {
this.setState({disabled: !(this.state.disabled)});
});
} else if (this.props.statusType === 'initiatives') {
StatusMixin.initiativeToggle(this).initiativeRequest(function(data) {
this.setState({disabled: !(this.state.disabled)});
});
}
if (!this.props.publisher) {
return;
}
},
componentWillUpdate: function(nextProps, nextState) {
debugger;
},
render: function() {
var disabled = this.state.disabled;
var input = <input onChange={this.changeStatus} id={"statusSwitch_" + this.props.id} defaultChecked={!(disabled)} className="onoffswitch-checkbox" type="checkbox" name="onoffswitch"/>;
if (this.props.statusType) {
input = <input onChange={this.changeStatus} disabled={this.state.disabled} id={"statusSwitch_" + this.props.id} defaultChecked={!(disabled)} className="onoffswitch-checkbox" type="checkbox" name="onoffswitch"/>;
}
return (
<div className="onoffswitch">
{input}
<label htmlFor={"statusSwitch_" + this.props.id} className="onoffswitch-label">
<span className="onoffswitch-inner"></span>
<span className="onoffswitch-switch"></span>
</label>
</div>
);
}
});
module.exports = StatusComponent;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment