| 1 |
import React, { Component, Fragment } from 'react'; |
| 2 |
|
| 3 |
import '../../../css/admin/modal/select.scss'; |
| 4 |
|
| 5 |
import { __wpupg } from 'Shared/Translations'; |
| 6 |
import Header from '../general/Header'; |
| 7 |
import Footer from '../general/Footer'; |
| 8 |
|
| 9 |
import SelectFilter from './SelectFilter'; |
| 10 |
import SelectGrid from './SelectGrid'; |
| 11 |
|
| 12 |
export default class Select extends Component { |
| 13 |
constructor(props) { |
| 14 |
super(props); |
| 15 |
|
| 16 |
this.state = { |
| 17 |
grid: false, |
| 18 |
filter: false, |
| 19 |
}; |
| 20 |
} |
| 21 |
|
| 22 |
selectionsMade() { |
| 23 |
return ( ! this.props.args.fields.grid || false !== this.state.grid ) |
| 24 |
&& ( ! this.props.args.fields.filter || false !== this.state.filter ); |
| 25 |
} |
| 26 |
|
| 27 |
render() { |
| 28 |
return ( |
| 29 |
<Fragment> |
| 30 |
<Header |
| 31 |
onCloseModal={ this.props.maybeCloseModal } |
| 32 |
> |
| 33 |
{ |
| 34 |
this.props.args.title |
| 35 |
? |
| 36 |
this.props.args.title |
| 37 |
: |
| 38 |
'WP Ultimate Post Grid' |
| 39 |
} |
| 40 |
</Header> |
| 41 |
<div className="wpupg-admin-modal-select-container"> |
| 42 |
{ |
| 43 |
this.props.args.fields.grid |
| 44 |
? |
| 45 |
<SelectGrid |
| 46 |
placeholder={ __wpupg( 'Select Grid' ) } |
| 47 |
value={ this.state.grid } |
| 48 |
onChange={(grid) => { |
| 49 |
this.setState({ |
| 50 |
grid, |
| 51 |
filter: false, |
| 52 |
}); |
| 53 |
}} |
| 54 |
/> |
| 55 |
: |
| 56 |
null |
| 57 |
} |
| 58 |
{ |
| 59 |
this.props.args.fields.filter |
| 60 |
? |
| 61 |
<Fragment> |
| 62 |
<br/> |
| 63 |
<SelectFilter |
| 64 |
placeholder={ __wpupg( 'Select Filter' ) } |
| 65 |
grid={ this.state.grid } |
| 66 |
value={ this.state.filter } |
| 67 |
onChange={(filter) => { |
| 68 |
this.setState({ filter }); |
| 69 |
}} |
| 70 |
/> |
| 71 |
</Fragment> |
| 72 |
: |
| 73 |
null |
| 74 |
} |
| 75 |
</div> |
| 76 |
<Footer |
| 77 |
savingChanges={ false } |
| 78 |
> |
| 79 |
<button |
| 80 |
className="button button-primary" |
| 81 |
onClick={ () => { |
| 82 |
if ( 'function' === typeof this.props.args.nextStepCallback ) { |
| 83 |
this.props.args.nextStepCallback( this.state ); |
| 84 |
} else { |
| 85 |
if ( 'function' === typeof this.props.args.insertCallback ) { |
| 86 |
this.props.args.insertCallback( this.state ); |
| 87 |
} |
| 88 |
this.props.maybeCloseModal(); |
| 89 |
} |
| 90 |
} } |
| 91 |
disabled={ ! this.selectionsMade() } |
| 92 |
> |
| 93 |
{ |
| 94 |
this.props.args.button |
| 95 |
? |
| 96 |
this.props.args.button |
| 97 |
: |
| 98 |
__wpupg( 'Select' ) |
| 99 |
} |
| 100 |
</button> |
| 101 |
</Footer> |
| 102 |
</Fragment> |
| 103 |
); |
| 104 |
} |
| 105 |
} |