Skip to content

Commit ed52cdf

Browse files
committed
Add basic CreateRoom organism. Supports setting room name and selecting preset
1 parent 98baa0c commit ed52cdf

9 files changed

Lines changed: 315 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: 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+
var PresetsController = require("../../../../../src/controllers/atoms/create_room/Presets");
22+
23+
module.exports = React.createClass({
24+
displayName: 'CreateRoomPresets',
25+
mixins: [PresetsController],
26+
27+
render: function() {
28+
return (
29+
<select className="mx_PresetOption" onChange={this.onValueChanged} defaultValue={this.state.preset}>
30+
<option value="private_chat">Private Chat</option>
31+
<option value="public_chat">Public Chat</option>
32+
</select>
33+
);
34+
}
35+
});
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 RoomNameTextboxController = require("../../../../../src/controllers/atoms/create_room/RoomNameTextbox");
22+
23+
module.exports = React.createClass({
24+
displayName: 'CreateRoomButton',
25+
mixins: [RoomNameTextboxController],
26+
27+
render: function() {
28+
return (
29+
<input type="text" className="mx_RoomNameTextbox" placeholder="ex. MyNewRoom" onChange={this.onValueChanged}/>
30+
);
31+
}
32+
});
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
29+
30+
module.exports = React.createClass({
31+
displayName: 'CreateRoom',
32+
mixins: [CreateRoomController],
33+
34+
render: function() {
35+
return (
36+
<div className="mx_CreateRoom">
37+
<label>Room Name <RoomNameTextbox ref="name_textbox" /></label>
38+
<Presets ref="presets"/>
39+
<CreateRoomButton onCreateRoom={this.onCreateRoom} />
40+
</div>
41+
);
42+
}
43+
});

‎src/ComponentBroker.js‎

Lines changed: 4 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,5 @@ 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');
8589
}
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: 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+
module.exports = {
22+
propTypes: {
23+
default_preset: React.PropTypes.string
24+
},
25+
26+
onValueChanged: function(ev) {
27+
this.setState({preset: ev.target.value})
28+
},
29+
30+
getDefaultProps: function() {
31+
return {
32+
default_preset: 'private_chat',
33+
};
34+
},
35+
36+
getInitialState: function() {
37+
return {
38+
preset: this.props.default_preset,
39+
}
40+
},
41+
42+
getPreset: function() {
43+
return this.state.preset;
44+
},
45+
};
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+
module.exports = {
22+
propTypes: {
23+
default_name: React.PropTypes.string
24+
},
25+
26+
onValueChanged: function(ev) {
27+
this.setState({room_name: ev.target.value})
28+
},
29+
30+
getDefaultProps: function() {
31+
return {
32+
default_name: '',
33+
};
34+
},
35+
36+
getInitialState: function() {
37+
return {
38+
room_name: this.props.default_name,
39+
}
40+
},
41+
42+
getName: function() {
43+
return this.state.room_name;
44+
},
45+
};
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+
var MatrixClientPeg = require("../../MatrixClientPeg");
21+
22+
module.exports = {
23+
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+
};
30+
31+
if (room_name) {
32+
options.name = room_name;
33+
}
34+
35+
var cli = MatrixClientPeg.get();
36+
if (!cli) {
37+
// TODO: Error.
38+
console.error("Cannot create room: No matrix client.");
39+
return;
40+
}
41+
42+
var deferred = MatrixClientPeg.get().createRoom(options);
43+
}
44+
};

0 commit comments

Comments
 (0)