Skip to content

Commit b53e710

Browse files
committed
Add invite selection to create room dialog
1 parent ed52cdf commit b53e710

5 files changed

Lines changed: 129 additions & 6 deletions

File tree

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
Copyright 2015 OpenMarket Ltd
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 or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
'use strict';
18+
19+
var React = require('react');
20+
21+
var UserSelectorController = require("../../../../src/controllers/molecules/UserSelector");
22+
23+
module.exports = React.createClass({
24+
displayName: 'UserSelector',
25+
mixins: [UserSelectorController],
26+
27+
onAddUserId: function() {
28+
this.addUser(this.refs.user_id_input.getDOMNode().value);
29+
},
30+
31+
render: function() {
32+
console.log("Render");
33+
return (
34+
<div>
35+
<ul className="mx_UserIdList" ref="list">
36+
{this.state.selected_users.map(function(user_id, i) {
37+
return <li key={user_id}>{user_id}</li>
38+
})}
39+
</ul>
40+
<input type="text" ref="user_id_input" className="mx_UserIdInput" placeholder="ex. @bob:example.com"/>
41+
<button onClick={this.onAddUserId} className="mx_AddUserId">Add User</button>
42+
</div>
43+
);
44+
}
45+
});

‎skins/base/views/organisms/CreateRoom.js‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,31 @@ var ComponentBroker = require('../../../../src/ComponentBroker');
2525
var CreateRoomButton = ComponentBroker.get("atoms/create_room/CreateRoomButton");
2626
var RoomNameTextbox = ComponentBroker.get("atoms/create_room/RoomNameTextbox");
2727
var Presets = ComponentBroker.get("atoms/create_room/Presets");
28+
var UserSelector = ComponentBroker.get("molecules/UserSelector");
2829

2930

3031
module.exports = React.createClass({
3132
displayName: 'CreateRoom',
3233
mixins: [CreateRoomController],
3334

35+
getPreset: function() {
36+
return this.refs.presets.getPreset();
37+
},
38+
39+
getName: function() {
40+
return this.refs.name_textbox.getName();
41+
},
42+
43+
getInvitedUsers: function() {
44+
return this.refs.user_selector.getUserIds();
45+
},
46+
3447
render: function() {
3548
return (
3649
<div className="mx_CreateRoom">
3750
<label>Room Name <RoomNameTextbox ref="name_textbox" /></label>
3851
<Presets ref="presets"/>
52+
<UserSelector ref="user_selector"/>
3953
<CreateRoomButton onCreateRoom={this.onCreateRoom} />
4054
</div>
4155
);

‎src/ComponentBroker.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,5 @@ require('../skins/base/views/organisms/RoomView');
8686
require('../skins/base/views/templates/Login');
8787
require('../skins/base/views/organisms/Notifier');
8888
require('../skins/base/views/organisms/CreateRoom');
89+
require('../skins/base/views/molecules/UserSelector');
8990
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
Copyright 2015 OpenMarket Ltd
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 or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
'use strict';
18+
19+
var React = require('react');
20+
21+
module.exports = {
22+
propTypes: {
23+
initially_selected: React.PropTypes.arrayOf(React.PropTypes.string),
24+
},
25+
26+
getDefaultProps: function() {
27+
return {
28+
initially_selected: [],
29+
};
30+
},
31+
32+
getInitialState: function() {
33+
return {
34+
selected_users: this.props.initially_selected,
35+
}
36+
},
37+
38+
addUser: function(user_id) {
39+
if (this.state.selected_users.indexOf(user_id == -1)) {
40+
this.setState({
41+
selected_users: this.state.selected_users.concat([user_id]),
42+
});
43+
}
44+
},
45+
46+
removeUser: function(user_id) {
47+
this.setState({
48+
selected_users: this.state.selected_users.filter(function(e) {
49+
return e != user_id;
50+
}),
51+
});
52+
},
53+
54+
getUserIds: function() {
55+
return this.state.selected_users;
56+
}
57+
};

‎src/controllers/organisms/CreateRoom.js‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,23 @@ var MatrixClientPeg = require("../../MatrixClientPeg");
2121

2222
module.exports = {
2323
onCreateRoom: function() {
24-
var room_name = this.refs.name_textbox.getName();
25-
console.log("Create room clicked. Name: " + room_name);
26-
27-
var options = {
28-
preset: this.refs.presets.getPreset(),
29-
};
24+
var options = {};
3025

26+
var room_name = this.getName();
3127
if (room_name) {
3228
options.name = room_name;
3329
}
3430

31+
var preset = this.getPreset();
32+
if (preset) {
33+
options.preset = preset;
34+
}
35+
36+
var invited_users = this.getInvitedUsers();
37+
if (invited_users) {
38+
options.invite = invited_users;
39+
}
40+
3541
var cli = MatrixClientPeg.get();
3642
if (!cli) {
3743
// TODO: Error.

0 commit comments

Comments
 (0)