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