2016-01-18 18:19:49 +03:00
|
|
|
/*
|
|
|
|
Copyright 2015, 2016 OpenMarket Ltd
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var React = require('react');
|
|
|
|
|
|
|
|
var MatrixClientPeg = require('../../../MatrixClientPeg');
|
|
|
|
var sdk = require('../../../index');
|
|
|
|
|
|
|
|
|
|
|
|
var PRESENCE_CLASS = {
|
2016-01-18 19:47:31 +03:00
|
|
|
"offline": "mx_EntityTile_offline",
|
|
|
|
"online": "mx_EntityTile_online",
|
|
|
|
"unavailable": "mx_EntityTile_unavailable"
|
2016-01-18 18:19:49 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = React.createClass({
|
|
|
|
displayName: 'EntityTile',
|
|
|
|
|
|
|
|
propTypes: {
|
|
|
|
name: React.PropTypes.string,
|
|
|
|
title: React.PropTypes.string,
|
|
|
|
avatarJsx: React.PropTypes.any, // <BaseAvatar />
|
|
|
|
presenceState: React.PropTypes.string,
|
|
|
|
presenceActiveAgo: React.PropTypes.number,
|
|
|
|
showInviteButton: React.PropTypes.bool,
|
|
|
|
shouldComponentUpdate: React.PropTypes.func,
|
|
|
|
onClick: React.PropTypes.func
|
|
|
|
},
|
|
|
|
|
|
|
|
getDefaultProps: function() {
|
|
|
|
return {
|
|
|
|
shouldComponentUpdate: function(nextProps, nextState) { return false; },
|
|
|
|
onClick: function() {},
|
|
|
|
presenceState: "offline",
|
|
|
|
presenceActiveAgo: -1,
|
|
|
|
showInviteButton: false,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
getInitialState: function() {
|
|
|
|
return {
|
|
|
|
hover: false
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
shouldComponentUpdate: function(nextProps, nextState) {
|
|
|
|
if (this.state.hover !== nextState.hover) return true;
|
|
|
|
return this.props.shouldComponentUpdate(nextProps, nextState);
|
|
|
|
},
|
|
|
|
|
|
|
|
mouseEnter: function(e) {
|
|
|
|
this.setState({ 'hover': true });
|
|
|
|
},
|
|
|
|
|
|
|
|
mouseLeave: function(e) {
|
|
|
|
this.setState({ 'hover': false });
|
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
|
|
|
var presenceClass = PRESENCE_CLASS[this.props.presenceState];
|
2016-01-18 19:47:31 +03:00
|
|
|
var mainClassName = "mx_EntityTile ";
|
2016-01-18 18:19:49 +03:00
|
|
|
mainClassName += presenceClass;
|
|
|
|
if (this.state.hover) {
|
2016-01-18 19:47:31 +03:00
|
|
|
mainClassName += " mx_EntityTile_hover";
|
2016-01-18 18:19:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
var nameEl;
|
|
|
|
if (this.state.hover) {
|
|
|
|
var PresenceLabel = sdk.getComponent("rooms.PresenceLabel");
|
|
|
|
nameEl = (
|
2016-01-18 19:47:31 +03:00
|
|
|
<div className="mx_EntityTile_details">
|
|
|
|
<img className="mx_EntityTile_chevron" src="img/member_chevron.png" width="8" height="12"/>
|
|
|
|
<div className="mx_EntityTile_name_hover">{ this.props.name }</div>
|
2016-01-18 18:19:49 +03:00
|
|
|
<PresenceLabel activeAgo={this.props.presenceActiveAgo}
|
|
|
|
presenceState={this.props.presenceState} />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nameEl = (
|
2016-01-18 19:47:31 +03:00
|
|
|
<div className="mx_EntityTile_name">
|
2016-01-18 18:19:49 +03:00
|
|
|
{ this.props.name }
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-01-18 19:47:31 +03:00
|
|
|
var inviteButton;
|
|
|
|
if (this.props.showInviteButton) {
|
|
|
|
inviteButton = (
|
|
|
|
<div className="mx_EntityTile_invite">
|
2016-01-18 20:21:28 +03:00
|
|
|
<img src="img/plus.svg" width="16" height="16" />
|
2016-01-18 19:47:31 +03:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-01-18 20:37:17 +03:00
|
|
|
var power;
|
|
|
|
var powerLevel = this.props.powerLevel;
|
|
|
|
if (powerLevel >= 50 && powerLevel < 99) {
|
|
|
|
power = <img src="img/mod.svg" className="mx_EntityTile_power" width="16" height="17" alt="Mod"/>;
|
|
|
|
}
|
|
|
|
if (powerLevel >= 99) {
|
|
|
|
power = <img src="img/admin.svg" className="mx_EntityTile_power" width="16" height="17" alt="Admin"/>;
|
|
|
|
}
|
|
|
|
|
2016-01-18 19:47:31 +03:00
|
|
|
|
2016-01-18 18:19:49 +03:00
|
|
|
var MemberAvatar = sdk.getComponent('avatars.MemberAvatar');
|
|
|
|
var BaseAvatar = sdk.getComponent('avatars.BaseAvatar');
|
|
|
|
|
2016-01-20 17:14:04 +03:00
|
|
|
var av = this.props.avatarJsx || <BaseAvatar name={this.props.name} width={36} height={36} />;
|
2016-01-18 18:19:49 +03:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className={mainClassName} title={ this.props.title }
|
|
|
|
onClick={ this.props.onClick } onMouseEnter={ this.mouseEnter }
|
|
|
|
onMouseLeave={ this.mouseLeave }>
|
2016-01-18 19:47:31 +03:00
|
|
|
<div className="mx_EntityTile_avatar">
|
2016-01-20 18:52:34 +03:00
|
|
|
{ av }
|
|
|
|
{ power }
|
2016-01-18 18:19:49 +03:00
|
|
|
</div>
|
|
|
|
{ nameEl }
|
2016-01-18 19:47:31 +03:00
|
|
|
{ inviteButton }
|
2016-01-18 18:19:49 +03:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|