Add new code new version
[sdc.git] / openecomp-ui / src / nfvo-components / listEditor / ListEditorItemView.jsx
1 import React from 'react';
2 import FontAwesome from 'react-fontawesome';
3 import store from 'sdc-app/AppStore.js';
4 import NotificationConstants from 'nfvo-components/notifications/NotificationConstants.js';
5
6 class ListEditorItem extends React.Component {
7         static propTypes = {
8                 onSelect: React.PropTypes.func,
9                 onDelete: React.PropTypes.func,
10                 onEdit: React.PropTypes.func,
11                 children: React.PropTypes.node,
12                 isReadOnlyMode: React.PropTypes.bool
13         }
14
15         render() {
16                 let {onDelete, onSelect, onEdit, children, isReadOnlyMode} = this.props;
17                 let isAbilityToDelete = isReadOnlyMode === undefined ? true : !isReadOnlyMode;
18                 return (
19                         <div className='list-editor-item-view'>
20                                 <div className='list-editor-item-view-content' onClick={onSelect}>
21                                         {children}
22                                 </div>
23                                 <div className='list-editor-item-view-controller'>
24                                         {onEdit && <FontAwesome name='sliders' onClick={() => this.onClickedItem(onEdit)}/>}
25                                         {onDelete && isAbilityToDelete && <FontAwesome name='trash-o' onClick={() => this.onClickedItem(onDelete)}/>}
26                                 </div>
27                         </div>
28                 );
29         }
30
31         onClickedItem(callBackFunc) {
32                 if(typeof callBackFunc === 'function') {
33                         let {isCheckedOut} = this.props;
34                         if (isCheckedOut === false) {
35                                 store.dispatch({
36                                         type: NotificationConstants.NOTIFY_ERROR,
37                                         data: {title: 'Error', msg: 'This item is checkedin/submitted, Click Check Out to continue'}
38                                 });
39                         }
40                         else {
41                                 callBackFunc();
42                         }
43                 }
44         }
45 }
46
47 export default ListEditorItem;