inspector.js
67 lines
| 1 | /** |
| 2 | * WordPress dependencies |
| 3 | */ |
| 4 | const { __ } = wp.i18n; |
| 5 | const { Component, Fragment } = wp.element; |
| 6 | const { InspectorControls } = wp.editor; |
| 7 | const { SelectControl, PanelBody } = wp.components; |
| 8 | |
| 9 | |
| 10 | /** |
| 11 | * Inspector controls |
| 12 | */ |
| 13 | export default class Inspector extends Component { |
| 14 | |
| 15 | constructor( props ) { |
| 16 | super( ...arguments ); |
| 17 | } |
| 18 | |
| 19 | onAuthorSelect( authorID ) { |
| 20 | |
| 21 | this.props.setAttributes( { |
| 22 | status: 'loading', |
| 23 | } ); |
| 24 | |
| 25 | this.props.changeAuthor( authorID ); |
| 26 | } |
| 27 | |
| 28 | render() { |
| 29 | |
| 30 | const { |
| 31 | attributes, |
| 32 | setAttributes |
| 33 | } = this.props; |
| 34 | |
| 35 | const { |
| 36 | authorID, |
| 37 | } = attributes; |
| 38 | |
| 39 | let authors = sabVars.authors; |
| 40 | authors.forEach(function(author) { |
| 41 | author.value = author.ID; |
| 42 | author.label = author.display_name; |
| 43 | }); |
| 44 | |
| 45 | let isEditor = false; |
| 46 | if( sabVars.currentUserRoles.indexOf("administrator") != -1 || sabVars.currentUserRoles.indexOf("editor") != -1 ) { |
| 47 | isEditor = true; |
| 48 | } |
| 49 | |
| 50 | return ( |
| 51 | <Fragment> |
| 52 | <InspectorControls> |
| 53 | { isEditor && ( |
| 54 | <PanelBody title={ __( 'Author Settings' ) } initialOpen={ true }> |
| 55 | <SelectControl |
| 56 | label={ __( 'Select author' ) } |
| 57 | value={ authorID } |
| 58 | options={ authors } |
| 59 | onChange={ ( value ) => this.onAuthorSelect( value ) } |
| 60 | /> |
| 61 | </PanelBody> |
| 62 | ) } |
| 63 | </InspectorControls> |
| 64 | </Fragment> |
| 65 | ); |
| 66 | } |
| 67 | } |