import React from 'react'; import ButtonGroup from 'react-bootstrap/lib/ButtonGroup.js'; import Button from 'react-bootstrap/lib/Button.js'; import ValidationForm from 'nfvo-components/input/validation/ValidationForm.jsx'; import ValidationTabs from 'nfvo-components/input/validation/ValidationTabs.jsx'; import ValidationTab from 'nfvo-components/input/validation/ValidationTab.jsx'; import ValidationInput from 'nfvo-components/input/validation/ValidationInput.jsx'; import DualListboxView from 'nfvo-components/input/dualListbox/DualListboxView.jsx'; import ListEditorView from 'nfvo-components/listEditor/ListEditorView.jsx'; import ListEditorViewItem from 'nfvo-components/listEditor/ListEditorItemView.jsx'; import i18n from 'nfvo-utils/i18n/i18n.js'; import {enums as LicenseAgreementEnums, optionsInputValues as LicenseAgreementOptionsInputValues} from './LicenseAgreementConstants.js'; const LicenseAgreementPropType = React.PropTypes.shape({ id: React.PropTypes.string, name: React.PropTypes.string, description: React.PropTypes.string, requirementsAndConstrains: React.PropTypes.string, licenseTerm: React.PropTypes.object, featureGroupsIds: React.PropTypes.arrayOf(React.PropTypes.string) }); class LicenseAgreementEditorView extends React.Component { static propTypes = { data: LicenseAgreementPropType, previousData: LicenseAgreementPropType, isReadOnlyMode: React.PropTypes.bool, onDataChanged: React.PropTypes.func.isRequired, onSubmit: React.PropTypes.func.isRequired, onCancel: React.PropTypes.func.isRequired, selectedTab: React.PropTypes.number, onTabSelect: React.PropTypes.func, selectedFeatureGroupsButtonTab: React.PropTypes.number, onFeatureGroupsButtonTabSelect: React.PropTypes.func, featureGroupsList: DualListboxView.propTypes.availableList }; static defaultProps = { selectedTab: LicenseAgreementEnums.SELECTED_LICENSE_AGREEMENT_TAB.GENERAL, selectedFeatureGroupsButtonTab: LicenseAgreementEnums.SELECTED_FEATURE_GROUPS_BUTTONTAB.AVAILABLE_FEATURE_GROUPS, data: {} }; state = { localFeatureGroupsListFilter: '' }; render() { let {selectedTab, onTabSelect, isReadOnlyMode} = this.props; return ( this.submit() } onReset={ () => this.props.onCancel() } labledButtons={true} isReadOnlyMode={isReadOnlyMode} className='license-agreement-form'> {this.renderGeneralTab()} {this.renderFeatureGroupsTab()} ); } submit() { const {data: licenseAgreement, previousData: previousLicenseAgreement} = this.props; this.props.onSubmit({licenseAgreement, previousLicenseAgreement}); } renderGeneralTab() { let {data = {}, onDataChanged} = this.props; let {name, description, requirementsAndConstrains, licenseTerm} = data; return (
onDataChanged({name})} label={i18n('Name')} value={name} name='license-agreement-name' validations={{maxLength: 25, required: true}} type='text'/> onDataChanged({requirementsAndConstrains})} label={i18n('Requirements and Constraints')} value={requirementsAndConstrains} name='license-agreement-requirements-and-constraints' validations={{maxLength: 1000}} type='textarea'/>
onDataChanged({description})} label={i18n('Description')} value={description} name='license-agreement-description' validations={{maxLength: 1000, required: true}} type='textarea'/>
onDataChanged({licenseTerm:{choice: licenseTerm, other: ''}})} selectedEnum={licenseTerm && licenseTerm.choice} validations={{required: true}} type='select' label={i18n('License Term')} values={LicenseAgreementOptionsInputValues.LICENSE_MODEL_TYPE}/>
); } renderFeatureGroupsTab() { let {onFeatureGroupsButtonTabSelect, selectedFeatureGroupsButtonTab, featureGroupsList} = this.props; if (featureGroupsList.length > 0) { return ( { this.renderFeatureGroupsButtonTab( LicenseAgreementEnums.SELECTED_FEATURE_GROUPS_BUTTONTAB.ASSOCIATED_FEATURE_GROUPS, selectedFeatureGroupsButtonTab, i18n('Associated Feature Groups'), onFeatureGroupsButtonTabSelect ) } { this.renderFeatureGroupsButtonTab( LicenseAgreementEnums.SELECTED_FEATURE_GROUPS_BUTTONTAB.AVAILABLE_FEATURE_GROUPS, selectedFeatureGroupsButtonTab, i18n('Available Feature Groups'), onFeatureGroupsButtonTabSelect ) } {this.renderFeatureGroupsButtonTabContent(selectedFeatureGroupsButtonTab)} ); } else { return (

{i18n('There is no available feature groups')}

); } } renderFeatureGroupsButtonTabContent(selectedFeatureGroupsButtonTab) { const {featureGroupsList = [], data: {featureGroupsIds = []}} = this.props; const {localFeatureGroupsListFilter} = this.state; let selectedFeatureGroups = featureGroupsIds.map(featureGroupId => featureGroupsList.find(featureGroup => featureGroup.id === featureGroupId)); const dualBoxFilterTitle = { left: i18n('Available Feature Groups'), right: i18n('Selected Feature Groups') }; switch (selectedFeatureGroupsButtonTab) { case LicenseAgreementEnums.SELECTED_FEATURE_GROUPS_BUTTONTAB.ASSOCIATED_FEATURE_GROUPS: if (!selectedFeatureGroups.length) { return (
{i18n('There are currently no feature groups associated with this license agreement. Click "Available Feature Groups" to associate.')}
); } if (featureGroupsList.length) { return ( this.setState({localFeatureGroupsListFilter})}> {this.filterAssociatedFeatureGroupsList(selectedFeatureGroups).map(featureGroup => this.renderAssociatedFeatureGroupListItem(featureGroup))} ); } return; case LicenseAgreementEnums.SELECTED_FEATURE_GROUPS_BUTTONTAB.AVAILABLE_FEATURE_GROUPS: return ( this.props.onDataChanged( { featureGroupsIds: selectedValuesList } )}/> ); } } renderFeatureGroupsButtonTab(buttonTab, selectedButtonTab, title, onClick) { const isSelected = buttonTab === selectedButtonTab; return ( ); } renderAssociatedFeatureGroupListItem({id, name, entitlementPoolsIds = [], licenseKeyGroupsIds = []}) { const {onDataChanged, data: {featureGroupsIds}, isReadOnlyMode} = this.props; return ( onDataChanged({featureGroupsIds: featureGroupsIds.filter(featureGroupId => featureGroupId !== id)})} isReadOnlyMode={isReadOnlyMode}>
{name}
{ i18n( 'Entitlement Pools({entitlementPoolsCounter}), License Key Groups({licenseKeyGroupsCount})', { entitlementPoolsCounter: entitlementPoolsIds.length, licenseKeyGroupsCount: licenseKeyGroupsIds.length } ) }
); } filterAssociatedFeatureGroupsList(featureGroupsList) { let {localFeatureGroupsListFilter} = this.state; if (localFeatureGroupsListFilter) { const filter = new RegExp(escape(localFeatureGroupsListFilter), 'i'); return featureGroupsList.filter(({name}) => name.match(filter)); } else { return featureGroupsList; } } } export default LicenseAgreementEditorView;