import React from 'react'; import classnames from 'classnames'; import i18n from 'nfvo-utils/i18n/i18n.js'; import Navbar from 'react-bootstrap/lib/Navbar.js'; import Nav from 'react-bootstrap/lib/Nav.js'; import ValidationInput from 'nfvo-components/input/validation/ValidationInput.jsx'; import {actionsEnum, statusEnum} from './VersionControllerConstants.js'; class VersionController extends React.Component { static propTypes = { version: React.PropTypes.string, viewableVersions: React.PropTypes.array, onVersionSwitching: React.PropTypes.func, isCheckedOut: React.PropTypes.bool.isRequired, status: React.PropTypes.string.isRequired, callVCAction: React.PropTypes.func, onSave: React.PropTypes.func, onClose: React.PropTypes.func, isFormDataValid: React.PropTypes.bool }; render() { let {status, isCheckedOut, version = '', viewableVersions = [], onVersionSwitching, callVCAction, onSave, isFormDataValid, onClose} = this.props; let isCheckedIn = Boolean(status === statusEnum.CHECK_IN_STATUS); let isLatestVersion = Boolean(version === viewableVersions[viewableVersions.length - 1]); if (!isLatestVersion) { status = statusEnum.PREVIOUS_VERSION; } return (
); } renderStatus(status) { switch (status) { case statusEnum.CHECK_OUT_STATUS: return (
{i18n('CHECKED OUT')}
); case statusEnum.LOCK_STATUS: return (
{i18n('LOCKED')}
); case statusEnum.CHECK_IN_STATUS: return (
{i18n('CHECKED IN')}
); case statusEnum.SUBMIT_STATUS: return (
{i18n('SUBMITTED')}
); default: return (
{i18n(status)}
); } } checkinCheckoutVersion(callVCAction) { if (this.props.isCheckedOut) { this.checkin(callVCAction); } else { this.checkout(callVCAction); } } checkin(callVCAction) { const action = actionsEnum.CHECK_IN; if (this.props.onSave) { this.props.onSave().then(()=>{ callVCAction(action); }); }else{ callVCAction(action); } } checkout(callVCAction) { const action = actionsEnum.CHECK_OUT; callVCAction(action); } submit(callVCAction) { const action = actionsEnum.SUBMIT; callVCAction(action); } revertCheckout(callVCAction) { const action = actionsEnum.UNDO_CHECK_OUT; callVCAction(action); } } export default VersionController;