8c197f0d49f1f61807b16bf00150b16e39576f56
[sdc.git] / openecomp-ui / src / sdc-app / onboarding / softwareProduct / components / compute / SoftwareProductComponentComputeView.jsx
1 /*!
2  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13  * or implied. See the License for the specific language governing
14  * permissions and limitations under the License.
15  */
16 import React from 'react';
17 import Form from 'nfvo-components/input/validation/Form.jsx';
18 import VmSizing from './computeComponents/VmSizing.jsx';
19 import NumberOfVms from './computeComponents/NumberOfVms.jsx';
20 import GuestOs from './computeComponents/GuestOs.jsx';
21 import Validator from 'nfvo-utils/Validator.js';
22
23 class SoftwareProductComponentComputeView extends React.Component {
24
25         static propTypes = {
26                 dataMap: React.PropTypes.object,
27                 qgenericFieldInfo: React.PropTypes.object,
28                 isReadOnlyMode: React.PropTypes.bool,
29                 onQDataChanged: React.PropTypes.func.isRequired,
30                 qValidateData: React.PropTypes.func.isRequired,
31                 onSubmit: React.PropTypes.func.isRequired
32         };
33
34         render() {
35                 let {qdata, dataMap, qgenericFieldInfo, isReadOnlyMode, onQDataChanged, qValidateData, onSubmit} = this.props;
36
37                 return (
38                         <div className='vsp-component-questionnaire-view'>
39                                 { qgenericFieldInfo && <Form
40                                         ref={ (form) => { this.form = form; }}
41                                         formReady={null}
42                                         isValid={true}
43                                         hasButtons={false}
44                                         onSubmit={() => onSubmit({qdata})}
45                                         className='component-questionnaire-validation-form'
46                                         isReadOnlyMode={isReadOnlyMode} >
47                                         <VmSizing onQDataChanged={onQDataChanged} dataMap={dataMap} qgenericFieldInfo={qgenericFieldInfo} />
48                                         <NumberOfVms onQDataChanged={onQDataChanged} dataMap={dataMap}
49                                                  qgenericFieldInfo={qgenericFieldInfo} qValidateData={qValidateData}
50                                                  customValidations={{'compute/numOfVMs/maximum' : this.validateMax, 'compute/numOfVMs/minimum': this.validateMin}} />
51                                         <GuestOs onQDataChanged={onQDataChanged} dataMap={dataMap} qgenericFieldInfo={qgenericFieldInfo} />
52                                 </Form> }
53                         </div>
54                 );
55         }
56
57         save(){
58                 return this.form.handleFormSubmit(new Event('dummy'));
59         }
60
61         validateMin(value, state) {
62                 let maxVal = state.dataMap['compute/numOfVMs/maximum'];
63                 return Validator.validateItem(value,maxVal,'maximum');
64         }
65
66         validateMax(value, state) {
67                 let minVal = state.dataMap['compute/numOfVMs/minimum'];
68                 return Validator.validateItem(value,minVal,'minimum');
69         }
70 }
71
72 export default SoftwareProductComponentComputeView;