This repository was archived by the owner on Sep 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 798
/
Copy pathchat-box.js
executable file
·110 lines (105 loc) · 5.12 KB
/
chat-box.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
define(
[
'react',
'create-react-class',
'react-dom',
'../../services/common-functions'
],
function (React, createReactClass, ReactDOM, commonFunctions) {
var ChatBox = createReactClass({
getDefaultProps: function() {
return {
headerTheme: 'box-primary',
notificationTheme: 'bg-light-blue',
chatTheme: 'direct-chat-primary',
buttonTheme: 'btn-primary',
title: 'Chat Box',
notifications: 0,
sendMessage: function() {}
}
},
getInitialState: function() {
return {
message: ''
};
},
changeMessage: function(ev) {
this.setState({message: ev.target.value})
},
sendMessage: function (e) {
e.preventDefault();
this.props.sendMessage(this.state.message);
},
toggleCollapse: function(event) {
var box = ReactDOM.findDOMNode(this).children[0],
boxBody = ReactDOM.findDOMNode(this).children[0].children[1],
icon = event.currentTarget.children[0];
commonFunctions.toggleBoxCollapse(box, boxBody, icon);
},
removeBox: function(event){
var box = ReactDOM.findDOMNode(this).children[0];
commonFunctions.removeBox(box);
},
toggleChat: function(){
var box = ReactDOM.findDOMNode(this).children[0];
if(box.className.indexOf('direct-chat-contacts-open') === -1){
box.className += ' direct-chat-contacts-open';
}else{
box.className = box.className.replace(/ direct-chat-contacts-open/g,'');
}
},
render: function() {
var borderClass = '', that = this;
var a = React.Children.map(this.props.children, function(child){
return child
});
if(this.props.border === true){
borderClass = 'box-solid';
}
return (
<div className={"col-md-"+this.props.width}>
{/* DIRECT CHAT PRIMARY */}
<div className={"box " + this.props.headerTheme + " direct-chat " + this.props.chatTheme + " " + borderClass}>
<div className="box-header with-border">
<h3 className="box-title">{this.props.title}</h3>
<div className="box-tools pull-right">
<span data-toggle="tooltip" title="" className={"badge "+this.props.notificationTheme}
data-original-title={this.props.notifications+ " New Messages"}>
{this.props.notifications}
</span>
<button className="btn btn-box-tool" data-widget="collapse" onClick={that.toggleCollapse}>
<i className="fa fa-minus"></i>
</button>
<button className="btn btn-box-tool" data-toggle="tooltip" title="" data-widget="chat-pane-toggle" data-original-title="Contacts" onClick={that.toggleChat}>
<i className="fa fa-comments"></i>
</button>
<button className="btn btn-box-tool" data-widget="remove" onClick={that.removeBox}>
<i className="fa fa-times"></i>
</button>
</div>
</div>
{/* /.box-header */}
<div className="box-body">
{this.props.children}
</div>
{/* /.box-body */}
<div className="box-footer">
<form onSubmit={this.sendMessage}>
<div className="input-group">
<input type="text" name="message" placeholder="Type Message ..." className="form-control" onChange={this.changeMessage} />
<span className="input-group-btn">
<button type="submit" className={"btn btn-flat "+this.props.buttonTheme}>Send Message</button>
</span>
</div>
</form>
</div>
{/* /.box-footer*/}
</div>
{/*/.direct-chat */}
</div>
)
}
});
return ChatBox;
}
)