mirror of
https://github.com/ascribe/onion.git
synced 2025-01-03 10:25:08 +01:00
input checkbox functionality
This commit is contained in:
parent
fd6fad5da3
commit
b364414e16
@ -2,48 +2,43 @@
|
|||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
import AlertMixin from '../../mixins/alert_mixin';
|
import { getLangText } from '../../utils/lang_utils';
|
||||||
|
|
||||||
let InputCheckbox = React.createClass({
|
let InputCheckbox = React.createClass({
|
||||||
propTypes: {
|
propTypes: {
|
||||||
submitted: React.PropTypes.bool.isRequired,
|
|
||||||
required: React.PropTypes.string.isRequired,
|
required: React.PropTypes.string.isRequired,
|
||||||
label: React.PropTypes.string.isRequired
|
label: React.PropTypes.string.isRequired
|
||||||
},
|
},
|
||||||
|
|
||||||
mixins: [AlertMixin],
|
|
||||||
|
|
||||||
getInitialState() {
|
getInitialState() {
|
||||||
return {
|
return {
|
||||||
value: null,
|
show: false
|
||||||
alerts: null // needed in AlertMixin
|
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
handleChange(event) {
|
handleFocus() {
|
||||||
this.setState({value: event.target.value});
|
this.refs.checkbox.getDOMNode().checked = !this.refs.checkbox.getDOMNode().checked;
|
||||||
|
this.setState({
|
||||||
|
show: this.refs.checkbox.getDOMNode().checked
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
let alerts = (this.props.submitted) ? null : this.state.alerts;
|
|
||||||
return (
|
return (
|
||||||
<div className="form-group">
|
<span
|
||||||
{alerts}
|
onClick={this.handleFocus}
|
||||||
<div className="input-checkbox-ascribe">
|
onFocus={this.handleFocus}>
|
||||||
<div className="checkbox">
|
<input type="checkbox" ref="checkbox"/>
|
||||||
<label>
|
<span className="checkbox">
|
||||||
<input
|
<span>
|
||||||
type="checkbox"
|
{getLangText('I agree to the Terms of Service') + ' '}
|
||||||
required={this.props.required}
|
(<a href="/terms" target="_blank" style={{fontSize: '0.9em', color: 'rgba(0,0,0,0.7)'}}>
|
||||||
onChange={this.handleChange}
|
{getLangText('read')}
|
||||||
/>
|
</a>)
|
||||||
{this.props.label}
|
</span>
|
||||||
</label>
|
</span>
|
||||||
</div>
|
</span>
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -18,13 +18,21 @@ let Property = React.createClass({
|
|||||||
]),
|
]),
|
||||||
footer: React.PropTypes.element,
|
footer: React.PropTypes.element,
|
||||||
handleChange: React.PropTypes.func,
|
handleChange: React.PropTypes.func,
|
||||||
ignoreFocus: React.PropTypes.bool
|
ignoreFocus: React.PropTypes.bool,
|
||||||
|
className: React.PropTypes.string,
|
||||||
|
onClick: React.PropTypes.func,
|
||||||
|
onChange: React.PropTypes.func,
|
||||||
|
children: React.PropTypes.oneOfType([
|
||||||
|
React.PropTypes.arrayOf(React.PropTypes.element),
|
||||||
|
React.PropTypes.element
|
||||||
|
])
|
||||||
},
|
},
|
||||||
|
|
||||||
getDefaultProps() {
|
getDefaultProps() {
|
||||||
return {
|
return {
|
||||||
editable: true,
|
editable: true,
|
||||||
hidden: false
|
hidden: false,
|
||||||
|
className: ''
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -36,12 +44,14 @@ let Property = React.createClass({
|
|||||||
errors: null
|
errors: null
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
componentWillReceiveProps(){
|
componentWillReceiveProps(){
|
||||||
this.setState({
|
this.setState({
|
||||||
initialValue: this.refs.input.getDOMNode().defaultValue,
|
initialValue: this.refs.input.getDOMNode().defaultValue,
|
||||||
value: this.refs.input.getDOMNode().value
|
value: this.refs.input.getDOMNode().value
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
reset(){
|
reset(){
|
||||||
// maybe do reset by reload instead of frontend state?
|
// maybe do reset by reload instead of frontend state?
|
||||||
this.setState({value: this.state.initialValue});
|
this.setState({value: this.state.initialValue});
|
||||||
@ -62,26 +72,39 @@ let Property = React.createClass({
|
|||||||
}
|
}
|
||||||
this.setState({value: event.target.value});
|
this.setState({value: event.target.value});
|
||||||
},
|
},
|
||||||
|
|
||||||
handleFocus() {
|
handleFocus() {
|
||||||
|
// if ignoreFocus (bool) is defined, then just ignore focusing on
|
||||||
|
// the property and input
|
||||||
if(this.props.ignoreFocus) {
|
if(this.props.ignoreFocus) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if onClick is defined from the outside,
|
||||||
|
// just call it
|
||||||
|
if(this.props.onClick) {
|
||||||
|
this.props.onClick();
|
||||||
|
}
|
||||||
|
|
||||||
this.refs.input.getDOMNode().focus();
|
this.refs.input.getDOMNode().focus();
|
||||||
this.setState({
|
this.setState({
|
||||||
isFocused: true
|
isFocused: true
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
handleBlur() {
|
handleBlur() {
|
||||||
this.setState({
|
this.setState({
|
||||||
isFocused: false
|
isFocused: false
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
handleSuccess(){
|
handleSuccess(){
|
||||||
this.setState({
|
this.setState({
|
||||||
isFocused: false,
|
isFocused: false,
|
||||||
errors: null
|
errors: null
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
setErrors(errors){
|
setErrors(errors){
|
||||||
this.setState({
|
this.setState({
|
||||||
errors: errors.map((error) => {
|
errors: errors.map((error) => {
|
||||||
@ -89,9 +112,11 @@ let Property = React.createClass({
|
|||||||
})
|
})
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
clearErrors(){
|
clearErrors(){
|
||||||
this.setState({errors: null});
|
this.setState({errors: null});
|
||||||
},
|
},
|
||||||
|
|
||||||
getClassName() {
|
getClassName() {
|
||||||
if(this.props.hidden){
|
if(this.props.hidden){
|
||||||
return 'is-hidden';
|
return 'is-hidden';
|
||||||
@ -108,6 +133,7 @@ let Property = React.createClass({
|
|||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
renderChildren() {
|
renderChildren() {
|
||||||
return ReactAddons.Children.map(this.props.children, (child) => {
|
return ReactAddons.Children.map(this.props.children, (child) => {
|
||||||
return ReactAddons.addons.cloneWithProps(child, {
|
return ReactAddons.addons.cloneWithProps(child, {
|
||||||
@ -120,6 +146,7 @@ let Property = React.createClass({
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
let tooltip = <span/>;
|
let tooltip = <span/>;
|
||||||
if (this.props.tooltip){
|
if (this.props.tooltip){
|
||||||
@ -139,12 +166,12 @@ let Property = React.createClass({
|
|||||||
<div
|
<div
|
||||||
className={'ascribe-settings-wrapper ' + this.getClassName()}
|
className={'ascribe-settings-wrapper ' + this.getClassName()}
|
||||||
onClick={this.handleFocus}
|
onClick={this.handleFocus}
|
||||||
onfocus={this.handleFocus}>
|
onFocus={this.handleFocus}>
|
||||||
<OverlayTrigger
|
<OverlayTrigger
|
||||||
delay={500}
|
delay={500}
|
||||||
placement="top"
|
placement="top"
|
||||||
overlay={tooltip}>
|
overlay={tooltip}>
|
||||||
<div className="ascribe-settings-property">
|
<div className={'ascribe-settings-property ' + this.props.className}>
|
||||||
{this.state.errors}
|
{this.state.errors}
|
||||||
<span>{ this.props.label}</span>
|
<span>{ this.props.label}</span>
|
||||||
{this.renderChildren()}
|
{this.renderChildren()}
|
||||||
|
@ -15,6 +15,7 @@ import Form from './ascribe_forms/form';
|
|||||||
import Property from './ascribe_forms/property';
|
import Property from './ascribe_forms/property';
|
||||||
import InputCheckbox from './ascribe_forms/input_checkbox';
|
import InputCheckbox from './ascribe_forms/input_checkbox';
|
||||||
|
|
||||||
|
|
||||||
import apiUrls from '../constants/api_urls';
|
import apiUrls from '../constants/api_urls';
|
||||||
|
|
||||||
|
|
||||||
@ -77,6 +78,10 @@ let SignupContainer = React.createClass({
|
|||||||
|
|
||||||
|
|
||||||
let SignupForm = React.createClass({
|
let SignupForm = React.createClass({
|
||||||
|
propTypes: {
|
||||||
|
handleSuccess: React.PropTypes.func
|
||||||
|
},
|
||||||
|
|
||||||
mixins: [Router.Navigation],
|
mixins: [Router.Navigation],
|
||||||
|
|
||||||
handleSuccess(response){
|
handleSuccess(response){
|
||||||
@ -142,16 +147,11 @@ let SignupForm = React.createClass({
|
|||||||
type="text"
|
type="text"
|
||||||
placeholder={getLangText('Enter a promocode here (Optional)')}/>
|
placeholder={getLangText('Enter a promocode here (Optional)')}/>
|
||||||
</Property>
|
</Property>
|
||||||
<hr />
|
<Property
|
||||||
<InputCheckbox
|
name="terms"
|
||||||
name='terms'
|
className="ascribe-settings-property-collapsible-toggle">
|
||||||
required="required"
|
<InputCheckbox />
|
||||||
label={
|
</Property>
|
||||||
<div>
|
|
||||||
<a href="/terms" target="_blank" style={{fontSize: '0.9em', color: 'rgba(0,0,0,0.7)'}}>
|
|
||||||
{getLangText('I agree to the')} {getLangText('Terms of Service')}
|
|
||||||
</a>
|
|
||||||
</div>}/>
|
|
||||||
</Form>
|
</Form>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -207,6 +207,8 @@ const languages = {
|
|||||||
'Specify editions': 'Specify editions',
|
'Specify editions': 'Specify editions',
|
||||||
'Editions': 'Editions',
|
'Editions': 'Editions',
|
||||||
'Create editions': 'Create editions',
|
'Create editions': 'Create editions',
|
||||||
|
'I agree to the Terms of Service': 'I agree to the Terms of Service',
|
||||||
|
'read': 'read',
|
||||||
},
|
},
|
||||||
'de': {
|
'de': {
|
||||||
'ID': 'ID',
|
'ID': 'ID',
|
||||||
@ -414,6 +416,8 @@ const languages = {
|
|||||||
'Specify editions': 'Specify editions',
|
'Specify editions': 'Specify editions',
|
||||||
'Editions': 'Editions',
|
'Editions': 'Editions',
|
||||||
'Create editions': 'Create editions',
|
'Create editions': 'Create editions',
|
||||||
|
'I agree to the Terms of Service': 'I agree to the Terms of Service',
|
||||||
|
'read': 'read',
|
||||||
},
|
},
|
||||||
'fr': {
|
'fr': {
|
||||||
'ID': 'ID',
|
'ID': 'ID',
|
||||||
@ -621,6 +625,8 @@ const languages = {
|
|||||||
'Specify editions': 'Specify editions',
|
'Specify editions': 'Specify editions',
|
||||||
'Editions': 'Editions',
|
'Editions': 'Editions',
|
||||||
'Create editions': 'Create editions',
|
'Create editions': 'Create editions',
|
||||||
|
'I agree to the Terms of Service': 'I agree to the Terms of Service',
|
||||||
|
'read': 'read',
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -122,8 +122,11 @@ $ascribe-accordion-list-font: 'Source Sans Pro';
|
|||||||
}
|
}
|
||||||
|
|
||||||
span.ascribe-accordion-list-table-toggle {
|
span.ascribe-accordion-list-table-toggle {
|
||||||
::selection { background: transparent; }
|
-webkit-user-select: none;
|
||||||
::-moz-selection { background: transparent; }
|
-moz-user-select: none;
|
||||||
|
-khtml-user-select: none;
|
||||||
|
-ms-user-select: none;
|
||||||
|
|
||||||
&:hover {
|
&:hover {
|
||||||
color: $ascribe-color-dark;
|
color: $ascribe-color-dark;
|
||||||
cursor:pointer;
|
cursor:pointer;
|
||||||
|
@ -58,8 +58,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
.ascribe-settings-property {
|
.ascribe-settings-property {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
@ -145,7 +143,7 @@
|
|||||||
cursor:pointer;
|
cursor:pointer;
|
||||||
|
|
||||||
/* Taken from: http://www.htmllion.com/css3-checkbox.html */
|
/* Taken from: http://www.htmllion.com/css3-checkbox.html */
|
||||||
.checkbox {
|
> .checkbox {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
|
||||||
@ -155,14 +153,15 @@
|
|||||||
color: rgba(0, 0, 0, .5);
|
color: rgba(0, 0, 0, .5);
|
||||||
vertical-align:middle;
|
vertical-align:middle;
|
||||||
|
|
||||||
span {
|
> span {
|
||||||
position: relative;
|
position: relative;
|
||||||
top: 1px;
|
top: 1px;
|
||||||
left: 5px;
|
left: 5px;
|
||||||
|
|
||||||
&:hover {
|
-webkit-user-select: none;
|
||||||
color: rgba(2, 182, 163, 1);
|
-moz-user-select: none;
|
||||||
}
|
-khtml-user-select: none;
|
||||||
|
-ms-user-select: none;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,6 +92,11 @@ hr {
|
|||||||
padding-right:0;
|
padding-right:0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.clear-margins {
|
||||||
|
margin-top:0;
|
||||||
|
margin-bottom:0;
|
||||||
|
}
|
||||||
|
|
||||||
.ascribe-color {
|
.ascribe-color {
|
||||||
color: $ascribe-color;
|
color: $ascribe-color;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user