Skip to content

Commit e0fae13

Browse files
committed
Merge pull request element-hq#2 from matrix-org/create_room
CreateRoom organism
2 parents 98baa0c + 4f7dcdf commit e0fae13

11 files changed

Lines changed: 495 additions & 0 deletions

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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 CreateRoomButtonController = require("../../../../../src/controllers/atoms/create_room/CreateRoomButton");
22+
23+
module.exports = React.createClass({
24+
displayName: 'CreateRoomButton',
25+
mixins: [CreateRoomButtonController],
26+
27+
render: function() {
28+
return (
29+
<button className="mx_CreateRoomButton" onClick={this.onClick}>Create Room</button>
30+
);
31+
}
32+
});
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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 PresetsController = require("../../../../../src/controllers/atoms/create_room/Presets");
22+
23+
module.exports = React.createClass({
24+
displayName: 'CreateRoomPresets',
25+
mixins: [PresetsController],
26+
27+
onValueChanged: function(ev) {
28+
this.setState({preset: ev.target.value})
29+
},
30+
31+
render: function() {
32+
return (
33+
<select className="mx_Presets" onChange={this.onValueChanged} defaultValue={this.state.preset}>
34+
<option value="private_chat">Private Chat</option>
35+
<option value="public_chat">Public Chat</option>
36+
</select>
37+
);
38+
}
39+
});
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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 RoomNameTextboxController = require("../../../../../src/controllers/atoms/create_room/RoomNameTextbox");
22+
23+
module.exports = React.createClass({
24+
displayName: 'RoomNameTextbox',
25+
mixins: [RoomNameTextboxController],
26+
27+
onValueChanged: function(ev) {
28+
this.setState({room_name: ev.target.value})
29+
},
30+
31+
render: function() {
32+
return (
33+
<input type="text" className="mx_RoomNameTextbox" placeholder="ex. MyNewRoom" onChange={this.onValueChanged}/>
34+
);
35+
}
36+
});
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
return (
33+
<div>
34+
<ul className="mx_UserSelector_UserIdList" ref="list">
35+
{this.state.selected_users.map(function(user_id, i) {
36+
return <li key={user_id}>{user_id}</li>
37+
})}
38+
</ul>
39+
<input type="text" ref="user_id_input" className="mx_UserSelector_userIdInput" placeholder="ex. @bob:example.com"/>
40+
<button onClick={this.onAddUserId} className="mx_UserSelector_AddUserId">Add User</button>
41+
</div>
42+
);
43+
}
44+
});
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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 CreateRoomController = require("../../../../src/controllers/organisms/CreateRoom");
22+
23+
var ComponentBroker = require('../../../../src/ComponentBroker');
24+
25+
var CreateRoomButton = ComponentBroker.get("atoms/create_room/CreateRoomButton");
26+
var RoomNameTextbox = ComponentBroker.get("atoms/create_room/RoomNameTextbox");
27+
var Presets = ComponentBroker.get("atoms/create_room/Presets");
28+
var UserSelector = ComponentBroker.get("molecules/UserSelector");
29+
30+
31+
module.exports = React.createClass({
32+
displayName: 'CreateRoom',
33+
mixins: [CreateRoomController],
34+
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+
47+
render: function() {
48+
var curr_phase = this.state.phase;
49+
if (curr_phase == this.phases.CREATING) {
50+
return (
51+
<div>Creating...</div>
52+
);
53+
} else {
54+
var error_box = "";
55+
if (curr_phase == this.phases.ERROR) {
56+
error_box = (
57+
<div className="mx_Error">
58+
An error occured: {this.state.error_string}
59+
</div>
60+
);
61+
}
62+
return (
63+
<div className="mx_CreateRoom">
64+
<label>Room Name <RoomNameTextbox ref="name_textbox" /></label>
65+
<Presets ref="presets"/>
66+
<UserSelector ref="user_selector"/>
67+
<CreateRoomButton onCreateRoom={this.onCreateRoom} />
68+
{error_box}
69+
</div>
70+
);
71+
}
72+
}
73+
});

‎src/ComponentBroker.js‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ if (0) {
6161
require('../skins/base/views/atoms/LogoutButton');
6262
require('../skins/base/views/atoms/EnableNotificationsButton');
6363
require('../skins/base/views/atoms/MessageTimestamp');
64+
require('../skins/base/views/atoms/create_room/CreateRoomButton');
65+
require('../skins/base/views/atoms/create_room/RoomNameTextbox');
66+
require('../skins/base/views/atoms/create_room/Presets');
6467
require('../skins/base/views/molecules/MatrixToolbar');
6568
require('../skins/base/views/molecules/RoomTile');
6669
require('../skins/base/views/molecules/MessageTile');
@@ -82,4 +85,6 @@ require('../skins/base/views/organisms/RoomList');
8285
require('../skins/base/views/organisms/RoomView');
8386
require('../skins/base/views/templates/Login');
8487
require('../skins/base/views/organisms/Notifier');
88+
require('../skins/base/views/organisms/CreateRoom');
89+
require('../skins/base/views/molecules/UserSelector');
8590
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
onCreateRoom: React.PropTypes.func,
24+
},
25+
26+
getDefaultProps: function() {
27+
return {
28+
onCreateRoom: function() {},
29+
};
30+
},
31+
32+
onClick: function() {
33+
this.props.onCreateRoom();
34+
},
35+
};
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
default_preset: React.PropTypes.string
24+
},
25+
26+
getDefaultProps: function() {
27+
return {
28+
default_preset: 'private_chat',
29+
};
30+
},
31+
32+
getInitialState: function() {
33+
return {
34+
preset: this.props.default_preset,
35+
}
36+
},
37+
38+
getPreset: function() {
39+
return this.state.preset;
40+
},
41+
};
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
default_name: React.PropTypes.string
24+
},
25+
26+
getDefaultProps: function() {
27+
return {
28+
default_name: '',
29+
};
30+
},
31+
32+
getInitialState: function() {
33+
return {
34+
room_name: this.props.default_name,
35+
}
36+
},
37+
38+
getName: function() {
39+
return this.state.room_name;
40+
},
41+
};

0 commit comments

Comments
 (0)