|
| 1 | +var vcCake = require('vc-cake') |
| 2 | +var React = require('react') |
| 3 | +var classNames = require('classnames') |
| 4 | +require('../../../../../sources/less/ui/loader/init.less') |
| 5 | + |
| 6 | +class WordPressPostSaveControl extends React.Component { |
| 7 | + constructor (props) { |
| 8 | + super(props) |
| 9 | + this.state = { |
| 10 | + saving: false |
| 11 | + } |
| 12 | + } |
| 13 | + |
| 14 | + clickSaveData () { |
| 15 | + this.setState({ 'saving': true }) |
| 16 | + setTimeout((() => { |
| 17 | + this.setState({ 'saving': false }) |
| 18 | + this.setState({ 'saved': true }) |
| 19 | + }).bind(this), 500 |
| 20 | + ) |
| 21 | + setTimeout((() => { |
| 22 | + this.setState({ 'saved': false }) |
| 23 | + }).bind(this), 5000 |
| 24 | + ) |
| 25 | + this.props.api.notify('save') |
| 26 | + } |
| 27 | + |
| 28 | + render () { |
| 29 | + var saveButtonClasses = classNames({ |
| 30 | + 'vcv-ui-navbar-control': true, |
| 31 | + 'vcv-ui-state--success': this.state.saved |
| 32 | + }) |
| 33 | + var saveIconClasses = classNames({ |
| 34 | + 'vcv-ui-navbar-control-icon': true, |
| 35 | + 'vcv-ui-wp-spinner': this.state.saving, |
| 36 | + 'vcv-ui-icon': !this.state.saving, |
| 37 | + 'vcv-ui-icon-save': !this.state.saving |
| 38 | + }) |
| 39 | + return ( |
| 40 | + <div className="vcv-ui-navbar-controls-group vcv-ui-pull-end"> |
| 41 | + <a className={saveButtonClasses} title="Save" onClick={this.clickSaveData.bind(this)}><span |
| 42 | + className="vcv-ui-navbar-control-content"> |
| 43 | + <i className={saveIconClasses}></i><span>Save</span> |
| 44 | + </span></a> |
| 45 | + </div> |
| 46 | + ) |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +class WordPressAdminControl extends React.Component { |
| 51 | + constructor (props) { |
| 52 | + super(props) |
| 53 | + this.state = window.vcvPostData |
| 54 | + } |
| 55 | + |
| 56 | + render () { |
| 57 | + var saveDraftButton = '' |
| 58 | + if ( |
| 59 | + this.state.status !== 'publish' && |
| 60 | + this.state.status !== 'future' && |
| 61 | + this.state.status !== 'pending' && |
| 62 | + this.state.status !== 'private' |
| 63 | + ) { |
| 64 | + saveDraftButton = ( |
| 65 | + <a className="vcv-ui-navbar-control" href={this.state.permalink} title="Save Draft"><span |
| 66 | + className="vcv-ui-navbar-control-content">Save Draft</span></a> |
| 67 | + ) |
| 68 | + } |
| 69 | + |
| 70 | + var viewButton = '' |
| 71 | + if (this.state.status === 'publish') { |
| 72 | + viewButton = ( |
| 73 | + <a className="vcv-ui-navbar-control" href={this.state.permalink} title="View Page"><span |
| 74 | + className="vcv-ui-navbar-control-content">View Page</span></a> |
| 75 | + ) |
| 76 | + } |
| 77 | + var previewText = this.state.status === 'publish' ? 'Preview Changes' : 'Preview' |
| 78 | + var previewButton = ( |
| 79 | + <a className="vcv-ui-navbar-control" href={this.state.previewUrl} title={previewText}><span |
| 80 | + className="vcv-ui-navbar-control-content">{previewText}</span></a> |
| 81 | + ) |
| 82 | + |
| 83 | + return ( |
| 84 | + <div> |
| 85 | + {saveDraftButton} |
| 86 | + {previewButton} |
| 87 | + {viewButton} |
| 88 | + </div> |
| 89 | + ) |
| 90 | + } |
| 91 | +} |
| 92 | + |
| 93 | +vcCake.add('ui-wordpress-navbar-wp-admin', |
| 94 | + (api) => { |
| 95 | + api.module('ui-navbar').do('addElement', 'Wordpress Post Save Button', <WordPressPostSaveControl api={api} />, |
| 96 | + { |
| 97 | + pin: 'visible' |
| 98 | + } |
| 99 | + ) |
| 100 | + api.module('ui-navbar').do('addElement', 'Wordpress Admin Controls', WordPressAdminControl, |
| 101 | + { |
| 102 | + pin: 'hidden' |
| 103 | + } |
| 104 | + ) |
| 105 | + } |
| 106 | +) |
| 107 | + |
0 commit comments