| 1 |
/** |
| 2 |
* WordPress dependencies |
| 3 |
*/ |
| 4 |
const { __ } = wp.i18n; |
| 5 |
|
| 6 |
const { |
| 7 |
Component, |
| 8 |
Fragment |
| 9 |
} = wp.element; |
| 10 |
|
| 11 |
const { |
| 12 |
Button, |
| 13 |
CheckboxControl, |
| 14 |
PanelBody |
| 15 |
} = wp.components; |
| 16 |
|
| 17 |
class FrontendActions extends Component { |
| 18 |
constructor() { |
| 19 |
super( ...arguments ); |
| 20 |
} |
| 21 |
|
| 22 |
componentDidMount() { |
| 23 |
const settings = this.props.chart['visualizer-settings']; |
| 24 |
|
| 25 |
if ( settings.actions === undefined ) { |
| 26 |
settings.actions = []; |
| 27 |
} |
| 28 |
|
| 29 |
this.props.edit( settings ); |
| 30 |
} |
| 31 |
|
| 32 |
render() { |
| 33 |
|
| 34 |
const settings = this.props.chart['visualizer-settings']; |
| 35 |
const type = this.props.chart['visualizer-chart-type']; |
| 36 |
|
| 37 |
return ( |
| 38 |
( '' !== visualizerLocalize.proFeaturesLocked ) ? |
| 39 |
<PanelBody |
| 40 |
title={ __( 'Frontend Actions' ) } |
| 41 |
initialOpen={ false } |
| 42 |
className="visualizer-advanced-panel" |
| 43 |
> |
| 44 |
|
| 45 |
{ ( settings.actions !== undefined && |
| 46 |
|
| 47 |
<Fragment> |
| 48 |
|
| 49 |
<CheckboxControl |
| 50 |
label={ __( 'Print' ) } |
| 51 |
help={ __( 'To enable printing the data.' ) } |
| 52 |
checked={ ( 0 <= settings.actions.indexOf( 'print' ) ) } |
| 53 |
onChange={ e => { |
| 54 |
if ( 0 <= settings.actions.indexOf( 'print' ) ) { |
| 55 |
const index = settings.actions.indexOf( 'print' ); |
| 56 |
if ( -1 !== index ) { |
| 57 |
settings.actions.splice( index, 1 ); |
| 58 |
} |
| 59 |
} else { |
| 60 |
settings.actions.push( 'print' ); |
| 61 |
} |
| 62 |
this.props.edit( settings ); |
| 63 |
} } |
| 64 |
/> |
| 65 |
|
| 66 |
<CheckboxControl |
| 67 |
label={ __( 'CSV' ) } |
| 68 |
help={ __( 'To enable downloading the data as a CSV.' ) } |
| 69 |
checked={ ( 0 <= settings.actions.indexOf( 'csv;application/csv' ) ) } |
| 70 |
onChange={ e => { |
| 71 |
if ( 0 <= settings.actions.indexOf( 'csv;application/csv' ) ) { |
| 72 |
const index = settings.actions.indexOf( 'csv;application/csv' ); |
| 73 |
if ( -1 !== index ) { |
| 74 |
settings.actions.splice( index, 1 ); |
| 75 |
} |
| 76 |
} else { |
| 77 |
settings.actions.push( 'csv;application/csv' ); |
| 78 |
} |
| 79 |
this.props.edit( settings ); |
| 80 |
} } |
| 81 |
/> |
| 82 |
|
| 83 |
<CheckboxControl |
| 84 |
label={ __( 'Excel' ) } |
| 85 |
help={ __( 'To enable downloading the data as an Excel spreadsheet.' ) } |
| 86 |
checked={ ( 0 <= settings.actions.indexOf( 'xls;application/vnd.ms-excel' ) ) } |
| 87 |
onChange={ e => { |
| 88 |
if ( 0 <= settings.actions.indexOf( 'xls;application/vnd.ms-excel' ) ) { |
| 89 |
const index = settings.actions.indexOf( 'xls;application/vnd.ms-excel' ); |
| 90 |
if ( -1 !== index ) { |
| 91 |
settings.actions.splice( index, 1 ); |
| 92 |
} |
| 93 |
} else { |
| 94 |
settings.actions.push( 'xls;application/vnd.ms-excel' ); |
| 95 |
} |
| 96 |
this.props.edit( settings ); |
| 97 |
} } |
| 98 |
/> |
| 99 |
|
| 100 |
<CheckboxControl |
| 101 |
label={ __( 'Copy' ) } |
| 102 |
help={ __( 'To enable copying the data to the clipboard.' ) } |
| 103 |
checked={ ( 0 <= settings.actions.indexOf( 'copy' ) ) } |
| 104 |
onChange={ e => { |
| 105 |
if ( 0 <= settings.actions.indexOf( 'copy' ) ) { |
| 106 |
const index = settings.actions.indexOf( 'copy' ); |
| 107 |
if ( -1 !== index ) { |
| 108 |
settings.actions.splice( index, 1 ); |
| 109 |
} |
| 110 |
} else { |
| 111 |
settings.actions.push( 'copy' ); |
| 112 |
} |
| 113 |
this.props.edit( settings ); |
| 114 |
} } |
| 115 |
/> |
| 116 |
|
| 117 |
{ ( -1 >= [ 'dataTable', 'tabular', 'gauge', 'table' ].indexOf( type ) ) && ( |
| 118 |
<CheckboxControl |
| 119 |
label={ __( 'Download Image' ) } |
| 120 |
help={ __( 'To download the chart as an image.' ) } |
| 121 |
checked={ ( 0 <= settings.actions.indexOf( 'image' ) ) } |
| 122 |
onChange={ e => { |
| 123 |
if ( 0 <= settings.actions.indexOf( 'image' ) ) { |
| 124 |
const index = settings.actions.indexOf( 'image' ); |
| 125 |
if ( -1 !== index ) { |
| 126 |
settings.actions.splice( index, 1 ); |
| 127 |
} |
| 128 |
} else { |
| 129 |
settings.actions.push( 'image' ); |
| 130 |
} |
| 131 |
this.props.edit( settings ); |
| 132 |
} } |
| 133 |
/> |
| 134 |
) } |
| 135 |
|
| 136 |
</Fragment> |
| 137 |
|
| 138 |
) } |
| 139 |
|
| 140 |
</PanelBody> : |
| 141 |
<PanelBody |
| 142 |
title={ __( 'Frontend Actions' ) } |
| 143 |
initialOpen={ false } |
| 144 |
icon="lock" |
| 145 |
className="visualizer-advanced-panel" |
| 146 |
> |
| 147 |
|
| 148 |
<p>{ __( 'Enable this feature in PRO version!' ) }</p> |
| 149 |
|
| 150 |
<Button |
| 151 |
isPrimary |
| 152 |
href={ visualizerLocalize.proTeaser } |
| 153 |
target="_blank" |
| 154 |
> |
| 155 |
{ __( 'Upgrade Now' ) } |
| 156 |
</Button> |
| 157 |
|
| 158 |
</PanelBody> |
| 159 |
); |
| 160 |
} |
| 161 |
} |
| 162 |
|
| 163 |
export default FrontendActions; |
| 164 |
|