2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017-2018 Amdocs
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
21 import React, {Component} from 'react';
22 import {Field, Fields, reduxForm, propTypes} from 'redux-form';
23 import i18n from 'utils/i18n/i18n';
42 } from './ChangeAttributeFormConstants.js';
43 import validate from './validate.js';
45 class ChangeAttributeForm extends Component {
51 renderTextField = ({input, label, type, meta: {touched, error}}) => (
52 <div className='attribute-field'>
53 <label>{label}</label>
55 <input {...input} placeholder={label} type={type}
56 onBlur={() => input.value === '' ? input.onBlur(' ') : input.onBlur()}/>
57 {touched && ((error && <span className='error-message'>{error}</span>))}
64 <option value={NO_VALUE_SELECTED}>{i18n(NO_VALUE_SELECTED)}</option>,
65 <option value='true'>{i18n(TRUE)}</option>,
66 <option value='false'>{i18n(FALSE)}</option>
70 <option value={NO_VALUE_SELECTED}>{i18n(NO_VALUE_SELECTED)}</option>,
71 <option value={PREPROV}>{PREPROV}</option>,
72 <option value={NVTPROV}>{NVTPROV}</option>,
73 <option value={PROV}>{PROV}</option>,
74 <option value={CAPPED}>{CAPPED}</option>,
75 <option value={DECOM}>{DECOM}</option>,
76 <option value={RETIRED}>{RETIRED}</option>
79 renderAttributeFields = (fields) => (
81 <div className='centre'>
82 {(fields.provStatus.meta.touched ||
83 fields.inMaint.meta.touched ||
84 fields.isClosedLoopDisabled.meta.touched) &&
85 fields.provStatus.meta.error &&
86 <span className='error-message'>{fields.provStatus.meta.error}</span>}
88 <div className='attribute-field'>
89 <label>{LABEL_PROV_STATUS}</label>
91 <select {...fields.provStatus.input}>
92 {this.provStatusOptions}
96 <div className='attribute-field'>
97 <label>{LABEL_IN_MAINT}</label>
99 <select {...fields.inMaint.input}>
100 {this.booleanOptions}
104 <div className='attribute-field'>
105 <label>{LABEL_IS_CLOSED_LOOP}</label>
107 <select {...fields.isClosedLoopDisabled.input}>
108 {this.booleanOptions}
121 submitting} = this.props;
124 <form onSubmit={handleSubmit}>
125 <Field name='uri' type='text' component={this.renderTextField}
126 label={i18n(LABEL_NODE_URI)}/>
127 <div className='centre'><h2>{i18n(LABEL_ATTRIBUTES)}</h2></div>
128 <Fields names={['provStatus', 'inMaint', 'isClosedLoopDisabled']}
129 component={this.renderAttributeFields}/>
130 <div className='centre'>
131 <button type='submit'
132 disabled={pristine || submitting}
136 {i18n(BUTTON_SUBMIT)}
138 <button type='button'
139 disabled={pristine || submitting}
152 export default reduxForm({
153 form: 'changeAttributeForm',
155 })(ChangeAttributeForm);